@brightspace-ui/testing 1.3.0 → 1.5.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 +50 -5
- package/package.json +5 -3
- package/src/browser/constructor.js +7 -0
- package/src/browser/index.js +1 -0
- package/src/server/wtr-config.js +3 -2
package/README.md
CHANGED
|
@@ -65,6 +65,18 @@ it('should have the correct class', async() => {
|
|
|
65
65
|
|
|
66
66
|
Each call to `fixture()` will restore the browser to its default state, making subsequent calls isolated from each other. There's therefore no need to manually restore the viewport, language, mouse, or keyboard in between tests.
|
|
67
67
|
|
|
68
|
+
#### Ensuring Custom Elements Construct
|
|
69
|
+
|
|
70
|
+
The `runConstructor` helper acts as a bare minimum test for a custom element, making sure that it properly registered with `window.customElements` and that its constructor does not fail.
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
import { runConstructor } from '@brightspace-ui/testing';
|
|
74
|
+
|
|
75
|
+
it('should construct', () => {
|
|
76
|
+
runConstructor('my-elem');
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
68
80
|
#### Configuring the Viewport Size
|
|
69
81
|
|
|
70
82
|
The viewport defaults to `800px` wide by `800px` tall. To use different viewport sizes, pass a `viewport` option to `fixture()`.
|
|
@@ -259,14 +271,23 @@ In other scenarios, a component may have an initial loading state (e.g. loading
|
|
|
259
271
|
|
|
260
272
|
```javascript
|
|
261
273
|
class SlowElem extends LitElement {
|
|
262
|
-
|
|
263
|
-
|
|
274
|
+
constructor() {
|
|
275
|
+
super();
|
|
276
|
+
this._loadingCompletePromise = new Promise(
|
|
277
|
+
resolve => this._loadingCompleteResolve = resolve
|
|
278
|
+
);
|
|
264
279
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
280
|
+
connectedCallback() {
|
|
281
|
+
this._fetchMyData().then(() => {
|
|
282
|
+
if (this._loadingCompleteResolve) {
|
|
283
|
+
this._loadingCompleteResolve();
|
|
284
|
+
this._loadingCompleteResolve = undefined;
|
|
285
|
+
}
|
|
268
286
|
});
|
|
269
287
|
}
|
|
288
|
+
async getLoadingComplete() {
|
|
289
|
+
return this._loadingCompletePromise;
|
|
290
|
+
}
|
|
270
291
|
}
|
|
271
292
|
```
|
|
272
293
|
|
|
@@ -522,6 +543,30 @@ const tag = defineCE(
|
|
|
522
543
|
);
|
|
523
544
|
```
|
|
524
545
|
|
|
546
|
+
### Components with Motion
|
|
547
|
+
|
|
548
|
+
Components with animations or transitions can cause inconsistent vdiff snapshots, since small timing variations to the snapshot can catch the motion at slightly different points along its path. To help address this, `d2l-test-runner` configures the browser with the `prefers-reduced-motion` setting enabled.
|
|
549
|
+
|
|
550
|
+
To opt-in to this setting, adjust the component's animation/transition CSS such that it only applies the motion when `prefers-reduced-motion` is set to `no-preference`.
|
|
551
|
+
|
|
552
|
+
For example:
|
|
553
|
+
|
|
554
|
+
```css
|
|
555
|
+
my-elem {
|
|
556
|
+
opacity: 1;
|
|
557
|
+
}
|
|
558
|
+
my-elem.faded-out {
|
|
559
|
+
opacity: 0;
|
|
560
|
+
}
|
|
561
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
562
|
+
my-elem {
|
|
563
|
+
transition: opacity 0.2s ease-in-out;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
In addition to making vdiff testing more reliable, disabling or reducing motion based on the `prefers-reduced-motion` setting is recommended to help avoid discomfort for those with [vestibular motion disorders](https://www.a11yproject.com/posts/understanding-vestibular-disorders/).
|
|
569
|
+
|
|
525
570
|
### Running Vdiff Tests
|
|
526
571
|
|
|
527
572
|
Vdiff tests must be in files with the `*.vdiff.js` extension. They are run with the special `vdiff` command:
|
package/package.json
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
"name": "@brightspace-ui/testing",
|
|
3
3
|
"description": "Utilities for testing front-end components and applications",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.5.0",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/testing.git",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "eslint . --ext .js",
|
|
9
9
|
"start": "npx d2l-test-vdiff-report",
|
|
10
10
|
"test": "npm run lint && npm run test:bin && npm run test:server && npm run test:browser",
|
|
11
11
|
"test:bin": "mocha './test/bin/**/*.test.js'",
|
|
12
|
-
"test:browser": "
|
|
12
|
+
"test:browser": "npm run test:browser:other && npm run test:browser:ctor",
|
|
13
|
+
"test:browser:other": "npx d2l-test-runner --files './test/browser/**/*.test.js'",
|
|
14
|
+
"test:browser:ctor": "npx d2l-test-runner --config ./test/browser/ctor.config.js",
|
|
13
15
|
"test:server": "mocha './test/server/**/*.test.js'",
|
|
14
16
|
"test:vdiff": "npx d2l-test-runner vdiff --config ./test/browser/vdiff.config.js"
|
|
15
17
|
},
|
|
@@ -52,6 +54,6 @@
|
|
|
52
54
|
"page": "^1",
|
|
53
55
|
"pixelmatch": "^5",
|
|
54
56
|
"pngjs": "^7",
|
|
55
|
-
"rollup": "^
|
|
57
|
+
"rollup": "^4"
|
|
56
58
|
}
|
|
57
59
|
}
|
package/src/browser/index.js
CHANGED
|
@@ -3,3 +3,4 @@ import './vdiff.js';
|
|
|
3
3
|
export { assert, aTimeout, defineCE, expect, html, nextFrame, oneDefaultPreventedEvent, oneEvent, waitUntil } from '@open-wc/testing';
|
|
4
4
|
export { clickAt, clickElem, focusElem, hoverAt, hoverElem, sendKeys, sendKeysElem } from './commands.js';
|
|
5
5
|
export { fixture } from './fixture.js';
|
|
6
|
+
export { runConstructor } from './constructor.js';
|
package/src/server/wtr-config.js
CHANGED
|
@@ -14,6 +14,7 @@ const BROWSER_MAP = {
|
|
|
14
14
|
safari: 'webkit',
|
|
15
15
|
webkit: 'webkit'
|
|
16
16
|
};
|
|
17
|
+
const TIMEZONE = '{"name":"Canada - Toronto","identifier":"America/Toronto"}';
|
|
17
18
|
const SUPPRESS_RESIZE_OBSERVER_ERRORS = `
|
|
18
19
|
<script>
|
|
19
20
|
window.addEventListener('error', (err) => {
|
|
@@ -43,7 +44,7 @@ export class WTRConfig {
|
|
|
43
44
|
nodeResolve: true,
|
|
44
45
|
testRunnerHtml: testFramework =>
|
|
45
46
|
`<!DOCTYPE html>
|
|
46
|
-
<html lang="en">
|
|
47
|
+
<html lang="en" data-timezone='${TIMEZONE}'>
|
|
47
48
|
<body>
|
|
48
49
|
${SUPPRESS_RESIZE_OBSERVER_ERRORS}
|
|
49
50
|
<script type="module" src="${testFramework}"></script>
|
|
@@ -69,7 +70,7 @@ export class WTRConfig {
|
|
|
69
70
|
browsers: ['chrome'],
|
|
70
71
|
testRunnerHtml: testFramework =>
|
|
71
72
|
`<!DOCTYPE html>
|
|
72
|
-
<html lang="en">
|
|
73
|
+
<html lang="en" data-timezone='${TIMEZONE}'>
|
|
73
74
|
<head>
|
|
74
75
|
<link rel="preload" href="https://s.brightspace.com/lib/fonts/0.5.0/assets/Lato-400.woff2" as="font" type="font/woff2" crossorigin>
|
|
75
76
|
<link rel="preload" href="https://s.brightspace.com/lib/fonts/0.5.0/assets/Lato-700.woff2" as="font" type="font/woff2" crossorigin>
|