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.
- package/CHANGELOG.md +135 -0
- package/README.md +2 -1
- package/dist/ast.d.ts +7 -2
- package/dist/ast.js +43 -3
- package/dist/case-titles.d.ts +5 -11
- package/dist/case-titles.js +69 -55
- package/dist/config-runs.d.ts +19 -2
- package/dist/config-runs.js +379 -90
- package/dist/config.d.ts +0 -5
- package/dist/config.js +0 -7
- package/dist/dependency-hash.js +1 -32
- package/dist/diagnostics.js +17 -2
- package/dist/diff.d.ts +2 -45
- package/dist/extract.d.ts +13 -3
- package/dist/extract.js +837 -89
- package/dist/frameworks/bun.js +47 -24
- package/dist/frameworks/common.d.ts +4 -2
- package/dist/frameworks/common.js +10 -11
- package/dist/frameworks/jasmine-registration.d.ts +47 -0
- package/dist/frameworks/jasmine-registration.js +632 -0
- package/dist/frameworks/jasmine.d.ts +7 -1
- package/dist/frameworks/jasmine.js +65 -70
- package/dist/frameworks/jest.d.ts +2 -2
- package/dist/frameworks/jest.js +126 -51
- package/dist/frameworks/vitest.d.ts +2 -3
- package/dist/frameworks/vitest.js +80 -16
- package/dist/generator-steps.d.ts +56 -0
- package/dist/generator-steps.js +254 -0
- package/dist/model.d.ts +37 -5
- package/dist/mutation-arrays.d.ts +25 -0
- package/dist/mutation-arrays.js +229 -0
- package/dist/mutation-calls.d.ts +33 -0
- package/dist/mutation-calls.js +774 -0
- package/dist/mutation-order.d.ts +19 -0
- package/dist/mutation-order.js +55 -0
- package/dist/mutation-references.d.ts +109 -0
- package/dist/mutation-references.js +462 -0
- package/dist/mutation-returns.d.ts +13 -0
- package/dist/mutation-returns.js +71 -0
- package/dist/node-scripts.d.ts +4 -1
- package/dist/node-scripts.js +77 -11
- package/dist/options.d.ts +2 -0
- package/dist/options.js +6 -1
- package/dist/records.d.ts +5 -3
- package/dist/records.js +81 -28
- package/dist/scan-file.d.ts +18 -4
- package/dist/scan-file.js +44 -5
- package/dist/scan-source.js +2 -1
- package/dist/scan.js +30 -13
- package/dist/types.d.ts +45 -1
- package/dist/values.d.ts +72 -18
- package/dist/values.js +651 -172
- package/dist/vitest-concurrency.d.ts +16 -0
- package/dist/vitest-concurrency.js +55 -0
- package/package.json +1 -1
- package/schema/v1.json +1 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isFunctionNode, unwrap } from "../ast.js";
|
|
2
2
|
import { snippet } from "../source.js";
|
|
3
|
-
import { atLeast,
|
|
3
|
+
import { atLeast, problem, readChain, readCount, readReason, readTitle, refused, text, wrappedFunction, } from "./common.js";
|
|
4
4
|
import { SuiteAdapter } from "./test-functions.js";
|
|
5
|
+
import { functionLength, isRuntimeFunction, jasmineSpread, jasmineArguments, jasmineCallback, jasmineRegistration, jasmineTitleValue, jasmineValue, registrationExit, } from "./jasmine-registration.js";
|
|
5
6
|
const HOOKS = ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'];
|
|
6
7
|
const JASMINE = {
|
|
7
8
|
name: 'Jasmine',
|
|
@@ -40,6 +41,16 @@ const JASMINE = {
|
|
|
40
41
|
const IN_SPEC = Symbol('in a spec');
|
|
41
42
|
const IN_DESCRIBE = Symbol('in a describe');
|
|
42
43
|
export class JasmineAdapter extends SuiteAdapter {
|
|
44
|
+
catchesSuiteErrors = true;
|
|
45
|
+
registrationSpread(operand, scopes) {
|
|
46
|
+
return jasmineSpread(operand, scopes, this.file);
|
|
47
|
+
}
|
|
48
|
+
registrationValue(operand, scopes) {
|
|
49
|
+
return jasmineValue(operand, scopes, this.file);
|
|
50
|
+
}
|
|
51
|
+
registrationExit(block, scopes) {
|
|
52
|
+
return registrationExit(block, scopes, this.file);
|
|
53
|
+
}
|
|
43
54
|
/** What the runner does with a call it refuses at the top level of a file, as the end of a sentence. */
|
|
44
55
|
refusedEffect = 'Jasmine stops before it runs any spec';
|
|
45
56
|
/** Whether a number after a spec's timeout is a retry count, as WebdriverIO reads it. */
|
|
@@ -55,7 +66,12 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
55
66
|
return link.name === 'skip' || link.name === 'only';
|
|
56
67
|
}
|
|
57
68
|
hook(call, name, context) {
|
|
58
|
-
const
|
|
69
|
+
const [body, limit] = jasmineArguments(call.arguments, context.scopes, this.file, 2);
|
|
70
|
+
const { status, fn } = jasmineRegistration(jasmineCallback(body, this.file), limit, this.file, false);
|
|
71
|
+
if (status === 'callback' || status === 'timeout') {
|
|
72
|
+
const reason = status === 'callback' ? 'requires a non-generator function' : 'refuses a timeout above 2147483647';
|
|
73
|
+
return { kind: 'invalid', problem: this.refusal('invalid-hook', call, `${name}() ${reason}`, context) };
|
|
74
|
+
}
|
|
59
75
|
// In `beforeAll` and `afterAll`, `pending()` is an error of the describe, and the specs keep the state they get.
|
|
60
76
|
const testContext = name === 'beforeEach' || name === 'afterEach' ? IN_SPEC : null;
|
|
61
77
|
return { kind: 'hook', name, fn, testContext, fixtures: [], takesAllFixtures: false };
|
|
@@ -111,22 +127,24 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
111
127
|
}
|
|
112
128
|
const flags = new Set(links.map((link) => link.name));
|
|
113
129
|
const problems = [];
|
|
130
|
+
const spec = kind === 'test';
|
|
131
|
+
const slots = jasmineArguments(args, context.scopes, this.file, spec ? (this.trailingRetries ? 4 : 3) : 2);
|
|
132
|
+
const [titleArg, bodyArg] = slots;
|
|
114
133
|
let title = { text: '', withoutTags: '', isDynamic: false };
|
|
115
|
-
if (
|
|
116
|
-
const read = readTitle(this.file,
|
|
134
|
+
if (titleArg) {
|
|
135
|
+
const read = readTitle(this.file, titleArg.scopes, titleArg.node, { stripTags: false, functionNames: false }, jasmineTitleValue(titleArg, this.file, spec));
|
|
117
136
|
title = read.title;
|
|
118
137
|
if (read.problem)
|
|
119
138
|
problems.push(read.problem);
|
|
120
139
|
}
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const
|
|
140
|
+
const body = bodyArg?.node;
|
|
141
|
+
const read = jasmineCallback(bodyArg, this.file);
|
|
142
|
+
const binding = read.binding;
|
|
143
|
+
const callback = binding?.fn;
|
|
144
|
+
// A function in a named tuple uses its defining scope, like a named callback.
|
|
145
|
+
const fn = isFunctionNode(body) && bodyArg?.scopes === context.scopes ? body : null;
|
|
127
146
|
const line = this.file.source.line(call.start);
|
|
128
|
-
|
|
129
|
-
const isSkipped = flags.has('skip') || (kind === 'test' && body === undefined);
|
|
147
|
+
const isSkipped = flags.has('skip') || (spec && read.status === 'missing');
|
|
130
148
|
const base = {
|
|
131
149
|
title,
|
|
132
150
|
states: isSkipped
|
|
@@ -136,13 +154,14 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
136
154
|
mode: null,
|
|
137
155
|
details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
|
|
138
156
|
fn,
|
|
139
|
-
hashed: callback ?? wrappedFunction(body
|
|
157
|
+
hashed: callback ?? wrappedFunction(body),
|
|
140
158
|
isParameterized: false,
|
|
141
159
|
caseCount: null,
|
|
142
160
|
cases: null,
|
|
143
161
|
problems,
|
|
144
162
|
};
|
|
145
|
-
if (
|
|
163
|
+
if (spec) {
|
|
164
|
+
const registration = jasmineRegistration(read, slots[2], this.file, !flags.has('only'));
|
|
146
165
|
const declared = {
|
|
147
166
|
kind: 'test',
|
|
148
167
|
...base,
|
|
@@ -151,44 +170,48 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
151
170
|
takesAllFixtures: false,
|
|
152
171
|
usesBench: false,
|
|
153
172
|
};
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const option = { node: retries, resolved: this.file.values.resolve(retries, context.scopes) };
|
|
164
|
-
const count = readCount(this.file, 'retries', option, problems);
|
|
165
|
-
if (count !== null)
|
|
166
|
-
declared.details.run = { ...declared.details.run, retry: { count, delay: null, condition: null } };
|
|
173
|
+
const readOption = (name, slot) => {
|
|
174
|
+
if (!slot || slot.node.type === 'SpreadElement')
|
|
175
|
+
return null;
|
|
176
|
+
const resolved = slot.resolved ?? this.file.values.resolve(slot.node, slot.scopes);
|
|
177
|
+
return readCount(this.file, name, { node: slot.node, resolved }, problems);
|
|
178
|
+
};
|
|
179
|
+
if (registration.status === 'timeout') {
|
|
180
|
+
const refusal = this.refusal('unresolved-option', call, `${callee}() refuses a timeout above 2147483647`, context);
|
|
181
|
+
return refused(call, { ...refusal, level: 'error' }, context, () => declared);
|
|
167
182
|
}
|
|
168
|
-
|
|
183
|
+
const timeout = readOption('timeout', slots[2]);
|
|
184
|
+
if (timeout !== null)
|
|
185
|
+
declared.details.run = { timeout };
|
|
186
|
+
const retries = readOption('retries', slots[3]);
|
|
187
|
+
if (retries !== null)
|
|
188
|
+
declared.details.run = { ...declared.details.run, retry: { count: retries, delay: null, condition: null } };
|
|
189
|
+
if (registration.status !== 'callback')
|
|
169
190
|
return declared;
|
|
170
|
-
const reason =
|
|
191
|
+
const reason = registration.missing ? `${callee}() has no function` : `${callee}() takes a function second`;
|
|
171
192
|
return refused(call, this.refusal('test-without-body', call, reason, context), context, () => declared);
|
|
172
193
|
}
|
|
173
194
|
const declared = { kind: 'describe', ...base, isShuffled: false, passesDown: IN_DESCRIBE };
|
|
174
|
-
if (
|
|
175
|
-
return declared;
|
|
176
|
-
if (body === undefined || !isFunctionLike(body)) {
|
|
195
|
+
if (read.status === 'missing' || read.status === 'callback') {
|
|
177
196
|
const refusal = this.refusal('test-without-body', call, `${callee}() has no function`, context);
|
|
178
197
|
return refused(call, refusal, context, () => declared);
|
|
179
198
|
}
|
|
180
|
-
if (callback
|
|
181
|
-
const refusal = this.refusal('async-describe', callback,
|
|
182
|
-
return refused(call, refusal, context, () => declared);
|
|
183
|
-
}
|
|
184
|
-
if (callback && declaresNothing(callback)) {
|
|
185
|
-
const refusal = this.refusal('describe-throws', callback, 'The describe declares no spec or describe, which Jasmine refuses', context);
|
|
199
|
+
if (callback && (callback.async || callback.generator)) {
|
|
200
|
+
const refusal = this.refusal(callback.async ? 'async-describe' : 'describe-throws', callback, `The describe callback is ${callback.async ? 'async' : 'a generator'}, which Jasmine refuses`, context);
|
|
186
201
|
return refused(call, refusal, context, () => declared);
|
|
187
202
|
}
|
|
188
|
-
|
|
203
|
+
const plain = flags.size === 0;
|
|
204
|
+
if (callback && plain && functionLength(callback) > 0) {
|
|
189
205
|
const refusal = this.refusal('describe-throws', callback, 'The describe callback takes arguments, which Jasmine refuses', context);
|
|
190
206
|
return refused(call, refusal, context, () => declared);
|
|
191
207
|
}
|
|
208
|
+
if (isRuntimeFunction(binding?.fn) &&
|
|
209
|
+
atLeast(this.file.version, 4, plain ? 0 : 5) &&
|
|
210
|
+
registrationExit({ call, fn: binding.fn, definition: binding.scopes, plain }, context.scopes, this.file) ===
|
|
211
|
+
'throw') {
|
|
212
|
+
const refusal = this.refusal('describe-throws', binding.fn, 'The describe declares no spec or describe, which Jasmine refuses', context);
|
|
213
|
+
return { ...declared, emptySuiteError: { problem: refusal, keepsScope: atLeast(this.file.version, 4, 5) } };
|
|
214
|
+
}
|
|
192
215
|
return declared;
|
|
193
216
|
}
|
|
194
217
|
/**
|
|
@@ -197,6 +220,9 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
197
220
|
*/
|
|
198
221
|
refusal(code, node, what, context) {
|
|
199
222
|
const source = snippet(text(this.file, node));
|
|
223
|
+
if (context.handlesRegistrationError) {
|
|
224
|
+
return problem(code, node, `${what}, so this call throws during Jasmine registration.`, source);
|
|
225
|
+
}
|
|
200
226
|
if (context.passedDown !== IN_DESCRIBE) {
|
|
201
227
|
return problem(code, node, `${what}, so ${this.refusedEffect}.`, source);
|
|
202
228
|
}
|
|
@@ -204,34 +230,3 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
204
230
|
return { ...problem(code, node, message, source), afterLoad: true };
|
|
205
231
|
}
|
|
206
232
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Whether a describe callback surely declares nothing: its body is empty or holds only hook calls. A call to anything
|
|
209
|
-
* else, as a helper that declares specs, may declare some.
|
|
210
|
-
*/
|
|
211
|
-
function declaresNothing(fn) {
|
|
212
|
-
if (fn.body?.type !== 'BlockStatement')
|
|
213
|
-
return false;
|
|
214
|
-
return fn.body.body.every((statement) => {
|
|
215
|
-
if (statement.type !== 'ExpressionStatement')
|
|
216
|
-
return false;
|
|
217
|
-
const expression = unwrap(statement.expression);
|
|
218
|
-
if (expression.type !== 'CallExpression')
|
|
219
|
-
return false;
|
|
220
|
-
const callee = unwrap(expression.callee);
|
|
221
|
-
return callee.type === 'Identifier' && HOOKS.includes(callee.name);
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
/** Whether an argument may be a function: anything but a value that can't be one, as a number or an object. */
|
|
225
|
-
function isFunctionLike(node) {
|
|
226
|
-
const value = unwrap(node);
|
|
227
|
-
return !['Literal', 'ObjectExpression', 'ArrayExpression', 'TemplateLiteral'].includes(value.type);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* A function's `length`, which Jasmine checks: its parameters before the first with a default value or a rest, without
|
|
231
|
-
* TypeScript's `this`, which is no parameter at run time.
|
|
232
|
-
*/
|
|
233
|
-
function functionLength(fn) {
|
|
234
|
-
const params = fn.params.filter((param) => param.type !== 'Identifier' || param.name !== 'this');
|
|
235
|
-
const end = params.findIndex((param) => param.type === 'AssignmentPattern' || param.type === 'RestElement');
|
|
236
|
-
return end === -1 ? params.length : end;
|
|
237
|
-
}
|
|
@@ -18,9 +18,9 @@ export declare class JestAdapter extends SuiteAdapter {
|
|
|
18
18
|
/** Whether an expression is Jest's `jest` object: the global, a name imported from Jest, or a member of the module. */
|
|
19
19
|
private isJest;
|
|
20
20
|
private chainCall;
|
|
21
|
+
/** The title Jest registers, false for a rejected descriptor, or null when the value is unknown. */
|
|
22
|
+
private titleName;
|
|
21
23
|
private declaration;
|
|
22
|
-
/** Whether a table makes `describe.each` throw, as jest-each does on an empty array or a value that isn't a table. */
|
|
23
|
-
private isInvalidTable;
|
|
24
24
|
/** Jest's order: `todo` and `skip` set the test's mode, `only` runs it, and `failing` applies when it runs. */
|
|
25
25
|
private states;
|
|
26
26
|
/**
|
package/dist/frameworks/jest.js
CHANGED
|
@@ -144,24 +144,83 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
144
144
|
// Which of its parts the chain means is not known, so it declares a plain test or describe.
|
|
145
145
|
return refused(call, refusal, context, () => this.declaration(call, kind, [], context));
|
|
146
146
|
}
|
|
147
|
+
/** The title Jest registers, false for a rejected descriptor, or null when the value is unknown. */
|
|
148
|
+
titleName(arg, scopes, stringsOnly, modern, functionName) {
|
|
149
|
+
if (arg.type === 'SpreadElement')
|
|
150
|
+
return null;
|
|
151
|
+
if (functionName) {
|
|
152
|
+
if (stringsOnly)
|
|
153
|
+
return false;
|
|
154
|
+
if (!functionName.ok)
|
|
155
|
+
return null;
|
|
156
|
+
const value = functionName.value;
|
|
157
|
+
if (typeof value === 'string')
|
|
158
|
+
return modern && !value ? false : value;
|
|
159
|
+
if (typeof value === 'number' && value)
|
|
160
|
+
return String(value);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const resolved = this.file.values.resolve(arg, scopes);
|
|
164
|
+
if (resolved.ok) {
|
|
165
|
+
const value = resolved.value;
|
|
166
|
+
if (typeof value === 'string')
|
|
167
|
+
return value;
|
|
168
|
+
if (!stringsOnly && (typeof value === 'number' || value === undefined))
|
|
169
|
+
return String(value);
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
let node = unwrap(arg);
|
|
173
|
+
const seen = new Set();
|
|
174
|
+
while (node.type === 'Identifier') {
|
|
175
|
+
const binding = this.file.values.constantOf(node.name, scopes);
|
|
176
|
+
if (!binding || seen.has(binding.init))
|
|
177
|
+
return null;
|
|
178
|
+
seen.add(binding.init);
|
|
179
|
+
node = unwrap(binding.init);
|
|
180
|
+
scopes = binding.scopes;
|
|
181
|
+
}
|
|
182
|
+
if (node.type === 'ArrayExpression' ||
|
|
183
|
+
node.type === 'ObjectExpression' ||
|
|
184
|
+
(node.type === 'Literal' && ('regex' in node || 'bigint' in node)))
|
|
185
|
+
return false;
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
147
188
|
declaration(call, kind, links, context) {
|
|
148
189
|
const args = call.arguments;
|
|
149
|
-
if (args.length === 0)
|
|
150
|
-
return { kind: 'other' };
|
|
151
190
|
const callee = snippet(text(this.file, call.callee));
|
|
152
191
|
const flags = new Set(links.map((link) => link.name));
|
|
153
192
|
const problems = [];
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
193
|
+
const table = links.find((link) => link.name === 'each') ?? null;
|
|
194
|
+
const modern = atLeast(this.file.version, 28, 0);
|
|
195
|
+
const stringsOnly = flags.has('todo') || (!modern && (kind === 'test' || table !== null));
|
|
196
|
+
const argument = args.at(0);
|
|
197
|
+
const functionName = argument && argument.type !== 'SpreadElement' ? this.file.values.functionName(argument, context.scopes) : null;
|
|
198
|
+
const name = argument ? this.titleName(argument, context.scopes, stringsOnly, modern, functionName) : 'undefined';
|
|
199
|
+
const invalidName = name === false || (args.length === 0 && stringsOnly);
|
|
200
|
+
const { title, problem: titleProblem } = typeof name === 'string'
|
|
201
|
+
? { title: { text: name, withoutTags: name, isDynamic: false }, problem: null }
|
|
202
|
+
: readTitle(this.file, context.scopes, args[0], { stripTags: false, functionNames: false });
|
|
203
|
+
if (titleProblem && name !== false)
|
|
159
204
|
problems.push(titleProblem);
|
|
160
205
|
const spread = args.some((arg) => arg.type === 'SpreadElement');
|
|
161
206
|
const body = spread ? undefined : args.at(1);
|
|
162
207
|
const fn = isFunctionNode(body) ? body : null;
|
|
163
208
|
const callback = fn ?? namedFunction(this.file, context.scopes, body);
|
|
164
|
-
const
|
|
209
|
+
const cases = table ? this.tableCases(table, title, context) : null;
|
|
210
|
+
// A class can replace its name with a number. The table formatter receives that number before Jest stringifies it.
|
|
211
|
+
const titleFailed = cases === 'invalid-title' ||
|
|
212
|
+
(table !== null && functionName?.ok === true && typeof functionName.value === 'number');
|
|
213
|
+
const count = table ? this.caseCount(table, context, problems) : null;
|
|
214
|
+
const invalidTable = count === 'invalid-table';
|
|
215
|
+
const resolvedBody = (table || kind === 'describe') && body && !callback ? this.file.values.resolve(body, context.scopes) : null;
|
|
216
|
+
const nullishBody = !spread &&
|
|
217
|
+
(body === undefined || (resolvedBody?.ok && (resolvedBody.value === null || resolvedBody.value === undefined)));
|
|
218
|
+
const nonCallable = body !== undefined && (isNotFunction(body) || resolvedBody?.ok === true);
|
|
219
|
+
// Jest 27 installs its concurrent skip binding on test.skip itself. Later versions share the ordinary skip binding.
|
|
220
|
+
const readsArity = !flags.has('failing') && (flags.has('skip') ? atLeast(this.file.version, 28, 0) : !flags.has('concurrent'));
|
|
221
|
+
const missingBodyFallback = table !== null && kind === 'test' && nullishBody && readsArity;
|
|
222
|
+
const single = titleFailed || invalidTable || missingBodyFallback;
|
|
223
|
+
const fallbackTest = kind === 'test' && single;
|
|
165
224
|
const line = this.file.source.line(call.start);
|
|
166
225
|
const declared = (given = fn) => {
|
|
167
226
|
const base = {
|
|
@@ -170,15 +229,28 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
170
229
|
isOnly: flags.has('only'),
|
|
171
230
|
mode: flags.has('concurrent') && !flags.has('skip') ? 'parallel' : null,
|
|
172
231
|
details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
|
|
173
|
-
fn: given,
|
|
174
|
-
hashed: given ?? callback ?? wrappedFunction(body),
|
|
232
|
+
fn: fallbackTest ? null : given,
|
|
233
|
+
hashed: fallbackTest ? null : (given ?? callback ?? wrappedFunction(body)),
|
|
175
234
|
isParameterized: table !== null,
|
|
176
|
-
caseCount:
|
|
177
|
-
cases:
|
|
235
|
+
caseCount: single ? 1 : count,
|
|
236
|
+
cases: single
|
|
237
|
+
? [
|
|
238
|
+
{
|
|
239
|
+
title: {
|
|
240
|
+
reason: titleFailed
|
|
241
|
+
? 'Jest cannot format a case title and registers a single declaration with the original title'
|
|
242
|
+
: invalidTable
|
|
243
|
+
? 'Jest rejects the table and registers a single declaration with the original title'
|
|
244
|
+
: 'Jest registers a single fallback test when it cannot read the callback arity',
|
|
245
|
+
},
|
|
246
|
+
args: [],
|
|
247
|
+
},
|
|
248
|
+
]
|
|
249
|
+
: cases,
|
|
178
250
|
problems,
|
|
179
251
|
};
|
|
180
252
|
// With the function given third, after an argument that isn't one, there is no timeout to read.
|
|
181
|
-
const timeout = spread || kind === 'describe' || given !== fn ? undefined : args.at(2);
|
|
253
|
+
const timeout = spread || kind === 'describe' || fallbackTest || given !== fn ? undefined : args.at(2);
|
|
182
254
|
if (timeout && timeout.type !== 'SpreadElement') {
|
|
183
255
|
const option = { node: timeout, resolved: this.file.values.resolve(timeout, context.scopes) };
|
|
184
256
|
const value = readCount(this.file, 'timeout', option, problems);
|
|
@@ -189,6 +261,12 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
189
261
|
return { kind: 'describe', ...base, isShuffled: false, passesDown: null };
|
|
190
262
|
return { kind: 'test', ...base, testContext: null, fixtures: [], takesAllFixtures: false, usesBench: false };
|
|
191
263
|
};
|
|
264
|
+
// Ordinary describe validates its callback first. The table binder validates its title before binding any row.
|
|
265
|
+
if (invalidName && !(kind === 'describe' && !table && (nullishBody || nonCallable))) {
|
|
266
|
+
const expected = stringsOnly ? 'a string title' : 'a string, number, undefined, or a named function or class';
|
|
267
|
+
const refusal = problem('invalid-chain', args[0] ?? call, `${callee}() requires ${expected}. Jest fails to load the file.`, callee);
|
|
268
|
+
return refused(call, refusal, context, declared);
|
|
269
|
+
}
|
|
192
270
|
if (flags.has('todo')) {
|
|
193
271
|
if (args.length === 1 && !spread)
|
|
194
272
|
return declared();
|
|
@@ -196,23 +274,31 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
196
274
|
return refused(call, refusal, context, declared);
|
|
197
275
|
}
|
|
198
276
|
const head = snippet(text(this.file, eachHead(call)));
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
277
|
+
if (table && kind === 'test' && (nullishBody || nonCallable)) {
|
|
278
|
+
if (!titleFailed && !invalidTable) {
|
|
279
|
+
const message = missingBodyFallback
|
|
280
|
+
? `${head}() has no test body, so Jest registers one test titled '${title.text}' that always fails.`
|
|
281
|
+
: `${head}() has no callable test body. Jest registers each row, which throws if its body runs.`;
|
|
282
|
+
problems.push({ ...problem('test-without-body', call, message, head), level: 'warning' });
|
|
283
|
+
}
|
|
284
|
+
return declared();
|
|
205
285
|
}
|
|
286
|
+
if (fallbackTest)
|
|
287
|
+
return declared();
|
|
206
288
|
if (!spread && args.length < 2) {
|
|
207
289
|
const what = kind === 'test' ? 'test body' : 'function';
|
|
208
290
|
const refusal = problem('test-without-body', call, `${callee}() has no ${what}, so Jest fails to load the file and runs none of its tests.`, callee);
|
|
209
291
|
return refused(call, refusal, context, declared);
|
|
210
292
|
}
|
|
211
|
-
if (
|
|
293
|
+
if (nonCallable) {
|
|
212
294
|
const refusal = problem('test-without-body', call, `${callee}() takes its function second, and ${snippet(text(this.file, body))} is not one, so Jest fails the file.`, callee);
|
|
213
295
|
return refused(call, refusal, context, () => declared(findFunction(args, 2)));
|
|
214
296
|
}
|
|
215
|
-
if (kind === 'describe' &&
|
|
297
|
+
if (kind === 'describe' && titleFailed) {
|
|
298
|
+
const refusal = problem('describe-throws', call, `${head}() cannot format a case title, so its describe throws and Jest fails the file.`, head);
|
|
299
|
+
return refused(call, refusal, context, declared);
|
|
300
|
+
}
|
|
301
|
+
if (kind === 'describe' && invalidTable) {
|
|
216
302
|
const refusal = problem('describe-throws', call, `${head}() has an empty table or one that isn't a table, so its describe throws, and Jest fails the file.`, head);
|
|
217
303
|
return refused(call, refusal, context, declared);
|
|
218
304
|
}
|
|
@@ -231,21 +317,6 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
231
317
|
}
|
|
232
318
|
return declared();
|
|
233
319
|
}
|
|
234
|
-
/** Whether a table makes `describe.each` throw, as jest-each does on an empty array or a value that isn't a table. */
|
|
235
|
-
isInvalidTable(table, context) {
|
|
236
|
-
if (table.template) {
|
|
237
|
-
const headings = templateHeadings(table.template);
|
|
238
|
-
const values = table.template.expressions.length;
|
|
239
|
-
return headings === null || values === 0 || values % headings.length !== 0;
|
|
240
|
-
}
|
|
241
|
-
const cases = table.args.at(0);
|
|
242
|
-
if (!cases)
|
|
243
|
-
return true;
|
|
244
|
-
if (cases.type === 'SpreadElement')
|
|
245
|
-
return false;
|
|
246
|
-
const resolved = this.file.values.resolve(cases, context.scopes);
|
|
247
|
-
return resolved.ok ? !Array.isArray(resolved.value) || resolved.value.length === 0 : false;
|
|
248
|
-
}
|
|
249
320
|
/** Jest's order: `todo` and `skip` set the test's mode, `only` runs it, and `failing` applies when it runs. */
|
|
250
321
|
states(flags, line) {
|
|
251
322
|
const setting = (state) => [
|
|
@@ -265,21 +336,23 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
265
336
|
if (table.template) {
|
|
266
337
|
const headings = templateHeadings(table.template);
|
|
267
338
|
const values = table.template.expressions.length;
|
|
268
|
-
return headings === null || values === 0 || values % headings.length !== 0
|
|
339
|
+
return headings === null || values === 0 || values % headings.length !== 0
|
|
340
|
+
? 'invalid-table'
|
|
341
|
+
: values / headings.length;
|
|
269
342
|
}
|
|
270
343
|
const cases = table.args.at(0);
|
|
271
344
|
if (!cases)
|
|
272
|
-
return
|
|
345
|
+
return 'invalid-table';
|
|
273
346
|
const resolved = cases.type === 'SpreadElement' ? null : this.file.values.resolve(cases, context.scopes);
|
|
274
347
|
// A table that isn't an array makes Jest register one test that fails, as an empty one does.
|
|
275
348
|
if (resolved?.ok && !Array.isArray(resolved.value))
|
|
276
|
-
return
|
|
349
|
+
return 'invalid-table';
|
|
277
350
|
const length = this.arrayLength(cases, context);
|
|
278
351
|
if (length === null) {
|
|
279
352
|
const source = snippet(text(this.file, cases));
|
|
280
353
|
problems.push(problem('unresolved-cases', cases, 'The cases of .each() could not be counted; caseCount is null.', source));
|
|
281
354
|
}
|
|
282
|
-
return length === 0 ?
|
|
355
|
+
return length === 0 ? 'invalid-table' : length;
|
|
283
356
|
}
|
|
284
357
|
/**
|
|
285
358
|
* The cases of a table whose values the scan can work out, as Jest passes them: a case that is an array is spread
|
|
@@ -288,6 +361,14 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
288
361
|
*/
|
|
289
362
|
tableCases(table, title, context) {
|
|
290
363
|
const version = this.file.version;
|
|
364
|
+
const keyedCases = (items, tagged) => {
|
|
365
|
+
const rows = items.map((item, index) => ({
|
|
366
|
+
title: title.isDynamic ? null : jestKeysTitle(title.text, item, index, version, tagged),
|
|
367
|
+
args: [item],
|
|
368
|
+
}));
|
|
369
|
+
// jest-each formats every row before registering the first. One interpolation error rejects the whole table.
|
|
370
|
+
return !title.isDynamic && rows.some((row) => row.title === null) ? 'invalid-title' : rows;
|
|
371
|
+
};
|
|
291
372
|
if (table.template) {
|
|
292
373
|
const headings = templateHeadings(table.template);
|
|
293
374
|
const resolved = table.template.expressions.map((item) => this.file.values.resolve(item, context.scopes));
|
|
@@ -295,10 +376,8 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
295
376
|
if (!headings || !rows || !Number.isInteger(rows) || !resolved.every((item) => item.ok))
|
|
296
377
|
return null;
|
|
297
378
|
const values = resolved.map((item) => item.value);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return { title: title.isDynamic ? null : jestKeysTitle(title.text, item, row, version, true), args: [item] };
|
|
301
|
-
});
|
|
379
|
+
const items = Array.from({ length: rows }, (_, row) => Object.fromEntries(headings.map((name, column) => [name, values[row * headings.length + column]])));
|
|
380
|
+
return keyedCases(items, true);
|
|
302
381
|
}
|
|
303
382
|
const first = table.args.at(0);
|
|
304
383
|
const resolved = first && first.type !== 'SpreadElement' ? this.file.values.resolve(first, context.scopes) : null;
|
|
@@ -309,15 +388,11 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
309
388
|
const byKeys = !arraysOnly &&
|
|
310
389
|
!/%[#Odfijops]/.test(title.text.replaceAll('%%', '')) &&
|
|
311
390
|
cases.every((item) => item !== null && typeof item === 'object');
|
|
391
|
+
if (byKeys)
|
|
392
|
+
return keyedCases(cases, false);
|
|
312
393
|
return cases.map((item, index) => {
|
|
313
394
|
const row = arraysOnly ? item : [item];
|
|
314
|
-
|
|
315
|
-
if (!title.isDynamic) {
|
|
316
|
-
caseTitle = byKeys
|
|
317
|
-
? jestKeysTitle(title.text, item, index, version, false)
|
|
318
|
-
: jestRowTitle(title.text, row, index, version);
|
|
319
|
-
}
|
|
320
|
-
return { title: caseTitle, args: row };
|
|
395
|
+
return { title: title.isDynamic ? null : jestRowTitle(title.text, row, index, version), args: row };
|
|
321
396
|
});
|
|
322
397
|
}
|
|
323
398
|
}
|
|
@@ -6,9 +6,8 @@ import { type FileContext, type Link } from './common.ts';
|
|
|
6
6
|
import { SuiteAdapter, type Kind } from './test-functions.ts';
|
|
7
7
|
export declare class VitestAdapter extends SuiteAdapter {
|
|
8
8
|
private warnedAboutTags;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(parsed: ParsedFile, file: FileContext, readModule: ModuleReader | null, titleTruncate?: number);
|
|
9
|
+
private readonly titleThresholds;
|
|
10
|
+
constructor(parsed: ParsedFile, file: FileContext, readModule: ModuleReader | null, titleThresholds?: readonly (number | null)[]);
|
|
12
11
|
protected isAliasLink(kind: Kind, link: Link): boolean;
|
|
13
12
|
classify(call: CallExpression, context: CallContext): ApiCall | null;
|
|
14
13
|
/** A call to `bench` imported from Vitest 5, which is undefined there, so the call throws. */
|