Skip to content

Commit 8403dde

Browse files
committed
add playwright-based e2e tests with visual regression testing, add a snapshot test of the 03_graphs example for starters. Update tsconfig to ignore compiling TS files in e2e/, playwright handles those directly
1 parent 55ac163 commit 8403dde

8 files changed

Lines changed: 107 additions & 2 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ jobs:
2020
with:
2121
node-version: ${{ matrix.node-version }}
2222
- run: npm clean-install
23+
- run: npx playwright install --with-deps chromium
2324
- run: npm test

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
build/npm*
66
node_modules
77
npm-debug.log
8+
test-results/

‎e2e/graphs.spec.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {test, expect} from '@playwright/test'
2+
3+
test('03_graphs.html — easing curve thumbnails', async ({page}) => {
4+
await page.goto('/examples/03_graphs.html', {waitUntil: 'load'})
5+
6+
// Wait for the 2000ms tween animations to finish drawing all curves.
7+
await page.waitForTimeout(2500)
8+
9+
// The grid of canvas thumbnails should now show complete easing curves.
10+
await expect(page).toHaveScreenshot('03_graphs.webp', {
11+
fullPage: true,
12+
maxDiffPixelRatio: 0.01,
13+
})
14+
})
77.8 KB
Loading

‎e2e/playwright.config.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {defineConfig} from '@playwright/test'
2+
3+
export default defineConfig({
4+
testDir: '.',
5+
snapshotPathTemplate: '{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{ext}',
6+
webServer: {
7+
command: 'python3 -m http.server 3333',
8+
cwd: process.cwd(),
9+
port: 3333,
10+
reuseExistingServer: true,
11+
},
12+
use: {
13+
baseURL: 'http://localhost:3333',
14+
viewport: {width: 1280, height: 1030},
15+
},
16+
})

‎package-lock.json‎

Lines changed: 70 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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
"tween",
3232
"interpolation"
3333
],
34-
"dependencies": {},
3534
"scripts": {
3635
"dev": "(npm run tsc-watch -- --preserveWatchOutput & p1=$!; npm run rollup-build -- --watch & p2=$!; wait $p1 $p2)",
3736
"build": "rimraf dist .tmp && node scripts/write-version.js && npm run tsc && npm run rollup-build",
3837
"rollup-build": "rollup -c ./rollup.config.js",
3938
"tsc": "tsc",
4039
"tsc-watch": "tsc --watch",
4140
"examples": "npx serve .",
42-
"test": "npm run build && npm run test-lint && npm run test-unit",
41+
"test": "npm run build && npm run test-lint && npm run test-unit && npm run test-e2e",
4342
"test-unit": "nodeunit test/unit/nodeunitheadless.cjs",
43+
"test-e2e": "playwright test e2e/ --config=e2e/playwright.config.ts",
44+
"test-e2e-update-snapshots": "playwright test e2e/ --config=e2e/playwright.config.ts --update-snapshots",
4445
"test-lint": "npm run prettier -- --check",
4546
"lint": "npm run prettier -- --write",
4647
"prettier": "prettier .",
@@ -53,6 +54,7 @@
5354
},
5455
"author": "tween.js contributors (https://github.com/tweenjs/tween.js/graphs/contributors)",
5556
"devDependencies": {
57+
"@playwright/test": "^1.63.0",
5658
"nodeunit": "^0.11.3",
5759
"prettier": "^3.0.0",
5860
"rimraf": "^3.0.0",

‎tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
"ignoreDeprecations": "5.0",
1515
"importsNotUsedAsValues": "error"
1616
},
17+
"include": ["src"], // we don't need to compile e2e/ (playwright handles .ts files there), only src/
1718
"exclude": ["node_modules", "examples"]
1819
}

0 commit comments

Comments
 (0)