test-inventory 0.12.1 → 0.12.3

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 +141 -0
  2. package/README.md +74 -49
  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 +2 -2
  56. package/schema/v1.json +1 -0
@@ -125,11 +125,10 @@ function readsItsFunction(kind, member, version) {
125
125
  }
126
126
  export class VitestAdapter extends SuiteAdapter {
127
127
  warnedAboutTags = false;
128
- /** The length a value in a case title is shortened to, as the config sets it. */
129
- titleTruncate;
130
- constructor(parsed, file, readModule, titleTruncate = 40) {
128
+ titleThresholds;
129
+ constructor(parsed, file, readModule, titleThresholds = [40]) {
131
130
  super(parsed, file, readModule, VITEST, TEST_MEMBERS);
132
- this.titleTruncate = titleTruncate;
131
+ this.titleThresholds = titleThresholds;
133
132
  if (atLeast(file.version, 5, 0)) {
134
133
  for (const call of nestedHoistedCalls(parsed.program)) {
135
134
  const callee = snippet(text(this.file, call.callee));
@@ -305,7 +304,7 @@ export class VitestAdapter extends SuiteAdapter {
305
304
  const callee = snippet(text(this.file, call.callee));
306
305
  if (args.length === 0)
307
306
  return { kind: 'other' };
308
- if (kind === 'describe' && isFunctionNode(args[0])) {
307
+ if (kind === 'describe' && args.length === 1 && isFunctionNode(args[0])) {
309
308
  return {
310
309
  kind: 'invalid',
311
310
  problem: problem('describe-not-called', call, `${callee}() has no title, so Vitest never calls its function.`, callee),
@@ -314,7 +313,7 @@ export class VitestAdapter extends SuiteAdapter {
314
313
  const problems = [];
315
314
  const { title, problem: titleProblem } = readTitle(this.file, context.scopes, args[0], {
316
315
  stripTags: false,
317
- functionNames: true,
316
+ functionNames: 'vitest',
318
317
  });
319
318
  if (titleProblem)
320
319
  problems.push(titleProblem);
@@ -372,7 +371,11 @@ export class VitestAdapter extends SuiteAdapter {
372
371
  }
373
372
  // A test's own options win over its chain, so `test.skip('title', { skip: false }, fn)` runs. The chain wins for a
374
373
  // test's mode, and for everything on a describe.
374
+ const suiteOptionModes = atLeast(this.file.version, 4, 1);
375
+ const readsOwnMode = kind === 'test' || suiteOptionModes;
375
376
  for (const [flag, value] of read.flags) {
377
+ if (!readsOwnMode && (flag === 'todo' || flag === 'only'))
378
+ continue;
376
379
  if (value)
377
380
  flags.add(flag);
378
381
  else if (kind === 'test' && flag !== 'sequential')
@@ -382,17 +385,36 @@ export class VitestAdapter extends SuiteAdapter {
382
385
  flags.delete('skip');
383
386
  conditions = [read.skip];
384
387
  }
385
- else if (read.skip) {
388
+ else if (read.skip && readsOwnMode) {
386
389
  conditions.push(read.skip);
387
390
  }
388
391
  // Vitest passes a describe's options down to the tests and describes inside, where their own options and `only`
389
392
  // win. A `skip` passed down skips them, and turns todo into skip, as skip goes before todo.
390
393
  const line = this.file.source.line(call.start);
391
394
  const around = context.passedDown;
392
- const passed = read.skip || conditionSetsSkip ? null : around;
393
- const skips = passed?.condition.applies === 'always' && !flags.has('only');
395
+ const passed = read.skip || conditionSetsSkip ? null : around?.skip;
396
+ // Before Vitest 5, test options inherited from a suite override the test's chain; its own options still win.
397
+ const inheritsBeforeChain = !atLeast(this.file.version, 5, 0);
398
+ const inheritsOnly = around?.only === true && !read.flags.has('only');
399
+ if (kind === 'describe' && suiteOptionModes && inheritsOnly)
400
+ flags.add('only');
401
+ if (kind === 'test' && inheritsBeforeChain) {
402
+ if (around?.only === false && !read.flags.has('only'))
403
+ flags.delete('only');
404
+ if (passed?.condition.applies === 'never') {
405
+ flags.delete('skip');
406
+ conditions = [];
407
+ }
408
+ if (around?.todo?.enabled === false && !read.flags.has('todo'))
409
+ flags.delete('todo');
410
+ if (around?.fails?.enabled === false && !read.flags.has('fails'))
411
+ flags.delete('fails');
412
+ if (!suiteOptionModes && passed?.condition.applies === 'sometimes')
413
+ conditions.push(passed.condition);
414
+ }
415
+ const skips = readsOwnMode && passed?.condition.applies === 'always' && !flags.has('only');
394
416
  const table = links.find((link) => TABLES.has(link.name)) ?? null;
395
- const isTodo = flags.has('todo') || body === undefined;
417
+ const isTodo = flags.has('todo') || (body === undefined && readsOwnMode);
396
418
  const states = this.states(flags, conditions, isTodo && !skips, line);
397
419
  const skipped = () => states.some((setting) => setting.state === 'skip' && !setting.condition);
398
420
  // The skip is set where the describe that passes it down sets it. A skipped describe around already skips what is
@@ -413,7 +435,21 @@ export class VitestAdapter extends SuiteAdapter {
413
435
  states,
414
436
  isOnly: flags.has('only'),
415
437
  mode,
416
- ...(skips ? { skipPassedDown: passed.line } : {}),
438
+ vitestConcurrency: inheritsBeforeChain &&
439
+ (chain.has('concurrent') || chain.has('sequential') || read.concurrent !== null || read.flags.has('sequential'))
440
+ ? {
441
+ concurrent: read.concurrent ?? undefined,
442
+ sequential: read.flags.get('sequential'),
443
+ chainConcurrent: chain.has('concurrent'),
444
+ chainSequential: chain.has('sequential'),
445
+ }
446
+ : undefined,
447
+ ...(skips
448
+ ? { skipPassedDown: { line: passed.line, withoutSkip: this.states(flags, conditions, isTodo, line) } }
449
+ : {}),
450
+ todoPassedDown: !isTodo && !read.flags.has('todo') && !flags.has('only') && around?.todo?.enabled
451
+ ? around.todo.line
452
+ : undefined,
417
453
  details: read.details,
418
454
  fn,
419
455
  hashed: fn ?? namedFunction(this.file, context.scopes, body) ?? wrappedFunction(body),
@@ -428,8 +464,15 @@ export class VitestAdapter extends SuiteAdapter {
428
464
  const first = table ? null : fn?.params.at(0);
429
465
  if (fn && first?.type === 'Identifier')
430
466
  this.suiteParameters.set(fn, first.name);
431
- const own = read.skip ? { condition: read.skip, line } : around;
432
- const passesDown = own && { ...own, covered: (around?.covered ?? false) || skipped() };
467
+ const own = read.skip ? { condition: read.skip, line } : around?.skip;
468
+ const todo = read.flags.get('todo');
469
+ const fails = read.flags.get('fails');
470
+ const passesDown = {
471
+ skip: own ? { ...own, covered: (around?.skip?.covered ?? false) || skipped() } : null,
472
+ todo: todo === undefined ? around?.todo : { enabled: todo, line },
473
+ fails: fails === undefined ? around?.fails : { enabled: fails, line },
474
+ only: read.flags.get('only') ?? around?.only,
475
+ };
433
476
  declared = { kind: 'describe', ...base, isShuffled: flags.has('shuffle'), passesDown };
434
477
  }
435
478
  else {
@@ -441,9 +484,12 @@ export class VitestAdapter extends SuiteAdapter {
441
484
  fixtures: fixturesOf(base.hashed, index, this.file.version),
442
485
  takesAllFixtures: takesWhole(base.hashed, index),
443
486
  usesBench: atLeast(this.file.version, 5, 0) && destructuredNames(base.hashed, index).includes('bench'),
487
+ inheritsOnly,
488
+ failsLine: flags.has('fails') ? line : undefined,
489
+ failsPassedDown: around?.fails?.enabled && !read.flags.has('fails') ? around.fails.line : undefined,
444
490
  ownStateOptions: [
445
- ...(read.skip || conditionSetsSkip ? ['skip'] : []),
446
- ...STATE_FLAGS.filter((flag) => read.flags.has(flag)),
491
+ ...(read.skip || conditionSetsSkip || (inheritsBeforeChain && around?.skip) ? ['skip'] : []),
492
+ ...STATE_FLAGS.filter((flag) => read.flags.has(flag) || (inheritsBeforeChain && around?.[flag] !== undefined)),
447
493
  ],
448
494
  };
449
495
  }
@@ -511,6 +557,8 @@ export class VitestAdapter extends SuiteAdapter {
511
557
  return isUndefined && atLeast(this.file.version, 5, 0) ? undefined : option;
512
558
  };
513
559
  for (const flag of ['only', 'todo', 'fails', 'concurrent', 'sequential', 'shuffle']) {
560
+ if (flag === 'sequential' && atLeast(this.file.version, 5, 0))
561
+ continue;
514
562
  const option = given(flag);
515
563
  if (option && !option.resolved.ok) {
516
564
  const { importedFrom } = option.resolved;
@@ -637,7 +685,23 @@ export class VitestAdapter extends SuiteAdapter {
637
685
  return null;
638
686
  cases = resolved.value;
639
687
  }
640
- const caseTitle = (items, index) => title.isDynamic ? null : vitestCaseTitle(title.text, items, index, this.file.version, this.titleTruncate);
688
+ const [first = 40, ...others] = this.titleThresholds.filter((length) => length !== null);
689
+ const unknownLimit = this.titleThresholds.includes(null);
690
+ const caseTitle = (items, index) => {
691
+ if (title.isDynamic)
692
+ return null;
693
+ const format = (length) => vitestCaseTitle(title.text, items, index, this.file.version, length);
694
+ const rendered = format(first);
695
+ if (rendered === null)
696
+ return null;
697
+ if (others.some((length) => format(length) !== rendered)) {
698
+ return { reason: 'the Vitest projects that run this file give a case different titles' };
699
+ }
700
+ if (unknownLimit && format(null) === null) {
701
+ return { reason: 'a case title depends on a Vitest truncation setting the scan cannot resolve' };
702
+ }
703
+ return rendered;
704
+ };
641
705
  if (table.name === 'for') {
642
706
  return cases.map((item, index) => ({
643
707
  title: caseTitle(item === null || item === undefined ? [] : Array.isArray(item) ? item : [item], index),
@@ -0,0 +1,56 @@
1
+ import type { BlockStatement, CatchClause, Expression, Node, Statement, YieldExpression } from 'oxc-parser';
2
+ import { type GeneratorLocals, type Resolved } from './values.ts';
3
+ export type IteratorMethod = 'next' | 'return' | 'throw';
4
+ type Instruction = {
5
+ kind: 'statement' | 'finally';
6
+ node: Statement;
7
+ scopes: readonly Node[];
8
+ } | {
9
+ kind: 'catch';
10
+ node: CatchClause;
11
+ scopes: readonly Node[];
12
+ } | {
13
+ kind: 'completion';
14
+ method: 'return' | 'throw';
15
+ value: Resolved;
16
+ } | {
17
+ kind: 'forward';
18
+ iterator: Resolved;
19
+ receive?: YieldExpression;
20
+ } | {
21
+ kind: 'delegate';
22
+ items: readonly Resolved[];
23
+ index: number;
24
+ };
25
+ interface Pending {
26
+ instruction: Instruction;
27
+ next: Pending | null;
28
+ handlesThrow: boolean;
29
+ }
30
+ interface Suspension {
31
+ stack: Pending | null;
32
+ locals: GeneratorLocals;
33
+ receive?: YieldExpression;
34
+ }
35
+ export type IteratorPosition = Suspension | 'closed' | 'unknown' | 'running';
36
+ export declare const omitted: Resolved;
37
+ export interface GeneratorStep {
38
+ position: IteratorPosition;
39
+ outcome: 'next' | 'throw' | 'unknown';
40
+ value: Resolved;
41
+ }
42
+ export interface Thrown {
43
+ thrown: Resolved;
44
+ }
45
+ interface GeneratorEnvironment {
46
+ locals: GeneratorLocals;
47
+ evaluate: (node: Node, scopes: readonly Node[], read: boolean, handlesThrow: boolean) => Resolved | Thrown;
48
+ bindCatch: (clause: CatchClause, scopes: readonly Node[], value: Resolved, handlesThrow: boolean) => Resolved | Thrown;
49
+ enterCall: (name: string, scopes: readonly Node[]) => void;
50
+ iteratorOf: (operand: Expression, scopes: readonly Node[]) => Resolved | undefined;
51
+ resumeDelegate: (iterator: Resolved, method: IteratorMethod, value: Resolved, handlesThrow: boolean) => GeneratorStep;
52
+ spreadDelegate?: (operand: Expression, scopes: readonly Node[]) => GeneratorStep['outcome'];
53
+ }
54
+ /** Resume a synchronous generator with its lexical blocks and pending catch/finally handlers intact. */
55
+ export declare function stepGenerator(body: BlockStatement, position: IteratorPosition | undefined, method: IteratorMethod, argument: Resolved, { locals, evaluate, bindCatch, enterCall, iteratorOf, resumeDelegate, spreadDelegate }: GeneratorEnvironment): GeneratorStep;
56
+ export {};
@@ -0,0 +1,254 @@
1
+ import { childNodes, isFunctionNode, unwrap } from "./ast.js";
2
+ import { usesRightOperand } from "./values.js";
3
+ export const omitted = { ok: true, value: undefined };
4
+ const unresolved = { ok: false, importedFrom: null };
5
+ function unknownStep() {
6
+ return { position: 'unknown', outcome: 'unknown', value: unresolved };
7
+ }
8
+ function completed(result) {
9
+ return typeof result === 'object' && 'ok' in result;
10
+ }
11
+ const yielding = new WeakMap();
12
+ /** A nested function has its own suspensions, even when it shares the enclosing generator's lexical scope. */
13
+ function suspends(node) {
14
+ const known = yielding.get(node);
15
+ if (known !== undefined)
16
+ return known;
17
+ const result = node.type === 'YieldExpression' ||
18
+ (node.type !== 'FunctionDeclaration' && !isFunctionNode(node) && childNodes(node).some(suspends));
19
+ yielding.set(node, result);
20
+ return result;
21
+ }
22
+ /** Completed operands survive a pause. On resumption only the selected, unfinished operands can run. */
23
+ function resumeExpression(expression, operands, evaluate, enterCall) {
24
+ function read(input) {
25
+ const node = unwrap(input);
26
+ const known = operands.get(node);
27
+ if (known)
28
+ return known;
29
+ const result = suspends(node) ? resume(node) : evaluate(node);
30
+ if (completed(result))
31
+ operands.set(node, result);
32
+ return result;
33
+ }
34
+ function resume(node) {
35
+ if (node.type === 'YieldExpression') {
36
+ const value = node.argument ? read(node.argument) : omitted;
37
+ return completed(value) ? { receive: node, value } : value;
38
+ }
39
+ if (node.type === 'ConditionalExpression' || node.type === 'LogicalExpression') {
40
+ const control = read(node.type === 'ConditionalExpression' ? node.test : node.left);
41
+ if (!completed(control))
42
+ return control;
43
+ if (!control.ok && !control.truthy)
44
+ return 'unknown';
45
+ const value = control.ok ? control.value : true;
46
+ if (node.type === 'ConditionalExpression')
47
+ return read(value ? node.consequent : node.alternate);
48
+ return usesRightOperand(node.operator, value) ? read(node.right) : control;
49
+ }
50
+ let parts;
51
+ if (node.type === 'CallExpression' && !node.optional && node.callee.type === 'Identifier') {
52
+ enterCall(node.callee.name);
53
+ parts = node.arguments;
54
+ }
55
+ else if (node.type === 'BinaryExpression')
56
+ parts = [node.left, node.right];
57
+ else if (node.type === 'TemplateLiteral')
58
+ parts = node.expressions;
59
+ else if (node.type === 'UnaryExpression')
60
+ parts = [node.argument];
61
+ else
62
+ return 'unknown';
63
+ // The ordinary evaluator can finish the suffix, including a spread after the last suspension.
64
+ const last = parts.findLastIndex(suspends);
65
+ for (let i = 0; i <= last; i++) {
66
+ const part = parts[i];
67
+ if (part.type === 'SpreadElement' || part.type === 'PrivateIdentifier')
68
+ return 'unknown';
69
+ const value = read(part);
70
+ if (!completed(value))
71
+ return value;
72
+ }
73
+ return evaluate(node);
74
+ }
75
+ return read(expression);
76
+ }
77
+ /** Resume a synchronous generator with its lexical blocks and pending catch/finally handlers intact. */
78
+ export function stepGenerator(body, position, method, argument, { locals, evaluate, bindCatch, enterCall, iteratorOf, resumeDelegate, spreadDelegate }) {
79
+ const { operands } = locals;
80
+ if (position === 'running')
81
+ return { position, outcome: 'throw', value: unresolved };
82
+ if (position === 'unknown')
83
+ return unknownStep();
84
+ // Branches can share a suspension without copying the remaining body on every next() call.
85
+ let stack = typeof position === 'object' ? position.stack : null;
86
+ if (typeof position === 'object' && position.receive && method === 'next')
87
+ operands.set(position.receive, argument);
88
+ const push = (instruction) => {
89
+ stack = { instruction, next: stack, handlesThrow: instruction.kind === 'catch' || !!stack?.handlesThrow };
90
+ };
91
+ if (position === undefined)
92
+ push({ kind: 'statement', node: body, scopes: [] });
93
+ let value = argument;
94
+ while (stack) {
95
+ const handlesThrow = stack.handlesThrow;
96
+ const entry = stack.instruction;
97
+ stack = stack.next;
98
+ if (entry.kind === 'forward') {
99
+ const step = resumeDelegate(entry.iterator, method, value, handlesThrow);
100
+ if (step.outcome === 'unknown')
101
+ return unknownStep();
102
+ value = step.value;
103
+ if (step.outcome === 'throw')
104
+ method = 'throw';
105
+ else if (step.position !== 'closed') {
106
+ push(entry);
107
+ return { position: { stack, locals }, outcome: 'next', value };
108
+ }
109
+ else if (method !== 'return') {
110
+ method = 'next';
111
+ if (entry.receive)
112
+ operands.set(entry.receive, value);
113
+ }
114
+ continue;
115
+ }
116
+ if (entry.kind === 'completion') {
117
+ if (method === 'next') {
118
+ method = entry.method;
119
+ value = entry.value;
120
+ }
121
+ continue;
122
+ }
123
+ if (entry.kind === 'catch') {
124
+ if (method !== 'throw')
125
+ continue;
126
+ const inside = [...entry.scopes, entry.node];
127
+ if (entry.node.param) {
128
+ const result = bindCatch(entry.node, inside, value, !!stack?.handlesThrow);
129
+ if ('thrown' in result) {
130
+ value = result.thrown;
131
+ continue;
132
+ }
133
+ }
134
+ method = 'next';
135
+ push({ kind: 'statement', node: entry.node.body, scopes: inside });
136
+ continue;
137
+ }
138
+ else if (entry.kind === 'finally') {
139
+ if (method !== 'next')
140
+ push({ kind: 'completion', method, value });
141
+ method = 'next';
142
+ }
143
+ if (entry.kind === 'delegate') {
144
+ if (method === 'throw')
145
+ value = unresolved;
146
+ if (method !== 'next' || entry.index === entry.items.length)
147
+ continue;
148
+ const index = entry.index;
149
+ push({ ...entry, index: index + 1 });
150
+ return { position: { stack, locals }, outcome: 'next', value: entry.items[index] };
151
+ }
152
+ if (method !== 'next')
153
+ continue;
154
+ const { node, scopes } = entry;
155
+ if (node.type === 'BlockStatement') {
156
+ const inside = [...scopes, node];
157
+ for (let i = node.body.length - 1; i >= 0; i--)
158
+ push({ kind: 'statement', node: node.body[i], scopes: inside });
159
+ }
160
+ else if (node.type === 'TryStatement') {
161
+ if (node.finalizer)
162
+ push({ kind: 'finally', node: node.finalizer, scopes });
163
+ if (node.handler)
164
+ push({ kind: 'catch', node: node.handler, scopes });
165
+ push({ kind: 'statement', node: node.block, scopes });
166
+ }
167
+ else {
168
+ const expression = node.type === 'ExpressionStatement' ? unwrap(node.expression) : null;
169
+ let yieldNode = expression?.type === 'YieldExpression' ? expression : null;
170
+ let receive;
171
+ const operand = yieldNode
172
+ ? yieldNode.argument
173
+ : node.type === 'ReturnStatement' || node.type === 'ThrowStatement'
174
+ ? node.argument
175
+ : node.type === 'IfStatement'
176
+ ? node.test
177
+ : node;
178
+ let result;
179
+ if (operand && suspends(operand)) {
180
+ const declaration = node.type === 'VariableDeclaration' && node.declarations.length === 1 && node.declarations[0];
181
+ const input = operand !== node
182
+ ? operand
183
+ : (expression ?? (declaration && declaration.id.type === 'Identifier' && declaration.init));
184
+ if (!input)
185
+ return unknownStep();
186
+ result = resumeExpression(input, operands, (part) => evaluate(part, scopes, true, handlesThrow), (name) => {
187
+ enterCall(name, scopes);
188
+ });
189
+ if (result === 'unknown')
190
+ return unknownStep();
191
+ if (typeof result === 'object' && 'receive' in result) {
192
+ push(entry);
193
+ receive = yieldNode = result.receive;
194
+ result = result.value;
195
+ }
196
+ }
197
+ else
198
+ result = operand ? evaluate(operand, scopes, operand !== node, handlesThrow) : omitted;
199
+ if ('thrown' in result) {
200
+ method = 'throw';
201
+ value = result.thrown;
202
+ }
203
+ else if (yieldNode) {
204
+ if (!yieldNode.delegate)
205
+ return { position: { stack, locals, receive }, outcome: 'next', value: result };
206
+ const iterable = yieldNode.argument;
207
+ const iterator = iteratorOf(iterable, scopes);
208
+ if (iterator) {
209
+ push({ kind: 'forward', iterator, receive });
210
+ value = omitted;
211
+ continue;
212
+ }
213
+ // Built-in string and array iterators finish with an undefined value.
214
+ if (receive)
215
+ operands.set(receive, omitted);
216
+ if (spreadDelegate) {
217
+ const outcome = spreadDelegate(iterable, scopes);
218
+ if (outcome === 'unknown')
219
+ return unknownStep();
220
+ method = outcome;
221
+ value = unresolved;
222
+ continue;
223
+ }
224
+ if (!result.ok)
225
+ return unknownStep();
226
+ if (typeof result.value !== 'string' && !Array.isArray(result.value)) {
227
+ method = 'throw';
228
+ value = unresolved;
229
+ }
230
+ else {
231
+ const items = Array.from(result.value, (value) => ({ ok: true, value }));
232
+ if (items.length)
233
+ push({ kind: 'delegate', items, index: 0 });
234
+ }
235
+ }
236
+ else if (node.type === 'ReturnStatement' || node.type === 'ThrowStatement') {
237
+ method = node.type === 'ReturnStatement' ? 'return' : 'throw';
238
+ value = result;
239
+ }
240
+ else if (node.type === 'IfStatement') {
241
+ if (!result.ok)
242
+ return unknownStep();
243
+ const branch = result.value ? node.consequent : node.alternate;
244
+ if (branch)
245
+ push({ kind: 'statement', node: branch, scopes });
246
+ }
247
+ }
248
+ }
249
+ return {
250
+ position: 'closed',
251
+ outcome: method === 'throw' ? 'throw' : 'next',
252
+ value: method === 'next' ? omitted : value,
253
+ };
254
+ }
package/dist/model.d.ts CHANGED
@@ -2,7 +2,8 @@ import type { CallExpression, Expression, Node } from 'oxc-parser';
2
2
  import type { FunctionNode } from './ast.ts';
3
3
  import type { Scope } from './extract.ts';
4
4
  import type { Annotation, DiagnosticCode, DiagnosticLevel, HookCounts, MetaValue } from './types.ts';
5
- import type { Value } from './values.ts';
5
+ import type { IteratorSpread, Resolved, Value } from './values.ts';
6
+ import type { VitestConcurrency } from './vitest-concurrency.ts';
6
7
  export type State = 'skip' | 'fixme' | 'todo' | 'expectedToFail';
7
8
  /** The Vitest options that set a test's state. */
8
9
  export type StateOption = 'skip' | 'only' | 'todo' | 'fails';
@@ -79,8 +80,14 @@ interface Declaration {
79
80
  states: StateSetting[];
80
81
  isOnly: boolean;
81
82
  mode: Mode | null;
82
- /** Vitest: the line of the describe whose `skip` option reaches this declaration, merged into its options. */
83
- skipPassedDown?: number;
83
+ vitestConcurrency?: VitestConcurrency;
84
+ /** A Vitest suite's inherited skip, and the declaration's states if a config tag clears it. */
85
+ skipPassedDown?: {
86
+ line: number;
87
+ withoutSkip: StateSetting[];
88
+ };
89
+ /** Vitest: a suite's todo option merged into the test's options, independent of a nested suite's mode. */
90
+ todoPassedDown?: number;
84
91
  details: Details;
85
92
  fn: FunctionNode | null;
86
93
  /**
@@ -97,8 +104,10 @@ interface Declaration {
97
104
  }
98
105
  /** One case of a `.each` or `.for` table: the title the runner gives it, and the arguments its callback gets. */
99
106
  export interface TableCase {
100
- /** Null when the scan can't format it the way the runner does, as for a title that shows an object. */
101
- title: string | null;
107
+ /** Null for an unsupported value, or a reason when the runner's config prevents expansion. */
108
+ title: string | null | {
109
+ reason: string;
110
+ };
102
111
  args: Value[];
103
112
  }
104
113
  export interface TestDeclaration extends Declaration {
@@ -114,9 +123,20 @@ export interface TestDeclaration extends Declaration {
114
123
  usesBench: boolean;
115
124
  /** Vitest: the state options the test sets itself, to `false` too, which replace those of its tags. */
116
125
  ownStateOptions?: StateOption[];
126
+ /** Vitest: a suite's only option takes priority over skip and todo unless a tag clears the inherited focus. */
127
+ inheritsOnly?: boolean;
128
+ /** Line of the test's fails flag, including when skip or todo would otherwise hide it. */
129
+ failsLine?: number;
130
+ /** Vitest: line of the inherited fails option, before the test's tags are resolved. */
131
+ failsPassedDown?: number;
117
132
  }
118
133
  export interface SuiteDeclaration extends Declaration {
119
134
  kind: 'describe';
135
+ /** Jasmine adds the suite before it checks for children. Since 4.5 a failure leaves it current. */
136
+ emptySuiteError?: {
137
+ problem: Problem;
138
+ keepsScope: boolean;
139
+ };
120
140
  isShuffled: boolean;
121
141
  /** What the describe passes down to the calls inside it, such as Vitest's `skip` option; null for nothing. */
122
142
  passesDown: unknown;
@@ -181,6 +201,8 @@ export type ApiCall = TestDeclaration | SuiteDeclaration | {
181
201
  kind: 'other';
182
202
  };
183
203
  export interface CallContext {
204
+ /** The call runs inside a try block or helper whose registration error may be caught by user code. */
205
+ handlesRegistrationError?: boolean;
184
206
  scopes: readonly Node[];
185
207
  /** The test context of the test or hook whose body the call is in, as the framework returned it. */
186
208
  testContext: unknown;
@@ -232,6 +254,16 @@ export interface Adapter {
232
254
  usesGlobals: boolean;
233
255
  /** Whether a test declared in a test's body is a subtest the runner runs as the test does, as in `node:test`. */
234
256
  nestsTests?: boolean;
257
+ /** A suite callback catches registration errors and preserves the children registered before them. */
258
+ catchesSuiteErrors?: boolean;
259
+ /** Read the values supplied by a spread operand during registration. */
260
+ registrationSpread?(operand: Expression, scopes: readonly Node[]): IteratorSpread;
261
+ /** Resolve a value computed during registration, including a local helper return. */
262
+ registrationValue?(operand: Expression, scopes: readonly Node[]): Resolved;
263
+ /** How a synchronous registration block completes, when the runner and local helpers determine its path. */
264
+ registrationExit?(block: Extract<Node, {
265
+ type: 'BlockStatement';
266
+ }>, scopes: readonly Node[]): 'next' | 'return' | 'throw' | 'unknown';
235
267
  classify(call: CallExpression, context: CallContext): ApiCall | null;
236
268
  /**
237
269
  * The test or describe function a value holds, in the adapter's own terms, as `it.skip` in `return it.skip`; null
@@ -0,0 +1,25 @@
1
+ import type { ArrayExpression, CallExpression, Expression, Node } from 'oxc-parser';
2
+ import type { MethodWrite } from './mutation-calls.ts';
3
+ import { type Reference } from './mutation-references.ts';
4
+ import { type ArrayReadTime } from './mutation-order.ts';
5
+ export interface PropertySource {
6
+ ref: Reference | null;
7
+ scopes: readonly Node[];
8
+ }
9
+ export interface ArrayMethod extends Omit<MethodWrite, 'assigned' | 'expression' | 'name'> {
10
+ name: string;
11
+ expression: CallExpression;
12
+ args: {
13
+ spread: boolean;
14
+ choices: PropertySource[];
15
+ }[];
16
+ }
17
+ export type ArrayChange = MethodWrite | ArrayMethod;
18
+ export declare function arrayArguments(call: CallExpression, scopes: readonly Node[], resolve?: (expression: Expression) => {
19
+ value: Expression;
20
+ scopes: readonly Node[];
21
+ }[]): ArrayMethod['args'];
22
+ /** Array methods can move numeric slots without replacing named properties such as the method itself. */
23
+ export declare function changesMember(change: ArrayChange, key: string | null): boolean;
24
+ /** Index the edits once. Read a slot at the requested point in module evaluation. */
25
+ export declare function arrayPropertyReader(array: ArrayExpression, scopes: readonly Node[], program: Node, history: readonly ArrayChange[], spreadLength: (source: Expression, scopes: readonly Node[]) => number | null): (key: string | null, time: ArrayReadTime) => PropertySource[] | null;