@public-ui/visual-tests 1.7.0-rc.11 → 1.7.0-rc.12

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": "1.7.0-rc.11",
3
+ "version": "1.7.0-rc.12",
4
4
  "license": "EUPL-1.2",
5
5
  "homepage": "https://public-ui.github.io",
6
6
  "repository": "https://github.com/public-ui/kolibri",
@@ -16,7 +16,7 @@
16
16
  "sideEffects": false,
17
17
  "description": "Provides utility to run visual regression tests for themes.",
18
18
  "scripts": {
19
- "depcheck": "depcheck --ignores=@public-ui/sample-react,http-server,tslib",
19
+ "depcheck": "depcheck --ignores=@babel/plugin-syntax-import-attributes,@babel/preset-env,@public-ui/sample-react,portfinder,serve",
20
20
  "format": "prettier --check src",
21
21
  "lint": "eslint src",
22
22
  "unused": "knip"
@@ -26,16 +26,18 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@playwright/test": "1.38.0",
29
- "@public-ui/sample-react": "1.7.0-rc.11",
30
- "http-server": "14.1.1",
31
- "portfinder": "1.0.32"
29
+ "@public-ui/sample-react": "1.7.0-rc.12",
30
+ "portfinder": "1.0.32",
31
+ "serve": "14.2.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@babel/eslint-parser": "7.22.15",
35
+ "@babel/plugin-syntax-import-attributes": "7.22.5",
36
+ "@babel/preset-env": "7.22.20",
35
37
  "depcheck": "1.4.6",
36
38
  "eslint": "8.49.0",
37
39
  "eslint-plugin-no-loops": "0.3.0",
38
- "knip": "2.24.1",
40
+ "knip": "2.25.2",
39
41
  "prettier": "3.0.3"
40
42
  },
41
43
  "files": [
@@ -52,7 +52,7 @@ export default defineConfig({
52
52
 
53
53
  /* Run your local dev server before starting the tests */
54
54
  webServer: {
55
- command: `http-server ${process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH} -p ${PORT}`,
55
+ command: `serve ${process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH} -p ${PORT}`,
56
56
  url: URL,
57
57
  reuseExistingServer: false,
58
58
  },
package/src/index.js CHANGED
@@ -19,11 +19,18 @@ 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
+ const workingDir = fileURLToPath(new URL('../node_modules/@public-ui/sample-react', import.meta.url));
22
23
  const buildPath = path.join(tempDir, `kolibri-visual-testing-build-${crypto.randomUUID()}`);
24
+ const packageJsonPath = await import(new URL('../node_modules/@public-ui/sample-react/package.json', import.meta.url), {
25
+ assert: { type: 'json' },
26
+ });
27
+
23
28
  process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH = buildPath;
24
29
 
25
- console.log('Building React Sample App …');
26
- child_process.execFileSync(path.join(binaryPath, 'kolibri-sample-react-test-build'), [buildPath], {
30
+ console.log(`
31
+ Building React Sample App (v${packageJsonPath?.default?.version ?? '#.#.#'}) …`);
32
+ child_process.execFileSync('npm', ['run', 'build', '--', `--output-path=${buildPath}`], {
33
+ cwd: workingDir,
27
34
  encoding: 'utf-8',
28
35
  });
29
36
 
@@ -46,8 +53,15 @@ void (async () => {
46
53
 
47
54
  playwright.on('exit', (code) => {
48
55
  console.log(`Playwright test finished with exit code ${code}.`);
49
- console.log('Cleaning up build folder …');
50
- fs.rmSync(buildPath, { recursive: true, force: true });
56
+
57
+ if (process.env.KOLIBRI_CLEANUP === '0') {
58
+ console.log('Skipping cleanup up build folder.');
59
+ console.log(`You can serve this build with "npx serve ${buildPath}".`);
60
+ } else {
61
+ console.log('Cleaning up build folder …');
62
+ fs.rmSync(buildPath, { recursive: true, force: true });
63
+ console.log('Cleaning up finished successfully.');
64
+ }
51
65
  process.exit(code ?? 1);
52
66
  });
53
67
  })();
@@ -1,80 +1,114 @@
1
- export const ROUTES = [
2
- '/handout/basic',
3
- '/abbr/basic',
4
- '/accordion/basic',
5
- '/accordion/header',
6
- '/accordion/headlines',
7
- '/accordion/list',
8
- '/alert/basic',
9
- '/alert/card-msg',
10
- '/alert/html',
11
- '/avatar/basic',
12
- '/badge/basic',
13
- '/badge/button',
14
- '/breadcrumb/basic',
15
- '/button/basic',
16
- '/button/hide-label',
17
- '/button/icons',
18
- '/button/width',
19
- '/button-link/basic',
20
- '/button-link/icons',
21
- '/button-link/image',
22
- '/button-link/target',
23
- '/button-group/basic',
24
- '/card/basic',
25
- '/card/confirm',
26
- '/card/flex',
27
- '/card/selection',
28
- '/details/basic',
29
- '/heading/badge',
30
- '/heading/basic',
31
- '/heading/paragraph',
32
- '/icon/basic',
33
- '/indented-text/basic',
34
- '/input-checkbox/basic',
35
- '/input-color/basic',
36
- '/input-date/basic',
37
- '/input-email/basic',
38
- '/input-file/basic',
39
- '/input-number/basic',
40
- '/input-password/basic',
41
- '/input-password/show-password',
42
- '/input-radio/basic',
43
- '/input-radio/horizontal',
44
- '/input-radio/select',
45
- '/input-range/basic',
46
- '/input-text/basic',
47
- '/input-text/hidden-label',
48
- '/input-text/blur',
49
- '/input-text/focus',
50
- '/link/basic',
51
- '/link/icons',
52
- '/link/image',
53
- '/link/target',
54
- '/link-button/basic',
55
- '/nav/basic',
56
- '/nav/active',
57
- '/nav/aria-current',
58
- '/nav/horizontal',
59
- '/pagination/basic',
60
- '/popover/basic',
61
- '/progress/basic',
62
- '/select/basic',
63
- '/skip-nav/basic',
64
- '/spin/basic',
65
- '/spin/cycle',
66
- '/spin/custom',
67
- '/split-button/basic',
68
- '/table/badge-size',
69
- '/table/render-cell',
70
- '/table/sort-data',
71
- '/textarea/basic',
72
- '/textarea/adjust-height',
73
- '/textarea/disabled',
74
- '/textarea/placeholder',
75
- '/textarea/readonly',
76
- '/textarea/resize',
77
- '/textarea/rows',
78
- '/version/basic',
79
- '/version/context',
80
- ];
1
+ export const ROUTES = new Map();
2
+
3
+ /**
4
+ * Actually we support the following options:
5
+ *
6
+ * Details: https://playwright.dev/docs/api/class-pageassertions#page-assertions-to-have-screenshot-1
7
+ * - fullPage: boolean (Default: true)
8
+ * - maxDiffPixelRatio: number (Default: undefined)
9
+ * - maxDiffPixels: number (Default: undefined)
10
+ * - threshold: number (Default: undefined)
11
+ * - timeout: number (Default: 0)
12
+ *
13
+ * To set the viewport size, use the following options:
14
+ * - viewportSize: { width, height } (Default: 800x600)
15
+ *
16
+ */
17
+
18
+ ROUTES.set('handout/basic', {
19
+ viewportSize: {
20
+ width: 1920,
21
+ height: 1280,
22
+ },
23
+ waitForTimeout: 500,
24
+ });
25
+ ROUTES.set('abbr/basic', null);
26
+ ROUTES.set('accordion/basic', null);
27
+ ROUTES.set('accordion/header', null);
28
+ ROUTES.set('accordion/headlines', null);
29
+ ROUTES.set('accordion/list', null);
30
+ ROUTES.set('alert/basic', null);
31
+ ROUTES.set('alert/card-msg', null);
32
+ ROUTES.set('alert/html', null);
33
+ ROUTES.set('avatar/basic', null);
34
+ ROUTES.set('badge/basic', null);
35
+ ROUTES.set('badge/button', null);
36
+ ROUTES.set('breadcrumb/basic', null);
37
+ ROUTES.set('button-group/basic', null);
38
+ ROUTES.set('button-link/basic', null);
39
+ ROUTES.set('button-link/icons', null);
40
+ ROUTES.set('button-link/image', null);
41
+ ROUTES.set('button-link/target', null);
42
+ ROUTES.set('button/basic', null);
43
+ ROUTES.set('button/hide-label', null);
44
+ ROUTES.set('button/icons', null);
45
+ ROUTES.set('button/width', null);
46
+ ROUTES.set('card/basic', null);
47
+ ROUTES.set('card/confirm', null);
48
+ ROUTES.set('card/flex', null);
49
+ ROUTES.set('card/selection', null);
50
+ ROUTES.set('details/basic', null);
51
+ ROUTES.set('heading/badge', null);
52
+ ROUTES.set('heading/basic', null);
53
+ ROUTES.set('heading/paragraph', null);
54
+ ROUTES.set('icon/basic', null);
55
+ ROUTES.set('image/basic', null);
56
+ ROUTES.set('indented-text/basic', null);
57
+ ROUTES.set('input-checkbox/basic', null);
58
+ ROUTES.set('input-checkbox/button', null);
59
+ ROUTES.set('input-checkbox/switch', null);
60
+ ROUTES.set('input-color/basic', null);
61
+ ROUTES.set('input-date/basic', null);
62
+ ROUTES.set('input-email/basic', null);
63
+ ROUTES.set('input-file/basic', null);
64
+ ROUTES.set('input-number/basic', null);
65
+ ROUTES.set('input-password/basic', null);
66
+ ROUTES.set('input-password/show-password', null);
67
+ ROUTES.set('input-radio/basic', null);
68
+ ROUTES.set('input-radio/horizontal', null);
69
+ ROUTES.set('input-radio/select', null);
70
+ ROUTES.set('input-range/basic', null);
71
+ ROUTES.set('input-text/basic', null);
72
+ ROUTES.set('input-text/blur', null);
73
+ ROUTES.set('input-text/focus', null);
74
+ ROUTES.set('input-text/hidden-label', null);
75
+ ROUTES.set('kolibri/animated', null);
76
+ ROUTES.set('kolibri/basic', null);
77
+ ROUTES.set('kolibri/no-label', null);
78
+ ROUTES.set('link-button/basic', null);
79
+ ROUTES.set('link-group/basic', null);
80
+ ROUTES.set('link-group/horizontal', null);
81
+ ROUTES.set('link/basic', null);
82
+ ROUTES.set('link/icons', null);
83
+ ROUTES.set('link/image', null);
84
+ ROUTES.set('link/target', null);
85
+ ROUTES.set('logo/basic', null);
86
+ ROUTES.set('nav/active', null);
87
+ ROUTES.set('nav/aria-current', null);
88
+ ROUTES.set('nav/basic', null);
89
+ ROUTES.set('nav/horizontal', null);
90
+ ROUTES.set('pagination/basic', null);
91
+ ROUTES.set('popover/basic', null);
92
+ ROUTES.set('progress/basic', null);
93
+ ROUTES.set('quote/basic', null);
94
+ ROUTES.set('quote/block', null);
95
+ ROUTES.set('select/basic', null);
96
+ ROUTES.set('skip-nav/basic', null);
97
+ ROUTES.set('spin/basic', null);
98
+ ROUTES.set('spin/custom', null);
99
+ ROUTES.set('spin/cycle', null);
100
+ ROUTES.set('split-button/basic', null);
101
+ ROUTES.set('table/badge-size', null);
102
+ ROUTES.set('table/render-cell', null);
103
+ ROUTES.set('table/sort-data', null);
104
+ ROUTES.set('tabs/basic', null);
105
+ ROUTES.set('tabs/icons-only', null);
106
+ ROUTES.set('textarea/adjust-height', null);
107
+ ROUTES.set('textarea/basic', null);
108
+ ROUTES.set('textarea/disabled', null);
109
+ ROUTES.set('textarea/placeholder', null);
110
+ ROUTES.set('textarea/readonly', null);
111
+ ROUTES.set('textarea/resize', null);
112
+ ROUTES.set('textarea/rows', null);
113
+ ROUTES.set('version/basic', null);
114
+ ROUTES.set('version/context', null);
@@ -15,9 +15,9 @@ export const configureSnapshotPath =
15
15
  // .replace('-firefox', '')
16
16
 
17
17
  // Remove os name from snapshot name
18
- .replace('-darwin', '')
19
- .replace('-linux', '')
20
- .replace('-windows', '')
18
+ // .replace('-darwin', '')
19
+ // .replace('-linux', '')
20
+ // .replace('-windows', '')
21
21
 
22
22
  // Remove test counter from snapshot name
23
23
  .replace('-1-', '-')
@@ -31,22 +31,39 @@ export const configureSnapshotPath =
31
31
 
32
32
  test.beforeEach(configureSnapshotPath());
33
33
 
34
+ // https://playwright.dev/docs/emulation
35
+ test.use({
36
+ colorScheme: 'light',
37
+ locale: 'de-DE',
38
+ isMobile: false,
39
+ timezoneId: 'Europe/Berlin',
40
+ viewport: {
41
+ width: 800,
42
+ height: 0,
43
+ },
44
+ });
45
+
34
46
  /**
35
47
  * @todo stabilize and re-enable test
36
48
  */
37
49
  const blocklist = [];
38
50
 
39
- ROUTES.filter((route) => !blocklist.includes(route)).forEach((route) => {
51
+ ROUTES.forEach((options, route) => {
52
+ if (blocklist.includes(route)) {
53
+ return;
54
+ }
40
55
  test(`snapshot for ${route}`, async ({ page }) => {
41
56
  await page.goto(`/#${route}?hideMenus`, { waitUntil: 'networkidle' });
42
- await page.setViewportSize({
43
- width: 1920,
44
- height: 1280,
45
- });
46
- // await page.waitForTimeout(250);
57
+ if (options?.viewportSize) {
58
+ await page.setViewportSize(options.viewportSize);
59
+ }
60
+ if (options?.waitForTimeout) {
61
+ await page.waitForTimeout(options.waitForTimeout);
62
+ }
47
63
  await expect(page).toHaveScreenshot({
48
- // fullPage: true,
49
- maxDiffPixelRatio: 0.1, // 0.03,
64
+ fullPage: true,
65
+ maxDiffPixelRatio: 0.025,
66
+ ...options,
50
67
  });
51
68
  });
52
69
  });