test-inventory 0.8.0 → 0.9.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/README.md +16 -11
  3. package/dist/case-titles.d.ts +9 -0
  4. package/dist/case-titles.js +82 -0
  5. package/dist/cli.d.ts +1 -1
  6. package/dist/cli.js +4 -2
  7. package/dist/config-dependencies.js +19 -0
  8. package/dist/config-runs.d.ts +95 -3
  9. package/dist/config-runs.js +784 -16
  10. package/dist/config.d.ts +24 -0
  11. package/dist/config.js +139 -19
  12. package/dist/diagnostics.js +14 -1
  13. package/dist/extract.d.ts +2 -0
  14. package/dist/extract.js +36 -10
  15. package/dist/files.d.ts +3 -2
  16. package/dist/files.js +52 -8
  17. package/dist/filter.js +1 -0
  18. package/dist/framework-version.d.ts +4 -2
  19. package/dist/framework-version.js +170 -15
  20. package/dist/frameworks/bun.d.ts +44 -0
  21. package/dist/frameworks/bun.js +280 -0
  22. package/dist/frameworks/common.d.ts +3 -1
  23. package/dist/frameworks/common.js +11 -9
  24. package/dist/frameworks/cypress.d.ts +31 -0
  25. package/dist/frameworks/cypress.js +70 -0
  26. package/dist/frameworks/jasmine.d.ts +29 -0
  27. package/dist/frameworks/jasmine.js +228 -0
  28. package/dist/frameworks/jest.js +1 -1
  29. package/dist/frameworks/mocha.d.ts +50 -0
  30. package/dist/frameworks/mocha.js +307 -0
  31. package/dist/frameworks/node.d.ts +30 -0
  32. package/dist/frameworks/node.js +271 -0
  33. package/dist/frameworks/playwright.d.ts +18 -0
  34. package/dist/frameworks/playwright.js +84 -0
  35. package/dist/frameworks/test-functions.d.ts +26 -1
  36. package/dist/frameworks/test-functions.js +73 -22
  37. package/dist/frameworks/vitest.d.ts +9 -1
  38. package/dist/frameworks/vitest.js +36 -5
  39. package/dist/frameworks/webdriverio.d.ts +27 -0
  40. package/dist/frameworks/webdriverio.js +37 -0
  41. package/dist/model.d.ts +4 -0
  42. package/dist/node-scripts.d.ts +11 -0
  43. package/dist/node-scripts.js +136 -0
  44. package/dist/options.d.ts +13 -4
  45. package/dist/options.js +22 -3
  46. package/dist/records.d.ts +10 -2
  47. package/dist/records.js +83 -16
  48. package/dist/resolve.d.ts +27 -4
  49. package/dist/resolve.js +64 -16
  50. package/dist/scan-file.d.ts +8 -0
  51. package/dist/scan-file.js +18 -2
  52. package/dist/scan.js +42 -7
  53. package/dist/toml.d.ts +13 -0
  54. package/dist/toml.js +179 -0
  55. package/dist/types.d.ts +19 -9
  56. package/dist/values.d.ts +5 -0
  57. package/dist/values.js +13 -0
  58. package/dist/yaml.d.ts +13 -0
  59. package/dist/yaml.js +287 -0
  60. package/package.json +13 -6
  61. package/schema/v1.json +26 -6
@@ -0,0 +1,136 @@
1
+ import picomatch from 'picomatch';
2
+ /** Node.js options that take their value as the next argument, so it is not a file to test. */
3
+ const VALUE_OPTIONS = new Set([
4
+ '--allow-fs-read',
5
+ '--allow-fs-write',
6
+ '--conditions',
7
+ '-C',
8
+ '--config-file',
9
+ '--cpu-prof-dir',
10
+ '--cpu-prof-name',
11
+ '--diagnostic-dir',
12
+ '--disable-warning',
13
+ '--dns-result-order',
14
+ '--env-file',
15
+ '--env-file-if-exists',
16
+ '--experimental-config-file',
17
+ '--experimental-loader',
18
+ '--heap-prof-dir',
19
+ '--heap-prof-name',
20
+ '--heapsnapshot-signal',
21
+ '--icu-data-dir',
22
+ '--import',
23
+ '--input-type',
24
+ '--loader',
25
+ '--localstorage-file',
26
+ '--max-http-header-size',
27
+ '--openssl-config',
28
+ '--redirect-warnings',
29
+ '--report-dir',
30
+ '--report-filename',
31
+ '--require',
32
+ '-r',
33
+ '--secure-heap',
34
+ '--secure-heap-min',
35
+ '--test-concurrency',
36
+ '--test-coverage-branches',
37
+ '--test-coverage-exclude',
38
+ '--test-coverage-functions',
39
+ '--test-coverage-include',
40
+ '--test-coverage-lines',
41
+ '--test-global-setup',
42
+ '--test-isolation',
43
+ '--test-name-pattern',
44
+ '--test-random-seed',
45
+ '--test-reporter',
46
+ '--test-reporter-destination',
47
+ '--test-rerun-failures',
48
+ '--test-shard',
49
+ '--test-skip-pattern',
50
+ '--test-timeout',
51
+ '--title',
52
+ '--unhandled-rejections',
53
+ '--watch-kill-signal',
54
+ '--watch-path',
55
+ ]);
56
+ /**
57
+ * The `node --test` commands of a package.json script, each as the files and globs it gives; empty for a command
58
+ * that gives none. A command runs node:test when `--test` comes before any file, as `node build.js --test` passes it on
59
+ * to the script.
60
+ */
61
+ export function nodeTestCommands(script) {
62
+ const commands = [];
63
+ for (const words of commandsOf(script)) {
64
+ const node = words.findIndex((word) => /(^|[/\\])node(\.exe)?$/.test(word));
65
+ if (node === -1)
66
+ continue;
67
+ let runsTests = false;
68
+ const files = [];
69
+ for (let index = node + 1; index < words.length; index++) {
70
+ const word = words[index];
71
+ if (word === '--test')
72
+ runsTests = true;
73
+ else if (VALUE_OPTIONS.has(word))
74
+ index++;
75
+ else if (!word.startsWith('-')) {
76
+ if (!runsTests)
77
+ break;
78
+ files.push(word);
79
+ }
80
+ }
81
+ if (runsTests)
82
+ commands.push(files);
83
+ }
84
+ return commands;
85
+ }
86
+ /** The commands of a script, each as its words, without quotes. */
87
+ function commandsOf(script) {
88
+ return script
89
+ .split(/&&|\|\||[;|]/)
90
+ .map((command) => [...command.matchAll(/'([^']*)'|"([^"]*)"|(\S+)/g)].map((match) => match[1] ?? match[2] ?? match[3]));
91
+ }
92
+ /**
93
+ * A package.json script and those it runs in turn, each once: through `npm run`, `npm test`, `pnpm`, `yarn`,
94
+ * `bun run`, or `npm-run-all`, `run-s` and `run-p`, whose names may be globs where `*` stops at a `:`.
95
+ */
96
+ export function scriptsRunBy(scripts, name) {
97
+ const names = Object.keys(scripts).filter((key) => typeof scripts[key] === 'string');
98
+ const run = [];
99
+ const visit = (current) => {
100
+ if (run.includes(current) || !names.includes(current))
101
+ return;
102
+ run.push(current);
103
+ for (const words of commandsOf(scripts[current])) {
104
+ for (const called of calledScripts(words, names))
105
+ visit(called);
106
+ }
107
+ };
108
+ visit(name);
109
+ return run.map((key) => scripts[key]);
110
+ }
111
+ const NPM_RUN = new Set(['run', 'run-script', 'rum', 'urn']);
112
+ const NPM_TEST = new Set(['test', 't', 'tst']);
113
+ /** The scripts a command runs; a word that names no script, as `pnpm install`, runs none. */
114
+ function calledScripts(words, names) {
115
+ // Variables set before the command, as in `TZ=UTC npm test` or `cross-env TZ=UTC npm test`, don't change it.
116
+ let start = 0;
117
+ while (start < words.length && (/^\w+=/.test(words[start]) || words[start] === 'cross-env'))
118
+ start++;
119
+ const [tool = '', ...rest] = words.slice(start);
120
+ const end = rest.indexOf('--');
121
+ const args = (end === -1 ? rest : rest.slice(0, end)).filter((word) => !word.startsWith('-'));
122
+ const [first = '', second = ''] = args;
123
+ if (['npm-run-all', 'run-s', 'run-p'].includes(tool)) {
124
+ // As npm-run-all 4 and npm-run-all2 9 match names: `:` and `/` swapped, no `!` negation, no dot names for `*`.
125
+ const swap = (text) => text.replaceAll(/[:/]/g, (char) => (char === ':' ? '/' : ':'));
126
+ const matches = picomatch(args.map(swap), { nonegate: true });
127
+ return names.filter((key) => matches(swap(key)));
128
+ }
129
+ if (tool === 'npm')
130
+ return NPM_RUN.has(first) ? [second] : NPM_TEST.has(first) ? ['test'] : [];
131
+ if (tool === 'bun')
132
+ return first === 'run' ? [second] : [];
133
+ if (tool === 'pnpm' || tool === 'yarn')
134
+ return first === 'run' ? [second] : [first];
135
+ return [];
136
+ }
package/dist/options.d.ts CHANGED
@@ -4,13 +4,16 @@ export type { CommentsMode };
4
4
  /** @inline */
5
5
  export interface ScanOptions {
6
6
  /**
7
- * Glob patterns for the test files, relative to `root`. As in Playwright and Vitest, they match names that start with
8
- * a dot too. Without them, the test files are those the configs in the root and the folders below it run.
7
+ * Glob patterns for the test files, relative to `root`. As in the runners, they match names that start with a dot
8
+ * too. Without them, the test files are those the configs in the root and the folders below it run, or for node:test
9
+ * and Bun those `node --test` and `bun test` run.
9
10
  */
10
11
  patterns?: string[];
11
12
  /**
12
- * The runner whose tests are listed. Without it, the one the project uses: whose package a package.json lists, or
13
- * whose config is in the root or below. With none of them or several, the scan throws a `TypeError` that names them.
13
+ * The runner whose tests are listed. Without it, the one the project uses: whose package a package.json in the root
14
+ * or below lists, whose config is there, or for node:test and Bun, run by a package.json script, else one a
15
+ * package.json above the root lists. With none of them or
16
+ * several, the scan throws a `TypeError` that names them.
14
17
  */
15
18
  framework?: Framework;
16
19
  /** The project root. Paths in the output are relative to it. Defaults to the current directory. */
@@ -26,6 +29,11 @@ export interface ScanOptions {
26
29
  * out, each with the title the runner gives it. Defaults to `false`: one record per declaration.
27
30
  */
28
31
  expandCases?: boolean;
32
+ /**
33
+ * Stops the scan when it aborts: the scan checks it before it starts and between files, and then rejects with the
34
+ * signal's `reason`, as `fetch` does.
35
+ */
36
+ signal?: AbortSignal;
29
37
  }
30
38
  /** @inline */
31
39
  export interface ScanSourceOptions {
@@ -51,6 +59,7 @@ export declare function checkObject(value: unknown, name: string): Record<string
51
59
  export declare function checkFramework(value: unknown, option: string): Framework;
52
60
  export declare function checkComments(value: unknown, option: string): CommentsMode;
53
61
  export declare function checkFlag(value: unknown, option: string): boolean;
62
+ export declare function checkSignal(value: unknown, option: string): AbortSignal | null;
54
63
  export declare function checkVersion(value: unknown, option: string): string | null;
55
64
  export declare function checkString(value: unknown, option: string): string;
56
65
  export declare function checkStrings(value: unknown, option: string, required: boolean): string[];
package/dist/options.js CHANGED
@@ -1,4 +1,14 @@
1
- const FRAMEWORKS = ['playwright', 'vitest', 'jest'];
1
+ const FRAMEWORKS = [
2
+ 'playwright',
3
+ 'vitest',
4
+ 'jest',
5
+ 'mocha',
6
+ 'jasmine',
7
+ 'cypress',
8
+ 'webdriverio',
9
+ 'node',
10
+ 'bun',
11
+ ];
2
12
  const COMMENTS = ['all', 'non-active', 'none'];
3
13
  // A prerelease and build metadata each appear once, so a long input can't make the match backtrack for long.
4
14
  const VERSION = /^v?(\d+)\.(\d+)(?:\.\d+)?(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
@@ -14,8 +24,10 @@ export function checkObject(value, name) {
14
24
  return value;
15
25
  }
16
26
  export function checkFramework(value, option) {
17
- if (!FRAMEWORKS.includes(value))
18
- throw invalid(option, '"playwright", "vitest" or "jest"');
27
+ if (!FRAMEWORKS.includes(value)) {
28
+ const names = FRAMEWORKS.map((name) => `"${name}"`);
29
+ throw invalid(option, `${names.slice(0, -1).join(', ')} or ${names.at(-1)}`);
30
+ }
19
31
  return value;
20
32
  }
21
33
  export function checkComments(value, option) {
@@ -32,6 +44,13 @@ export function checkFlag(value, option) {
32
44
  throw invalid(option, 'true or false');
33
45
  return value;
34
46
  }
47
+ export function checkSignal(value, option) {
48
+ if (value === undefined)
49
+ return null;
50
+ if (!(value instanceof AbortSignal))
51
+ throw invalid(option, 'an AbortSignal');
52
+ return value;
53
+ }
35
54
  export function checkVersion(value, option) {
36
55
  if (value === undefined || value === null)
37
56
  return null;
package/dist/records.d.ts CHANGED
@@ -52,8 +52,14 @@ export interface VitestTags {
52
52
  }
53
53
  /** What the config the file uses gives it. */
54
54
  export interface FileConfig {
55
- /** Whether a `.only` fails the run: Playwright's `forbidOnly`, always, never, or under the condition with this text. */
56
- forbidOnly: boolean | string;
55
+ /**
56
+ * Why a `.only` fails, from Playwright's `forbidOnly` or Vitest's `allowOnly`, and whether it surely does; null when
57
+ * it doesn't.
58
+ */
59
+ forbidOnly: {
60
+ message: string;
61
+ isSure: boolean;
62
+ } | null;
57
63
  /** The names of the projects that run a test, null when unknown, and what they set for it. */
58
64
  forTest(test: TestRecord, suites: SuiteRecord[]): {
59
65
  projects: string[] | null;
@@ -67,6 +73,8 @@ export interface FileConfig {
67
73
  interface RecordOptions {
68
74
  relativeFilePath: string;
69
75
  framework: Framework;
76
+ /** Jasmine's focus rules apply: for Jasmine, and for WebdriverIO on Jasmine. */
77
+ focusesLikeJasmine: boolean;
70
78
  comments: CommentsMode;
71
79
  isTypeTest: boolean;
72
80
  /** A Vitest 5 benchmark file, such as `*.bench.ts`. */
package/dist/records.js CHANGED
@@ -3,6 +3,22 @@ import { anySlow, eitherCondition, noHooks, } from "./extract.js";
3
3
  import { problem } from "./frameworks/common.js";
4
4
  import { hashNodes, shortHash } from "./hash.js";
5
5
  import { snippet } from "./source.js";
6
+ /**
7
+ * The states of a describe that win over those of the describes inside it and of the test itself: node:test creates
8
+ * nothing inside a skipped describe, and in Bun the outermost skipped or todo describe decides (checked with Node.js
9
+ * 26.12.1 and Bun 1.2.23, 1.3.14 and 1.4.4). Elsewhere the state nearest the test wins.
10
+ */
11
+ const OVERRIDING_DESCRIBES = {
12
+ playwright: [],
13
+ vitest: [],
14
+ jest: [],
15
+ mocha: [],
16
+ jasmine: [],
17
+ cypress: [],
18
+ webdriverio: [],
19
+ node: ['skip'],
20
+ bun: ['skip', 'todo'],
21
+ };
6
22
  /**
7
23
  * The state the runner applies, from the candidates nearest the test first. An unconditional skip, fixme or todo wins
8
24
  * over an unconditional expected failure, since the test doesn't run, and one set while the file loads wins over one
@@ -184,11 +200,16 @@ class RecordBuilder {
184
200
  fileName;
185
201
  ordinals = new Map();
186
202
  suiteIds = new Map();
203
+ testIds = new Map();
187
204
  diagnostics = [];
188
205
  /** The line of the first problem for which the runner refuses the file; null when it loads. */
189
206
  rejectedAt = null;
207
+ /** Whether the tests declared before the line that stops the file loading still run. */
208
+ keepsEarlierTests = false;
190
209
  /** Jest: the describes with a test of their own that uses `.only`, which then keep their mode from their others. */
191
210
  focused = new Set();
211
+ /** Jasmine: scopes with a focused spec or describe below them, whose own focus Jasmine gives up for the inner one. */
212
+ focusedBelow = new Set();
192
213
  constructor(parsed, options) {
193
214
  this.parsed = parsed;
194
215
  this.options = options;
@@ -215,7 +236,14 @@ class RecordBuilder {
215
236
  const lines = [...rejecting, ...(firstTag ? [firstTag] : [])].map((item) => this.parsed.source.line(item.node.start));
216
237
  if (lines.length > 0)
217
238
  this.rejectedAt = Math.min(...lines);
239
+ this.keepsEarlierTests = rejecting.length > 0 && rejecting.every((item) => item.keepsEarlierTests === true);
218
240
  this.focused = new Set(extraction.tests.filter((test) => test.declaration.isOnly).map((test) => test.scope));
241
+ const focusedAt = [
242
+ ...extraction.tests.filter((test) => test.declaration.isOnly).map((test) => test.scope),
243
+ // A describe's scope is inside the file's, so it has a parent.
244
+ ...extraction.suites.filter((suite) => suite.declaration.isOnly).map((suite) => suite.scope.parent),
245
+ ];
246
+ this.focusedBelow = new Set(focusedAt.flatMap((scope) => outward(scope)));
219
247
  const suites = extraction.suites.map((suite) => this.suite(suite));
220
248
  const tests = extraction.tests.map((test) => this.test(test, suites));
221
249
  for (const item of problems) {
@@ -265,15 +293,12 @@ class RecordBuilder {
265
293
  * warning. `call` is the `.only` call when it is in this file, whose callee the diagnostic shows.
266
294
  */
267
295
  forbidOnly(located, call) {
268
- const forbid = this.options.config?.forbidOnly ?? false;
269
- if (forbid === false)
296
+ const forbid = this.options.config?.forbidOnly ?? null;
297
+ if (forbid === null)
270
298
  return;
271
- const message = forbid === true
272
- ? 'The config sets forbidOnly, so this .only fails the run before any test runs.'
273
- : `The config sets forbidOnly when ${forbid}, so then this .only fails the run before any test runs.`;
274
299
  const callee = call && snippet(this.parsed.source.text.slice(call.callee.start, call.callee.end));
275
- const found = problem('forbidden-only', located, message, callee);
276
- this.diagnostics.push(this.diagnostic(forbid === true ? found : { ...found, level: 'warning' }));
300
+ const found = problem('forbidden-only', located, forbid.message, callee);
301
+ this.diagnostics.push(this.diagnostic(forbid.isSure ? found : { ...found, level: 'warning' }));
277
302
  }
278
303
  suite(pending) {
279
304
  const { scope, declaration, call } = pending;
@@ -366,6 +391,17 @@ class RecordBuilder {
366
391
  const setting = own('skip') ?? own('todo') ?? own('expectedToFail');
367
392
  return { chosen: setting ? { setting, source: 'test' } : null, isOnly: declaration.isOnly || passesOnly };
368
393
  }
394
+ /**
395
+ * Where Jasmine's focus on a spec sits, as an index into its `scopes`, from the innermost: -1 for a `fit`, the
396
+ * `fdescribe` around it with no focused spec or describe below, as Jasmine runs only the innermost focus, or null
397
+ * when the spec isn't focused (checked with Jasmine 4.6.0 and 7.0.0).
398
+ */
399
+ jasmineFocus(pending, scopes) {
400
+ if (pending.declaration.isOnly)
401
+ return -1;
402
+ const nearest = scopes.findIndex((scope) => scope.isOnly);
403
+ return nearest !== -1 && !this.focusedBelow.has(scopes[nearest]) ? nearest : null;
404
+ }
369
405
  test(pending, suites) {
370
406
  const { declaration } = pending;
371
407
  const dependencies = this.options.dependencies(pending);
@@ -374,7 +410,14 @@ class RecordBuilder {
374
410
  const scopes = outward(pending.scope);
375
411
  const describes = scopes.filter((scope) => scope.kind === 'describe').reverse();
376
412
  const title = declaration.title;
377
- const id = this.id([this.describeTitles(describes), title.withoutTags]);
413
+ const parents = [];
414
+ for (let parent = pending.parent; parent; parent = parent.parent)
415
+ parents.unshift(parent);
416
+ const parentTitles = parents.map((parent) => parent.declaration.title.withoutTags);
417
+ const id = this.id(parents.length > 0
418
+ ? [this.describeTitles(describes), parentTitles, title.withoutTags]
419
+ : [this.describeTitles(describes), title.withoutTags]);
420
+ this.testIds.set(pending, id);
378
421
  const fileScope = scopes[scopes.length - 1];
379
422
  const tags = unique([
380
423
  ...(this.options.config?.configTags ?? []),
@@ -387,21 +430,42 @@ class RecordBuilder {
387
430
  const tagsFirst = this.options.config?.tags?.beatsDescribes ?? true;
388
431
  const tagged = (own, tag, around) => tagsFirst ? [...own, ...tag, ...around] : [...own, ...around, ...tag];
389
432
  const jest = this.options.framework === 'jest' ? this.jestState(pending, scopes) : null;
433
+ const focus = this.options.focusesLikeJasmine ? this.jasmineFocus(pending, scopes) : undefined;
434
+ // A focus inside an `xdescribe` runs, as the describe's own skip doesn't reach it; `pending()` still does. An
435
+ // `xdescribe` inside the focus stays skipped.
436
+ const declaredSkip = (scope, index, setting) => typeof focus === 'number' &&
437
+ index > focus &&
438
+ scope.kind === 'describe' &&
439
+ suiteOf(scope).declaration.states.includes(setting);
440
+ const overriding = OVERRIDING_DESCRIBES[this.options.framework];
441
+ const around = scopes.flatMap((scope, index) => scope.states
442
+ .filter((setting) => !declaredSkip(scope, index, setting))
443
+ .map((setting) => ({
444
+ setting,
445
+ source: scope.kind === 'file' ? 'file' : 'suite',
446
+ overrides: overriding.includes(setting.state) &&
447
+ scope.kind === 'describe' &&
448
+ suiteOf(scope).declaration.states.includes(setting),
449
+ })));
390
450
  const chosen = jest
391
451
  ? jest.chosen
392
452
  : chooseState([
453
+ // Outermost first, as the outermost of them decides.
454
+ ...around.filter((candidate) => candidate.overrides).reverse(),
393
455
  ...declaredStates(pending.states.slice(0, declaration.states.length), fromTags, declaration),
394
456
  ...pending.states.slice(declaration.states.length).map((setting) => ({ setting, source: 'test' })),
395
- ...scopes.flatMap((scope) => scope.states.map((setting) => ({
396
- setting,
397
- source: scope.kind === 'file' ? 'file' : 'suite',
398
- }))),
457
+ // A test the declaration skips never runs its body, so its subtests never run; one its body skips still runs it.
458
+ ...parents.flatMap((parent) => parent.declaration.states.map((setting) => ({ setting, source: 'suite' }))),
459
+ ...around.filter((candidate) => !candidate.overrides),
399
460
  ]);
400
- // When the runner refuses the file, no test in it runs, whatever else is written.
401
- const rejected = this.rejectedAt !== null;
461
+ // When the runner refuses the file, no test in it runs, whatever else is written, or none after the refused call.
462
+ const rejected = this.rejectedAt !== null && !(this.keepsEarlierTests && this.parsed.source.line(located.start) < this.rejectedAt);
402
463
  const state = rejected ? 'notLoaded' : (chosen?.setting.state ?? 'active');
403
464
  const setting = rejected ? null : (chosen?.setting ?? null);
404
- const suitePath = describes.flatMap((scope) => suiteOf(scope).declaration.title?.text ?? []);
465
+ const suitePath = [
466
+ ...describes.flatMap((scope) => suiteOf(scope).declaration.title?.text ?? []),
467
+ ...parents.map((parent) => parent.declaration.title.text),
468
+ ];
405
469
  const tagConcurrent = this.options.config?.tags?.concurrentBeatsTags ? undefined : fromTags?.concurrent;
406
470
  const tagMode = tagConcurrent === undefined ? null : tagConcurrent ? 'parallel' : 'default';
407
471
  const [mode = null] = tagged([declaration.mode], [tagMode], scopes.map((scope) => scope.mode)).filter((item) => item !== null);
@@ -411,7 +475,9 @@ class RecordBuilder {
411
475
  }
412
476
  const isOnly = jest
413
477
  ? jest.isOnly
414
- : declaration.isOnly || scopes.some((scope) => scope.isOnly) || fromTags?.only === true;
478
+ : focus !== undefined
479
+ ? focus !== null
480
+ : declaration.isOnly || scopes.some((scope) => scope.isOnly) || fromTags?.only === true;
415
481
  const comments = this.options.comments === 'all' || (this.options.comments === 'non-active' && state !== 'active')
416
482
  ? pending.comments
417
483
  : [];
@@ -442,6 +508,7 @@ class RecordBuilder {
442
508
  dependencies: dependencies.files,
443
509
  hasUnfollowedDependencies: !dependencies.isComplete,
444
510
  suiteId: describes.length > 0 ? this.suiteIds.get(describes[describes.length - 1]) : null,
511
+ parentTestId: pending.parent ? this.testIds.get(pending.parent) : null,
445
512
  suitePath,
446
513
  relativeFilePath: this.options.relativeFilePath,
447
514
  fileName: this.fileName,
package/dist/resolve.d.ts CHANGED
@@ -2,8 +2,31 @@ import type { ModuleReader } from './model.ts';
2
2
  /** Parses JSON written with comments and trailing commas, as tsconfig files often are; null when it isn't JSON. */
3
3
  export declare function parseJsonc(text: string): unknown;
4
4
  /**
5
- * Returns a reader for the modules a test file imports. It follows relative paths, tsconfig `paths` and `baseUrl` from
6
- * the tsconfig nearest the importing file, package.json `imports` (`#name`), and workspace packages whose entry is
7
- * TypeScript source. Each module it reads carries a reader for the modules that module imports in turn.
5
+ * How a runner's config maps imports, for every module a test imports: aliases, tried first, as Vite's
6
+ * `resolve.alias` and Jest's `moduleNameMapper`, and folders a bare name is looked for in, as Jest's `modulePaths` and
7
+ * `moduleDirectories`.
8
8
  */
9
- export declare function moduleResolver(root: string): (fromFile: string) => ModuleReader;
9
+ export interface ImportMap {
10
+ /**
11
+ * A string `find` maps the name itself and the names below it, as `@` maps `@/x`; a regex maps what it matches, as
12
+ * Vite does, or with `replacesName`, as Jest's `moduleNameMapper` does, the whole name, with `$1` for its groups.
13
+ */
14
+ aliases: {
15
+ find: string | RegExp;
16
+ replacements: string[];
17
+ replacesName: boolean;
18
+ }[];
19
+ /** Folders a bare name is looked for in. */
20
+ paths: string[];
21
+ /** Names of folders a bare name is looked for in, in the importing file's folder and each folder above it. */
22
+ directories: string[];
23
+ /** Vite's root, from which it takes an alias's path that starts with `/` first; null for Jest. */
24
+ root: string | null;
25
+ }
26
+ /**
27
+ * Returns a reader for the modules a test file imports. It follows the import map of the config the file runs with,
28
+ * relative paths, tsconfig `paths` and `baseUrl` from the tsconfig nearest the importing file, package.json `imports`
29
+ * (`#name`), and workspace packages whose entry is TypeScript source. Each module it reads carries a reader for the
30
+ * modules that module imports in turn, with the same import map.
31
+ */
32
+ export declare function moduleResolver(root: string): (fromFile: string, map?: ImportMap | null) => ModuleReader;
package/dist/resolve.js CHANGED
@@ -323,13 +323,40 @@ function workspaceSource(specifier, directory, packagesOf) {
323
323
  const local = packagesOf(directory).get(name);
324
324
  return local ? packageEntry(local, subpath) : null;
325
325
  }
326
+ /** A file a bare name stands for in the folders an import map adds; null when none has it. */
327
+ function searched(specifier, directory, map) {
328
+ const folders = [...map.paths];
329
+ for (let folder = directory;; folder = path.dirname(folder)) {
330
+ folders.push(...map.directories.map((name) => path.join(folder, name)));
331
+ if (path.dirname(folder) === folder)
332
+ break;
333
+ }
334
+ return folders.map((folder) => findFile(path.join(folder, specifier))).find((file) => file !== null) ?? null;
335
+ }
336
+ /** The names an alias maps a specifier to; null when it doesn't match. */
337
+ function mapped(specifier, alias) {
338
+ const { find, replacements, replacesName } = alias;
339
+ if (typeof find === 'string') {
340
+ if (specifier !== find && !specifier.startsWith(`${find}/`))
341
+ return null;
342
+ return replacements.map((replacement) => replacement + specifier.slice(find.length));
343
+ }
344
+ const match = specifier.match(find);
345
+ if (!match)
346
+ return null;
347
+ if (!replacesName)
348
+ return replacements.map((replacement) => specifier.replace(find, replacement));
349
+ // Jest fills in a group that matched nothing with an empty string.
350
+ return replacements.map((replacement) => replacement.replaceAll(/\$(\d+)/g, (_, index) => match[Number(index)] || ''));
351
+ }
326
352
  /**
327
- * Returns a reader for the modules a test file imports. It follows relative paths, tsconfig `paths` and `baseUrl` from
328
- * the tsconfig nearest the importing file, package.json `imports` (`#name`), and workspace packages whose entry is
329
- * TypeScript source. Each module it reads carries a reader for the modules that module imports in turn.
353
+ * Returns a reader for the modules a test file imports. It follows the import map of the config the file runs with,
354
+ * relative paths, tsconfig `paths` and `baseUrl` from the tsconfig nearest the importing file, package.json `imports`
355
+ * (`#name`), and workspace packages whose entry is TypeScript source. Each module it reads carries a reader for the
356
+ * modules that module imports in turn, with the same import map.
330
357
  */
331
358
  export function moduleResolver(root) {
332
- // Many test files import the same fixtures file and share a tsconfig; each is read once.
359
+ // Many test files import the same fixtures file and share a tsconfig; each is read once per import map.
333
360
  const modules = new Map();
334
361
  const tsconfigs = new Map();
335
362
  const pathOptions = new Map();
@@ -362,11 +389,11 @@ export function moduleResolver(root) {
362
389
  workspaces.set(folder, packages);
363
390
  return packages;
364
391
  };
365
- const reader = (fromFile) => (specifier) => {
366
- const directory = path.dirname(fromFile);
392
+ /** The file a name stands for from a folder, or why it can't be followed. */
393
+ const locate = (specifier, directory, map) => {
367
394
  let candidates;
368
395
  // `.` and `..` are paths too: the index of the file's folder, or of the folder above.
369
- if (/^\.\.?(?:\/|$)/.test(specifier)) {
396
+ if (/^\.\.?(?:\/|$)/.test(specifier) || path.isAbsolute(specifier)) {
370
397
  candidates = [path.resolve(directory, specifier)];
371
398
  }
372
399
  else if (specifier.startsWith('#')) {
@@ -388,29 +415,50 @@ export function moduleResolver(root) {
388
415
  const workspace = fromBaseUrl ? null : workspaceSource(specifier, directory, packagesOf);
389
416
  if (workspace && 'reason' in workspace)
390
417
  return workspace;
391
- const file = fromBaseUrl ?? workspace?.file;
418
+ const file = fromBaseUrl ?? workspace?.file ?? (map && searched(specifier, directory, map));
392
419
  // No package name starts with `@/` or `~/`, so these are aliases, as Vite's `resolve.alias` sets them; any
393
420
  // other name with no file may still be a package or a built-in module, as TypeScript takes it to be.
394
421
  if (!file && /^[@~]\//.test(specifier)) {
395
- return { reason: targets ? 'could not be read' : 'is a path alias that no tsconfig paths define' };
422
+ return { reason: targets ? 'could not be read' : 'is a path alias that no tsconfig paths or config define' };
396
423
  }
397
424
  if (!file)
398
425
  return { reason: 'is not a local file, a path alias or a workspace package' };
399
426
  candidates = [file];
400
427
  }
401
428
  }
402
- const found = candidates.map(findFile).find((file) => file !== null);
403
- if (!found)
404
- return { reason: 'could not be read' };
405
- if (!modules.has(found)) {
429
+ return candidates.map(findFile).find((file) => file !== null) ?? { reason: 'could not be read' };
430
+ };
431
+ // A path a config gives is absolute, as with `path.resolve()` or `<rootDir>`; output paths are relative to the root.
432
+ const shown = (name) => (path.isAbsolute(name) ? path.relative(root, name).replaceAll('\\', '/') : name);
433
+ const reader = (fromFile, map = null) => (specifier) => {
434
+ const directory = path.dirname(fromFile);
435
+ const aliased = map?.aliases.map((alias) => mapped(specifier, alias)).find((names) => names !== null);
436
+ // Vite takes `/src/x` from its root first, unless it is already a path inside the root.
437
+ const fromRoot = (name) => map?.root && name.startsWith('/') && !name.startsWith(map.root + path.sep)
438
+ ? [path.join(map.root, name), name]
439
+ : [name];
440
+ // The config maps the name to others, each a path or a name looked up as written, the first that is found.
441
+ const located = (aliased?.flatMap(fromRoot) ?? [specifier]).map((name) => locate(name, directory, map));
442
+ const found = located.find((item) => typeof item === 'string');
443
+ if (found === undefined) {
444
+ return aliased
445
+ ? { reason: `is mapped by the config to ${aliased.map(shown).join(' or ')}, which could not be read` }
446
+ : located[0];
447
+ }
448
+ let known = modules.get(map);
449
+ if (!known) {
450
+ known = new Map();
451
+ modules.set(map, known);
452
+ }
453
+ if (!known.has(found)) {
406
454
  const content = readContent(found);
407
- modules.set(found, content && {
455
+ known.set(found, content && {
408
456
  ...content,
409
457
  relativeFilePath: path.relative(root, found).replaceAll('\\', '/'),
410
- readModule: reader(found),
458
+ readModule: reader(found, map),
411
459
  });
412
460
  }
413
- return modules.get(found) ?? { reason: 'could not be read' };
461
+ return known.get(found) ?? { reason: 'could not be read' };
414
462
  };
415
463
  return reader;
416
464
  }
@@ -1,6 +1,8 @@
1
1
  import type { RunsWith } from './config-dependencies.ts';
2
2
  import { DependencyGraph, type SnapshotFiles } from './dependency-hash.ts';
3
3
  import { ExportedValues } from './imported-values.ts';
4
+ import { type MochaInterface } from './frameworks/mocha.ts';
5
+ import { type WebdriverIOFramework } from './frameworks/webdriverio.ts';
4
6
  import type { ModuleReader } from './model.ts';
5
7
  import { type CommentsMode, type FileConfig, type FileRecords } from './records.ts';
6
8
  import type { Framework } from './types.ts';
@@ -18,6 +20,12 @@ export interface FileSettings {
18
20
  isBenchmarkFile?: boolean | null;
19
21
  /** What the config the file uses sets for its tests; null without a config. */
20
22
  config?: FileConfig | null;
23
+ /** The interface Mocha's config sets for the tests: `describe` and `it`, or `suite` and `test`. */
24
+ mochaInterface?: MochaInterface;
25
+ /** The length Vitest's config shortens a value in a case title to; Vitest's default, 40, when unset. */
26
+ titleTruncate?: number;
27
+ /** The framework a WebdriverIO config runs the specs with. */
28
+ webdriverioFramework?: WebdriverIOFramework;
21
29
  /** Shared by the files of one scan, so that code many tests reach is read once. */
22
30
  graph?: DependencyGraph;
23
31
  /** Shared by the files of one scan, so that each module's exported values are worked out once. */
package/dist/scan-file.js CHANGED
@@ -7,6 +7,12 @@ import { atLeast, problem } from "./frameworks/common.js";
7
7
  import { PlaywrightAdapter } from "./frameworks/playwright.js";
8
8
  import { VitestAdapter } from "./frameworks/vitest.js";
9
9
  import { JestAdapter } from "./frameworks/jest.js";
10
+ import { MochaAdapter } from "./frameworks/mocha.js";
11
+ import { BunAdapter } from "./frameworks/bun.js";
12
+ import { CypressAdapter } from "./frameworks/cypress.js";
13
+ import { NodeAdapter } from "./frameworks/node.js";
14
+ import { WebdriverIOJasmineAdapter, WebdriverIOMochaAdapter, } from "./frameworks/webdriverio.js";
15
+ import { JasmineAdapter } from "./frameworks/jasmine.js";
10
16
  import { parseFile } from "./parse.js";
11
17
  import { buildRecords, fileRecord } from "./records.js";
12
18
  import { snippet } from "./source.js";
@@ -15,14 +21,22 @@ const TYPE_TEST = /\.(test|spec)-d\.[cm]?[jt]sx?$/;
15
21
  const BENCHMARK = /\.(bench|benchmark)\.[cm]?[jt]sx?$/;
16
22
  const ADAPTERS = {
17
23
  playwright: (parsed, file, readModule) => new PlaywrightAdapter(parsed.program, file, readModule),
18
- vitest: (parsed, file, readModule) => new VitestAdapter(parsed, file, readModule),
24
+ vitest: (parsed, file, readModule, settings) => new VitestAdapter(parsed, file, readModule, settings.titleTruncate),
19
25
  jest: (parsed, file, readModule) => new JestAdapter(parsed, file, readModule),
26
+ mocha: (parsed, file, readModule, settings) => new MochaAdapter(parsed, file, readModule, settings.mochaInterface),
27
+ jasmine: (parsed, file, readModule) => new JasmineAdapter(parsed, file, readModule),
28
+ cypress: (parsed, file, readModule) => new CypressAdapter(parsed, file, readModule),
29
+ webdriverio: (parsed, file, readModule, settings) => settings.webdriverioFramework === 'jasmine'
30
+ ? new WebdriverIOJasmineAdapter(parsed, file, readModule)
31
+ : new WebdriverIOMochaAdapter(parsed, file, readModule, settings.mochaInterface),
32
+ node: (parsed, file, readModule) => new NodeAdapter(parsed, file, readModule),
33
+ bun: (parsed, file, readModule) => new BunAdapter(parsed, file, readModule),
20
34
  };
21
35
  /** A file read for the scan: the scanned file, or a module a helper function is imported from. */
22
36
  function frame(parsed, relativeFilePath, settings, readModule, exports) {
23
37
  const values = new Values(exports.reader(readModule));
24
38
  const file = { source: parsed.source, values, version: settings.version };
25
- const adapter = ADAPTERS[settings.framework](parsed, file, readModule);
39
+ const adapter = ADAPTERS[settings.framework](parsed, file, readModule, settings);
26
40
  return { parsed, adapter, values: file.values, readModule, relativeFilePath };
27
41
  }
28
42
  /** The records of a file the scan read no tests from. */
@@ -53,6 +67,8 @@ export function scanFile(code, relativeFilePath, settings) {
53
67
  const records = buildRecords(extraction, parsed, {
54
68
  relativeFilePath,
55
69
  framework: settings.framework,
70
+ focusesLikeJasmine: settings.framework === 'jasmine' ||
71
+ (settings.framework === 'webdriverio' && settings.webdriverioFramework === 'jasmine'),
56
72
  comments: settings.comments,
57
73
  isTypeTest,
58
74
  // Vitest 5's default `benchmark.include`, when no config says.