-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
460 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: CI | ||
on: [ push, pull_request ] | ||
|
||
jobs: | ||
test: | ||
# Prevent workflow being run twice, https://github.com/orgs/community/discussions/57827#discussioncomment-6579237 | ||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name | ||
|
||
name: ${{ matrix.cmd }} (${{ matrix.os }}) | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- windows-latest | ||
cmd: | ||
- pnpm run test:e2e | ||
- pnpm run test:units | ||
- pnpm run test:types | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v3 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 21 | ||
cache: "pnpm" | ||
|
||
- run: pnpm install | ||
- run: pnpm exec playwright install chromium | ||
- run: pnpm run build | ||
|
||
- run: ${{ matrix.cmd }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { test, expect, run, fetchHtml, page, getServerUrl, autoRetry } from '@brillout/test-e2e' | ||
|
||
runTest() | ||
|
||
function runTest() { | ||
run('pnpm run dev') | ||
|
||
testUrl({ | ||
url: '/', | ||
title: 'My Vike + React App', | ||
text: 'My Vike + React app', | ||
counter: true | ||
}) | ||
|
||
testUrl({ | ||
url: '/star-wars', | ||
title: '6 Star Wars Movies', | ||
text: 'A New Hope' | ||
}) | ||
|
||
testUrl({ | ||
url: '/star-wars/3', | ||
title: 'Return of the Jedi', | ||
text: '1983-05-25' | ||
}) | ||
} | ||
|
||
function testUrl({ url, title, text, counter }: { url: string; title: string; text: string; counter?: true }) { | ||
test(url + ' (HTML)', async () => { | ||
const html = await fetchHtml(url) | ||
expect(html).toContain(text) | ||
expect(getTitle(html)).toBe(title) | ||
}) | ||
test(url + ' (Hydration)', async () => { | ||
await page.goto(getServerUrl() + url) | ||
const body = await page.textContent('body') | ||
expect(body).toContain(text) | ||
if (counter) { | ||
await testCounter() | ||
} | ||
}) | ||
} | ||
|
||
function getTitle(html: string) { | ||
const title = html.match(/<title>(.*?)<\/title>/i)?.[1] | ||
return title | ||
} | ||
|
||
async function testCounter() { | ||
expect(await page.textContent('button')).toBe('Counter 0') | ||
// autoRetry() for awaiting client-side code loading & executing | ||
await autoRetry(async () => { | ||
await page.click('button') | ||
expect(await page.textContent('button')).toContain('Counter 1') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.