diff --git a/examples/accident-counter/.gitignore b/examples/accident-counter/.gitignore new file mode 100644 index 0000000..68c5d18 --- /dev/null +++ b/examples/accident-counter/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/examples/accident-counter/package.json b/examples/accident-counter/package.json index af2089a..987666e 100644 --- a/examples/accident-counter/package.json +++ b/examples/accident-counter/package.json @@ -19,9 +19,11 @@ }, "homepage": "https://github.com/stevekinney/testing-javascript#readme", "devDependencies": { + "@playwright/test": "^1.47.2", "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^6.5.0", "@testing-library/react": "^16.0.1", + "@types/node": "^22.7.4", "@types/react": "^18.3.6", "@types/react-dom": "^18.3.0", "@types/testing-library__jest-dom": "^5.14.9", diff --git a/examples/accident-counter/playwright.config.js b/examples/accident-counter/playwright.config.js new file mode 100644 index 0000000..5d440da --- /dev/null +++ b/examples/accident-counter/playwright.config.js @@ -0,0 +1,78 @@ +// @ts-check +import { defineConfig, devices } from '@playwright/test'; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('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 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://127.0.0.1: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://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); diff --git a/examples/accident-counter/src/counter.tsx b/examples/accident-counter/src/counter.tsx index 2fe75b5..7998413 100644 --- a/examples/accident-counter/src/counter.tsx +++ b/examples/accident-counter/src/counter.tsx @@ -1,3 +1,4 @@ +import React from 'react'; import { useReducer, useEffect } from 'react'; import { reducer } from './reducer'; @@ -6,37 +7,39 @@ export const Counter = () => { const unit = state.count === 1 ? 'day' : 'days'; useEffect(() => { - window.document.title = `${state.count} ${unit}`; + window.document.title = `${state.count} ${unit} — Accident Counter`; }, [state.count]); return ( -
-
-
- {state.count} +
+
+
+
+ {state.count} +
+

+ {unit} since the last + JavaScript-related accident. +

+
+
+ + +
-

- {unit} since the last - JavaScript-related accident. -

-
- - - -
-
+ ); }; diff --git a/examples/accident-counter/tests/counter.spec.js b/examples/accident-counter/tests/counter.spec.js new file mode 100644 index 0000000..e924d05 --- /dev/null +++ b/examples/accident-counter/tests/counter.spec.js @@ -0,0 +1,2 @@ +import { test, expect } from '@playwright/test'; +import { createServer } from 'vite'; diff --git a/package-lock.json b/package-lock.json index 84f8793..91f6d09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,9 +32,11 @@ "version": "1.0.0", "license": "MIT", "devDependencies": { + "@playwright/test": "^1.47.2", "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^6.5.0", "@testing-library/react": "^16.0.1", + "@types/node": "^22.7.4", "@types/react": "^18.3.6", "@types/react-dom": "^18.3.0", "@types/testing-library__jest-dom": "^5.14.9", @@ -984,6 +986,22 @@ "node": ">=14" } }, + "node_modules/@playwright/test": { + "version": "1.47.2", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.47.2.tgz", + "integrity": "sha512-jTXRsoSPONAs8Za9QEQdyjFn+0ZQFjCiIztAIF6bi1HqhBzG9Ma7g1WotyiGqFSBRZjIEqMdT8RUlbk1QVhzCQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.47.2" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@polka/url": { "version": "1.0.0-next.25", "dev": true, @@ -1573,7 +1591,9 @@ } }, "node_modules/@types/node": { - "version": "22.5.5", + "version": "22.7.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.4.tgz", + "integrity": "sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==", "devOptional": true, "license": "MIT", "dependencies": { @@ -4209,6 +4229,53 @@ "node": ">= 6" } }, + "node_modules/playwright": { + "version": "1.47.2", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.47.2.tgz", + "integrity": "sha512-nx1cLMmQWqmA3UsnjaaokyoUpdVaaDhJhMoxX2qj3McpjnsqFHs516QAKYhqHAgOP+oCFTEOCOAaD1RgD/RQfA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.47.2" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.47.2", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.47.2.tgz", + "integrity": "sha512-3JvMfF+9LJfe16l7AbSmU555PaTl2tPyQsVInqm3id16pdDfvZ8TTZ/pyzmkbDrZTQefyzU7AIHlZqQnxpqHVQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/postcss": { "version": "8.4.45", "funding": [