@brightspace-ui/testing 0.28.0 → 0.29.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
@@ -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.28.0",
5
+ "version": "0.29.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "eslint . --ext .js",
@@ -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) {
@@ -195,11 +195,14 @@ export function renderBrowserResults(browser, tests, options) {
195
195
  return acc;
196
196
  }
197
197
 
198
- let status = STATUS_TYPE.WARNING;
199
- if (resultData.duration > resultData.info.slowDuration) {
200
- status = STATUS_TYPE.ERROR;
201
- } else if (resultData.duration < (resultData.info.slowDuration / 2)) {
202
- status = STATUS_TYPE.NORMAL;
198
+ let status = STATUS_TYPE.NORMAL;
199
+ if (resultData.info) {
200
+ status = STATUS_TYPE.WARNING;
201
+ if (resultData.duration > resultData.info.slowDuration) {
202
+ status = STATUS_TYPE.ERROR;
203
+ } else if (resultData.duration < (resultData.info.slowDuration / 2)) {
204
+ status = STATUS_TYPE.NORMAL;
205
+ }
203
206
  }
204
207
 
205
208
  return acc.push(html`
@@ -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
- clip: {
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
- path: updateGoldens ? goldenFileName : screenshotFileName
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 };
@@ -70,6 +70,11 @@ function flattenResults(session, browserData, fileData) {
70
70
  tests.forEach(t => {
71
71
  const testName = `${prefix}${t.name}`;
72
72
  const testKey = testName.replaceAll(' > ', ' ');
73
+ const info = getTestInfo(session, testKey);
74
+
75
+ // tests missing info but with no error were skipped via grep, so exclude them
76
+ if (!info && !t.error) return;
77
+
73
78
  if (!fileData.tests.has(testName)) {
74
79
  fileData.tests.set(testName, {
75
80
  name: testName,
@@ -87,7 +92,7 @@ function flattenResults(session, browserData, fileData) {
87
92
  duration: t.duration,
88
93
  error: t.error?.message,
89
94
  passed: t.passed,
90
- info: getTestInfo(session, testKey)
95
+ info: info
91
96
  });
92
97
  });
93
98
  }