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
package/dist/scan.js CHANGED
@@ -3,15 +3,16 @@ import { readFile } from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import { glob } from 'tinyglobby';
5
5
  import { ConfigDependencies } from "./config-dependencies.js";
6
- import { ConfigRuns, fileConfig } from "./config-runs.js";
6
+ import { ConfigRuns, fileConfig, importMap, mochaInterface, webdriverioFramework, webdriverioInterface, } from "./config-runs.js";
7
7
  import { Configs, settingAt } from "./config.js";
8
+ import { atLeast } from "./frameworks/common.js";
8
9
  import { DependencyGraph } from "./dependency-hash.js";
9
10
  import { ExportedValues } from "./imported-values.js";
10
11
  import { fileDiagnostic } from "./diagnostics.js";
11
12
  import { findFiles, normalizePattern, readFailure } from "./files.js";
12
13
  import { detectFramework, detectFrameworkVersion, FRAMEWORK_NAMES, OLDEST } from "./framework-version.js";
13
14
  import { createInventory } from "./inventory.js";
14
- import { checkComments, checkFlag, checkFramework, checkObject, checkStrings, checkVersion, invalid, majorMinor, toPosixPath, } from "./options.js";
15
+ import { checkComments, checkFlag, checkFramework, checkObject, checkSignal, checkStrings, checkVersion, invalid, majorMinor, toPosixPath, } from "./options.js";
15
16
  import { moduleResolver } from "./resolve.js";
16
17
  import { noRecords, scanFile } from "./scan-file.js";
17
18
  import { globalsCheck } from "./vitest-config.js";
@@ -23,12 +24,17 @@ function versionDiagnostics(framework, version, source, range) {
23
24
  ];
24
25
  }
25
26
  const [major, minor] = majorMinor(version);
26
- const [oldestMajor, oldestMinor] = OLDEST[framework];
27
+ const patch = Number(/^v?\d+\.\d+\.(\d+)/.exec(version)?.[1] ?? 0);
28
+ const [oldestMajor, oldestMinor, oldestPatch = 0] = OLDEST[framework];
29
+ const oldest = OLDEST[framework].join('.');
27
30
  // A range gets the newest rules of its major, so only its major has to be supported.
28
- const tooOld = major < oldestMajor || (major === oldestMajor && minor < oldestMinor && range === null);
31
+ const tooOld = major < oldestMajor ||
32
+ (major === oldestMajor &&
33
+ range === null &&
34
+ (minor < oldestMinor || (minor === oldestMinor && patch < oldestPatch)));
29
35
  if (tooOld) {
30
36
  return [
31
- fileDiagnostic('unsupported-framework-version', source, `${name} ${version} is older than ${oldestMajor}.${oldestMinor}, the oldest supported version; the results follow ${oldestMajor}.${oldestMinor}.`),
37
+ fileDiagnostic('unsupported-framework-version', source, `${name} ${version} is older than ${oldest}, the oldest supported version; the results follow ${oldest}.`),
32
38
  ];
33
39
  }
34
40
  if (range === null)
@@ -37,6 +43,18 @@ function versionDiagnostics(framework, version, source, range) {
37
43
  fileDiagnostic('approximate-framework-version', source, `Only the range "${range}" was found for ${name}, so the rules of the newest ${major}.x release apply.`),
38
44
  ];
39
45
  }
46
+ /**
47
+ * The length Vitest shortens a value in a case title to: `test.taskTitleValueFormatTruncate` from Vitest 5,
48
+ * `test.chaiConfig.truncateThreshold` before, from the project that runs the file; 40, Vitest's default, when it sets
49
+ * none or the scan can't read it.
50
+ */
51
+ function titleTruncate(placement, version) {
52
+ const key = atLeast(version, 5, 0)
53
+ ? ['test', 'taskTitleValueFormatTruncate']
54
+ : ['test', 'chaiConfig', 'truncateThreshold'];
55
+ const setting = placement.settings && settingAt(placement.settings, key);
56
+ return setting?.kind === 'value' && typeof setting.value === 'number' ? setting.value : 40;
57
+ }
40
58
  /** Why Jest gives a file that uses its globals none: a project that runs it sets `injectGlobals` to false. */
41
59
  function jestGlobals(placement) {
42
60
  const off = placement.projects?.find(({ settings }) => {
@@ -111,6 +129,9 @@ function noFiles(root, patterns, framework, placements) {
111
129
  if ([...placements.values()].some((placement) => placement.config)) {
112
130
  return 'No test files were found from the configs in the root.';
113
131
  }
132
+ if (framework === 'node') {
133
+ return "No patterns were given, and no file in the root matches what node --test runs: Node.js's default patterns, or the files a package.json script gives it.";
134
+ }
114
135
  const name = FRAMEWORK_NAMES[framework];
115
136
  return `No patterns were given, and no ${name} config is in the root or a folder below it, so there are no test files to find.`;
116
137
  }
@@ -127,6 +148,8 @@ export async function scan(options) {
127
148
  const comments = checkComments(checked.comments, 'options.comments');
128
149
  const expandCases = checkFlag(checked.expandCases, 'options.expandCases');
129
150
  const override = checkVersion(checked.frameworkVersion, 'options.frameworkVersion');
151
+ const signal = checkSignal(checked.signal, 'options.signal');
152
+ signal?.throwIfAborted();
130
153
  if (checked.root !== undefined && (typeof checked.root !== 'string' || checked.root === '')) {
131
154
  throw invalid('options.root', 'a non-empty string');
132
155
  }
@@ -138,6 +161,7 @@ export async function scan(options) {
138
161
  : checkFramework(checked.framework, 'options.framework');
139
162
  // Without patterns, the configs choose among all JavaScript and TypeScript files.
140
163
  const found = await findFiles(root, patterns ?? [SCRIPT_FILES], ignore, framework);
164
+ signal?.throwIfAborted();
141
165
  const scanned = found.files.map((file) => file.relativeFilePath);
142
166
  const detected = override === null ? detectFrameworkVersion(root, framework, scanned) : null;
143
167
  const frameworkVersion = override ?? detected?.version ?? null;
@@ -186,6 +210,7 @@ export async function scan(options) {
186
210
  const results = [];
187
211
  const globalsFiles = [];
188
212
  for (const { absolutePath, relativeFilePath } of files) {
213
+ signal?.throwIfAborted();
189
214
  const placement = placements.get(absolutePath);
190
215
  if (placement.config)
191
216
  configs.use(placement.config);
@@ -211,10 +236,17 @@ export async function scan(options) {
211
236
  version: rules,
212
237
  comments,
213
238
  expandCases,
214
- readModule: readerFor(absolutePath),
239
+ readModule: readerFor(absolutePath, importMap(placement, framework)),
215
240
  root,
216
241
  isBenchmarkFile: placement.runs === null ? null : placement.runs === 'benchmark',
217
242
  config: fileConfig(placement, framework, rules, absolutePath),
243
+ mochaInterface: framework === 'mocha'
244
+ ? mochaInterface(placement, configs)
245
+ : framework === 'webdriverio'
246
+ ? webdriverioInterface(placement, configs)
247
+ : undefined,
248
+ webdriverioFramework: framework === 'webdriverio' ? webdriverioFramework(placement, configs) : undefined,
249
+ titleTruncate: framework === 'vitest' ? titleTruncate(placement, rules) : undefined,
218
250
  graph,
219
251
  exports,
220
252
  runsWith,
@@ -229,9 +261,12 @@ export async function scan(options) {
229
261
  }
230
262
  results.push({ ...result, file: { ...result.file, config } });
231
263
  }
264
+ // Mocha, Jasmine, Cypress, WebdriverIO and Bun always set their globals, and Playwright and node:test have none.
232
265
  const missingGlobals = framework === 'jest'
233
266
  ? (file) => jestGlobals(placements.get(file))
234
- : globalsCheck(root, configs, (file) => placements.get(file));
267
+ : ['mocha', 'jasmine', 'cypress', 'webdriverio', 'node', 'bun'].includes(framework)
268
+ ? () => null
269
+ : globalsCheck(root, configs, (file) => placements.get(file));
235
270
  let globals = null;
236
271
  for (const { absolutePath, relativeFilePath } of globalsFiles) {
237
272
  const message = missingGlobals(absolutePath);
package/dist/toml.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { Value } from './values.ts';
2
+ /** A line of TOML the reader doesn't take, with its line number. */
3
+ export declare class TomlError extends Error {
4
+ readonly line: number;
5
+ constructor(message: string, line: number);
6
+ }
7
+ type Table = Record<string, Value>;
8
+ /**
9
+ * The part of TOML a `bunfig.toml` uses: tables and dotted keys, strings, numbers, booleans, arrays over several lines,
10
+ * inline tables and comments. Dates and arrays of tables are refused with a `TomlError`.
11
+ */
12
+ export declare function readToml(text: string): Table;
13
+ export {};
package/dist/toml.js ADDED
@@ -0,0 +1,179 @@
1
+ /** A line of TOML the reader doesn't take, with its line number. */
2
+ export class TomlError extends Error {
3
+ line;
4
+ constructor(message, line) {
5
+ super(message);
6
+ this.line = line;
7
+ }
8
+ }
9
+ /**
10
+ * A table without a prototype, so keys such as `__proto__` and `constructor` are its own, as in Bun, and a project's
11
+ * `bunfig.toml` can't reach `Object.prototype`, which every later scan in the process would see.
12
+ */
13
+ function newTable() {
14
+ return Object.create(null);
15
+ }
16
+ /**
17
+ * The part of TOML a `bunfig.toml` uses: tables and dotted keys, strings, numbers, booleans, arrays over several lines,
18
+ * inline tables and comments. Dates and arrays of tables are refused with a `TomlError`.
19
+ */
20
+ export function readToml(text) {
21
+ const root = newTable();
22
+ let table = root;
23
+ const reader = { text, at: 0, line: 1 };
24
+ for (;;) {
25
+ skipBlank(reader, true);
26
+ if (reader.at >= text.length)
27
+ return root;
28
+ if (text[reader.at] === '[') {
29
+ if (text[reader.at + 1] === '[')
30
+ throw new TomlError('Arrays of tables are not read', reader.line);
31
+ reader.at++;
32
+ const keys = readKeys(reader, ']');
33
+ reader.at++;
34
+ table = tableAt(root, keys, reader.line);
35
+ }
36
+ else {
37
+ const keys = readKeys(reader, '=');
38
+ reader.at++;
39
+ skipBlank(reader, false);
40
+ const value = readValue(reader);
41
+ const owner = tableAt(table, keys.slice(0, -1), reader.line);
42
+ owner[keys[keys.length - 1]] = value;
43
+ }
44
+ skipBlank(reader, false);
45
+ if (reader.at < text.length && text[reader.at] !== '\n') {
46
+ throw new TomlError(`Unexpected "${text[reader.at]}"`, reader.line);
47
+ }
48
+ }
49
+ }
50
+ /** Skips spaces and comments, and line breaks too when `lines` is set. */
51
+ function skipBlank(reader, lines) {
52
+ const { text } = reader;
53
+ while (reader.at < text.length) {
54
+ const char = text[reader.at];
55
+ if (char === '#') {
56
+ while (reader.at < text.length && text[reader.at] !== '\n')
57
+ reader.at++;
58
+ }
59
+ else if (char === ' ' || char === '\t' || char === '\r') {
60
+ reader.at++;
61
+ }
62
+ else if (char === '\n' && lines) {
63
+ reader.line++;
64
+ reader.at++;
65
+ }
66
+ else {
67
+ return;
68
+ }
69
+ }
70
+ }
71
+ /** A dotted key, bare or quoted, up to `end`. */
72
+ function readKeys(reader, end) {
73
+ const keys = [];
74
+ for (;;) {
75
+ skipBlank(reader, false);
76
+ const char = reader.text[reader.at];
77
+ if (char === '"' || char === "'")
78
+ keys.push(readString(reader));
79
+ else {
80
+ const bare = /^[A-Za-z0-9_-]+/.exec(reader.text.slice(reader.at));
81
+ if (!bare)
82
+ throw new TomlError('Expected a key', reader.line);
83
+ keys.push(bare[0]);
84
+ reader.at += bare[0].length;
85
+ }
86
+ skipBlank(reader, false);
87
+ if (reader.text[reader.at] === end)
88
+ return keys;
89
+ if (reader.text[reader.at] !== '.')
90
+ throw new TomlError(`Expected "${end}"`, reader.line);
91
+ reader.at++;
92
+ }
93
+ }
94
+ function tableAt(root, keys, line) {
95
+ let table = root;
96
+ for (const key of keys) {
97
+ table[key] ??= newTable();
98
+ const next = table[key];
99
+ if (typeof next !== 'object' || Array.isArray(next)) {
100
+ throw new TomlError(`${key} is not a table`, line);
101
+ }
102
+ table = next;
103
+ }
104
+ return table;
105
+ }
106
+ function readValue(reader) {
107
+ const { text } = reader;
108
+ const char = text[reader.at];
109
+ if (char === '"' || char === "'")
110
+ return readString(reader);
111
+ if (char === '[') {
112
+ reader.at++;
113
+ const items = [];
114
+ for (;;) {
115
+ skipBlank(reader, true);
116
+ if (text[reader.at] === ']')
117
+ break;
118
+ items.push(readValue(reader));
119
+ skipBlank(reader, true);
120
+ if (text[reader.at] === ',')
121
+ reader.at++;
122
+ else if (text[reader.at] !== ']')
123
+ throw new TomlError('Expected "," or "]"', reader.line);
124
+ }
125
+ reader.at++;
126
+ return items;
127
+ }
128
+ if (char === '{') {
129
+ reader.at++;
130
+ const table = newTable();
131
+ skipBlank(reader, false);
132
+ while (text[reader.at] !== '}') {
133
+ const keys = readKeys(reader, '=');
134
+ reader.at++;
135
+ skipBlank(reader, false);
136
+ tableAt(table, keys.slice(0, -1), reader.line)[keys[keys.length - 1]] = readValue(reader);
137
+ skipBlank(reader, false);
138
+ if (text[reader.at] === ',')
139
+ reader.at++;
140
+ skipBlank(reader, false);
141
+ }
142
+ reader.at++;
143
+ return table;
144
+ }
145
+ const word = /^[^\s,\]}#]+/.exec(text.slice(reader.at))?.[0] ?? '';
146
+ reader.at += word.length;
147
+ if (word === 'true' || word === 'false')
148
+ return word === 'true';
149
+ const number = word.replaceAll('_', '');
150
+ if (/^[+-]?(\d+(\.\d+)?([eE][+-]?\d+)?|inf|nan)$/.test(number)) {
151
+ return number.endsWith('inf') ? (number.startsWith('-') ? -Infinity : Infinity) : Number(number);
152
+ }
153
+ throw new TomlError(`Value ${word || text[reader.at]} is not read`, reader.line);
154
+ }
155
+ /** A basic string, with escapes, or a literal one; one line each. */
156
+ function readString(reader) {
157
+ const { text } = reader;
158
+ const quote = text[reader.at++];
159
+ let value = '';
160
+ while (text[reader.at] !== quote) {
161
+ const char = text[reader.at];
162
+ if (reader.at >= text.length || char === '\n')
163
+ throw new TomlError('The string is not closed', reader.line);
164
+ if (char === '\\' && quote === '"') {
165
+ const escape = text[reader.at + 1];
166
+ const escapes = { n: '\n', t: '\t', r: '\r', '"': '"', '\\': '\\' };
167
+ if (!(escape in escapes))
168
+ throw new TomlError(`Escape \\${escape} is not read`, reader.line);
169
+ value += escapes[escape];
170
+ reader.at += 2;
171
+ }
172
+ else {
173
+ value += char;
174
+ reader.at++;
175
+ }
176
+ }
177
+ reader.at++;
178
+ return value;
179
+ }
package/dist/types.d.ts CHANGED
@@ -11,7 +11,7 @@ type Position = number;
11
11
  /** @pattern ^[0-9a-f]{16}$ */
12
12
  type Hash = string;
13
13
  /** @inline */
14
- export type Framework = 'playwright' | 'vitest' | 'jest';
14
+ export type Framework = 'playwright' | 'vitest' | 'jest' | 'mocha' | 'jasmine' | 'cypress' | 'webdriverio' | 'node' | 'bun';
15
15
  /**
16
16
  * The state the runner applies to a test, after describes and file-level calls are taken into account. `notLoaded`:
17
17
  * the runner refuses to load the file, so none of its tests run.
@@ -38,7 +38,7 @@ export type SettingSource = 'test' | 'suite' | 'file' | 'config';
38
38
  * @inline
39
39
  */
40
40
  export type DiagnosticLevel = 'error' | 'warning';
41
- export type DiagnosticCode = 'unresolved-test-import' | 'parse-error' | 'read-error' | 'framework-mismatch' | 'unresolved-tag' | 'unresolved-annotation' | 'unresolved-cases' | 'cases-not-expanded' | 'test-in-loop' | 'dynamic-title' | 'duplicate-title' | 'duplicate-id' | 'internal-error' | 'invalid-chain' | 'skip-without-body' | 'test-without-body' | 'describe-not-called' | 'async-describe' | 'describe-throws' | 'nested-test' | 'tag-without-at' | 'removed-api' | 'only-in-skipped-describe' | 'config-may-change-state' | 'undefined-tag' | 'symlink-ignored' | 'invalid-import' | 'globals-not-enabled' | 'unknown-framework-version' | 'unsupported-framework-version' | 'local-test-object' | 'state-in-helper' | 'unresolved-option' | 'dynamic-reason' | 'no-files-matched' | 'unsupported-file' | 'approximate-framework-version' | 'test-in-function' | 'empty-title' | 'bench-outside-benchmark-file' | 'config-value-unknown' | 'file-not-run' | 'forbidden-only' | 'dependency-not-followed';
41
+ export type DiagnosticCode = 'unresolved-test-import' | 'parse-error' | 'read-error' | 'framework-mismatch' | 'unresolved-tag' | 'unresolved-annotation' | 'unresolved-cases' | 'cases-not-expanded' | 'test-in-loop' | 'dynamic-title' | 'duplicate-title' | 'duplicate-id' | 'internal-error' | 'invalid-chain' | 'skip-without-body' | 'test-without-body' | 'describe-not-called' | 'async-describe' | 'describe-throws' | 'nested-test' | 'tag-without-at' | 'removed-api' | 'invalid-fixture-argument' | 'only-in-skipped-describe' | 'config-may-change-state' | 'undefined-tag' | 'symlink-ignored' | 'invalid-import' | 'globals-not-enabled' | 'unknown-framework-version' | 'unsupported-framework-version' | 'local-test-object' | 'state-in-helper' | 'unresolved-option' | 'dynamic-reason' | 'no-files-matched' | 'unsupported-file' | 'approximate-framework-version' | 'test-in-function' | 'empty-title' | 'bench-outside-benchmark-file' | 'config-value-unknown' | 'file-not-run' | 'forbidden-only' | 'dependency-not-followed';
42
42
  export type MetaValue = string | number | boolean | null | MetaValue[] | {
43
43
  [key: string]: MetaValue;
44
44
  };
@@ -115,8 +115,9 @@ export interface Summary {
115
115
  annotationCounts: Record<string, Count>;
116
116
  }
117
117
  /**
118
- * A Playwright or Vitest config that scanned files use: the nearest one in a file's folder or a folder above it, up to
119
- * the root, as the runner started in that folder would. Read as code, never run.
118
+ * A runner's config that scanned files use. For Playwright and Vitest, the nearest one in a file's folder or a folder
119
+ * above it, up to the root, as the runner started in that folder would; for Jest, the one at the root and the projects
120
+ * it names; for the other runners, the one config they read for the whole run. Read as code, never run.
120
121
  */
121
122
  export interface ConfigRecord {
122
123
  /** Path from the project root, with `/` separators. */
@@ -125,7 +126,8 @@ export interface ConfigRecord {
125
126
  extends: string[];
126
127
  /**
127
128
  * The projects the config runs tests in: Playwright's `projects`, or one for a config without them; Vitest's, with
128
- * each browser instance as one. Null when the scan can't work them out.
129
+ * each browser instance as one; Cypress's testing types, `e2e` and `component`; one for the other runners. Null when
130
+ * the scan can't work them out.
129
131
  */
130
132
  projects: ProjectRecord[] | null;
131
133
  }
@@ -133,7 +135,10 @@ export interface ConfigRecord {
133
135
  export interface ProjectRecord {
134
136
  /** As the runner names it: `''` for a project without a name. */
135
137
  name: string;
136
- /** The folder the project's test files are found in, from the project root: Playwright's `testDir`, Vitest's `dir`. */
138
+ /**
139
+ * The folder the project's test files are found in, from the project root: Playwright's `testDir`, Vitest's `dir`,
140
+ * Jest's `rootDir`, Jasmine's `spec_dir`, Bun's `[test] root`; for the other runners, the config's folder.
141
+ */
137
142
  testDir: string;
138
143
  /** Playwright's projects that run before this one; `[]` for Vitest. */
139
144
  dependencies: string[];
@@ -270,7 +275,12 @@ export interface TestRecord {
270
275
  hasUnfollowedDependencies: boolean;
271
276
  /** The nearest describe; null outside any describe. */
272
277
  suiteId: Hash | null;
273
- /** Titles of the describes around the test, outermost first. */
278
+ /**
279
+ * The test whose body declares this one as a subtest, which `node:test` runs while it runs that test; null for every
280
+ * other test.
281
+ */
282
+ parentTestId: Hash | null;
283
+ /** Titles of the describes around the test, and of the tests a subtest is declared in, outermost first. */
274
284
  suitePath: string[];
275
285
  /** Path from the project root, with `/` separators. */
276
286
  relativeFilePath: string;
@@ -350,8 +360,8 @@ export interface TestRecord {
350
360
  /** Vitest only: source text of the `retry` object's `condition`, a RegExp or a function. */
351
361
  retryCondition: string | null;
352
362
  /**
353
- * How many times the runner runs the test again after the first run: Vitest's `repeats`, or Playwright's `repeatEach`
354
- * from the config less one.
363
+ * How many times the runner runs the test again after the first run: Vitest's or Bun's `repeats`, or Playwright's
364
+ * `repeatEach` from the config less one.
355
365
  */
356
366
  repeats: Count | null;
357
367
  /**
package/dist/values.d.ts CHANGED
@@ -55,6 +55,11 @@ export declare class Values {
55
55
  * the file does not declare it, as with globals.
56
56
  */
57
57
  declarationOf(name: string, scopes: readonly Node[]): Node | null;
58
+ /**
59
+ * The function a name is declared as, with `function name() {}` or a variable holding one; null for any other name.
60
+ * A parameter is not its function, though the function declares it.
61
+ */
62
+ functionOf(name: string, scopes: readonly Node[]): FunctionNode | null;
58
63
  /** The value a `const` name is declared with, and the scopes around that declaration; null for any other name. */
59
64
  constantOf(name: string, scopes: readonly Node[]): {
60
65
  init: Expression;
package/dist/values.js CHANGED
@@ -309,6 +309,19 @@ export class Values {
309
309
  declarationOf(name, scopes) {
310
310
  return this.lookup(name, scopes)?.binding.declaration ?? null;
311
311
  }
312
+ /**
313
+ * The function a name is declared as, with `function name() {}` or a variable holding one; null for any other name.
314
+ * A parameter is not its function, though the function declares it.
315
+ */
316
+ functionOf(name, scopes) {
317
+ const binding = this.lookup(name, scopes)?.binding;
318
+ const declaration = binding?.declaration;
319
+ // A class is bound like a function, but has no body to walk.
320
+ if (binding?.kind === 'function' && declaration?.type === 'FunctionDeclaration')
321
+ return declaration;
322
+ const init = declaration?.type === 'VariableDeclarator' && declaration.init ? unwrap(declaration.init) : null;
323
+ return isFunctionNode(init) ? init : null;
324
+ }
312
325
  /** The value a `const` name is declared with, and the scopes around that declaration; null for any other name. */
313
326
  constantOf(name, scopes) {
314
327
  const binding = this.lookup(name, scopes)?.binding;
package/dist/yaml.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { Value } from './values.ts';
2
+ /** Where a YAML text uses something `readYaml` doesn't read, with its 1-based line. */
3
+ export declare class YamlError extends Error {
4
+ readonly line: number;
5
+ constructor(message: string, line: number);
6
+ }
7
+ /**
8
+ * The value of a YAML config as Mocha's `.mocharc.yml` files write it: a map of keys to scalars, to lists written one
9
+ * item per line or in brackets, and to maps of those. Anchors, multi-line strings, flow maps and documents after the
10
+ * first are refused with a `YamlError`, as a guess at them could read the wrong test files, and so is what js-yaml,
11
+ * Mocha's reader, refuses: a key set twice, a tab in the indent, or `: ` in a plain value.
12
+ */
13
+ export declare function readYaml(text: string): Value;