8000 Create Playwright test harness (#8) · staticwebdev/vanilla-basic@0ead191 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ead191

Browse files
authored
Create Playwright test harness (#8)
* added playwright test and github actions * added install sirv to github action * added readme file and reverted start script * changed start script and github links * Update Test.README.md * removed links from package.json and commented out stuff from playwright config * updated with recommendations * changed pull_request to pull_request_target * change github action to run on pull_request * updated github action to run on all branches * updated comments and job name in github action
1 parent e740d0d commit 0ead191

File tree

7 files changed

+210
-0
lines changed

7 files changed

+210
-0
lines changed

.github/workflows/playwright.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Playwright Tests
2+
3+
# Controls when the workflow will run
4+
on:
5+
# Triggers the workflow on push or pull request and nightly
6+
push:
7+
pull_request:
8+
schedule:
9+
# nightly
10+
- cron: '0 0 * * *'
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
jobs:
16+
playwright_tests:
17+
# Runs on an ubuntu runner
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
node-version: [14.x, 16.x, 18.x]
23+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: actions/setup-node@v3
28+
- name: Install dependencies
29+
run: npm ci
30+
- name: Install Playwright
31+
run: npx playwright install --with-deps
32+
- name: Install Sirv
33+
run: npm install --g sirv-cli
34+
- name: Run playwright tests
35+
run: npm run playwright_test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/playwright/.cache/

package-lock.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "vanilla-basic",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"start": "sirv ./src public --cors --single --no-clear --port 8000",
6+
"playwright_test" : "playwright test"
7+
},
8+
"devDependencies": {
9+
"@playwright/test": "^1.22.2"
10+
}
11+
}

playwright.config.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { devices } from '@playwright/test';
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// require('dotenv').config();
9+
10+
/**
11+
* See https://playwright.dev/docs/test-configuration.
12+
*/
13+
const config: PlaywrightTestConfig = {
14+
testDir: './tests',
15+
/* Maximum time one test can run for. */
16+
timeout: 30 * 1000,
17+
expect: {
18+
/**
19+
* Maximum time expect() should wait for the condition to be met.
20+
* For example in `await expect(locator).toHaveText();`
21+
*/
22+
timeout: 5000
23+
},
24+
/* Run tests in files in parallel */
25+
fullyParallel: true,
26+
/* Fail the build on CI if you accidentally left test.only in the source code. */
27+
forbidOnly: !!process.env.CI,
28+
/* Retry on CI only */
29+
retries: process.env.CI ? 2 : 0,
30+
/* Opt out of parallel tests on CI. */
31+
workers: process.env.CI ? 1 : undefined,
32+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33+
reporter: 'html',
34+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35+
use: {
36+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
37+
actionTimeout: 0,
38+
/* Base URL to use in actions like `await page.goto('/')`. */
39+
baseURL: 'http://localhost:8000',
40+
41+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
42+
trace: 'on-first-retry',
43+
},
44+
45+
/* Configure projects for major browsers */
46+
projects: [
47+
{
48+
name: 'chromium',
49+
use: {
50+
...devices['Desktop Chrome'],
51+
},
52+
},
53+
54+
{
55+
name: 'firefox',
56+
use: {
57+
...devices['Desktop Firefox'],
58+
},
59+
},
60+
61+
{
62+
name: 'webkit',
63+
use: {
64+
...devices['Desktop Safari'],
65+
},
66+
},
67+
],
68+
69+
/* Run your local dev server before starting the tests */
70+
webServer: {
71+
command: 'npm run start',
72+
port: 8000,
73+
}
74+
};
75+
76+
export default config;

tests/Test.README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Testing
2+
3+
To run playwright tests run `npm run playwright_test`. Note for the purposes of running playwright tests a package.json (and start script) was made.

tests/playwright.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('basic test', async ({ page }) => {
4+
await page.goto('/');
5+
await page.waitForSelector('h1');
6+
await expect(page.locator('h1')).toContainText('Vanilla JavaScript App');
7+
})

0 commit comments

Comments
 (0)
0