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

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
@@ -48,8 +48,12 @@ Add the following npm scripts to the theme's `package.json`:
48
48
  }
49
49
  ```
50
50
 
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`.
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).
53
57
 
54
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.
55
59
  In the following runs, new screenshots will be compared to this reference.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@public-ui/visual-tests",
3
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.10",
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.0",
26
- "axe-playwright": "2.0.3",
27
- "portfinder": "1.0.32",
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-rc.1"
32
+ "@public-ui/sample-react": "3.0.0-rc.10"
30
33
  },
31
34
  "devDependencies": {
32
- "@babel/eslint-parser": "7.25.9",
35
+ "@babel/eslint-parser": "7.26.10",
33
36
  "@babel/plugin-syntax-import-attributes": "7.26.0",
34
- "@babel/preset-env": "7.26.0",
37
+ "@babel/preset-env": "7.26.9",
35
38
  "eslint": "8.57.1",
36
- "knip": "5.37.1",
37
- "prettier": "3.3.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 src",
49
+ "lint": "pnpm lint:eslint",
50
+ "lint:eslint": "eslint src",
47
51
  "unused": "knip",
48
52
  "postinstall": "pnpm exec playwright install"
49
53
  }
@@ -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
- const PORT = Number(process.env.KOLIBRI_VISUAL_TEST_PORT);
6
- const URL = `http://localhost:${PORT}`;
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
- console.log('Serving React Sample app:', URL);
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(process.env.KOLIBRI_CWD ?? '', 'snapshots'),
20
+ snapshotDir: path.join(CWD, 'snapshots'),
16
21
  // snapshotPathTemplate: '',
17
- outputDir: path.join(process.env.KOLIBRI_CWD ?? '', 'test-results'),
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: process.env.KOLIBRI_VISUAL_TESTS_TIMEOUT ? Number(process.env.KOLIBRI_VISUAL_TESTS_TIMEOUT) : undefined,
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: URL,
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(process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH),
59
- url: 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
@@ -19,15 +19,8 @@ if (!tempDir) {
19
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
20
20
  const visualsTestModulePath = fileURLToPath(new URL('..', import.meta.url));
21
21
  const binaryPath = fileURLToPath(new URL('../node_modules/.bin', import.meta.url));
22
-
23
- let sampleReactPath = '../node_modules/@public-ui/sample-react';
24
- let backSteps = ``;
25
- let workingDir = null;
26
- do {
27
- const url = new URL(backSteps + sampleReactPath, import.meta.url);
28
- workingDir = fileURLToPath(url);
29
- backSteps += `../`;
30
- } 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));
31
24
 
32
25
  if (!fs.existsSync(workingDir)) {
33
26
  throw new Error('Could not find React Sample App package. Please install it with "npm install @public-ui/sample-react".');
@@ -36,21 +36,31 @@ test.use({
36
36
  },
37
37
  });
38
38
 
39
- const blocklist = [];
40
-
41
39
  ROUTES.forEach((options, route) => {
42
- if (blocklist.includes(route)) {
40
+ // Skip unnecessary axe tests
41
+ if (options?.axe?.skip === true) {
43
42
  return;
44
43
  }
45
44
  test(`snapshot for ${route}`, async ({ page }, testInfo) => {
46
45
  const outputPath = rename(testInfo.outputDir);
47
- await page.goto(`/#${route}?hideMenus`, { waitUntil: 'networkidle' });
48
- if (options?.viewportSize) {
49
- await page.setViewportSize(options.viewportSize);
46
+ const hideMenusParam = `${route.includes('?') ? '&' : '?'}hideMenus`;
47
+ await page.goto(`/#${route}${hideMenusParam}`);
48
+ await page.waitForLoadState('networkidle');
49
+ await page.addStyleTag({
50
+ content: `
51
+ * {
52
+ transition: none !important;
53
+ animation: none !important;
54
+ }
55
+ `,
56
+ });
57
+ if (options?.snapshot?.viewportSize) {
58
+ await page.setViewportSize(options?.snapshot?.viewportSize);
50
59
  }
51
- if (options?.waitForTimeout) {
52
- await page.waitForTimeout(options.waitForTimeout);
60
+ if (options?.snapshot?.waitForTimeout) {
61
+ await page.waitForTimeout(options?.snapshot?.waitForTimeout);
53
62
  }
63
+
54
64
  await injectAxe(page);
55
65
  await checkA11y(
56
66
  page,
@@ -67,7 +77,7 @@ ROUTES.forEach((options, route) => {
67
77
  html: true,
68
78
  },
69
79
  },
70
- options?.axe?.skipFailures ?? true,
80
+ options?.axe?.skipFailures ?? false,
71
81
  'html',
72
82
  {
73
83
  outputDirPath: outputPath.replace(/\/[^/]+$/, ''),