@public-ui/visual-tests 3.0.0-alpha.1 → 3.0.0-rc.1

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-alpha.1",
3
+ "version": "3.0.0-rc.1",
4
4
  "license": "EUPL-1.2",
5
5
  "homepage": "https://public-ui.github.io",
6
6
  "repository": {
@@ -26,7 +26,7 @@
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-alpha.1"
29
+ "@public-ui/sample-react": "3.0.0-rc.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/eslint-parser": "7.25.9",
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,
@@ -498,11 +498,6 @@ ROUTES.set('version/context', {
498
498
  skipFailures: false,
499
499
  },
500
500
  });
501
- ROUTES.set('scenarios/appointment-form', {
502
- axe: {
503
- skipFailures: false,
504
- },
505
- });
506
501
  ROUTES.set('scenarios/static-form', {
507
502
  axe: {
508
503
  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' });
@@ -59,6 +57,14 @@ ROUTES.forEach((options, route) => {
59
57
  if (options?.waitForTimeout) {
60
58
  await page.waitForTimeout(options.waitForTimeout);
61
59
  }
60
+ await expect(page).toHaveScreenshot({
61
+ fullPage: true,
62
+ maxDiffPixelRatio: 0.0,
63
+ ...options,
64
+ });
65
+ await page.evaluate(() => {
66
+ document.body.style.zoom = '400%';
67
+ });
62
68
  await expect(page).toHaveScreenshot({
63
69
  fullPage: true,
64
70
  maxDiffPixelRatio: 0.01,