From 2d7f2904a8c2bf90324d62765b75ff287058312b Mon Sep 17 00:00:00 2001 From: Corwin Perren Date: Sun, 9 Nov 2025 15:45:15 -0800 Subject: [PATCH] Add in the loop test for navigable pages, plus test workflow --- .gitea/workflows/build-staging.yaml | 16 +-- e2e/test-pages-navigable.spec.ts | 8 -- package.json | 3 +- playwright.config.ts | 121 +++++++++--------- src/data/site-layout.ts | 25 +++- .../all-site-layout-pages-navigable.spec.ts | 11 ++ .../{TestNavbar.ts => navbar.spec.ts} | 8 +- vitest.config.ts | 38 +++--- 8 files changed, 131 insertions(+), 99 deletions(-) delete mode 100644 e2e/test-pages-navigable.spec.ts create mode 100644 test-e2e/all-site-layout-pages-navigable.spec.ts rename test/components/{TestNavbar.ts => navbar.spec.ts} (58%) diff --git a/.gitea/workflows/build-staging.yaml b/.gitea/workflows/build-staging.yaml index 4e1c396..6900813 100644 --- a/.gitea/workflows/build-staging.yaml +++ b/.gitea/workflows/build-staging.yaml @@ -4,7 +4,7 @@ on: types: [ opened, synchronize, reopened ] jobs: - determine_version: + test: runs-on: ubuntu-latest outputs: repo_name: ${{ steps.project_metadata.outputs.REPO_NAME }} @@ -17,6 +17,12 @@ jobs: - name: Setup Node Environment uses: actions/setup-node@v4 + - name: Run Unit Tests + run: npm run test + + - name: Run E2E Tests + run: npm run e2e-test + - name: Acquire Project Metadata id: project_metadata run: | @@ -25,7 +31,7 @@ jobs: build_and_push: runs-on: ubuntu-latest - needs: determine_version + needs: test steps: - name: Checkout caperren-com Repository uses: actions/checkout@v4 @@ -53,12 +59,6 @@ jobs: REPO_VERSION_HASH=${{ needs.determine_version.outputs.repo_version_hash }} BUILD_ENVIRONMENT=staging - test: - runs-on: ubuntu-latest - needs: build_and_push - steps: - - run: echo "Placeholder" - deploy_staging: runs-on: ubuntu-latest needs: test diff --git a/e2e/test-pages-navigable.spec.ts b/e2e/test-pages-navigable.spec.ts deleted file mode 100644 index 4e995d6..0000000 --- a/e2e/test-pages-navigable.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { test, expect } from '@playwright/test'; - -test('Has Title', async ({ page }) => { - await page.goto('/'); - - // Expect a title "to contain" a substring. - await expect(page).toHaveTitle(/Corwin Perren/); -}); diff --git a/package.json b/package.json index d9c2d24..e8574a4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "astro build", "preview": "astro preview", "astro": "astro", - "test": "vitest" + "test": "vitest", + "e2e-test": "playwright test" }, "dependencies": { "astro": "^5.15.4", diff --git a/playwright.config.ts b/playwright.config.ts index cf9dc8d..d3710c4 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, devices } from '@playwright/test'; +import {defineConfig, devices} from '@playwright/test'; /** * Read environment variables from file. @@ -12,68 +12,69 @@ import { defineConfig, devices } from '@playwright/test'; * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ - testDir: './e2e', - /* Run tests in files in parallel */ - fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - /* Base URL to use in actions like `await page.goto('')`. */ - baseURL: 'http://localhost:4321', + testDir: './test-e2e', + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('')`. */ + baseURL: 'http://localhost:4321', - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', }, - // { - // name: 'firefox', - // use: { ...devices['Desktop Firefox'] }, - // }, - // - // { - // name: 'webkit', - // use: { ...devices['Desktop Safari'] }, - // }, + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: {...devices['Desktop Chrome']}, + }, - /* Test against mobile viewports. */ - { - name: 'Mobile Chrome', - use: { ...devices['Pixel 5'] }, + // { + // name: 'firefox', + // use: { ...devices['Desktop Firefox'] }, + // }, + // + // { + // name: 'webkit', + // use: { ...devices['Desktop Safari'] }, + // }, + + /* Test against mobile viewports. */ + { + name: 'Mobile Chrome', + use: {...devices['Pixel 5']}, + }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], + + /* Run your local dev server before starting the tests */ + webServer: { + command: 'npm run preview', + url: 'http://localhost:4321', + timeout: 120 * 1000, + reuseExistingServer: !process.env.CI, }, - // { - // name: 'Mobile Safari', - // use: { ...devices['iPhone 12'] }, - // }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, - // }, - // { - // name: 'Google Chrome', - // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, - // }, - ], - - /* Run your local dev server before starting the tests */ - // webServer: { - // command: 'npm run start', - // url: 'http://localhost:3000', - // reuseExistingServer: !process.env.CI, - // }, }); diff --git a/src/data/site-layout.ts b/src/data/site-layout.ts index 1c0145e..8ef64bb 100644 --- a/src/data/site-layout.ts +++ b/src/data/site-layout.ts @@ -116,11 +116,11 @@ export const siteLayout: navLink[] = [ ] }, // { - // title: "Trips", + // navText: "Trips", // path: "trips", // children: [ - // {title: "2025-08 | Alaska ", path: "2025-08-alaska"}, - // {title: "2024-10 | Norway ", path: "2024-10-norway"} + // {navText: "2025-08 | Alaska ", path: "2025-08-alaska"}, + // {navText: "2024-10 | Norway ", path: "2024-10-norway"} // ] // }, ] @@ -171,4 +171,23 @@ export const pathToMetadata = (path: string): navLink => { } return foundEntry; +} + +export const getPaths = ( + currentEntries: navLink[] = siteLayout, + paths: string[] = [] +): string[] => { + let foundPaths: string[] = []; + + for (const currentEntry of currentEntries) { + if (currentEntry.children && currentEntry.children.length > 0) { + foundPaths = [ + ...foundPaths, + ...getPaths(currentEntry.children, [...paths, currentEntry.path || ""]) + ] + } else { + foundPaths.push("/" + [...paths, currentEntry.path || ""].join("/")); + } + } + return foundPaths.filter(path => path !== "/"); } \ No newline at end of file diff --git a/test-e2e/all-site-layout-pages-navigable.spec.ts b/test-e2e/all-site-layout-pages-navigable.spec.ts new file mode 100644 index 0000000..cbd681e --- /dev/null +++ b/test-e2e/all-site-layout-pages-navigable.spec.ts @@ -0,0 +1,11 @@ +import {test, expect} from '@playwright/test'; + +import {getPaths} from "@data/site-layout.ts"; + + +for (const pagePath of getPaths()) { + test(`${pagePath} Navigable`, async ({page}) => { + const response = await page.request.get(pagePath); + await expect(response).toBeOK(); + }); +} diff --git a/test/components/TestNavbar.ts b/test/components/navbar.spec.ts similarity index 58% rename from test/components/TestNavbar.ts rename to test/components/navbar.spec.ts index 36331b9..d00bc6c 100644 --- a/test/components/TestNavbar.ts +++ b/test/components/navbar.spec.ts @@ -1,15 +1,15 @@ import { experimental_AstroContainer as AstroContainer } from 'astro/container'; import { expect, test } from 'vitest'; -import Navbar from "@components/Navbar.js" +import Navbar from "@components/Navbar.astro" test('Card with slots', async () => { const container = await AstroContainer.create(); - const result = await container.renderToString(Card, { + const result = await container.renderToString(Navbar, { slots: { default: 'Card content', }, }); - expect(result).toContain('This is a card'); - expect(result).toContain('Card content'); + // expect(result).toContain('This is a card'); + // expect(result).toContain('Card content'); }); \ No newline at end of file diff --git a/vitest.config.ts b/vitest.config.ts index 9afd9ef..1216f8b 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,15 +1,23 @@ -/// -// import {getViteConfig} from 'astro/config'; -// -// export default getViteConfig( -// { -// test: { -// /* for example, use global to avoid globals imports (describe, test, expect): */ -// // globals: true, -// }, -// }, -// { -// site: 'https://caperren.com/', -// trailingSlash: 'always', -// }, -// ); \ No newline at end of file +import path from 'path'; +import {getViteConfig} from 'astro/config'; + +export default getViteConfig( + { + test: { + exclude: [ + "test-e2e/**", + "node_modules/**", + ], + resolve: { + alias: { + '@': path.resolve(__dirname, './src') + }, + }, + /* for example, use global to avoid globals imports (describe, test, expect): */ + // globals: true, + }, + }, + { + site: 'https://caperren.com/' + }, +); \ No newline at end of file