@brightspace-ui/testing 1.18.0 → 1.20.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
@@ -4,7 +4,7 @@
4
4
 
5
5
  Testing utilities which are specifically designed and configured for Brightspace UI components and applications.
6
6
 
7
- > **Migrating from `@open-wc/testing` and/or `@brightspace-ui/visual-diff`?**
7
+ > **Migrating from `@open-wc/testing`/`@web/test-runner`?**
8
8
  > Refer to the [Migration Guide](docs/migration-guide.md) for help migrating a repo to `@brightspace-ui/testing`.
9
9
 
10
10
  Install from NPM:
@@ -479,6 +479,7 @@ Vdiff tests are written [just like other tests](#writing-tests), and the same ut
479
479
  Use the asynchronous `.to.be.golden()` Chai assertion to take a vdiff snapshot and [compare it against its golden](#generating-the-goldens).
480
480
 
481
481
  ```javascript
482
+ import './my-elem.js';
482
483
  import { fixture, html } from '@brightspace-ui/testing';
483
484
 
484
485
  describe('my-elem', () => {
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import commandLineArgs from 'command-line-args';
3
- import { execSync } from 'node:child_process';
4
3
  import process from 'node:process';
5
4
  import { runner } from '../src/server/cli/test-runner.js';
6
5
 
@@ -19,21 +18,6 @@ if (cli.subcommand === 'vdiff') {
19
18
  } else if (vdiff.subcommand === 'report') {
20
19
  const { report } = await import('../src/server/cli/vdiff/report.js');
21
20
  await report.start();
22
- } else if (vdiff.subcommand === 'migrate') {
23
- const { migrate } = await import('../src/server/cli/vdiff/migrate.js');
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);
37
21
  } else {
38
22
  stdout.write(`\nfatal: unknown subcommand: ${vdiff.subcommand}\n`);
39
23
  }
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.18.0",
5
+ "version": "1.20.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "npm run lint:eslint && npm run lint:style",
@@ -120,13 +120,6 @@ async function getTestRunnerOptions(argv = []) {
120
120
  type: Boolean,
121
121
  description: 'Run tests in Webkit',
122
122
  order: 4
123
- },
124
- {
125
- name: 'test-reporting',
126
- type: Boolean,
127
- defaultOption: false,
128
- description: 'Enables generating a D2L Test Reporting format JSON file',
129
- order: 14
130
123
  }
131
124
  ];
132
125
 
@@ -166,14 +159,6 @@ async function getTestRunnerOptions(argv = []) {
166
159
  {
167
160
  example: 'vdiff golden',
168
161
  desc: 'Generate new golden screenshots'
169
- },
170
- {
171
- example: 'vdiff migrate [directory]',
172
- desc: 'Migrate from @brightspace-ui/visual-diff. Restrict which goldens are migrated with a directory glob.'
173
- },
174
- {
175
- example: 'vdiff migrate-local [directory]',
176
- desc: 'Generate goldens with @brightspace-ui/visual-diff for local comparison while migrating tests. Restrict which goldens are generated with a directory glob.'
177
162
  }]
178
163
  }
179
164
  ]);
@@ -1,4 +1,5 @@
1
1
  import { defaultReporter } from '@web/test-runner';
2
+ import { env } from 'node:process';
2
3
  import { headedMode } from './headed-mode-plugin.js';
3
4
  import { playwrightLauncher } from '@web/test-runner-playwright';
4
5
  import { reporter as testReportingReporter } from 'd2l-test-reporting/reporters/web-test-runner.js';
@@ -6,6 +7,7 @@ import { visualDiff } from './visual-diff-plugin.js';
6
7
  import { visualDiffReporter } from './visual-diff-reporter.js';
7
8
 
8
9
  const DEFAULT_PATTERN = type => `./test/**/*.${type}.js`;
10
+ const DEFAULT_TEST_REPORTING = !!env['CI'];
9
11
  const BROWSER_MAP = {
10
12
  chrome: 'chromium',
11
13
  chromium: 'chromium',
@@ -182,7 +184,7 @@ export class WTRConfig {
182
184
  pattern = DEFAULT_PATTERN,
183
185
  slow,
184
186
  timeout,
185
- testReporting,
187
+ testReporting = DEFAULT_TEST_REPORTING,
186
188
  ...passthroughConfig
187
189
  } = {}) {
188
190
 
@@ -215,8 +217,6 @@ export class WTRConfig {
215
217
  });
216
218
  }
217
219
 
218
- testReporting = !!testReporting || this.#cliArgs['test-reporting'];
219
-
220
220
  if (group === 'vdiff' || testReporting) {
221
221
  config.reporters ??= [ defaultReporter() ];
222
222
  }
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env node
2
- import { appendFile, mkdir, readFile, rename, rm } from 'node:fs/promises';
3
- import { join, normalize, parse } from 'node:path';
4
- import commandLineArgs from 'command-line-args';
5
- import { glob } from 'glob';
6
- import { PATHS } from '../../paths.js';
7
- import { stdout } from 'node:process';
8
-
9
- async function start(argv = [], local = false) {
10
- const { pattern = './**' } = commandLineArgs({ name: 'pattern', type: String, defaultOption: true }, { partial: true, argv });
11
- const oldSuffix = local ? 'screenshots/golden' : 'screenshots/ci/golden';
12
-
13
- stdout.write(`\nMigrating goldens for pattern '${pattern}/${oldSuffix}'\n`);
14
- const dirs = await glob(`${pattern}/${oldSuffix}`, { ignore: 'node_modules/**', posix: true });
15
- let fileCount = 0;
16
-
17
- const gitignore = await readFile('.gitignore', { encoding: 'UTF8' }).catch(() => '');
18
- if (!new RegExp(`${PATHS.VDIFF_ROOT}/(\n|$)`).test(gitignore)) {
19
- const newline = gitignore.endsWith('\n') ? '' : '\n';
20
- await appendFile('.gitignore', `${newline}${PATHS.VDIFF_ROOT}/\n`);
21
- }
22
-
23
- await Promise.all(dirs.map(async dir => {
24
- const files = await glob(`${dir}/*/*.png`, { posix: true });
25
-
26
- await Promise.all(files.map(async file => {
27
- fileCount += 1;
28
- const { base: name, dir } = parse(file);
29
- const dirName = parse(dir).name;
30
-
31
- const newName = name
32
- .replace(/^d2l-/, '')
33
- .replace(new RegExp(`^${dirName}-`), '');
34
-
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`);
38
-
39
- await mkdir(newDir, { recursive: true });
40
- return rename(file, join(newDir, newName));
41
- }));
42
-
43
- if (!local) {
44
- return rm(normalize(join(dir, '..', '..')), { recursive: true });
45
- }
46
- }));
47
-
48
- stdout.write(`\nMigrated ${fileCount} ${fileCount === 1 ? 'golden' : 'goldens'} found in ${dirs.length} test ${dirs.length === 1 ? 'directory' : 'directories'}\n`);
49
- }
50
-
51
- export const migrate = {
52
- start
53
- };