Add in the loop test for navigable pages, plus test workflow
Some checks failed
Build and Test - Staging / test (pull_request) Failing after 27s
Build and Test - Staging / build_and_push (pull_request) Has been skipped
Build and Test - Staging / deploy_staging (pull_request) Has been skipped

This commit is contained in:
2025-11-09 15:45:15 -08:00
parent 6bb862e6e5
commit 2d7f2904a8
8 changed files with 131 additions and 99 deletions

View File

@@ -4,7 +4,7 @@ on:
types: [ opened, synchronize, reopened ] types: [ opened, synchronize, reopened ]
jobs: jobs:
determine_version: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
repo_name: ${{ steps.project_metadata.outputs.REPO_NAME }} repo_name: ${{ steps.project_metadata.outputs.REPO_NAME }}
@@ -17,6 +17,12 @@ jobs:
- name: Setup Node Environment - name: Setup Node Environment
uses: actions/setup-node@v4 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 - name: Acquire Project Metadata
id: project_metadata id: project_metadata
run: | run: |
@@ -25,7 +31,7 @@ jobs:
build_and_push: build_and_push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: determine_version needs: test
steps: steps:
- name: Checkout caperren-com Repository - name: Checkout caperren-com Repository
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -53,12 +59,6 @@ jobs:
REPO_VERSION_HASH=${{ needs.determine_version.outputs.repo_version_hash }} REPO_VERSION_HASH=${{ needs.determine_version.outputs.repo_version_hash }}
BUILD_ENVIRONMENT=staging BUILD_ENVIRONMENT=staging
test:
runs-on: ubuntu-latest
needs: build_and_push
steps:
- run: echo "Placeholder"
deploy_staging: deploy_staging:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: test needs: test

View File

@@ -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/);
});

View File

@@ -8,7 +8,8 @@
"build": "astro build", "build": "astro build",
"preview": "astro preview", "preview": "astro preview",
"astro": "astro", "astro": "astro",
"test": "vitest" "test": "vitest",
"e2e-test": "playwright test"
}, },
"dependencies": { "dependencies": {
"astro": "^5.15.4", "astro": "^5.15.4",

View File

@@ -1,4 +1,4 @@
import { defineConfig, devices } from '@playwright/test'; import {defineConfig, devices} from '@playwright/test';
/** /**
* Read environment variables from file. * Read environment variables from file.
@@ -12,68 +12,69 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration. * See https://playwright.dev/docs/test-configuration.
*/ */
export default defineConfig({ export default defineConfig({
testDir: './e2e', testDir: './test-e2e',
/* Run tests in files in parallel */ /* Run tests in files in parallel */
fullyParallel: true, fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */ /* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI, forbidOnly: !!process.env.CI,
/* Retry on CI only */ /* Retry on CI only */
retries: process.env.CI ? 2 : 0, retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */ /* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined, workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html', reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: { use: {
/* Base URL to use in actions like `await page.goto('')`. */ /* Base URL to use in actions like `await page.goto('')`. */
baseURL: 'http://localhost:4321', baseURL: 'http://localhost:4321',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry', trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
}, },
// { /* Configure projects for major browsers */
// name: 'firefox', projects: [
// use: { ...devices['Desktop Firefox'] }, {
// }, name: 'chromium',
// use: {...devices['Desktop Chrome']},
// { },
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
/* Test against mobile viewports. */ // {
{ // name: 'firefox',
name: 'Mobile Chrome', // use: { ...devices['Desktop Firefox'] },
use: { ...devices['Pixel 5'] }, // },
//
// {
// 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,
// },
}); });

View File

@@ -116,11 +116,11 @@ export const siteLayout: navLink[] = [
] ]
}, },
// { // {
// title: "Trips", // navText: "Trips",
// path: "trips", // path: "trips",
// children: [ // children: [
// {title: "2025-08 | Alaska ", path: "2025-08-alaska"}, // {navText: "2025-08 | Alaska ", path: "2025-08-alaska"},
// {title: "2024-10 | Norway ", path: "2024-10-norway"} // {navText: "2024-10 | Norway ", path: "2024-10-norway"}
// ] // ]
// }, // },
] ]
@@ -172,3 +172,22 @@ export const pathToMetadata = (path: string): navLink => {
return foundEntry; 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 !== "/");
}

View File

@@ -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();
});
}

View File

@@ -1,15 +1,15 @@
import { experimental_AstroContainer as AstroContainer } from 'astro/container'; import { experimental_AstroContainer as AstroContainer } from 'astro/container';
import { expect, test } from 'vitest'; import { expect, test } from 'vitest';
import Navbar from "@components/Navbar.js" import Navbar from "@components/Navbar.astro"
test('Card with slots', async () => { test('Card with slots', async () => {
const container = await AstroContainer.create(); const container = await AstroContainer.create();
const result = await container.renderToString(Card, { const result = await container.renderToString(Navbar, {
slots: { slots: {
default: 'Card content', default: 'Card content',
}, },
}); });
expect(result).toContain('This is a card'); // expect(result).toContain('This is a card');
expect(result).toContain('Card content'); // expect(result).toContain('Card content');
}); });

View File

@@ -1,15 +1,23 @@
/// <reference types="vitest" /> import path from 'path';
// import {getViteConfig} from 'astro/config'; import {getViteConfig} from 'astro/config';
//
// export default getViteConfig( export default getViteConfig(
// { {
// test: { test: {
// /* for example, use global to avoid globals imports (describe, test, expect): */ exclude: [
// // globals: true, "test-e2e/**",
// }, "node_modules/**",
// }, ],
// { resolve: {
// site: 'https://caperren.com/', alias: {
// trailingSlash: 'always', '@': path.resolve(__dirname, './src')
// }, },
// ); },
/* for example, use global to avoid globals imports (describe, test, expect): */
// globals: true,
},
},
{
site: 'https://caperren.com/'
},
);