@public-ui/visual-tests 3.0.0-rc.6 → 3.0.0-rc.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@public-ui/visual-tests",
3
- "version": "3.0.0-rc.6",
3
+ "version": "3.0.0-rc.7",
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.",
@@ -23,18 +26,18 @@
23
26
  },
24
27
  "dependencies": {
25
28
  "@playwright/test": "1.49.1",
26
- "axe-playwright": "2.0.3",
27
- "portfinder": "1.0.32",
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.6"
32
+ "@public-ui/sample-react": "3.0.0-rc.7"
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.7",
37
+ "@babel/preset-env": "7.26.9",
35
38
  "eslint": "8.57.1",
36
- "knip": "5.40.0",
37
- "prettier": "3.4.2"
39
+ "knip": "5.46.0",
40
+ "prettier": "3.5.3"
38
41
  },
39
42
  "files": [
40
43
  "playwright.config.js",
@@ -63,4 +63,5 @@ export default defineConfig({
63
63
  url: URL,
64
64
  reuseExistingServer: false,
65
65
  },
66
+ snapshotPathTemplate: `{snapshotDir}/theme-${(process.env.THEME_EXPORT || 'default').toLocaleLowerCase()}/{arg}-{projectName}-{platform}{ext}`,
66
67
  });
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".');
@@ -93,6 +93,11 @@ ROUTES.set('button/baselined', {
93
93
  skipFailures: false,
94
94
  },
95
95
  });
96
+ ROUTES.set('button/short-key', {
97
+ axe: {
98
+ skipFailures: false,
99
+ },
100
+ });
96
101
  ROUTES.set('card/basic', {
97
102
  axe: {
98
103
  skipFailures: false,
@@ -1,40 +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
- // Identify 2. test as zoom snapshot
27
- .replace('-2-', '-zoom-')
28
-
29
- // Make different snapshot folder for different themes
30
- .replace('theme-snapshots.spec.js', `theme-${(process.env.THEME_EXPORT || 'default').toLocaleLowerCase()}`)
31
- .replace('-snapshots', '');
32
- return result;
33
- };
34
- };
35
-
36
- test.beforeEach(configureSnapshotPath());
37
-
38
4
  // https://playwright.dev/docs/emulation
39
5
  test.use({
40
6
  colorScheme: 'light',
@@ -47,27 +13,52 @@ test.use({
47
13
  },
48
14
  });
49
15
 
16
+ const DEFAULT_SNAPSHOT_OPTIONS = {
17
+ animations: 'disabled',
18
+ fullPage: true,
19
+ maxDiffPixelRatio: 0,
20
+ scale: 'css', // 'css' or 'device'
21
+ timeout: 10000,
22
+ };
23
+
50
24
  ROUTES.forEach((options, route) => {
51
25
  test(`snapshot for ${route}`, async ({ page }) => {
52
26
  const hideMenusParam = `${route.includes('?') ? '&' : '?'}hideMenus`;
53
- await page.goto(`/#${route}${hideMenusParam}`, { waitUntil: 'networkidle' });
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
+ });
54
37
  if (options?.viewportSize) {
55
38
  await page.setViewportSize(options.viewportSize);
56
39
  }
57
40
  if (options?.waitForTimeout) {
58
41
  await page.waitForTimeout(options.waitForTimeout);
59
42
  }
60
- await expect(page).toHaveScreenshot({
61
- fullPage: true,
62
- maxDiffPixelRatio: 0.01,
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,
63
51
  ...options,
64
52
  });
65
53
  await page.evaluate(() => {
54
+ // eslint-disable-next-line no-undef
66
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';
67
59
  });
68
- await expect(page).toHaveScreenshot({
69
- fullPage: true,
70
- maxDiffPixelRatio: 0.02,
60
+ await expect(page).toHaveScreenshot(`${snapshotName}-zoom.png`, {
61
+ ...DEFAULT_SNAPSHOT_OPTIONS,
71
62
  ...options,
72
63
  });
73
64
  });