test-inventory 0.12.1 → 0.12.2

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 (56) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +2 -1
  3. package/dist/ast.d.ts +7 -2
  4. package/dist/ast.js +43 -3
  5. package/dist/case-titles.d.ts +5 -11
  6. package/dist/case-titles.js +69 -55
  7. package/dist/config-runs.d.ts +19 -2
  8. package/dist/config-runs.js +379 -90
  9. package/dist/config.d.ts +0 -5
  10. package/dist/config.js +0 -7
  11. package/dist/dependency-hash.js +1 -32
  12. package/dist/diagnostics.js +17 -2
  13. package/dist/diff.d.ts +2 -45
  14. package/dist/extract.d.ts +13 -3
  15. package/dist/extract.js +837 -89
  16. package/dist/frameworks/bun.js +47 -24
  17. package/dist/frameworks/common.d.ts +4 -2
  18. package/dist/frameworks/common.js +10 -11
  19. package/dist/frameworks/jasmine-registration.d.ts +47 -0
  20. package/dist/frameworks/jasmine-registration.js +632 -0
  21. package/dist/frameworks/jasmine.d.ts +7 -1
  22. package/dist/frameworks/jasmine.js +65 -70
  23. package/dist/frameworks/jest.d.ts +2 -2
  24. package/dist/frameworks/jest.js +126 -51
  25. package/dist/frameworks/vitest.d.ts +2 -3
  26. package/dist/frameworks/vitest.js +80 -16
  27. package/dist/generator-steps.d.ts +56 -0
  28. package/dist/generator-steps.js +254 -0
  29. package/dist/model.d.ts +37 -5
  30. package/dist/mutation-arrays.d.ts +25 -0
  31. package/dist/mutation-arrays.js +229 -0
  32. package/dist/mutation-calls.d.ts +33 -0
  33. package/dist/mutation-calls.js +774 -0
  34. package/dist/mutation-order.d.ts +19 -0
  35. package/dist/mutation-order.js +55 -0
  36. package/dist/mutation-references.d.ts +109 -0
  37. package/dist/mutation-references.js +462 -0
  38. package/dist/mutation-returns.d.ts +13 -0
  39. package/dist/mutation-returns.js +71 -0
  40. package/dist/node-scripts.d.ts +4 -1
  41. package/dist/node-scripts.js +77 -11
  42. package/dist/options.d.ts +2 -0
  43. package/dist/options.js +6 -1
  44. package/dist/records.d.ts +5 -3
  45. package/dist/records.js +81 -28
  46. package/dist/scan-file.d.ts +18 -4
  47. package/dist/scan-file.js +44 -5
  48. package/dist/scan-source.js +2 -1
  49. package/dist/scan.js +30 -13
  50. package/dist/types.d.ts +45 -1
  51. package/dist/values.d.ts +72 -18
  52. package/dist/values.js +651 -172
  53. package/dist/vitest-concurrency.d.ts +16 -0
  54. package/dist/vitest-concurrency.js +55 -0
  55. package/package.json +1 -1
  56. package/schema/v1.json +1 -0
@@ -1,5 +1,5 @@
1
1
  import { isFunctionNode, unwrap } from "../ast.js";
2
- import { bunCaseTitle } from "../case-titles.js";
2
+ import { BUN_INVALID_TITLE, bunCaseTitle } from "../case-titles.js";
3
3
  import { snippet } from "../source.js";
4
4
  import { requiredModule } from "./bindings.js";
5
5
  import { atLeast, hookFunction, namedFunction, problem, readChain, readCondition, readCount, readOptions, readTitle, refused, text, unresolvedOptions, wrappedFunction, } from "./common.js";
@@ -107,27 +107,41 @@ export class BunAdapter extends SuiteAdapter {
107
107
  const args = call.arguments;
108
108
  const callee = snippet(text(this.file, call.callee));
109
109
  const problems = [];
110
- const { title, problem: titleProblem } = readTitle(this.file, context.scopes, args[0], {
111
- stripTags: false,
112
- functionNames: true,
113
- });
114
- if (titleProblem)
115
- problems.push(titleProblem);
116
110
  const spread = args.some((arg) => arg.type === 'SpreadElement');
117
111
  // (title, fn, options) or (title, options, fn), by whether the second is a function; a number is the timeout. A
118
112
  // name the scan can't follow, as an imported function, is taken for the function unless the third is one.
119
113
  const [second, third] = [args.at(1), args.at(2)];
120
114
  const isFunction = (node) => isFunctionLike(node) || namedFunction(this.file, context.scopes, node) !== null;
115
+ const first = args.at(0);
116
+ const callbackOnly = args.length === 1 && isFunction(first);
117
+ const titleArg = callbackOnly ? undefined : first;
118
+ const written = titleArg && titleArg.type !== 'SpreadElement' ? unwrap(titleArg) : null;
119
+ const value = written ? this.file.values.resolve(written, context.scopes) : null;
120
+ const declaredName = written && !value?.ok
121
+ ? this.file.values.functionName(written, context.scopes, {
122
+ inferStaticFieldNames: atLeast(this.file.version, 1, 4),
123
+ })
124
+ : null;
125
+ const unnamed = !titleArg || (value?.ok && (value.value === undefined || value.value === null));
126
+ const defaultName = kind === 'test' ? '(unnamed)' : '';
127
+ const { title, problem: titleProblem } = unnamed
128
+ ? { title: { text: defaultName, withoutTags: defaultName, isDynamic: false }, problem: null }
129
+ : readTitle(this.file, context.scopes, titleArg, { stripTags: false, functionNames: { bun: declaredName } });
130
+ if (titleProblem)
131
+ problems.push(titleProblem);
121
132
  const fnSecond = third === undefined ||
122
133
  isFunction(second) ||
123
134
  (!isFunction(third) && !this.isKnownValue(second, context));
124
- const body = spread ? undefined : fnSecond ? second : third;
135
+ const body = spread ? undefined : callbackOnly ? first : fnSecond ? second : third;
125
136
  const options = spread ? undefined : fnSecond ? third : second;
126
137
  const fn = isFunctionNode(body) ? body : null;
127
138
  const names = new Set(links.map((link) => link.name));
128
139
  const line = this.file.source.line(call.start);
129
140
  const states = this.states(links, line, context);
130
141
  const table = links.find((link) => link.name === 'each') ?? null;
142
+ const rows = table?.args?.at(0);
143
+ const resolvedRows = rows && rows.type !== 'SpreadElement' ? this.file.values.resolve(rows, context.scopes) : null;
144
+ const cases = resolvedRows?.ok && Array.isArray(resolvedRows.value) ? this.tableCases(resolvedRows.value, title) : null;
131
145
  const run = this.options(options, problems, context);
132
146
  const base = {
133
147
  title,
@@ -139,24 +153,32 @@ export class BunAdapter extends SuiteAdapter {
139
153
  hashed: fn ?? namedFunction(this.file, context.scopes, body) ?? wrappedFunction(body),
140
154
  isParameterized: table !== null,
141
155
  caseCount: table ? this.caseCount(table, problems, context) : null,
142
- cases: table ? this.tableCases(table, title, context) : null,
156
+ cases: cases === BUN_INVALID_TITLE ? null : cases,
143
157
  problems,
144
158
  };
145
159
  const declared = kind === 'describe'
146
160
  ? { kind: 'describe', ...base, isShuffled: false, passesDown: null }
147
161
  : { kind: 'test', ...base, testContext: null, fixtures: [], takesAllFixtures: false, usesBench: false };
148
- // Only a skipped or todo test may leave out its function.
149
- const mayLeaveOut = kind === 'test' && (names.has('skip') || names.has('todo'));
150
- const rows = table?.args?.at(0);
151
- const resolvedRows = rows && rows.type !== 'SpreadElement' ? this.file.values.resolve(rows, context.scopes) : null;
162
+ if (cases === BUN_INVALID_TITLE) {
163
+ const refusal = problem('invalid-chain', call, `${callee}() cannot read a title property from null or undefined.`, title.text);
164
+ return refused(call, refusal, context, () => declared);
165
+ }
152
166
  if (resolvedRows?.ok && !Array.isArray(resolvedRows.value)) {
153
167
  const source = snippet(text(this.file, rows));
154
168
  const refusal = problem('invalid-chain', rows, `.each() takes an array, and ${source} is not one, so Bun fails the file and runs none of its tests.`, source);
155
169
  return refused(call, refusal, context, () => declared);
156
170
  }
157
- // Bun wants a function second or third; a value that can't be one, as options alone, is none.
158
- const missing = body === undefined || isValue(body);
159
- if (missing && !spread && !mayLeaveOut) {
171
+ if ((declaredName?.ok && declaredName.value === undefined) ||
172
+ (value?.ok && (typeof value.value === 'boolean' || (typeof value.value === 'object' && value.value !== null))) ||
173
+ written?.type === 'ArrayExpression' ||
174
+ written?.type === 'ObjectExpression') {
175
+ const refusal = problem('invalid-chain', call, `${callee}() rejects this title. Bun fails to load the file.`, callee);
176
+ return refused(call, refusal, context, () => declared);
177
+ }
178
+ const resolvedBody = body && body.type !== 'SpreadElement' ? this.file.values.resolve(body, context.scopes) : null;
179
+ const absent = body === undefined || (resolvedBody?.ok && (resolvedBody.value === null || resolvedBody.value === undefined));
180
+ const mayLeaveOut = states.some((setting) => (setting.state === 'skip' || setting.state === 'todo') && setting.condition === null);
181
+ if (!spread && (absent ? !mayLeaveOut : isValue(body) || resolvedBody?.ok)) {
160
182
  const refusal = problem('test-without-body', call, `${callee}() has no function, so Bun fails the file and runs none of its tests.`, callee);
161
183
  return refused(call, refusal, context, () => declared);
162
184
  }
@@ -255,15 +277,16 @@ export class BunAdapter extends SuiteAdapter {
255
277
  return node.type !== 'SpreadElement' && (isValue(node) || this.file.values.resolve(node, context.scopes).ok);
256
278
  }
257
279
  /** The cases of a table the scan can work out: an item that is an array is spread into the arguments, another is one. */
258
- tableCases(table, title, context) {
259
- const first = table.args.at(0);
260
- const resolved = first && first.type !== 'SpreadElement' ? this.file.values.resolve(first, context.scopes) : null;
261
- if (!resolved?.ok || !Array.isArray(resolved.value))
262
- return null;
263
- return resolved.value.map((item, index) => {
280
+ tableCases(items, title) {
281
+ const cases = [];
282
+ for (const [index, item] of items.entries()) {
264
283
  const row = Array.isArray(item) ? item : [item];
265
- return { title: title.isDynamic ? null : bunCaseTitle(title.text, row, index, this.file.version), args: row };
266
- });
284
+ const formatted = title.isDynamic ? null : bunCaseTitle(title.text, row, index, this.file.version);
285
+ if (formatted === BUN_INVALID_TITLE)
286
+ return formatted;
287
+ cases.push({ title: formatted, args: row });
288
+ }
289
+ return cases;
267
290
  }
268
291
  }
269
292
  function negated(condition) {
@@ -91,8 +91,10 @@ export declare function hookFunction(file: FileContext, scopes: readonly Node[],
91
91
  /** Reads a title. A title that cannot be worked out keeps its source text and gets a `dynamic-title` warning. */
92
92
  export declare function readTitle(file: FileContext, scopes: readonly Node[], node: Argument, options: {
93
93
  stripTags: boolean;
94
- functionNames: boolean;
95
- }): {
94
+ functionNames: false | 'vitest' | {
95
+ bun: Resolved | null;
96
+ };
97
+ }, known?: Resolved): {
96
98
  title: Title;
97
99
  problem: Problem | null;
98
100
  };
@@ -191,9 +191,9 @@ export function hookFunction(file, scopes, args) {
191
191
  return findFunction(args) ?? args.map((arg) => namedFunction(file, scopes, arg)).find((fn) => fn !== null) ?? null;
192
192
  }
193
193
  /** Reads a title. A title that cannot be worked out keeps its source text and gets a `dynamic-title` warning. */
194
- export function readTitle(file, scopes, node, options) {
194
+ export function readTitle(file, scopes, node, options, known) {
195
195
  const expression = node.type === 'SpreadElement' ? null : node;
196
- const resolved = expression ? file.values.resolve(expression, scopes) : null;
196
+ const resolved = known ?? (expression ? file.values.resolve(expression, scopes) : null);
197
197
  let value = resolved?.ok && typeof resolved.value === 'string' ? resolved.value : null;
198
198
  // Vitest turns a title that is a number, boolean or null into a string.
199
199
  const other = resolved?.ok ? resolved.value : undefined;
@@ -202,15 +202,14 @@ export function readTitle(file, scopes, node, options) {
202
202
  (other === null || typeof other === 'number' || typeof other === 'boolean')) {
203
203
  value = String(other);
204
204
  }
205
- if (value === null && options.functionNames && expression?.type === 'Identifier') {
206
- value = file.values.isFunction(expression.name, scopes) ? expression.name : null;
207
- }
208
- // A function or class written in place gives its name, as `describe(function OrderBook() {}, ...)` does.
209
- const written = expression && unwrap(expression);
210
- if (value === null &&
211
- options.functionNames &&
212
- (written?.type === 'FunctionExpression' || written?.type === 'ClassExpression')) {
213
- value = written.id?.name ?? '';
205
+ if (value === null && options.functionNames && expression) {
206
+ const name = options.functionNames === 'vitest' ? file.values.functionName(expression, scopes) : options.functionNames.bun;
207
+ if (name?.ok) {
208
+ if (!name.value && options.functionNames === 'vitest')
209
+ value = '<anonymous>';
210
+ else if (typeof name.value === 'string' && unwrap(expression).type !== 'ArrowFunctionExpression')
211
+ value = name.value;
212
+ }
214
213
  }
215
214
  if (value !== null) {
216
215
  const withoutTags = options.stripTags ? value.replace(/@\S+/g, ' ').replace(/\s+/g, ' ').trim() : value;
@@ -0,0 +1,47 @@
1
+ import type { Argument, BlockStatement, CallExpression, Expression, Node } from 'oxc-parser';
2
+ import { type FunctionNode } from '../ast.ts';
3
+ import { type IteratorSpread, type Resolved, type Value } from '../values.ts';
4
+ import { type FileContext } from './common.ts';
5
+ /** Runtime function length excludes a TypeScript this parameter and ends at the first default or rest parameter. */
6
+ export declare function functionLength(fn: FunctionNode): number;
7
+ type Flow = 'next' | 'throw' | 'unknown';
8
+ type RuntimeFunction = FunctionNode & {
9
+ body: NonNullable<FunctionNode['body']>;
10
+ };
11
+ export declare const isRuntimeFunction: (node: Node | null | undefined) => node is RuntimeFunction;
12
+ type RegistrationStatus = 'valid' | 'callback' | 'timeout' | 'unknown';
13
+ export interface JasmineArgument {
14
+ node: Argument;
15
+ scopes: readonly Node[];
16
+ resolved?: {
17
+ ok: true;
18
+ value: Value;
19
+ };
20
+ }
21
+ type Position = JasmineArgument | null | undefined;
22
+ export declare function jasmineArguments(args: readonly Argument[], scopes: readonly Node[], file: FileContext, count: number): Position[];
23
+ export declare function jasmineCallback(body: Position, file: FileContext): {
24
+ status: 'valid' | 'callback' | 'unknown' | 'missing';
25
+ binding: {
26
+ fn: FunctionNode;
27
+ scopes: readonly Node[];
28
+ } | null;
29
+ };
30
+ export declare function jasmineRegistration(read: ReturnType<typeof jasmineCallback>, limit: Position, file: FileContext, allowsPending: boolean): {
31
+ status: RegistrationStatus;
32
+ fn: FunctionNode | null;
33
+ missing: boolean;
34
+ };
35
+ interface SuiteCall {
36
+ call: CallExpression;
37
+ fn: RuntimeFunction;
38
+ definition: readonly Node[];
39
+ plain: boolean;
40
+ }
41
+ export declare function jasmineSpread(operand: Expression, scopes: readonly Node[], file: FileContext): IteratorSpread;
42
+ export declare function registrationExit(root: BlockStatement | SuiteCall, outer: readonly Node[], file: FileContext): Flow | 'return';
43
+ /** Read a value at registration time, including the result of a synchronous local helper. */
44
+ export declare function jasmineValue(expression: Expression, scopes: readonly Node[], file: FileContext): Resolved;
45
+ /** Specs replace falsy descriptions with an empty string. Suite paths keep false and zero. */
46
+ export declare function jasmineTitleValue(title: JasmineArgument, file: FileContext, spec: boolean): Resolved | undefined;
47
+ export {};