@public-ui/visual-tests 3.0.0-rc.0 → 3.0.0-rc.2

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # KoliBri - Visual Tests
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@public-ui/visual-tests)](https://www.npmjs.com/package/@public-ui/components)
4
+ [![license](https://img.shields.io/npm/l/@public-ui/visual-tests)](https://github.com/public-ui/kolibri/blob/main/LICENSE)
5
+ [![downloads](https://img.shields.io/npm/dt/@public-ui/visual-tests)](https://www.npmjs.com/package/@public-ui/visual-tests)
6
+ [![issues](https://img.shields.io/github/issues/public-ui/kolibri)](https://github.com/public-ui/kolibri/issues)
7
+ [![pull requests](https://img.shields.io/github/issues-pr/public-ui/kolibri)](https://github.com/public-ui/kolibri/pulls)
8
+ [![size](https://img.shields.io/bundlephobia/min/@public-ui/visual-tests)](https://bundlephobia.com/result?p=@public-ui/visual-tests)
9
+ ![contributors](https://img.shields.io/github/contributors/public-ui/kolibri)
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,17 @@ Add the following npm scripts to the theme's `package.json`:
21
41
 
22
42
  ```json
23
43
  {
24
- "scripts": {
25
- "test": "THEME_MODULE=src/index THEME_EXPORT=THEME_NAME kolibri-visual-test",
26
- "test-update": "THEME_MODULE=src/index THEME_EXPORT=THEME_NAME kolibri-visual-test --update-snapshots",
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
- * `THEME_MODULE` defines the relative path to the TypeScript module containing the the theme definitions. Without file extension.
32
- * `THEME_EXPERT` defines the name of the export within the the module. (e.g., `export const THEME_NAME = {/**/};`) Defaults to `default`.
51
+ - `THEME_MODULE` defines the relative path to the TypeScript module containing the the theme definitions. Without file extension.
52
+ - `THEME_EXPERT` defines the name of the export within the the module. (e.g., `export const THEME_NAME = {/**/};`) Defaults to `default`.
33
53
 
34
54
  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
55
  In the following runs, new screenshots will be compared to this reference.
36
56
 
37
- To update the reference screenshots call `npm run test-update`.
57
+ 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-rc.0",
3
+ "version": "3.0.0-rc.2",
4
4
  "license": "EUPL-1.2",
5
5
  "homepage": "https://public-ui.github.io",
6
6
  "repository": {
@@ -22,19 +22,19 @@
22
22
  "kolibri-visual-test": "src/index.js"
23
23
  },
24
24
  "dependencies": {
25
- "@playwright/test": "1.49.0",
25
+ "@playwright/test": "1.49.1",
26
26
  "axe-playwright": "2.0.3",
27
27
  "portfinder": "1.0.32",
28
28
  "serve": "14.2.4",
29
- "@public-ui/sample-react": "3.0.0-rc.0"
29
+ "@public-ui/sample-react": "3.0.0-rc.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/eslint-parser": "7.25.9",
33
33
  "@babel/plugin-syntax-import-attributes": "7.26.0",
34
34
  "@babel/preset-env": "7.26.0",
35
35
  "eslint": "8.57.1",
36
- "knip": "5.37.1",
37
- "prettier": "3.3.3"
36
+ "knip": "5.40.0",
37
+ "prettier": "3.4.2"
38
38
  },
39
39
  "files": [
40
40
  "playwright.config.js",
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';
@@ -35,12 +36,11 @@ if (!fs.existsSync(workingDir)) {
35
36
  const buildPath = path.join(tempDir, `kolibri-visual-testing-build-${crypto.randomUUID()}`);
36
37
  const rawPackageJsonPath = new URL(path.join(workingDir, 'package.json'), import.meta.url).href;
37
38
  const packageJsonPath = process.platform === 'win32' ? pathToFileURL(rawPackageJsonPath) : rawPackageJsonPath;
38
- const packageJson = await import(packageJsonPath, {
39
- assert: { type: 'json' },
40
- });
39
+ const packageJsonContent = await readFile(new URL(packageJsonPath, import.meta.url), 'utf8');
40
+ const packageJson = JSON.parse(packageJsonContent);
41
41
 
42
42
  console.log(`
43
- Building React Sample App (v${packageJson?.default?.version ?? '#.#.#'}) …`);
43
+ Building React Sample App (v${packageJson?.version ?? '#.#.#'}) …`);
44
44
 
45
45
  child_process.spawnSync('pnpm', ['run', 'build', '--', `--output-path="${buildPath}"`], {
46
46
  cwd: workingDir,
@@ -60,11 +60,6 @@ ROUTES.set('breadcrumb/basic', {
60
60
  skipFailures: false,
61
61
  },
62
62
  });
63
- ROUTES.set('button-group/basic', {
64
- axe: {
65
- skipFailures: false,
66
- },
67
- });
68
63
  ROUTES.set('button-link/basic', {
69
64
  axe: {
70
65
  skipFailures: false,
@@ -179,11 +174,6 @@ ROUTES.set('image/basic', {
179
174
  skipFailures: false,
180
175
  },
181
176
  });
182
- ROUTES.set('indented-text/basic', {
183
- axe: {
184
- skipFailures: false,
185
- },
186
- });
187
177
  ROUTES.set('input-checkbox/basic', null);
188
178
  ROUTES.set('input-checkbox/button', null);
189
179
  ROUTES.set('input-checkbox/switch', null);
@@ -210,16 +200,6 @@ ROUTES.set('link-button/basic', {
210
200
  skipFailures: false,
211
201
  },
212
202
  });
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
203
  ROUTES.set('link/basic', {
224
204
  axe: {
225
205
  skipFailures: false,
@@ -23,6 +23,9 @@ export const configureSnapshotPath =
23
23
  // Remove test counter from snapshot name
24
24
  .replace('-1-', '-')
25
25
 
26
+ // Identify 2. test as zoom snapshot
27
+ .replace('-2-', '-zoom-')
28
+
26
29
  // Make different snapshot folder for different themes
27
30
  .replace('theme-snapshots.spec.js', `theme-${(process.env.THEME_EXPORT || 'default').toLocaleLowerCase()}`)
28
31
  .replace('-snapshots', '');
@@ -44,12 +47,7 @@ test.use({
44
47
  },
45
48
  });
46
49
 
47
- const blocklist = [];
48
-
49
50
  ROUTES.forEach((options, route) => {
50
- if (blocklist.includes(route)) {
51
- return;
52
- }
53
51
  test(`snapshot for ${route}`, async ({ page }) => {
54
52
  const hideMenusParam = `${route.includes('?') ? '&' : '?'}hideMenus`;
55
53
  await page.goto(`/#${route}${hideMenusParam}`, { waitUntil: 'networkidle' });
@@ -64,5 +62,13 @@ ROUTES.forEach((options, route) => {
64
62
  maxDiffPixelRatio: 0.0,
65
63
  ...options,
66
64
  });
65
+ await page.evaluate(() => {
66
+ document.body.style.zoom = '400%';
67
+ });
68
+ await expect(page).toHaveScreenshot({
69
+ fullPage: true,
70
+ maxDiffPixelRatio: 0.01,
71
+ ...options,
72
+ });
67
73
  });
68
74
  });