@public-ui/visual-tests 3.0.0-alpha.1 → 3.0.0-dcba8228fa4178aa125eea17082fc647882faa96.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -8
- package/package.json +14 -10
- package/playwright.config.js +19 -9
- package/src/index.js +6 -13
- package/tests/sample-app.routes.js +30 -53
- package/tests/theme-snapshots.spec.js +36 -39
- /package/tests/{axe-snapshots.spec.js → axe-snapshots.spec.js.bak} +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# KoliBri - Visual Tests
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@public-ui/components)
|
|
4
|
+
[](https://github.com/public-ui/kolibri/blob/main/LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/@public-ui/visual-tests)
|
|
6
|
+
[](https://github.com/public-ui/kolibri/issues)
|
|
7
|
+
[](https://github.com/public-ui/kolibri/pulls)
|
|
8
|
+
[](https://bundlephobia.com/result?p=@public-ui/visual-tests)
|
|
9
|
+

|
|
10
|
+
|
|
3
11
|
## Motivation
|
|
4
12
|
|
|
5
13
|
The `KoliBri` Visual Tests provide a way to add visual regression testing to **theme** modules.
|
|
@@ -7,11 +15,23 @@ It takes screenshots of every component defined in the [React Sample App](https:
|
|
|
7
15
|
|
|
8
16
|
## Installation
|
|
9
17
|
|
|
18
|
+
It is recommended to configure NPM via `.npmrc`:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# - npm
|
|
22
|
+
engine-strict=true
|
|
23
|
+
save-exact=true
|
|
24
|
+
|
|
25
|
+
# - pnpm
|
|
26
|
+
shamefully-hoist=true # this is required for the visual tests to work
|
|
27
|
+
workspace-concurrency=1
|
|
28
|
+
```
|
|
29
|
+
|
|
10
30
|
You can install the `KoliBri` Visual Tests with `npm`, `pnpm` or `yarn`:
|
|
11
31
|
|
|
12
32
|
```bash
|
|
13
33
|
npm i -D @public-ui/visual-tests
|
|
14
|
-
pnpm i -D @public-ui/visual-tests
|
|
34
|
+
pnpm i -D @public-ui/visual-tests # recommended
|
|
15
35
|
yarn add -D @public-ui/visual-tests
|
|
16
36
|
```
|
|
17
37
|
|
|
@@ -21,17 +41,21 @@ Add the following npm scripts to the theme's `package.json`:
|
|
|
21
41
|
|
|
22
42
|
```json
|
|
23
43
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "THEME_MODULE=src/index THEME_EXPORT=THEME_NAME kolibri-visual-test",
|
|
46
|
+
"test-update": "THEME_MODULE=src/index THEME_EXPORT=THEME_NAME kolibri-visual-test --update-snapshots"
|
|
47
|
+
}
|
|
28
48
|
}
|
|
29
49
|
```
|
|
30
50
|
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
### Environment variables
|
|
52
|
+
|
|
53
|
+
- `THEME_MODULE`: Define the relative path to the TypeScript module containing the theme definitions. Without file extension.
|
|
54
|
+
- `THEME_EXPERT`: Define the name of the export within the module. (e.g., `export const THEME_NAME = {/**/};`) Defaults to `default`.
|
|
55
|
+
- `KOLIBRI_VISUAL_TESTS_TIMEOUT`: Define the Playwright [test timeout](https://playwright.dev/docs/test-timeouts).
|
|
56
|
+
- `KOLIBRI_VISUAL_TESTS_EXPECT_TIMEOUT`: Define the Playwright [expect timeout](https://playwright.dev/docs/test-timeouts).
|
|
33
57
|
|
|
34
58
|
Run the tests with `npm test`. The first time, this will create a new folder `snapshots` which is supposed to be committed to the repository.
|
|
35
59
|
In the following runs, new screenshots will be compared to this reference.
|
|
36
60
|
|
|
37
|
-
To update the reference screenshots call `npm run test-update`.
|
|
61
|
+
To update the reference screenshots call `npm run test-update`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@public-ui/visual-tests",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-dcba8228fa4178aa125eea17082fc647882faa96.0",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"homepage": "https://public-ui.github.io",
|
|
6
6
|
"repository": {
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"name": "Informationstechnikzentrum Bund",
|
|
16
16
|
"email": "kolibri@itzbund.de"
|
|
17
17
|
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"pnpm": "^10"
|
|
20
|
+
},
|
|
18
21
|
"type": "module",
|
|
19
22
|
"sideEffects": false,
|
|
20
23
|
"description": "Provides utility to run visual regression tests for themes.",
|
|
@@ -22,19 +25,19 @@
|
|
|
22
25
|
"kolibri-visual-test": "src/index.js"
|
|
23
26
|
},
|
|
24
27
|
"dependencies": {
|
|
25
|
-
"@playwright/test": "1.49.
|
|
26
|
-
"axe-playwright": "2.0
|
|
27
|
-
"portfinder": "1.0.
|
|
28
|
+
"@playwright/test": "1.49.1",
|
|
29
|
+
"axe-playwright": "2.1.0",
|
|
30
|
+
"portfinder": "1.0.35",
|
|
28
31
|
"serve": "14.2.4",
|
|
29
|
-
"@public-ui/sample-react": "3.0.0-
|
|
32
|
+
"@public-ui/sample-react": "3.0.0-dcba8228fa4178aa125eea17082fc647882faa96.0"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"@babel/eslint-parser": "7.
|
|
35
|
+
"@babel/eslint-parser": "7.26.10",
|
|
33
36
|
"@babel/plugin-syntax-import-attributes": "7.26.0",
|
|
34
|
-
"@babel/preset-env": "7.26.
|
|
37
|
+
"@babel/preset-env": "7.26.9",
|
|
35
38
|
"eslint": "8.57.1",
|
|
36
|
-
"knip": "5.
|
|
37
|
-
"prettier": "3.
|
|
39
|
+
"knip": "5.46.0",
|
|
40
|
+
"prettier": "3.5.3"
|
|
38
41
|
},
|
|
39
42
|
"files": [
|
|
40
43
|
"playwright.config.js",
|
|
@@ -43,7 +46,8 @@
|
|
|
43
46
|
],
|
|
44
47
|
"scripts": {
|
|
45
48
|
"format": "prettier --check src",
|
|
46
|
-
"lint": "eslint
|
|
49
|
+
"lint": "pnpm lint:eslint",
|
|
50
|
+
"lint:eslint": "eslint src",
|
|
47
51
|
"unused": "knip",
|
|
48
52
|
"postinstall": "pnpm exec playwright install"
|
|
49
53
|
}
|
package/playwright.config.js
CHANGED
|
@@ -2,19 +2,24 @@ import { defineConfig, devices } from '@playwright/test';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as process from 'process';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const
|
|
5
|
+
// Validate and set ENVs
|
|
6
|
+
const PORT = parseInt(process.env.KOLIBRI_VISUAL_TEST_PORT || '', 10);
|
|
7
|
+
const BASE_URL = `http://localhost:${PORT}`;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const CWD = process.env.KOLIBRI_CWD ?? '';
|
|
10
|
+
const TIMEOUT = parseInt(process.env.KOLIBRI_VISUAL_TESTS_TIMEOUT || '15000', 10);
|
|
11
|
+
const EXPECT_TIMEOUT = parseInt(process.env.KOLIBRI_VISUAL_TESTS_EXPECT_TIMEOUT || '5000', 10);
|
|
12
|
+
const BUILD_PATH = process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH ?? '';
|
|
13
|
+
const THEME = (process.env.THEME_EXPORT || 'default').toLocaleLowerCase();
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
16
|
* See https://playwright.dev/docs/test-configuration.
|
|
12
17
|
*/
|
|
13
18
|
export default defineConfig({
|
|
14
19
|
testDir: './tests',
|
|
15
|
-
snapshotDir: path.join(
|
|
20
|
+
snapshotDir: path.join(CWD, 'snapshots'),
|
|
16
21
|
// snapshotPathTemplate: '',
|
|
17
|
-
outputDir: path.join(
|
|
22
|
+
outputDir: path.join(CWD, 'test-results'),
|
|
18
23
|
/* Run tests in files in parallel */
|
|
19
24
|
fullyParallel: true,
|
|
20
25
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
@@ -24,18 +29,22 @@ export default defineConfig({
|
|
|
24
29
|
/* Opt out of parallel tests on CI. */
|
|
25
30
|
workers: process.env.CI ? 1 : undefined,
|
|
26
31
|
/* Allow to override the expectation timeout for slow environments */
|
|
27
|
-
timeout:
|
|
32
|
+
timeout: TIMEOUT,
|
|
28
33
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
29
34
|
reporter: 'line',
|
|
30
35
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
31
36
|
use: {
|
|
32
37
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
|
33
|
-
baseURL:
|
|
38
|
+
baseURL: BASE_URL,
|
|
34
39
|
|
|
35
40
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
36
41
|
trace: 'on-first-retry',
|
|
37
42
|
},
|
|
38
43
|
|
|
44
|
+
expect: {
|
|
45
|
+
timeout: EXPECT_TIMEOUT,
|
|
46
|
+
},
|
|
47
|
+
|
|
39
48
|
/* Configure projects for major browsers */
|
|
40
49
|
projects: [
|
|
41
50
|
// {
|
|
@@ -55,8 +64,9 @@ export default defineConfig({
|
|
|
55
64
|
/* Run your local dev server before starting the tests */
|
|
56
65
|
webServer: {
|
|
57
66
|
command: `npx serve -p ${PORT}`,
|
|
58
|
-
cwd: path.resolve(
|
|
59
|
-
url:
|
|
67
|
+
cwd: path.resolve(BUILD_PATH),
|
|
68
|
+
url: BASE_URL,
|
|
60
69
|
reuseExistingServer: false,
|
|
61
70
|
},
|
|
71
|
+
snapshotPathTemplate: `{snapshotDir}/theme-${THEME}/{arg}-{projectName}-{platform}{ext}`,
|
|
62
72
|
});
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import child_process from 'node:child_process';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
4
4
|
import * as crypto from 'crypto';
|
|
5
|
+
import { readFile } from 'fs/promises';
|
|
5
6
|
import * as fs from 'fs';
|
|
6
7
|
import portfinder from 'portfinder';
|
|
7
8
|
import * as process from 'process';
|
|
@@ -18,15 +19,8 @@ if (!tempDir) {
|
|
|
18
19
|
process.env.THEME_MODULE = path.join(process.cwd(), process.env.THEME_MODULE); // Use current working directory (i.e. the theme folder) to complete module path
|
|
19
20
|
const visualsTestModulePath = fileURLToPath(new URL('..', import.meta.url));
|
|
20
21
|
const binaryPath = fileURLToPath(new URL('../node_modules/.bin', import.meta.url));
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
let backSteps = ``;
|
|
24
|
-
let workingDir = null;
|
|
25
|
-
do {
|
|
26
|
-
const url = new URL(backSteps + sampleReactPath, import.meta.url);
|
|
27
|
-
workingDir = fileURLToPath(url);
|
|
28
|
-
backSteps += `../`;
|
|
29
|
-
} while (!fs.existsSync(workingDir) && path.resolve(process.cwd(), backSteps) !== '/');
|
|
22
|
+
const sampleReactPackageJsonPath = import.meta.resolve('@public-ui/sample-react/package.json');
|
|
23
|
+
const workingDir = fileURLToPath(path.dirname(sampleReactPackageJsonPath));
|
|
30
24
|
|
|
31
25
|
if (!fs.existsSync(workingDir)) {
|
|
32
26
|
throw new Error('Could not find React Sample App package. Please install it with "npm install @public-ui/sample-react".');
|
|
@@ -35,12 +29,11 @@ if (!fs.existsSync(workingDir)) {
|
|
|
35
29
|
const buildPath = path.join(tempDir, `kolibri-visual-testing-build-${crypto.randomUUID()}`);
|
|
36
30
|
const rawPackageJsonPath = new URL(path.join(workingDir, 'package.json'), import.meta.url).href;
|
|
37
31
|
const packageJsonPath = process.platform === 'win32' ? pathToFileURL(rawPackageJsonPath) : rawPackageJsonPath;
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
});
|
|
32
|
+
const packageJsonContent = await readFile(new URL(packageJsonPath, import.meta.url), 'utf8');
|
|
33
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
41
34
|
|
|
42
35
|
console.log(`
|
|
43
|
-
Building React Sample App (v${packageJson?.
|
|
36
|
+
Building React Sample App (v${packageJson?.version ?? '#.#.#'}) …`);
|
|
44
37
|
|
|
45
38
|
child_process.spawnSync('pnpm', ['run', 'build', '--', `--output-path="${buildPath}"`], {
|
|
46
39
|
cwd: workingDir,
|
|
@@ -15,13 +15,6 @@ export const ROUTES = new Map();
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
ROUTES.set('handout/basic', {
|
|
19
|
-
viewportSize: {
|
|
20
|
-
width: 1920,
|
|
21
|
-
height: 1280,
|
|
22
|
-
},
|
|
23
|
-
waitForTimeout: 500,
|
|
24
|
-
});
|
|
25
18
|
ROUTES.set('abbr/basic', {
|
|
26
19
|
axe: {
|
|
27
20
|
skipFailures: false,
|
|
@@ -60,11 +53,6 @@ ROUTES.set('breadcrumb/basic', {
|
|
|
60
53
|
skipFailures: false,
|
|
61
54
|
},
|
|
62
55
|
});
|
|
63
|
-
ROUTES.set('button-group/basic', {
|
|
64
|
-
axe: {
|
|
65
|
-
skipFailures: false,
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
56
|
ROUTES.set('button-link/basic', {
|
|
69
57
|
axe: {
|
|
70
58
|
skipFailures: false,
|
|
@@ -105,12 +93,17 @@ ROUTES.set('button/baselined', {
|
|
|
105
93
|
skipFailures: false,
|
|
106
94
|
},
|
|
107
95
|
});
|
|
96
|
+
ROUTES.set('button/short-key', {
|
|
97
|
+
axe: {
|
|
98
|
+
skipFailures: false,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
108
101
|
ROUTES.set('card/basic', {
|
|
109
102
|
axe: {
|
|
110
103
|
skipFailures: false,
|
|
111
104
|
},
|
|
112
105
|
});
|
|
113
|
-
ROUTES.set('combobox/basic', {
|
|
106
|
+
ROUTES.set('combobox/basic?noColumns', {
|
|
114
107
|
axe: {
|
|
115
108
|
skipFailures: false,
|
|
116
109
|
},
|
|
@@ -179,27 +172,21 @@ ROUTES.set('image/basic', {
|
|
|
179
172
|
skipFailures: false,
|
|
180
173
|
},
|
|
181
174
|
});
|
|
182
|
-
ROUTES.set('
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
ROUTES.set('input-
|
|
188
|
-
ROUTES.set('input-
|
|
189
|
-
ROUTES.set('input-
|
|
190
|
-
ROUTES.set('input-
|
|
191
|
-
ROUTES.set('input-
|
|
192
|
-
ROUTES.set('input-
|
|
193
|
-
ROUTES.set('input-
|
|
194
|
-
ROUTES.set('input-
|
|
195
|
-
ROUTES.set('input-
|
|
196
|
-
ROUTES.set('input-
|
|
197
|
-
ROUTES.set('input-radio/basic', null);
|
|
198
|
-
ROUTES.set('input-radio/horizontal', null);
|
|
199
|
-
ROUTES.set('input-radio/object', null);
|
|
200
|
-
ROUTES.set('input-range/basic', null);
|
|
201
|
-
ROUTES.set('input-text/basic', null);
|
|
202
|
-
ROUTES.set('input-text/focus', null);
|
|
175
|
+
ROUTES.set('input-checkbox/basic?noColumns', null);
|
|
176
|
+
ROUTES.set('input-checkbox/button?noColumns', null);
|
|
177
|
+
ROUTES.set('input-checkbox/switch?noColumns', null);
|
|
178
|
+
ROUTES.set('input-color/basic?noColumns', null);
|
|
179
|
+
ROUTES.set('input-date/basic?noColumns', null);
|
|
180
|
+
ROUTES.set('input-email/basic?noColumns', null);
|
|
181
|
+
ROUTES.set('input-file/basic?noColumns', null);
|
|
182
|
+
ROUTES.set('input-number/basic?noColumns', null);
|
|
183
|
+
ROUTES.set('input-password/basic?noColumns', null);
|
|
184
|
+
ROUTES.set('input-password/show-password?noColumns', null);
|
|
185
|
+
ROUTES.set('input-radio/basic?noColumns', null);
|
|
186
|
+
ROUTES.set('input-radio/horizontal?noColumns', null);
|
|
187
|
+
ROUTES.set('input-radio/object?noColumns', null);
|
|
188
|
+
ROUTES.set('input-range/basic?noColumns', null);
|
|
189
|
+
ROUTES.set('input-text/basic?noColumns', null);
|
|
203
190
|
ROUTES.set('kolibri/basic', {
|
|
204
191
|
axe: {
|
|
205
192
|
skipFailures: false,
|
|
@@ -210,16 +197,6 @@ ROUTES.set('link-button/basic', {
|
|
|
210
197
|
skipFailures: false,
|
|
211
198
|
},
|
|
212
199
|
});
|
|
213
|
-
ROUTES.set('link-group/basic', {
|
|
214
|
-
axe: {
|
|
215
|
-
skipFailures: false,
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
ROUTES.set('link-group/horizontal', {
|
|
219
|
-
axe: {
|
|
220
|
-
skipFailures: false,
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
200
|
ROUTES.set('link/basic', {
|
|
224
201
|
axe: {
|
|
225
202
|
skipFailures: false,
|
|
@@ -251,7 +228,12 @@ ROUTES.set('modal/basic?show-modal=true', {
|
|
|
251
228
|
height: 600,
|
|
252
229
|
},
|
|
253
230
|
});
|
|
254
|
-
|
|
231
|
+
ROUTES.set('modal/basic?show-modal=true&variant=card', {
|
|
232
|
+
viewportSize: {
|
|
233
|
+
width: 1920,
|
|
234
|
+
height: 600,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
255
237
|
ROUTES.set('nav/aria-current', {
|
|
256
238
|
axe: {
|
|
257
239
|
skipFailures: false,
|
|
@@ -283,7 +265,7 @@ ROUTES.set('quote/block', {
|
|
|
283
265
|
skipFailures: false,
|
|
284
266
|
},
|
|
285
267
|
});
|
|
286
|
-
ROUTES.set('select/basic', null);
|
|
268
|
+
ROUTES.set('select/basic?noColumns', null);
|
|
287
269
|
ROUTES.set('skip-nav/basic', {
|
|
288
270
|
axe: {
|
|
289
271
|
skipFailures: false,
|
|
@@ -294,7 +276,7 @@ ROUTES.set('spin/basic', {
|
|
|
294
276
|
skipFailures: false,
|
|
295
277
|
},
|
|
296
278
|
});
|
|
297
|
-
ROUTES.set('single-select/basic', {
|
|
279
|
+
ROUTES.set('single-select/basic?noColumns', {
|
|
298
280
|
axe: {
|
|
299
281
|
skipFailures: false,
|
|
300
282
|
},
|
|
@@ -384,7 +366,7 @@ ROUTES.set('textarea/adjust-height', {
|
|
|
384
366
|
skipFailures: false,
|
|
385
367
|
},
|
|
386
368
|
});
|
|
387
|
-
ROUTES.set('textarea/basic', null);
|
|
369
|
+
ROUTES.set('textarea/basic?noColumns', null);
|
|
388
370
|
ROUTES.set('textarea/resize', {
|
|
389
371
|
axe: {
|
|
390
372
|
skipFailures: false,
|
|
@@ -498,11 +480,6 @@ ROUTES.set('version/context', {
|
|
|
498
480
|
skipFailures: false,
|
|
499
481
|
},
|
|
500
482
|
});
|
|
501
|
-
ROUTES.set('scenarios/appointment-form', {
|
|
502
|
-
axe: {
|
|
503
|
-
skipFailures: false,
|
|
504
|
-
},
|
|
505
|
-
});
|
|
506
483
|
ROUTES.set('scenarios/static-form', {
|
|
507
484
|
axe: {
|
|
508
485
|
skipFailures: false,
|
|
@@ -1,37 +1,6 @@
|
|
|
1
1
|
import { test, expect } from '@playwright/test';
|
|
2
2
|
import { ROUTES } from './sample-app.routes.js';
|
|
3
3
|
|
|
4
|
-
// https://github.com/microsoft/playwright/issues/7575#issuecomment-1288164474
|
|
5
|
-
export const configureSnapshotPath =
|
|
6
|
-
() =>
|
|
7
|
-
// eslint-disable-next-line no-empty-pattern
|
|
8
|
-
({}, testInfo) => {
|
|
9
|
-
const originalSnapshotPath = testInfo.snapshotPath;
|
|
10
|
-
testInfo.snapshotPath = (snapshotName) => {
|
|
11
|
-
const result = originalSnapshotPath
|
|
12
|
-
.apply(testInfo, [snapshotName])
|
|
13
|
-
|
|
14
|
-
// Remove browser name from snapshot name
|
|
15
|
-
// .replace('-chromium', '')
|
|
16
|
-
// .replace('-firefox', '')
|
|
17
|
-
|
|
18
|
-
// Remove os name from snapshot name
|
|
19
|
-
// .replace('-darwin', '')
|
|
20
|
-
// .replace('-linux', '')
|
|
21
|
-
// .replace('-windows', '')
|
|
22
|
-
|
|
23
|
-
// Remove test counter from snapshot name
|
|
24
|
-
.replace('-1-', '-')
|
|
25
|
-
|
|
26
|
-
// Make different snapshot folder for different themes
|
|
27
|
-
.replace('theme-snapshots.spec.js', `theme-${(process.env.THEME_EXPORT || 'default').toLocaleLowerCase()}`)
|
|
28
|
-
.replace('-snapshots', '');
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
test.beforeEach(configureSnapshotPath());
|
|
34
|
-
|
|
35
4
|
// https://playwright.dev/docs/emulation
|
|
36
5
|
test.use({
|
|
37
6
|
colorScheme: 'light',
|
|
@@ -44,24 +13,52 @@ test.use({
|
|
|
44
13
|
},
|
|
45
14
|
});
|
|
46
15
|
|
|
47
|
-
const
|
|
16
|
+
const DEFAULT_SNAPSHOT_OPTIONS = {
|
|
17
|
+
animations: 'disabled',
|
|
18
|
+
fullPage: true,
|
|
19
|
+
maxDiffPixelRatio: 0,
|
|
20
|
+
scale: 'css', // 'css' or 'device'
|
|
21
|
+
timeout: 10000,
|
|
22
|
+
};
|
|
48
23
|
|
|
49
24
|
ROUTES.forEach((options, route) => {
|
|
50
|
-
if (blocklist.includes(route)) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
25
|
test(`snapshot for ${route}`, async ({ page }) => {
|
|
54
26
|
const hideMenusParam = `${route.includes('?') ? '&' : '?'}hideMenus`;
|
|
55
|
-
await page.goto(`/#${route}${hideMenusParam}
|
|
27
|
+
await page.goto(`/#${route}${hideMenusParam}`);
|
|
28
|
+
await page.waitForLoadState('networkidle');
|
|
29
|
+
await page.addStyleTag({
|
|
30
|
+
content: `
|
|
31
|
+
* {
|
|
32
|
+
transition: none !important;
|
|
33
|
+
animation: none !important;
|
|
34
|
+
}
|
|
35
|
+
`,
|
|
36
|
+
});
|
|
56
37
|
if (options?.viewportSize) {
|
|
57
38
|
await page.setViewportSize(options.viewportSize);
|
|
58
39
|
}
|
|
59
40
|
if (options?.waitForTimeout) {
|
|
60
41
|
await page.waitForTimeout(options.waitForTimeout);
|
|
61
42
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* We would like to use a readable name for the snapshot file.
|
|
46
|
+
*/
|
|
47
|
+
const snapshotName = `snapshot-for-${route.replace(/(\/|\?|&|=)/g, '-')}`;
|
|
48
|
+
|
|
49
|
+
await expect(page).toHaveScreenshot(`${snapshotName}.png`, {
|
|
50
|
+
...DEFAULT_SNAPSHOT_OPTIONS,
|
|
51
|
+
...options,
|
|
52
|
+
});
|
|
53
|
+
await page.evaluate(() => {
|
|
54
|
+
// eslint-disable-next-line no-undef
|
|
55
|
+
document.body.style.zoom = '400%';
|
|
56
|
+
// document.body.style.transform = 'scale(4)';
|
|
57
|
+
// document.body.style.transformOrigin = 'top left';
|
|
58
|
+
// document.body.style.width = '25vw';
|
|
59
|
+
});
|
|
60
|
+
await expect(page).toHaveScreenshot(`${snapshotName}-zoom.png`, {
|
|
61
|
+
...DEFAULT_SNAPSHOT_OPTIONS,
|
|
65
62
|
...options,
|
|
66
63
|
});
|
|
67
64
|
});
|
|
File without changes
|