@brightspace-ui/testing 1.4.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 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
- render() {
263
- return html`<p>I take my time</p>`;
274
+ constructor() {
275
+ super();
276
+ this._loadingCompletePromise = new Promise(
277
+ resolve => this._loadingCompleteResolve = resolve
278
+ );
264
279
  }
265
- async getLoadingComplete() {
266
- return new Promise(resolve => {
267
- setTimeout(() => resolve(), 2000);
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.4.0",
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": "npx d2l-test-runner --files './test/browser/**/*.test.js'",
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": "^3"
57
+ "rollup": "^4"
56
58
  }
57
59
  }
@@ -0,0 +1,7 @@
1
+ import { expect } from '@open-wc/testing';
2
+
3
+ export function runConstructor(nodeName) {
4
+ const ctor = customElements.get(nodeName);
5
+ expect(ctor).to.not.be.undefined;
6
+ document.createElement(nodeName);
7
+ }
@@ -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';