@public-ui/visual-tests 1.7.0-rc.8 → 1.7.0
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 +25 -140
- package/package.json +48 -45
- package/playwright.config.js +59 -0
- package/src/index.js +80 -0
- package/tests/axe-snapshots.spec.js +82 -0
- package/tests/sample-app.routes.js +387 -0
- package/tests/theme-snapshots.spec.js +70 -0
- package/src/index.ts +0 -33
- package/src/migrate/index.ts +0 -127
- package/src/migrate/runner/abstract-task.ts +0 -64
- package/src/migrate/runner/task-runner.ts +0 -163
- package/src/migrate/runner/tasks/common/GenericRenamePropertyTask.ts +0 -85
- package/src/migrate/runner/tasks/common/LabelExpertSlot.ts +0 -96
- package/src/migrate/runner/tasks/common/RemovePropertyNameTask.ts +0 -104
- package/src/migrate/runner/tasks/common/RenamePropertyNameTask.ts +0 -31
- package/src/migrate/runner/tasks/test/index.ts +0 -16
- package/src/migrate/runner/tasks/test/test-dummy.ts +0 -20
- package/src/migrate/runner/tasks/test/test-version-1.3.ts +0 -7
- package/src/migrate/runner/tasks/test/test-version-current.ts +0 -7
- package/src/migrate/runner/tasks/test/test-version-next-2.ts +0 -7
- package/src/migrate/runner/tasks/test/test-version-next-3.ts +0 -7
- package/src/migrate/runner/tasks/test/test-version-zero.ts +0 -7
- package/src/migrate/runner/tasks/v1/abbr.ts +0 -3
- package/src/migrate/runner/tasks/v1/accordion.ts +0 -3
- package/src/migrate/runner/tasks/v1/badge.ts +0 -6
- package/src/migrate/runner/tasks/v1/breadcrumb.ts +0 -3
- package/src/migrate/runner/tasks/v1/button-link.ts +0 -6
- package/src/migrate/runner/tasks/v1/button.ts +0 -8
- package/src/migrate/runner/tasks/v1/card.ts +0 -4
- package/src/migrate/runner/tasks/v1/details.ts +0 -3
- package/src/migrate/runner/tasks/v1/icon.ts +0 -5
- package/src/migrate/runner/tasks/v1/index.ts +0 -151
- package/src/migrate/runner/tasks/v1/input-checkbox.ts +0 -3
- package/src/migrate/runner/tasks/v1/input-color.ts +0 -3
- package/src/migrate/runner/tasks/v1/input-date.ts +0 -3
- package/src/migrate/runner/tasks/v1/input-email.ts +0 -3
- package/src/migrate/runner/tasks/v1/input-number.ts +0 -4
- package/src/migrate/runner/tasks/v1/input-radio.ts +0 -3
- package/src/migrate/runner/tasks/v1/input-range.ts +0 -3
- package/src/migrate/runner/tasks/v1/input-text.ts +0 -3
- package/src/migrate/runner/tasks/v1/link-button.ts +0 -15
- package/src/migrate/runner/tasks/v1/link-group.ts +0 -7
- package/src/migrate/runner/tasks/v1/link.ts +0 -15
- package/src/migrate/runner/tasks/v1/logo.ts +0 -3
- package/src/migrate/runner/tasks/v1/modal.ts +0 -3
- package/src/migrate/runner/tasks/v1/nav.ts +0 -7
- package/src/migrate/runner/tasks/v1/pagination.ts +0 -3
- package/src/migrate/runner/tasks/v1/progress.ts +0 -3
- package/src/migrate/runner/tasks/v1/quote.ts +0 -3
- package/src/migrate/runner/tasks/v1/select.ts +0 -4
- package/src/migrate/runner/tasks/v1/skip-nav.ts +0 -3
- package/src/migrate/runner/tasks/v1/span.ts +0 -3
- package/src/migrate/runner/tasks/v1/split-button.ts +0 -3
- package/src/migrate/runner/tasks/v1/table.ts +0 -3
- package/src/migrate/runner/tasks/v1/tabs.ts +0 -4
- package/src/migrate/runner/tasks/v1/toast.ts +0 -3
- package/src/migrate/runner/tasks/v1/version.ts +0 -3
- package/src/migrate/runner/types.ts +0 -2
- package/src/migrate/shares/reuse.ts +0 -182
- package/src/migrate/types.ts +0 -2
- package/src/types.ts +0 -23
package/README.md
CHANGED
|
@@ -1,168 +1,53 @@
|
|
|
1
|
-
# KoliBri -
|
|
1
|
+
# KoliBri - Visual Tests
|
|
2
2
|
|
|
3
3
|
## Motivation
|
|
4
4
|
|
|
5
|
-
The `KoliBri`
|
|
5
|
+
The `KoliBri` Visual Tests provide a way to add visual regression testing to **theme** modules.
|
|
6
|
+
It takes screenshots of every component defined in the [React Sample App](https://github.com/public-ui/kolibri/tree/develop/packages/samples/react) with the theme applied and compares them to their references.
|
|
6
7
|
|
|
7
8
|
## Installation
|
|
8
9
|
|
|
9
|
-
You can install the `KoliBri`
|
|
10
|
+
You can install the `KoliBri` Visual Tests with `npm`, `pnpm` or `yarn`:
|
|
10
11
|
|
|
11
12
|
```bash
|
|
12
|
-
npm i -
|
|
13
|
-
pnpm i -
|
|
14
|
-
yarn add -
|
|
13
|
+
npm i -D @public-ui/visual-tests
|
|
14
|
+
pnpm i -D @public-ui/visual-tests
|
|
15
|
+
yarn add -D @public-ui/visual-tests
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
## Usage
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Add the following npm scripts to the theme's `package.json`:
|
|
20
21
|
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| . ' | .-. | | | ,--. | .-. \ | .--' ,--.
|
|
29
|
-
| |\ \ | '-' | | | | | | '--' / | | | |
|
|
30
|
-
`--' `--´ `---´ `--' `--' `------´ `--' `--'
|
|
31
|
-
🚹 The accessible HTML-Standard | 👉 https://public-ui.github.io
|
|
32
|
-
|
|
33
|
-
Usage: kolibri [options] [command]
|
|
34
|
-
|
|
35
|
-
CLI for executing some helpful commands for KoliBri projects.
|
|
36
|
-
|
|
37
|
-
Options:
|
|
38
|
-
-V, --version output the version number
|
|
39
|
-
-h, --help display help for command
|
|
40
|
-
|
|
41
|
-
Commands:
|
|
42
|
-
migrate [options] <string> This command migrates KoliBri code to the current version.
|
|
43
|
-
help [command] display help for command
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
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
|
+
}
|
|
28
|
+
}
|
|
44
29
|
```
|
|
45
30
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
With the `migrate` command you can migrate your project to the latest version of `KoliBri`.
|
|
49
|
-
|
|
50
|
-
Actually the following migrations are available:
|
|
51
|
-
|
|
52
|
-
- Component renaming ✓
|
|
53
|
-
- Component removal ⏰
|
|
54
|
-
- Property renaming ✓
|
|
55
|
-
- Property removal ✓
|
|
56
|
-
- Property type change ⏰
|
|
57
|
-
- Logic refactoring ⏰
|
|
58
|
-
- Expert-Slot refactoring ⏰
|
|
59
|
-
- `.vscode/settings.json` add IntelliSense for HTML ⏰
|
|
60
|
-
- `.gitignore` exclude `.kolibri.migrate.json` ⏰
|
|
61
|
-
- `.tsconfig` add `@public-ui/components` to `types` array ⏰
|
|
62
|
-
|
|
63
|
-
#### How does it work?
|
|
64
|
-
|
|
65
|
-
1. The migration command will check your project for clear `git history` and the `installed version` of `KoliBri`. Now it loads all available migration tasks.
|
|
66
|
-
2. Tasks in the correct version range will be executed one by one. Otherwise they will be skipped.
|
|
67
|
-
3. After that the `package.json` will be updated with the new version of `KoliBri` and execute the `npm install` command.
|
|
68
|
-
4. If there are any pending tasks, the migration command will be executed again. Otherwise the migration is finished.
|
|
69
|
-
5. Now you can check the result and commit the changes.
|
|
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`.
|
|
70
33
|
|
|
71
|
-
|
|
34
|
+
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
|
+
In the following runs, new screenshots will be compared to this reference.
|
|
72
36
|
|
|
73
|
-
|
|
37
|
+
To update the reference screenshots call `npm run test-update`.
|
|
74
38
|
|
|
75
|
-
|
|
76
|
-
kolibri migrate --help
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
#### Execute
|
|
39
|
+
It's recommended to add the `test-results` folder to the `.gitignore` file:
|
|
80
40
|
|
|
81
41
|
```bash
|
|
82
|
-
|
|
42
|
+
/test-results/
|
|
83
43
|
```
|
|
84
44
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
| Option | Description | Type | Default |
|
|
88
|
-
| ------------------------------ | ----------------------------------------- | :------------------: | :------: |
|
|
89
|
-
| `--ignore-uncommitted-changes` | Allows execution with uncommitted changes | boolean | false |
|
|
90
|
-
| `--remove-mode` | Prefix property name or delete property | `delete` \| `prefix` | `prefix` |
|
|
91
|
-
|
|
92
|
-
#### Configuration
|
|
93
|
-
|
|
94
|
-
You can configure the migration with the `.kolibri.config.json` file in your project root folder. This file will be created automatically after the first migration.
|
|
95
|
-
|
|
96
|
-
**Troubleshooting:** If you have problems with migration, you can exclude some tasks with the configuration by setting the `false` flag (see `kol-select`).
|
|
45
|
+
It's also recommended to automatically run the tests before packing/publishing the module:
|
|
97
46
|
|
|
98
47
|
```json
|
|
99
48
|
{
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"kol-abbr-rename-property-_title-to-_label": true,
|
|
103
|
-
"kol-accordion-rename-property-_heading-to-_label": true,
|
|
104
|
-
"kol-badge-rename-property-_icon-only-to-_hide-label": true,
|
|
105
|
-
"kol-badge-remove-property-_hide-label": true,
|
|
106
|
-
"kol-badge-remove-property-_icon-only": true,
|
|
107
|
-
"kol-breadcrumb-rename-property-_aria-label-to-_label": true,
|
|
108
|
-
"kol-button-link-remove-property-_aria-current": true,
|
|
109
|
-
"kol-button-link-remove-property-_aria-label": true,
|
|
110
|
-
"kol-button-link-rename-property-_icon-only-to-_hide-label": true,
|
|
111
|
-
"kol-button-remove-property-_aria-current": true,
|
|
112
|
-
"kol-button-remove-property-_aria-label": true,
|
|
113
|
-
"kol-button-rename-property-_icon-only-to-_hide-label": true,
|
|
114
|
-
"kol-card-rename-property-_heading-to-_label": true,
|
|
115
|
-
"kol-card-rename-property-_headline-to-_label": true,
|
|
116
|
-
"kol-details-rename-property-_summary-to-_label": true,
|
|
117
|
-
"kol-icon-remove-property-_part": true,
|
|
118
|
-
"kol-icon-rename-property-_aria-label-to-_label": true,
|
|
119
|
-
"kol-checkbox-rename-property-_type-to-_variant": true,
|
|
120
|
-
"kol-color-rename-property-_list-to-_suggestions": true,
|
|
121
|
-
"kol-date-rename-property-_list-to-_suggestions": true,
|
|
122
|
-
"kol-input-email-rename-property-_list-to-_suggestions": true,
|
|
123
|
-
"kol-input-number-rename-property-_list-to-_suggestions": true,
|
|
124
|
-
"kol-input-radio-rename-property-_list-to-_options": true,
|
|
125
|
-
"kol-input-range-rename-property-_list-to-_suggestions": true,
|
|
126
|
-
"kol-input-text-rename-property-_list-to-_suggestions": true,
|
|
127
|
-
"kol-link-group-rename-property-_aria-label-to-_label": true,
|
|
128
|
-
"kol-link-group-remove-property-_ordered": true,
|
|
129
|
-
"kol-nav-rename-property-_aria-label-to-_label": true,
|
|
130
|
-
"kol-nav-rename-property-_compact-to-_hide-label": true,
|
|
131
|
-
"kol-nav-remove-property-_has-compact-button": true,
|
|
132
|
-
"kol-pagination-rename-property-_count-to-_total": true,
|
|
133
|
-
"kol-progress-rename-property-_type-to-_variant": true,
|
|
134
|
-
"kol-quote-rename-property-_caption-to-_label": true,
|
|
135
|
-
"kol-select-rename-property-_height-to-_rows": false,
|
|
136
|
-
"kol-select-rename-property-_list-to-_options": false,
|
|
137
|
-
"kol-skip-nav-rename-property-_aria-label-to-_label": true,
|
|
138
|
-
"kol-span-rename-property-_icon-only-to-_hide-label": true,
|
|
139
|
-
"kol-split-button-remove-property-_aria-label": true,
|
|
140
|
-
"kol-table-rename-property-_caption-to-_label": true,
|
|
141
|
-
"kol-tabs-rename-property-_aria-label-to-_label": true,
|
|
142
|
-
"kol-tabs-rename-property-_tab-align-to-_align": true,
|
|
143
|
-
"kol-toast-rename-property-_heading-to-_label": true,
|
|
144
|
-
"kol-version-rename-property-_version-to-_label": true
|
|
145
|
-
}
|
|
49
|
+
"scripts": {
|
|
50
|
+
"prepack": "npm test"
|
|
146
51
|
}
|
|
147
52
|
}
|
|
148
53
|
```
|
|
149
|
-
|
|
150
|
-
## Troubleshooting
|
|
151
|
-
|
|
152
|
-
If the migration failed, you can reset the migration with `git reset --hard HEAD~1`.
|
|
153
|
-
|
|
154
|
-
Use the configuration (`.kolibri.config.json`) to exclude some tasks.
|
|
155
|
-
|
|
156
|
-
If there are multiple obsolete properties that have been migrated to just one new property, the new property may appear multiple times in the tag. You can then decide which variant to use and remove all other variants accordingly.
|
|
157
|
-
|
|
158
|
-
Maybe it can help to prepare your code in the tricky places for migration.
|
|
159
|
-
|
|
160
|
-
Please give us feedback, if you have problems with the migration: [GitHub Issues](https://github.com/public-ui/kolibri/issues/new?assignees=&labels=useful+hint&projects=&template=7_feedback.md&title=%F0%9F%92%A1+CLI%3A+)
|
|
161
|
-
|
|
162
|
-
## Dry run
|
|
163
|
-
|
|
164
|
-
You have always the possibility of a dry run. Because before the migration will be executed, you need a clean git history of you project.
|
|
165
|
-
|
|
166
|
-
After the migration you can check the result with `git status` and `git diff`.
|
|
167
|
-
|
|
168
|
-
Is anything wrong, you can reset the migration with `git reset --hard HEAD~1` or by discarding the affected files.
|
package/package.json
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
2
|
+
"name": "@public-ui/visual-tests",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"license": "EUPL-1.2",
|
|
5
|
+
"homepage": "https://public-ui.github.io",
|
|
6
|
+
"repository": "https://github.com/public-ui/kolibri",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/public-ui/kolibri/issues",
|
|
9
|
+
"email": "kolibri@itzbund.de"
|
|
10
|
+
},
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Informationstechnikzentrum Bund",
|
|
13
|
+
"email": "kolibri@itzbund.de"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"description": "Provides utility to run visual regression tests for themes.",
|
|
18
|
+
"bin": {
|
|
19
|
+
"kolibri-visual-test": "src/index.js"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@playwright/test": "1.38.1",
|
|
23
|
+
"@public-ui/sample-react": "1.7.0",
|
|
24
|
+
"portfinder": "1.0.32",
|
|
25
|
+
"serve": "14.2.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@babel/eslint-parser": "7.22.15",
|
|
29
|
+
"@babel/plugin-syntax-import-attributes": "7.22.5",
|
|
30
|
+
"@babel/preset-env": "7.22.20",
|
|
31
|
+
"axe-playwright": "1.2.3",
|
|
32
|
+
"depcheck": "1.4.6",
|
|
33
|
+
"eslint": "8.50.0",
|
|
34
|
+
"eslint-plugin-no-loops": "0.3.0",
|
|
35
|
+
"knip": "2.30.0",
|
|
36
|
+
"prettier": "3.0.3"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"playwright.config.js",
|
|
40
|
+
"src",
|
|
41
|
+
"tests"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"depcheck": "depcheck --ignores=@babel/plugin-syntax-import-attributes,@babel/preset-env,@public-ui/sample-react,portfinder,serve",
|
|
45
|
+
"format": "prettier --check src",
|
|
46
|
+
"lint": "eslint src",
|
|
47
|
+
"unused": "knip"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { defineConfig, devices } from '@playwright/test';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as process from 'process';
|
|
4
|
+
|
|
5
|
+
const PORT = Number(process.env.KOLIBRI_VISUAL_TEST_PORT);
|
|
6
|
+
const URL = `http://127.0.0.1:${PORT}`;
|
|
7
|
+
|
|
8
|
+
console.log('Serving React Sample app:', URL);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* See https://playwright.dev/docs/test-configuration.
|
|
12
|
+
*/
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
testDir: './tests',
|
|
15
|
+
snapshotDir: path.join(process.env.KOLIBRI_CWD, 'snapshots'),
|
|
16
|
+
// snapshotPathTemplate: '',
|
|
17
|
+
outputDir: path.join(process.env.KOLIBRI_CWD, 'test-results'),
|
|
18
|
+
/* Run tests in files in parallel */
|
|
19
|
+
fullyParallel: true,
|
|
20
|
+
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
21
|
+
forbidOnly: !!process.env.CI,
|
|
22
|
+
/* Retry on CI only */
|
|
23
|
+
retries: process.env.CI ? 2 : 0,
|
|
24
|
+
/* Opt out of parallel tests on CI. */
|
|
25
|
+
workers: process.env.CI ? 1 : undefined,
|
|
26
|
+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
27
|
+
reporter: 'line',
|
|
28
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
29
|
+
use: {
|
|
30
|
+
/* Base URL to use in actions like `await page.goto('/')`. */
|
|
31
|
+
baseURL: URL,
|
|
32
|
+
|
|
33
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
34
|
+
trace: 'on-first-retry',
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/* Configure projects for major browsers */
|
|
38
|
+
projects: [
|
|
39
|
+
// {
|
|
40
|
+
// name: 'chrome',
|
|
41
|
+
// use: { ...devices['Desktop Chrome'] },
|
|
42
|
+
// },
|
|
43
|
+
// {
|
|
44
|
+
// name: 'edge',
|
|
45
|
+
// use: { ...devices['Desktop Edge'] },
|
|
46
|
+
// },
|
|
47
|
+
{
|
|
48
|
+
name: 'firefox',
|
|
49
|
+
use: { ...devices['Desktop Firefox'] },
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
|
|
53
|
+
/* Run your local dev server before starting the tests */
|
|
54
|
+
webServer: {
|
|
55
|
+
command: `serve ${process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH} -p ${PORT}`,
|
|
56
|
+
url: URL,
|
|
57
|
+
reuseExistingServer: false,
|
|
58
|
+
},
|
|
59
|
+
});
|
package/src/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import child_process from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import * as crypto from 'crypto';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import portfinder from 'portfinder';
|
|
7
|
+
import * as process from 'process';
|
|
8
|
+
|
|
9
|
+
process.env.KOLIBRI_CWD = process.cwd();
|
|
10
|
+
const tempDir = process.env.RUNNER_TEMP || process.env.TMPDIR; // TODO: Check on Windows
|
|
11
|
+
|
|
12
|
+
if (!process.env.THEME_MODULE) {
|
|
13
|
+
throw new Error('Environment variable THEME_MODULE not specified.');
|
|
14
|
+
}
|
|
15
|
+
if (!tempDir) {
|
|
16
|
+
throw new Error('Neither environment variable RUNNER_TEMP or TMPDIR specified.');
|
|
17
|
+
}
|
|
18
|
+
|
|
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
|
+
const visualsTestModulePath = fileURLToPath(new URL('..', import.meta.url));
|
|
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) !== '/');
|
|
31
|
+
|
|
32
|
+
if (!fs.existsSync(workingDir)) {
|
|
33
|
+
throw new Error('Could not find React Sample App package. Please install it with "npm install @public-ui/sample-react".');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const buildPath = path.join(tempDir, `kolibri-visual-testing-build-${crypto.randomUUID()}`);
|
|
37
|
+
const packageJsonPath = await import(new URL(`${workingDir}/package.json`, import.meta.url), {
|
|
38
|
+
assert: { type: 'json' },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH = buildPath;
|
|
42
|
+
|
|
43
|
+
console.log(`
|
|
44
|
+
Building React Sample App (v${packageJsonPath?.default?.version ?? '#.#.#'}) …`);
|
|
45
|
+
child_process.execFileSync('npm', ['run', 'build', '--', `--output-path=${buildPath}`], {
|
|
46
|
+
cwd: workingDir,
|
|
47
|
+
encoding: 'utf-8',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
console.log(`React Sample App build finished. Directory:`, buildPath);
|
|
51
|
+
|
|
52
|
+
void (async () => {
|
|
53
|
+
process.env.KOLIBRI_VISUAL_TEST_PORT = String(await portfinder.getPortPromise());
|
|
54
|
+
|
|
55
|
+
const playwright = child_process.spawn(path.join(binaryPath, 'playwright'), ['test', ...process.argv.slice(2)], {
|
|
56
|
+
cwd: visualsTestModulePath,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
playwright.stdout.on('data', (data) => {
|
|
60
|
+
console.log('Playwright: ' + data.toString());
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
playwright.stderr.on('data', (data) => {
|
|
64
|
+
console.log('Playwright stderr: ' + data.toString());
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
playwright.on('exit', (code) => {
|
|
68
|
+
console.log(`Playwright test finished with exit code ${code}.`);
|
|
69
|
+
|
|
70
|
+
if (process.env.KOLIBRI_CLEANUP === '0') {
|
|
71
|
+
console.log('Skipping cleanup up build folder.');
|
|
72
|
+
console.log(`You can serve this build with "npx serve ${buildPath}".`);
|
|
73
|
+
} else {
|
|
74
|
+
console.log('Cleaning up build folder …');
|
|
75
|
+
fs.rmSync(buildPath, { recursive: true, force: true });
|
|
76
|
+
console.log('Cleaning up finished successfully.');
|
|
77
|
+
}
|
|
78
|
+
process.exit(code ?? 1);
|
|
79
|
+
});
|
|
80
|
+
})();
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { test } from '@playwright/test';
|
|
2
|
+
import { checkA11y, injectAxe } from 'axe-playwright';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { ROUTES } from './sample-app.routes.js';
|
|
5
|
+
|
|
6
|
+
const rename = (snapshotName) => {
|
|
7
|
+
const result = snapshotName
|
|
8
|
+
|
|
9
|
+
// Remove browser name from snapshot name
|
|
10
|
+
// .replace('-chromium', '')
|
|
11
|
+
// .replace('-firefox', '')
|
|
12
|
+
|
|
13
|
+
// Remove os name from snapshot name
|
|
14
|
+
// .replace('-darwin', '')
|
|
15
|
+
// .replace('-linux', '')
|
|
16
|
+
// .replace('-windows', '')
|
|
17
|
+
|
|
18
|
+
// Remove test counter from snapshot name
|
|
19
|
+
.replace('-1-', '-')
|
|
20
|
+
|
|
21
|
+
// Make different snapshot folder for different themes
|
|
22
|
+
.replace('theme-snapshots.spec.js', `axe-${process.env.THEME_EXPORT.toLocaleLowerCase()}`)
|
|
23
|
+
.replace('-snapshots', '');
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// https://playwright.dev/docs/emulation
|
|
28
|
+
test.use({
|
|
29
|
+
colorScheme: 'light',
|
|
30
|
+
locale: 'de-DE',
|
|
31
|
+
isMobile: false,
|
|
32
|
+
timezoneId: 'Europe/Berlin',
|
|
33
|
+
viewport: {
|
|
34
|
+
width: 800,
|
|
35
|
+
height: 0,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @todo stabilize and re-enable test
|
|
41
|
+
*/
|
|
42
|
+
const blocklist = [];
|
|
43
|
+
|
|
44
|
+
ROUTES.forEach((options, route) => {
|
|
45
|
+
if (blocklist.includes(route)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
test(`snapshot for ${route}`, async ({ page }, testInfo) => {
|
|
49
|
+
const outputPath = rename(testInfo.outputDir);
|
|
50
|
+
await page.goto(`/#${route}?hideMenus`, { waitUntil: 'networkidle' });
|
|
51
|
+
if (options?.viewportSize) {
|
|
52
|
+
await page.setViewportSize(options.viewportSize);
|
|
53
|
+
}
|
|
54
|
+
if (options?.waitForTimeout) {
|
|
55
|
+
await page.waitForTimeout(options.waitForTimeout);
|
|
56
|
+
}
|
|
57
|
+
await injectAxe(page);
|
|
58
|
+
await checkA11y(
|
|
59
|
+
page,
|
|
60
|
+
undefined,
|
|
61
|
+
{
|
|
62
|
+
axeOptions: {
|
|
63
|
+
runOnly: {
|
|
64
|
+
type: 'tag',
|
|
65
|
+
values: ['best-practices', 'wcag2a', 'wcag2aa', 'wcag21aa'],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
detailedReport: true,
|
|
69
|
+
detailedReportOptions: {
|
|
70
|
+
html: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
options?.axe?.skipFailures ?? true,
|
|
74
|
+
'html',
|
|
75
|
+
{
|
|
76
|
+
outputDirPath: outputPath.replace(/\/[^/]+$/, ''),
|
|
77
|
+
outputDir: `axe-${process.env.THEME_EXPORT.toLocaleLowerCase()}`,
|
|
78
|
+
reportFileName: `${route.replace('/', '-')}.html`,
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
});
|