@brightspace-ui/testing 1.42.0 → 1.44.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/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.42.0",
5
+ "version": "1.44.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "npm run lint:eslint && npm run lint:style",
@@ -29,7 +29,7 @@
29
29
  "eslint-config-brightspace": "^3",
30
30
  "globals": "^17",
31
31
  "mocha": "^11",
32
- "sinon": "^21",
32
+ "sinon": "^22",
33
33
  "stylelint": "^17"
34
34
  },
35
35
  "exports": {
@@ -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 });
@@ -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);
@@ -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