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
@@ -0,0 +1,229 @@
1
+ import { unwrapChain } from "./ast.js";
2
+ import { literalArguments, property } from "./mutation-references.js";
3
+ import { upperBound, visibleAt } from "./mutation-order.js";
4
+ export function arrayArguments(call, scopes, resolve) {
5
+ return Array.from(literalArguments(call.arguments), (argument) => {
6
+ const spread = argument?.type === 'SpreadElement';
7
+ const value = spread ? argument.argument : argument;
8
+ const choices = value && resolve ? resolve(value).map((source) => slot(source.value, source.scopes)) : [slot(value, scopes)];
9
+ return { spread, choices };
10
+ });
11
+ }
12
+ function slot(value, scopes) {
13
+ return { ref: value && { value, path: [] }, scopes };
14
+ }
15
+ function indexOf(key) {
16
+ const index = Number(key);
17
+ return Number.isInteger(index) && index >= 0 && index < 0xffffffff && String(index) === key ? index : null;
18
+ }
19
+ /** Array methods can move numeric slots without replacing named properties such as the method itself. */
20
+ export function changesMember(change, key) {
21
+ if (key === null)
22
+ return true;
23
+ if (!('args' in change) && change.name !== 'length')
24
+ return change.name === null || change.name === key;
25
+ return key === 'length' || indexOf(key) !== null;
26
+ }
27
+ /** Only literal offsets can determine which existing slots an edit moves. */
28
+ function numberAt(expr, fallback) {
29
+ if (!expr)
30
+ return fallback;
31
+ const value = unwrapChain(expr);
32
+ if (value.type === 'Literal' && typeof value.value === 'number')
33
+ return Math.trunc(value.value);
34
+ if (value.type === 'UnaryExpression' &&
35
+ value.operator === '-' &&
36
+ value.argument.type === 'Literal' &&
37
+ typeof value.argument.value === 'number')
38
+ return Math.trunc(-value.argument.value);
39
+ return null;
40
+ }
41
+ function relative(n, length) {
42
+ return n < 0 ? Math.max(0, length + n) : Math.min(n, length);
43
+ }
44
+ /** Translate a slot in the edited array back to its source without allocating holes. */
45
+ function splice(length, start, count, inserted) {
46
+ const removed = Math.min(count, length - start);
47
+ return {
48
+ length: length - removed + inserted.length,
49
+ at(index) {
50
+ if (index < start)
51
+ return index;
52
+ const offset = index - start;
53
+ return offset < inserted.length ? inserted[offset] : index - inserted.length + removed;
54
+ },
55
+ };
56
+ }
57
+ function applyMethod(length, event) {
58
+ const { name } = event;
59
+ if (event.args.some((arg) => arg.spread || arg.choices.length !== 1))
60
+ return null;
61
+ const slots = event.args.map((arg) => arg.choices[0]);
62
+ const args = slots.map((source) => source.ref?.value);
63
+ switch (name) {
64
+ case 'push':
65
+ return splice(length, length, 0, slots);
66
+ case 'unshift':
67
+ return splice(length, 0, 0, slots);
68
+ case 'shift':
69
+ return splice(length, 0, 1, []);
70
+ case 'pop':
71
+ return { length: Math.max(0, length - 1) };
72
+ case 'reverse':
73
+ return { length, at: (index) => length - 1 - index };
74
+ case 'splice': {
75
+ const begin = numberAt(args[0], 0);
76
+ const count = numberAt(args[1], args.length === 1 ? length : 0);
77
+ return begin === null || count === null
78
+ ? null
79
+ : splice(length, relative(begin, length), Math.max(count, 0), slots.slice(2));
80
+ }
81
+ case 'fill': {
82
+ const begin = numberAt(args[1], 0), end = numberAt(args[2], length);
83
+ if (begin === null || end === null)
84
+ return null;
85
+ const start = relative(begin, length), stop = relative(end, length), element = slots[0] ?? slot(null, event.scopes);
86
+ return { length, at: (index) => (index >= start && index < stop ? element : index) };
87
+ }
88
+ case 'copyWithin': {
89
+ const dest = numberAt(args[0], 0), begin = numberAt(args[1], 0), end = numberAt(args[2], length);
90
+ if (dest === null || begin === null || end === null)
91
+ return null;
92
+ const target = relative(dest, length), start = relative(begin, length), count = relative(end, length) - start;
93
+ return { length, at: (index) => (index >= target && index < target + count ? start + index - target : index) };
94
+ }
95
+ default:
96
+ return null;
97
+ }
98
+ }
99
+ function applyWrite(length, write, own) {
100
+ if (write.name === null)
101
+ return null;
102
+ if (write.name === 'length') {
103
+ const value = write.assigned && unwrapChain(write.assigned);
104
+ const next = value?.type === 'Literal' ? value.value : null;
105
+ return typeof next === 'number' && Number.isInteger(next) && next >= 0 && next <= 0xffffffff
106
+ ? { length: next }
107
+ : null;
108
+ }
109
+ const key = indexOf(write.name);
110
+ if (key === null) {
111
+ if (write.assigned)
112
+ own.add(write.name);
113
+ else
114
+ own.delete(write.name);
115
+ return { length };
116
+ }
117
+ const assigned = slot(write.assigned, write.scopes);
118
+ return {
119
+ length: write.assigned ? Math.max(length, key + 1) : length,
120
+ at: (index) => (index === key ? assigned : index),
121
+ };
122
+ }
123
+ /** A conditional edit or an unknown layout can select an original slot or one of the inserted values. */
124
+ function possibleSlots(array, scopes, changes) {
125
+ const candidates = Array.from(property({ value: array, path: [] }, null), (ref) => ({ ref, scopes }));
126
+ for (const change of changes) {
127
+ if (!('args' in change)) {
128
+ if (change.assigned && (change.name === null || indexOf(change.name) !== null))
129
+ candidates.push(slot(change.assigned, change.scopes));
130
+ continue;
131
+ }
132
+ let args = change.args;
133
+ if (change.name === 'splice') {
134
+ if (!args.slice(0, 2).some((arg) => arg.spread))
135
+ args = args.slice(2);
136
+ }
137
+ else if (change.name === 'fill')
138
+ args = args.slice(0, 1);
139
+ else if (change.name !== 'push' && change.name !== 'unshift')
140
+ continue;
141
+ for (const arg of args)
142
+ for (const source of arg.choices)
143
+ candidates.push(arg.spread && source.ref ? { ref: { ...source.ref, path: [null] }, scopes: source.scopes } : source);
144
+ }
145
+ return candidates;
146
+ }
147
+ /** Index the edits once. Read a slot at the requested point in module evaluation. */
148
+ export function arrayPropertyReader(array, scopes, program, history, spreadLength) {
149
+ const elements = [...literalArguments(array.elements)];
150
+ let initialLength = 0;
151
+ let known = true;
152
+ const origins = [];
153
+ for (const element of elements) {
154
+ const width = element?.type === 'SpreadElement' ? spreadLength(element.argument, scopes) : 1;
155
+ if (width === null) {
156
+ known = false;
157
+ break;
158
+ }
159
+ if (width)
160
+ origins.push({ start: initialLength, element });
161
+ initialLength += width;
162
+ }
163
+ const missing = slot(null, scopes);
164
+ const layouts = [];
165
+ const own = new Set();
166
+ const ordered = history.every((change) => change.owner === program);
167
+ if (known && ordered) {
168
+ let length = initialLength;
169
+ for (const change of history) {
170
+ if (!change.unconditional)
171
+ break;
172
+ const next = 'args' in change
173
+ ? own.has(change.name)
174
+ ? { length }
175
+ : applyMethod(length, change)
176
+ : applyWrite(length, change, own);
177
+ if (!next)
178
+ break;
179
+ layouts.push(next);
180
+ length = next.length;
181
+ }
182
+ }
183
+ const firstMethod = history.findIndex((change) => 'args' in change);
184
+ // Collection can ask about an earlier copy after looking up a later invocation.
185
+ let cachedCount = -1;
186
+ const cache = new Map();
187
+ return (key, time) => {
188
+ const index = key === null ? null : indexOf(key);
189
+ if (key !== null && index === null)
190
+ return null;
191
+ const count = time !== null && ordered ? upperBound(history, (change) => visibleAt(change, time)) : history.length;
192
+ if (count <= firstMethod)
193
+ return null;
194
+ if (index === null || time === null || count > layouts.length) {
195
+ const changes = ordered
196
+ ? history.slice(0, count)
197
+ : history.filter((change) => change.owner !== program || visibleAt(change, time));
198
+ return possibleSlots(array, scopes, changes);
199
+ }
200
+ if (count !== cachedCount) {
201
+ cache.clear();
202
+ cachedCount = count;
203
+ }
204
+ const cached = cache.get(index);
205
+ if (cached)
206
+ return cached;
207
+ let position = index;
208
+ for (let i = count - 1; i >= 0 && typeof position === 'number'; i--) {
209
+ const layout = layouts[i];
210
+ if (position >= layout.length)
211
+ position = missing;
212
+ else if (layout.at)
213
+ position = layout.at(position);
214
+ }
215
+ let result = missing;
216
+ if (typeof position !== 'number')
217
+ result = position;
218
+ else if (position < initialLength) {
219
+ const origin = origins[upperBound(origins, (entry) => entry.start <= position) - 1];
220
+ result =
221
+ origin.element?.type === 'SpreadElement'
222
+ ? { scopes, ref: { value: origin.element.argument, path: [String(position - origin.start)] } }
223
+ : slot(origin.element, scopes);
224
+ }
225
+ const found = [result];
226
+ cache.set(index, found);
227
+ return found;
228
+ };
229
+ }
@@ -0,0 +1,33 @@
1
+ import type { CallExpression, Expression, Node } from 'oxc-parser';
2
+ import { type patternReferences, type CallbackContext, type HelperInvocation } from './mutation-references.ts';
3
+ import { type PropertySource } from './mutation-arrays.ts';
4
+ import type { Values } from './values.ts';
5
+ import { HelperReadTimes, type ArrayReadTime } from './mutation-order.ts';
6
+ export interface MutationCallSite {
7
+ call: CallExpression;
8
+ scopes: readonly Node[];
9
+ statement: Node | null;
10
+ runsLater: boolean;
11
+ bindOwner?: Expression;
12
+ arrayMethod?: string;
13
+ accessor?: 'get' | 'set';
14
+ }
15
+ export interface MethodWrite {
16
+ step?: number;
17
+ expression: Node;
18
+ name: string | null;
19
+ object: Expression;
20
+ assigned: Expression | null;
21
+ scopes: readonly Node[];
22
+ owner: Node;
23
+ end: number;
24
+ unconditional: boolean;
25
+ }
26
+ /** Calls with the same callback arguments share a walk of the helper body, including when it calls itself. */
27
+ export declare function mutationCalls(program: Node, callsByOwner: ReadonlyMap<Node, MutationCallSite[]>, methodWrites: readonly MethodWrite[], suspensions: readonly number[], values: Values, patterns: ReadonlyMap<Node, ReturnType<typeof patternReferences>>): {
28
+ calls: Map<CallExpression, HelperInvocation[]>;
29
+ callTimes: Map<Node, number | null>;
30
+ returnedContexts: Map<Node, CallbackContext[]>;
31
+ memberSources: (value: Expression, scopes: readonly Node[], key: string | null, time: ArrayReadTime) => PropertySource[];
32
+ readTimes: HelperReadTimes;
33
+ };