@brightspace-ui/testing 1.41.0 → 1.43.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 CHANGED
@@ -424,7 +424,7 @@ Use the `d2l-test-runner` binary to execute a set of tests and report their resu
424
424
  | timeout | `Number` | `2000` | Test timeout threshold in ms |
425
425
  | filter | `String` | | Filter test files by replacing wildcards with this glob |
426
426
  | grep | `String` | | Only run tests matching this string or regexp |
427
- | files | `String` | `'./test/**/*.<group>.js'` | Test files to run. Path or glob. |
427
+ | files | `String` | `'./**/test/**/*.<group>.js'` | Test files to run. Path or glob. |
428
428
  | config | `String` | `'./d2l-test-runner.config.js'` | Location of config file |
429
429
  | watch | `Boolean` | `false` | Reload tests on file changes. Allows debugging in all browsers. |
430
430
  | open | `Boolean` | `false` | Open the browser in headed mode |
@@ -461,9 +461,9 @@ export default {
461
461
 
462
462
  Tests are organized into groups, which can be configured and run together.
463
463
 
464
- The group name appears in the default `files` pattern (`'./test/**/*.<group>.js'`), making it typical for test files to have the group name as part of their extension. For example, the default group is `'test'` so all test files named `*.test.js` will belong to it by default. Similarly, the `vdiff` group contains files named `*.vdiff.js`.
464
+ The group name appears in the default `files` pattern (`'./**/test/**/*.<group>.js'`), making it typical for test files to have the group name as part of their extension. For example, the default group is `'test'` so all test files named `*.test.js` will belong to it by default. Similarly, the `vdiff` group contains files named `*.vdiff.js`.
465
465
 
466
- To run tests which match the pattern `'./test/**/*.mygroup.js'`:
466
+ To run tests which match the pattern `'./**/test/**/*.mygroup.js'`:
467
467
  ```bash
468
468
  d2l-test-runner --group mygroup
469
469
  ```
@@ -488,9 +488,9 @@ While writing or debugging tests, it can be desirable to focus the runner on a s
488
488
 
489
489
  Use the `filter` option to filter by file name. It replaces any wildcards in the file name portion of the `files` pattern with the provided [glob](https://en.wikipedia.org/wiki/Glob_(programming)).
490
490
 
491
- For example, with the `'test'` group and default pattern `'./test/**/*.<group>.js'`, passing `d2l-test-runner --filter foo` will run tests which match `'./test/**/foo.test.js'`.
491
+ For example, with the `'test'` group and default pattern `'./**/test/**/*.<group>.js'`, passing `d2l-test-runner --filter foo` will run tests which match `'./**/test/**/foo.test.js'`.
492
492
 
493
- Wildcards can still be used but need to be escaped. So `d2l-test-runner --filter foo\*` will run tests which match `'./test/**/foo*.test.js'`.
493
+ Wildcards can still be used but need to be escaped. So `d2l-test-runner --filter foo\*` will run tests which match `'./**/test/**/foo*.test.js'`.
494
494
 
495
495
  ### By Test Name
496
496
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@brightspace-ui/testing",
3
3
  "description": "Utilities for testing front-end components and applications",
4
4
  "type": "module",
5
- "version": "1.41.0",
5
+ "version": "1.43.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "npm run lint:eslint && npm run lint:style",
@@ -0,0 +1,12 @@
1
+ export const ALT_TESTS = {
2
+ dark: {
3
+ set() {
4
+ document.documentElement.setAttribute('data-color-mode', 'dark');
5
+ },
6
+ reset() {
7
+ document.documentElement.removeAttribute('data-color-mode');
8
+ }
9
+ }
10
+ };
11
+
12
+ export const allColorModes = ['dark'];
@@ -0,0 +1,35 @@
1
+ import { allColorModes, ALT_TESTS } from '../alt-tests.js';
2
+ import { chai } from '@open-wc/testing';
3
+
4
+ /* eslint-disable no-invalid-this, prefer-arrow-callback */
5
+ chai.Assertion.overwriteMethod('accessible', function(_super) {
6
+ return async function(opts = {}) {
7
+ let violationsHeader = '';
8
+ const violationsMessages = [];
9
+ const run = async(prefix = '') => {
10
+ try {
11
+ await _super.apply(this, arguments);
12
+ } catch (e) {
13
+ const violations = e.message.split('---');
14
+ violationsHeader = violations.shift();
15
+ violations.pop();
16
+ violationsMessages.push(...violations.map(v => `${prefix}${v}`));
17
+ }
18
+ };
19
+ await run();
20
+ if (opts.allColorModes) {
21
+ for (const mode of allColorModes) {
22
+ ALT_TESTS[mode].set();
23
+ await run(`\nColor mode: ${mode.charAt(0).toUpperCase() + mode.slice(1)}`);
24
+ ALT_TESTS[mode].reset();
25
+ }
26
+ }
27
+ if (violationsMessages.length > 0) {
28
+ violationsMessages.unshift(violationsHeader);
29
+ violationsMessages.push('---');
30
+ throw new Error(violationsMessages.join('---'));
31
+ }
32
+
33
+ };
34
+ });
35
+ /* eslint-enable */
@@ -1,4 +1,5 @@
1
1
  import './vdiff.js';
2
+ import './axe.js';
2
3
 
3
4
  export { assert, aTimeout, defineCE, expect, html, nextFrame, oneDefaultPreventedEvent, oneEvent, waitUntil } from '@open-wc/testing';
4
5
  export { clickAt, clickElem, clickElemAt, dragDropElems, focusElem, hoverAt, hoverElem, hoverElemAt, sendKeys, sendKeysElem, setViewport } from './commands.js';
@@ -1,4 +1,5 @@
1
1
  import { chai, expect } from '@open-wc/testing';
2
+ import { allColorModes } from '../alt-tests.js';
2
3
  import { executeServerCommand } from '@web/test-runner-commands';
3
4
 
4
5
  // start loading fonts early
@@ -90,7 +91,7 @@ async function ScreenshotAndCompare(opts = {}) {
90
91
  }
91
92
  const slowDuration = this.test.slow();
92
93
  const altTests = [];
93
- if (opts.allColorModes) altTests.push('dark');
94
+ if (opts.allColorModes) altTests.push(...allColorModes);
94
95
 
95
96
  this.test.timeout(0);
96
97
  const result = await executeServerCommand('brightspace-visual-diff-compare', { altTests, name, fullPage, rect, slowDuration });
@@ -16,7 +16,7 @@ async function getTestRunnerOptions(argv = []) {
16
16
  name: 'files',
17
17
  type: String,
18
18
  multiple: true,
19
- description: 'Test files to run. Path or glob.\n[Default: ./test/**/*.<group>.js]',
19
+ description: 'Test files to run. Path or glob.\n[Default: ./**/test/**/*.<group>.js]',
20
20
  order: 8
21
21
  },
22
22
  {
@@ -1,5 +1,6 @@
1
1
  import { access, constants, mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
2
2
  import { basename, dirname, join } from 'node:path';
3
+ import { ALT_TESTS } from '../alt-tests.js';
3
4
  import { env } from 'node:process';
4
5
  import { PATHS } from './paths.js';
5
6
  import pixelmatch from 'pixelmatch';
@@ -9,17 +10,6 @@ import { TestInfoManager } from './visual-diff-info.js';
9
10
  const isCI = !!env['CI'];
10
11
  const DEFAULT_TOLERANCE = 0; // TODO: Support tolerance override?
11
12
 
12
- const ALT_TESTS = {
13
- dark: {
14
- set() {
15
- document.documentElement.setAttribute('data-color-mode', 'dark');
16
- },
17
- reset() {
18
- document.documentElement.removeAttribute('data-color-mode');
19
- }
20
- }
21
- };
22
-
23
13
  async function checkFileExists(fileName) {
24
14
  try {
25
15
  await access(fileName, constants.F_OK);
@@ -35,7 +35,7 @@ const defaultReporterGrep = () => {
35
35
  };
36
36
  };
37
37
 
38
- const DEFAULT_PATTERN = type => `./test/**/*.${type}.js`;
38
+ const DEFAULT_PATTERN = type => `./**/test/**/*.${type}.js`;
39
39
  const DEFAULT_TEST_REPORTING = !!env['CI'];
40
40
  const BROWSER_MAP = {
41
41
  chrome: 'chromium',
@@ -59,6 +59,86 @@ const SUPPRESS_RESIZE_OBSERVER_ERRORS = `
59
59
  </script>
60
60
  `;
61
61
  export const DEFAULT_VDIFF_SLOW = 500;
62
+ const HTML_BODY = testFramework => `
63
+ <body>
64
+ ${TEST_PAGE}
65
+ ${SUPPRESS_RESIZE_OBSERVER_ERRORS}
66
+ <script type="module" src="${testFramework}"></script>
67
+ </body>
68
+ `;
69
+ const HTML_HEAD = `
70
+ <head>
71
+ <link rel="preload" href="${FONT_ASSETS}Lato-400.woff2" as="font" type="font/woff2" crossorigin>
72
+ <link rel="preload" href="${FONT_ASSETS}Lato-700.woff2" as="font" type="font/woff2" crossorigin>
73
+ <style>
74
+
75
+ html {
76
+ --d2l-cursor-resize-inline-end: e-resize;
77
+ --d2l-cursor-resize-inline-start: w-resize;
78
+ --d2l-document-direction: ltr;
79
+ --d2l-inline-end: right;
80
+ --d2l-inline-start: left;
81
+ --d2l-length-factor: 1;
82
+ --d2l-mirror-transform: none;
83
+ --d2l-theme-background-color-base: #ffffff;
84
+ --d2l-theme-text-color-static-standard: #202122;
85
+ font-size: 20px;
86
+ }
87
+
88
+ html[dir="rtl"] * {
89
+ --d2l-cursor-resize-inline-end: w-resize;
90
+ --d2l-cursor-resize-inline-start: e-resize;
91
+ --d2l-document-direction: rtl;
92
+ --d2l-inline-end: left;
93
+ --d2l-inline-start: right;
94
+ --d2l-length-factor: -1;
95
+ --d2l-mirror-transform: scale(-1, 1);
96
+ }
97
+
98
+ html[data-color-mode="dark"] {
99
+ --d2l-theme-background-color-base: #161718;
100
+ --d2l-theme-text-color-static-standard: #cdd5dc;
101
+ }
102
+
103
+ @font-face {
104
+ font-family: 'Lato';
105
+ font-style: normal;
106
+ font-weight: 400;
107
+ src: url(${FONT_ASSETS}Lato-400.woff2) format('woff2');
108
+ }
109
+ @font-face {
110
+ font-family: 'Lato';
111
+ font-style: normal;
112
+ font-weight: 700;
113
+ src: url(${FONT_ASSETS}Lato-700.woff2) format('woff2');
114
+ }
115
+
116
+ body {
117
+ background-color: var(--d2l-theme-background-color-base);
118
+ color: var(--d2l-theme-text-color-static-standard);
119
+ font-family: 'Lato', sans-serif;
120
+ letter-spacing: 0.01rem;
121
+ font-size: 0.95rem;
122
+ font-weight: 400;
123
+ line-height: 1.4rem;
124
+ margin: 0;
125
+ padding: 38px;
126
+ }
127
+ body.no-padding {
128
+ padding: 0;
129
+ }
130
+ </style>
131
+ </head>
132
+ `;
133
+ const DEFAULT_TEST_RUNNER_HTML = testFramework => `<!DOCTYPE html>
134
+ <html lang="en" data-timezone='${TIMEZONE}'>
135
+ ${HTML_BODY(testFramework)}
136
+ </html>`;
137
+ const FULL_TEST_RUNNER_HTML = testFramework => `<!DOCTYPE html>
138
+ <html lang="en" data-timezone='${TIMEZONE}'>
139
+ ${HTML_HEAD}
140
+ ${HTML_BODY(testFramework)}
141
+ </html>`;
62
142
 
63
143
  export class WTRConfig {
64
144
 
@@ -73,77 +153,7 @@ export class WTRConfig {
73
153
  name: 'vdiff',
74
154
  files: this.#pattern,
75
155
  browsers: [BROWSER_MAP.chrome],
76
- testRunnerHtml: testFramework =>
77
- `<!DOCTYPE html>
78
- <html lang="en" data-timezone='${TIMEZONE}'>
79
- <head>
80
- <link rel="preload" href="${FONT_ASSETS}Lato-400.woff2" as="font" type="font/woff2" crossorigin>
81
- <link rel="preload" href="${FONT_ASSETS}Lato-700.woff2" as="font" type="font/woff2" crossorigin>
82
- <style>
83
-
84
- html {
85
- --d2l-cursor-resize-inline-end: e-resize;
86
- --d2l-cursor-resize-inline-start: w-resize;
87
- --d2l-document-direction: ltr;
88
- --d2l-inline-end: right;
89
- --d2l-inline-start: left;
90
- --d2l-length-factor: 1;
91
- --d2l-mirror-transform: none;
92
- --d2l-theme-background-color-base: #ffffff;
93
- --d2l-theme-text-color-static-standard: #202122;
94
- font-size: 20px;
95
- }
96
-
97
- html[dir="rtl"] * {
98
- --d2l-cursor-resize-inline-end: w-resize;
99
- --d2l-cursor-resize-inline-start: e-resize;
100
- --d2l-document-direction: rtl;
101
- --d2l-inline-end: left;
102
- --d2l-inline-start: right;
103
- --d2l-length-factor: -1;
104
- --d2l-mirror-transform: scale(-1, 1);
105
- }
106
-
107
- html[data-color-mode="dark"] {
108
- --d2l-theme-background-color-base: #161718;
109
- --d2l-theme-text-color-static-standard: #cdd5dc;
110
- }
111
-
112
- @font-face {
113
- font-family: 'Lato';
114
- font-style: normal;
115
- font-weight: 400;
116
- src: url(${FONT_ASSETS}Lato-400.woff2) format('woff2');
117
- }
118
- @font-face {
119
- font-family: 'Lato';
120
- font-style: normal;
121
- font-weight: 700;
122
- src: url(${FONT_ASSETS}Lato-700.woff2) format('woff2');
123
- }
124
-
125
- body {
126
- background-color: var(--d2l-theme-background-color-base);
127
- color: var(--d2l-theme-text-color-static-standard);
128
- font-family: 'Lato', sans-serif;
129
- letter-spacing: 0.01rem;
130
- font-size: 0.95rem;
131
- font-weight: 400;
132
- line-height: 1.4rem;
133
- margin: 0;
134
- padding: 38px;
135
- }
136
- body.no-padding {
137
- padding: 0;
138
- }
139
- </style>
140
- </head>
141
- <body>
142
- ${TEST_PAGE}
143
- ${SUPPRESS_RESIZE_OBSERVER_ERRORS}
144
- <script type="module" src="${testFramework}"></script>
145
- </body>
146
- </html>`
156
+ testRunnerHtml: FULL_TEST_RUNNER_HTML
147
157
  };
148
158
  }
149
159
  create({
@@ -169,7 +179,9 @@ export class WTRConfig {
169
179
  };
170
180
 
171
181
  if (!['test', 'vdiff', ...passthroughGroupNames].includes(group)) {
172
- config.groups.push({ name: group, files: this.#pattern });
182
+ const groupConfig = { name: group, files: this.#pattern };
183
+ if (group === 'axe') groupConfig.testRunnerHtml = FULL_TEST_RUNNER_HTML;
184
+ config.groups.push(groupConfig);
173
185
  } else {
174
186
  const groupConfig = config.groups.find(g => g.name === group);
175
187
  if (groupConfig) {
@@ -177,12 +189,6 @@ export class WTRConfig {
177
189
  }
178
190
  }
179
191
 
180
- if (filter) {
181
- config.groups.forEach(group => {
182
- group.files = this.#filterFiles([ group.files ].flat());
183
- });
184
- }
185
-
186
192
  config.reporters ??= [ defaultReporterGrep() ];
187
193
 
188
194
  if (group === 'test') {
@@ -250,15 +256,7 @@ export class WTRConfig {
250
256
  nodeResolve: {
251
257
  exportConditions: ['default']
252
258
  },
253
- testRunnerHtml: testFramework =>
254
- `<!DOCTYPE html>
255
- <html lang="en" data-timezone='${TIMEZONE}'>
256
- <body>
257
- ${TEST_PAGE}
258
- ${SUPPRESS_RESIZE_OBSERVER_ERRORS}
259
- <script type="module" src="${testFramework}"></script>
260
- </body>
261
- </html>`,
259
+ testRunnerHtml: DEFAULT_TEST_RUNNER_HTML,
262
260
  };
263
261
  }
264
262