@brightspace-ui/testing 1.12.2 → 1.13.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.12.2",
5
+ "version": "1.13.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "eslint . --ext .js",
@@ -21,9 +21,9 @@
21
21
  "author": "D2L Corporation",
22
22
  "license": "Apache-2.0",
23
23
  "devDependencies": {
24
- "chai": "^4",
24
+ "chai": "^5",
25
25
  "eslint": "^8",
26
- "eslint-config-brightspace": "^0.23",
26
+ "eslint-config-brightspace": "^1",
27
27
  "mocha": "^10",
28
28
  "sinon": "^17"
29
29
  },
@@ -177,7 +177,7 @@ function renderResult(resultData, options) {
177
177
  newPart = html`<div class="result-graphic padding">${ICON_TADA}<p>Hooray! No changes here.</p></div>`;
178
178
  } else if (!resultData.info.diff && resultData.info.pixelsDiff === 0) {
179
179
  newPart = html`<div class="result-graphic padding">${ICON_BYTES}
180
- <p>No pixels have changed, but the byte size is different.</p>
180
+ <p>No pixels have changed, but the bytes are different.</p>
181
181
  <p class="details">
182
182
  Golden size: ${resultData.info.golden.byteSize} bytes<br />
183
183
  New size: ${resultData.info.new.byteSize} bytes
@@ -1,10 +1,11 @@
1
+ import { cwd } from 'node:process';
1
2
  import { rollupPluginHTML as html } from '@web/rollup-plugin-html';
2
3
  import { join } from 'path';
3
4
  import { nodeResolve } from '@rollup/plugin-node-resolve';
4
5
  import { PATHS } from './visual-diff-plugin.js';
5
6
 
6
7
  export default {
7
- input: join(PATHS.VDIFF_ROOT, PATHS.REPORT_ROOT, './temp/index.html'),
8
+ input: join(cwd(), PATHS.VDIFF_ROOT, PATHS.REPORT_ROOT, './temp/index.html'),
8
9
  output: {
9
10
  dir: join(PATHS.VDIFF_ROOT, PATHS.REPORT_ROOT)
10
11
  },
@@ -197,7 +197,8 @@ export function visualDiff({ updateGoldens = false, runSubset = false } = {}) {
197
197
 
198
198
  const rootLength = join(rootDir, PATHS.VDIFF_ROOT).length + 1;
199
199
 
200
- const screenshotImage = PNG.sync.read(await readFile(screenshotFileName));
200
+ const screenshotFileBuffer = await readFile(screenshotFileName);
201
+ const screenshotImage = PNG.sync.read(screenshotFileBuffer);
201
202
  setTestInfo(session, payload.name, {
202
203
  slowDuration: payload.slowDuration,
203
204
  new: {
@@ -217,7 +218,8 @@ export function visualDiff({ updateGoldens = false, runSubset = false } = {}) {
217
218
  return { pass: false, message: 'No golden exists. Use the "--golden" CLI flag to re-run and re-generate goldens.' };
218
219
  }
219
220
 
220
- const goldenImage = PNG.sync.read(await readFile(goldenFileName));
221
+ const goldenFileBuffer = await readFile(goldenFileName);
222
+ const goldenImage = PNG.sync.read(goldenFileBuffer);
221
223
  setTestInfo(session, payload.name, {
222
224
  golden: {
223
225
  height: goldenImage.height,
@@ -227,6 +229,14 @@ export function visualDiff({ updateGoldens = false, runSubset = false } = {}) {
227
229
  });
228
230
 
229
231
  if (screenshotImage.width === goldenImage.width && screenshotImage.height === goldenImage.height) {
232
+ const goldenSize = (await stat(goldenFileName)).size;
233
+ const screenshotSize = (await stat(screenshotFileName)).size;
234
+ if (goldenSize === screenshotSize && screenshotFileBuffer.equals(goldenFileBuffer)) {
235
+ const success = await tryMoveFile(screenshotFileName, passFileName);
236
+ if (!success) return { pass: false, message: 'Problem moving file to "pass" directory.' };
237
+ return { pass: true };
238
+ }
239
+
230
240
  const diff = new PNG({ width: screenshotImage.width, height: screenshotImage.height });
231
241
  const pixelsDiff = pixelmatch(
232
242
  screenshotImage.data, goldenImage.data, diff.data, screenshotImage.width, screenshotImage.height, { diffMask: true, threshold: DEFAULT_TOLERANCE }
@@ -243,25 +253,17 @@ export function visualDiff({ updateGoldens = false, runSubset = false } = {}) {
243
253
  await writeFile(`${screenshotFile}-diff.png`, PNG.sync.write(diff));
244
254
  return { pass: false, message: `Image does not match golden. ${pixelsDiff} pixels are different.` };
245
255
  } else {
246
- const goldenSize = (await stat(goldenFileName)).size;
247
- const screenshotSize = (await stat(screenshotFileName)).size;
248
- if (goldenSize !== screenshotSize) {
249
- setTestInfo(session, payload.name, {
250
- golden: {
251
- byteSize: goldenSize
252
- },
253
- new: {
254
- path: `${screenshotFile.substring(rootLength)}.png`,
255
- byteSize: screenshotSize
256
- },
257
- pixelsDiff
258
- });
259
- return { pass: false, message: 'Image diff is clean but the images do not have the same byte size.' };
260
- } else {
261
- const success = await tryMoveFile(screenshotFileName, passFileName);
262
- if (!success) return { pass: false, message: 'Problem moving file to "pass" directory.' };
263
- return { pass: true };
264
- }
256
+ setTestInfo(session, payload.name, {
257
+ golden: {
258
+ byteSize: goldenSize
259
+ },
260
+ new: {
261
+ path: `${screenshotFile.substring(rootLength)}.png`,
262
+ byteSize: screenshotSize
263
+ },
264
+ pixelsDiff
265
+ });
266
+ return { pass: false, message: 'Image diff is clean but the images do not have the same bytes.' };
265
267
  }
266
268
  } else {
267
269
  return { resizeRequired: true };