@brightspace-ui/testing 0.28.1 → 0.29.1
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 +15 -0
- package/package.json +3 -3
- package/src/browser/vdiff.js +1 -1
- package/src/server/visual-diff-plugin.js +12 -7
package/README.md
CHANGED
|
@@ -335,6 +335,21 @@ describe('my-elem', () => {
|
|
|
335
335
|
|
|
336
336
|
The filename and location of the resulting image will be based on the suite names and test name.
|
|
337
337
|
|
|
338
|
+
Sometimes you might be writing tests to verify a component's position within the whole viewport. For snapshots of the whole page, set up your components and pass `document` to the assertion:
|
|
339
|
+
|
|
340
|
+
```javascript
|
|
341
|
+
import { fixture, html } from '@brightspace-ui/testing';
|
|
342
|
+
|
|
343
|
+
describe('my-elem', () => {
|
|
344
|
+
describe('situation1', () => {
|
|
345
|
+
it('state1', async() => {
|
|
346
|
+
await fixture(html`<my-dialog opened></my-dialog>`);
|
|
347
|
+
await expect(document).to.be.golden();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
```
|
|
352
|
+
|
|
338
353
|
#### Configuring the Snapshot Area
|
|
339
354
|
|
|
340
355
|
By default, the snapshot area will be a rectangle around the source element plus a `10px` buffer margin on each side. To use a different margin, pass it as an option:
|
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": "0.
|
|
5
|
+
"version": "0.29.1",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/testing.git",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "eslint . --ext .js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"test:bin": "mocha './test/bin/**/*.test.js'",
|
|
12
12
|
"test:browser": "npx d2l-test-runner --files './test/browser/**/*.test.js'",
|
|
13
13
|
"test:server": "mocha './test/server/**/*.test.js'",
|
|
14
|
-
"test:vdiff": "npx d2l-test-runner --config ./test/browser/vdiff.config.js
|
|
14
|
+
"test:vdiff": "npx d2l-test-runner vdiff --config ./test/browser/vdiff.config.js"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
17
|
"d2l-test-runner": "./bin/d2l-test-runner.js",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
"author": "D2L Corporation",
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@web/dev-server": "^0.2",
|
|
24
23
|
"chai": "^4",
|
|
25
24
|
"eslint": "^8",
|
|
26
25
|
"eslint-config-brightspace": "^0.23",
|
|
@@ -40,6 +39,7 @@
|
|
|
40
39
|
"@rollup/plugin-node-resolve": "^15",
|
|
41
40
|
"@open-wc/testing": "^3",
|
|
42
41
|
"@web/config-loader": "^0.2",
|
|
42
|
+
"@web/dev-server": "^0.2",
|
|
43
43
|
"@web/rollup-plugin-html": "^2",
|
|
44
44
|
"@web/test-runner": "^0.16",
|
|
45
45
|
"@web/test-runner-commands": "^0.7",
|
package/src/browser/vdiff.js
CHANGED
|
@@ -27,7 +27,7 @@ async function ScreenshotAndCompare(opts) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const name = this.test.fullTitle();
|
|
30
|
-
const rect = this.elem.getBoundingClientRect();
|
|
30
|
+
const rect = this.elem === document ? null : this.elem.getBoundingClientRect();
|
|
31
31
|
const slowDuration = this.test.slow();
|
|
32
32
|
let result = await executeServerCommand('brightspace-visual-diff-compare', { name, rect, slowDuration, opts });
|
|
33
33
|
if (result.resizeRequired) {
|
|
@@ -182,18 +182,23 @@ export function visualDiff({ updateGoldens = false, runSubset = false } = {}) {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
const opts = { margin: DEFAULT_MARGIN, ...payload.opts };
|
|
185
|
-
|
|
186
|
-
const page = session.browser.getPage(session.id);
|
|
187
|
-
await page.screenshot({
|
|
185
|
+
const screenshotOpts = {
|
|
188
186
|
animations: 'disabled',
|
|
189
|
-
|
|
187
|
+
path: updateGoldens ? goldenFileName : screenshotFileName
|
|
188
|
+
};
|
|
189
|
+
if (!payload.rect) {
|
|
190
|
+
screenshotOpts.fullPage = true;
|
|
191
|
+
} else {
|
|
192
|
+
screenshotOpts.clip = {
|
|
190
193
|
x: payload.rect.x - opts.margin,
|
|
191
194
|
y: payload.rect.y - opts.margin,
|
|
192
195
|
width: payload.rect.width + (opts.margin * 2),
|
|
193
196
|
height: payload.rect.height + (opts.margin * 2)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const page = session.browser.getPage(session.id);
|
|
201
|
+
await page.screenshot(screenshotOpts);
|
|
197
202
|
|
|
198
203
|
if (updateGoldens) {
|
|
199
204
|
return { pass: true };
|