Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ public/
.venv
*~
**/.DS_Store
resources/

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
test-results/
resources/

27 changes: 27 additions & 0 deletions github-workflows-playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
97 changes: 97 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "nerdydaytrips",
"version": "0.0.0",
"description": "nerdydaytrips",
"main": "no,js",
"scripts": {},
"repository": {
"type": "git",
"url": "git+https://github.com/NerdyDayTrips/website.git"
},
"author": "popey",
"license": "UNLICENSED",
"bugs": {
"url": "https://github.com/NerdyDayTrips/website/issues"
},
"homepage": "https://github.com/NerdyDayTrips/website#readme",
"devDependencies": {
"@playwright/test": "^1.53.1",
"@types/node": "^24.0.3"
}
}
83 changes: 83 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// @ts-check
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* @see https://playwright.dev/docs/test-configuration
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in t
he 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: 'list',
/* 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:3000',

/* 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'] },
},
/*
{
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 start',
// url: 'http://localhost:3000',
// reuseExistingServer: !process.env.CI,
// },
});

36 changes: 36 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

echo "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo "┃ .-----.-----.----.--| |.--.--. ┃"
echo "┃ | | -__| _| _ || | | ┃"
echo "┃ |__|__|_____|__| |_____||___ | ┃"
echo "┃ |_____| ┃"
echo "┃ .--| |.---.-.--.--.| |_.----.|__|.-----.-----. ┃"
echo "┃ | _ || _ | | || _| _|| || _ |__ --| ┃"
echo "┃ |_____||___._|___ ||____|__| |__|| __|_____| ┃"
echo "┃ |_____| |__| ┃"
echo "┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫"
echo "┃ t̶e̶s̶t̶s̶?̶ s̶w̶e̶e̶t̶!̶ ┃"
echo "┃ test suite ┃"
echo "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"

# make sure everything we need is installed
# that is: playwright, which is our test runner
npm install --quiet
# and headless chrome to run tests in
npx playwright install chromium-headless-shell

# now run hugo server and trap exit to kill it when the test suite finishes
# we run hugo server so that the test suite is using a real webserver
# otherwise web browsers are super whiny about file:// urls
# we could just hugo build and then run a different web server
# but we've got hugo around, might as well use it
# We skip opengraph image building so that the test suite doesn't take ages
# and we render in memory so that we don't need to write to disk
# 61276 is the seating capacity of Anfield #YNWA
echo Building testing website in $TEMPD
HUGO_SKIP_OPENGRAPH=true hugo server --renderToMemory --port 61276 &
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

# finally, run the tests
npx playwright test
19 changes: 19 additions & 0 deletions tests/basics.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-check
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('http://localhost:61276/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Nerdy Day Trips/);
});

test('about link', async ({ page }) => {
await page.goto('http://localhost:61276/');

// Click the get started link.
await page.getByRole('link', { name: 'About' }).click();

// Expects page to have an About heading.
await expect(page.locator("#post-header").getByRole('heading', { name: 'About Nerdy Day Trips' })).toBeVisible();
});
2 changes: 2 additions & 0 deletions themes/ndt2/layouts/partials/opengraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
{{ $img := resources.Get "images/og.png" }}
{{ if not $img }}
{{ warnf "OG base image not found!" }}
{{ else if getenv "HUGO_SKIP_OPENGRAPH" }}
{{ warnf "Skipping opengraph image gen because HUGO_SKIP_OPENGRAPH is set" }}
{{ else }}
{{ $boldFont := resources.Get "fonts/Ubuntu-B.ttf"}}
{{ $mediumFont := resources.Get "fonts/Ubuntu-R.ttf"}}
Expand Down