@brightspace-ui/testing 0.29.1 → 0.30.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.
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import commandLineArgs from 'command-line-args';
3
+ import { execSync } from 'node:child_process';
3
4
  import process from 'node:process';
4
5
  import { runner } from '../src/server/cli/test-runner.js';
5
6
 
@@ -21,8 +22,20 @@ if (cli.subcommand === 'vdiff') {
21
22
  } else if (vdiff.subcommand === 'migrate') {
22
23
  const { migrate } = await import('../src/server/cli/vdiff/migrate.js');
23
24
  await migrate.start(vdiff._unknown);
25
+ } else if (vdiff.subcommand === 'migrate-local') {
26
+
27
+ const { pattern = './**' } = commandLineArgs({ name: 'pattern', type: String, defaultOption: true }, { partial: true, argv: vdiff._unknown || [] });
28
+
29
+ stdout.write('\nInstalling @brightspace-ui/visual-diff\n');
30
+ execSync('npm install @brightspace-ui/visual-diff@14 --no-save');
31
+ stdout.write(`\nRunning existing tests for pattern '${pattern}/*.visual-diff.js'\n`);
32
+ execSync(`npx mocha '${pattern}/*.visual-diff.js' -t 10000 --golden`);
33
+ stdout.write('\nTest run complete.\n');
34
+
35
+ const { migrate } = await import('../src/server/cli/vdiff/migrate.js');
36
+ await migrate.start(vdiff._unknown, true);
24
37
  } else {
25
- stdout.write(`\nfatal: unknown subcomamnd: ${vdiff.subcommand}\n`);
38
+ stdout.write(`\nfatal: unknown subcommand: ${vdiff.subcommand}\n`);
26
39
  }
27
40
  } else {
28
41
  runTests();
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.29.1",
5
+ "version": "0.30.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "eslint . --ext .js",
@@ -19,6 +19,13 @@ mocha.setup({
19
19
  });
20
20
  /* eslint-enable */
21
21
 
22
+ function findTarget(elem) {
23
+ if (!elem.shadowRoot) return elem;
24
+ const nestedTarget = elem.shadowRoot.querySelector('.vdiff-target');
25
+ if (!nestedTarget) return elem;
26
+ return findTarget(nestedTarget);
27
+ }
28
+
22
29
  async function ScreenshotAndCompare(opts) {
23
30
 
24
31
  if (window.d2lTest) {
@@ -27,7 +34,11 @@ async function ScreenshotAndCompare(opts) {
27
34
  }
28
35
 
29
36
  const name = this.test.fullTitle();
30
- const rect = this.elem === document ? null : this.elem.getBoundingClientRect();
37
+ let rect = null;
38
+ if (this.elem !== document) {
39
+ const target = findTarget(this.elem);
40
+ rect = target.getBoundingClientRect();
41
+ }
31
42
  const slowDuration = this.test.slow();
32
43
  let result = await executeServerCommand('brightspace-visual-diff-compare', { name, rect, slowDuration, opts });
33
44
  if (result.resizeRequired) {
@@ -163,6 +163,10 @@ async function getTestRunnerOptions(argv = []) {
163
163
  {
164
164
  example: 'vdiff migrate [directory]',
165
165
  desc: 'Migrate from @brightspace-ui/visual-diff. Restrict which goldens are migrated with a directory glob.'
166
+ },
167
+ {
168
+ example: 'vdiff migrate-local [directory]',
169
+ desc: 'Generate goldens with @brightspace-ui/visual-diff for local comparison while migrating tests. Restrict which goldens are generated with a directory glob.'
166
170
  }]
167
171
  }
168
172
  ]);
@@ -6,9 +6,11 @@ import { glob } from 'glob';
6
6
  import { PATHS } from '../../visual-diff-plugin.js';
7
7
  import { stdout } from 'node:process';
8
8
 
9
- async function start(argv = []) {
9
+ async function start(argv = [], local = false) {
10
10
  const { pattern = './**' } = commandLineArgs({ name: 'pattern', type: String, defaultOption: true }, { partial: true, argv });
11
- const oldSuffix = 'screenshots/ci/golden';
11
+ const oldSuffix = local ? 'screenshots/golden' : 'screenshots/ci/golden';
12
+
13
+ stdout.write(`\nMigrating goldens for pattern '${pattern}/${oldSuffix}'\n`);
12
14
  const dirs = await glob(`${pattern}/${oldSuffix}`, { ignore: 'node_modules/**', posix: true });
13
15
  let fileCount = 0;
14
16
 
@@ -30,12 +32,17 @@ async function start(argv = []) {
30
32
  .replace(/^d2l-/, '')
31
33
  .replace(new RegExp(`^${dirName}-`), '');
32
34
 
33
- const newDir = dir.replace(`${oldSuffix}/${dirName}`, `${PATHS.GOLDEN}/${dirName}/chromium`);
35
+ const newDir = local ?
36
+ `${PATHS.VDIFF_ROOT}/${dir.replace(`${oldSuffix}/${dirName}`, `${dirName}/${PATHS.GOLDEN}/chromium`)}` :
37
+ dir.replace(`${oldSuffix}/${dirName}`, `${PATHS.GOLDEN}/${dirName}/chromium`);
34
38
 
35
39
  await mkdir(newDir, { recursive: true });
36
40
  return rename(file, join(newDir, newName));
37
41
  }));
38
- return rm(normalize(join(dir, '..', '..')), { recursive: true });
42
+
43
+ if (!local) {
44
+ return rm(normalize(join(dir, '..', '..')), { recursive: true });
45
+ }
39
46
  }));
40
47
 
41
48
  stdout.write(`\nMigrated ${fileCount} ${fileCount === 1 ? 'golden' : 'goldens'} found in ${dirs.length} test ${dirs.length === 1 ? 'directory' : 'directories'}\n`);
@@ -182,12 +182,14 @@ class App extends LitElement {
182
182
  }
183
183
  _handleNextClick() {
184
184
  this._updateSearchParams(this._next);
185
+ this._scrollToTop();
185
186
  }
186
187
  _handleOverlayChange(e) {
187
188
  this._overlay = e.target.checked;
188
189
  }
189
190
  _handlePrevClick() {
190
191
  this._updateSearchParams(this._prev);
192
+ this._scrollToTop();
191
193
  }
192
194
  _renderError(message, source) {
193
195
  return html`<div class="padding"><p>${message}: <b>${source}</b>.</p></div>`;
@@ -325,7 +327,7 @@ class App extends LitElement {
325
327
  if (tabs.length < 2) return nothing;
326
328
  return renderTabButtons('browser results', tabs, index => {
327
329
  this._selectedBrowserIndex = index;
328
- this.shadowRoot.querySelector('.tab-panels').scrollTo(0, 0);
330
+ this._scrollToTop();
329
331
  this.requestUpdate();
330
332
  });
331
333
  }
@@ -410,6 +412,9 @@ class App extends LitElement {
410
412
  `;
411
413
 
412
414
  }
415
+ _scrollToTop() {
416
+ this.shadowRoot.querySelector('.tab-panels').scrollTo(0, 0);
417
+ }
413
418
  _updateFiles() {
414
419
 
415
420
  const files = [];
@@ -196,6 +196,7 @@ export class WTRConfig {
196
196
  config.groups.forEach(g => g.browsers = this.getBrowsers(g.browsers));
197
197
 
198
198
  if (open || watch) {
199
+ config.testsFinishTimeout = 15 * 60 * 1000;
199
200
  config.plugins ??= [];
200
201
  const currentPattern = files || config.groups.find(g => g.name === group)?.files;
201
202