test-inventory 0.9.1 → 0.10.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.
- package/CHANGELOG.md +35 -0
- package/README.md +3 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +80 -0
- package/dist/config-dependencies.d.ts +7 -2
- package/dist/config-dependencies.js +71 -15
- package/dist/config-runs.d.ts +7 -2
- package/dist/config-runs.js +46 -13
- package/dist/config.d.ts +1 -1
- package/dist/config.js +60 -2
- package/dist/dependency-hash.js +4 -2
- package/dist/diff-markdown.d.ts +3 -0
- package/dist/diff-markdown.js +30 -0
- package/dist/diff.d.ts +51 -0
- package/dist/diff.js +192 -0
- package/dist/extract.js +26 -8
- package/dist/frameworks/jasmine.js +8 -7
- package/dist/frameworks/jest.js +6 -5
- package/dist/frameworks/playwright.d.ts +3 -1
- package/dist/frameworks/playwright.js +54 -14
- package/dist/frameworks/vitest.js +2 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/inventory-input.d.ts +3 -0
- package/dist/inventory-input.js +62 -0
- package/dist/inventory.js +6 -0
- package/dist/model.d.ts +3 -0
- package/dist/node-scripts.d.ts +1 -1
- package/dist/node-scripts.js +12 -3
- package/dist/records.d.ts +1 -0
- package/dist/records.js +67 -15
- package/dist/resolve.js +2 -0
- package/dist/scan.js +1 -1
- package/dist/types.d.ts +2 -2
- package/package.json +2 -1
- package/schema/diff-v1.json +1291 -0
- package/schema/v1.json +2 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Escapes project text so titles cannot become markup, links or extra table rows. */
|
|
2
|
+
function cell(value) {
|
|
3
|
+
return value
|
|
4
|
+
.replaceAll('&', '&')
|
|
5
|
+
.replaceAll('<', '<')
|
|
6
|
+
.replaceAll('>', '>')
|
|
7
|
+
.replaceAll('|', '|')
|
|
8
|
+
.replaceAll('`', '`')
|
|
9
|
+
.replaceAll('*', '*')
|
|
10
|
+
.replaceAll('_', '_')
|
|
11
|
+
.replaceAll('[', '[')
|
|
12
|
+
.replaceAll(']', ']')
|
|
13
|
+
.replaceAll('\\', '\')
|
|
14
|
+
.replaceAll(/\r?\n|\r/g, ' ');
|
|
15
|
+
}
|
|
16
|
+
/** A report ready to save as Markdown or use as the body of a pull request comment. */
|
|
17
|
+
export function formatDiffMarkdown(diff) {
|
|
18
|
+
const lines = [
|
|
19
|
+
`Test inventory diff: ${diff.summary.added} added, ${diff.summary.removed} removed, ${diff.summary.changed} changed, ${diff.summary.unchanged} unchanged.`,
|
|
20
|
+
...diff.warnings.map((warning) => `\n${cell(warning)}`),
|
|
21
|
+
];
|
|
22
|
+
if (diff.changes.length > 0) {
|
|
23
|
+
lines.push('', '| Changes | Before | After | Match |', '| --- | --- | --- | --- |');
|
|
24
|
+
for (const change of diff.changes) {
|
|
25
|
+
const show = (test) => test === null ? '' : cell(`${test.relativeFilePath}:${test.lineStart} ${test.fullName}`);
|
|
26
|
+
lines.push(`| ${change.kinds.join(', ')} | ${show(change.before)} | ${show(change.after)} | ${change.match ?? ''} |`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return `${lines.join('\n')}\n`;
|
|
30
|
+
}
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Framework, Inventory, TestRecord, Tool } from './types.ts';
|
|
2
|
+
/** Changes a comparison can report; one matched test can have several. */
|
|
3
|
+
export type ChangeKind = 'added' | 'removed' | 'moved' | 'renamed' | 'bodyChanged' | 'dependenciesChanged' | 'newlySkipped' | 'reEnabled' | 'stateChanged' | 'tagsChanged' | 'metadataChanged';
|
|
4
|
+
/** The evidence that two records identify the same test; null for an addition or removal. */
|
|
5
|
+
export type MatchMethod = 'id' | 'bodyHash' | 'bodyHashAndFile' | 'bodyHashAndSuite' | 'bodyHashAndDependencies';
|
|
6
|
+
/** One addition, removal or changed test. Locations and records come from the saved scans unchanged. */
|
|
7
|
+
export type TestChange = {
|
|
8
|
+
kinds: ChangeKind[];
|
|
9
|
+
/** Changed record keys, excluding locations and ids. Hashes are included only when comparable. */
|
|
10
|
+
changedFields: (keyof TestRecord)[];
|
|
11
|
+
} & ({
|
|
12
|
+
match: MatchMethod;
|
|
13
|
+
before: TestRecord;
|
|
14
|
+
after: TestRecord;
|
|
15
|
+
} | {
|
|
16
|
+
match: null;
|
|
17
|
+
before: TestRecord;
|
|
18
|
+
after: null;
|
|
19
|
+
} | {
|
|
20
|
+
match: null;
|
|
21
|
+
before: null;
|
|
22
|
+
after: TestRecord;
|
|
23
|
+
});
|
|
24
|
+
/** Tests with identical syntax-tree bodies, including trivial bodies; this does not prove they test the same thing. */
|
|
25
|
+
export interface CloneGroup {
|
|
26
|
+
bodyHash: string;
|
|
27
|
+
testIds: string[];
|
|
28
|
+
}
|
|
29
|
+
/** The deterministic comparison of two saved inventories. */
|
|
30
|
+
export interface InventoryDiff {
|
|
31
|
+
schemaVersion: 1;
|
|
32
|
+
tool: Tool;
|
|
33
|
+
framework: Framework;
|
|
34
|
+
beforeToolVersion: string;
|
|
35
|
+
afterToolVersion: string;
|
|
36
|
+
hashesComparable: boolean;
|
|
37
|
+
/** Category counts overlap; changed counts matched tests, while unchanged counts matches with no changes. */
|
|
38
|
+
summary: Record<ChangeKind | 'changed' | 'unchanged', number>;
|
|
39
|
+
changes: TestChange[];
|
|
40
|
+
clones: {
|
|
41
|
+
before: CloneGroup[];
|
|
42
|
+
after: CloneGroup[];
|
|
43
|
+
};
|
|
44
|
+
warnings: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Compares complete inventories without mutating them. Match ids first, then mutually unique body hashes, narrowing
|
|
48
|
+
* ambiguous hashes by file, suite and dependencies. Remaining ambiguities stay additions and removals. Hashes from
|
|
49
|
+
* different tool versions are not compared; scan both revisions with one version for rename and body detection.
|
|
50
|
+
*/
|
|
51
|
+
export declare function diffInventories(before: Inventory, after: Inventory): InventoryDiff;
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { checkInventory } from "./inventory-input.js";
|
|
2
|
+
import { OptionsError } from "./options.js";
|
|
3
|
+
import { toolVersion } from "./version.js";
|
|
4
|
+
const KINDS = [
|
|
5
|
+
'added',
|
|
6
|
+
'removed',
|
|
7
|
+
'moved',
|
|
8
|
+
'renamed',
|
|
9
|
+
'bodyChanged',
|
|
10
|
+
'dependenciesChanged',
|
|
11
|
+
'newlySkipped',
|
|
12
|
+
'reEnabled',
|
|
13
|
+
'stateChanged',
|
|
14
|
+
'tagsChanged',
|
|
15
|
+
'metadataChanged',
|
|
16
|
+
];
|
|
17
|
+
const LOCATION = new Set([
|
|
18
|
+
'id',
|
|
19
|
+
'lineStart',
|
|
20
|
+
'lineEnd',
|
|
21
|
+
'columnStart',
|
|
22
|
+
'columnEnd',
|
|
23
|
+
'declaredAt',
|
|
24
|
+
'stateLine',
|
|
25
|
+
'suiteId',
|
|
26
|
+
'parentTestId',
|
|
27
|
+
'fileName',
|
|
28
|
+
]);
|
|
29
|
+
const CLASSIFIED = new Set([
|
|
30
|
+
'relativeFilePath',
|
|
31
|
+
'title',
|
|
32
|
+
'titleWithoutTags',
|
|
33
|
+
'fullName',
|
|
34
|
+
'suitePath',
|
|
35
|
+
'bodyHash',
|
|
36
|
+
'dependencyHash',
|
|
37
|
+
'state',
|
|
38
|
+
'tags',
|
|
39
|
+
'isActive',
|
|
40
|
+
'isSkipped',
|
|
41
|
+
'isFixme',
|
|
42
|
+
'isTodo',
|
|
43
|
+
'isExpectedToFail',
|
|
44
|
+
'isNotLoaded',
|
|
45
|
+
]);
|
|
46
|
+
/** Stable object-key order makes saved JSON comparisons independent of how a client serialized objects. */
|
|
47
|
+
function stable(value) {
|
|
48
|
+
return JSON.stringify(value, (_key, item) => {
|
|
49
|
+
if (typeof item !== 'object' || item === null || Array.isArray(item))
|
|
50
|
+
return item;
|
|
51
|
+
return Object.fromEntries(Object.entries(item).sort(([a], [b]) => (a < b ? -1 : 1)));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function groups(tests, keyOf) {
|
|
55
|
+
const found = new Map();
|
|
56
|
+
for (const test of tests) {
|
|
57
|
+
const key = keyOf(test);
|
|
58
|
+
if (key === null)
|
|
59
|
+
continue;
|
|
60
|
+
const group = found.get(key) ?? [];
|
|
61
|
+
group.push(test);
|
|
62
|
+
found.set(key, group);
|
|
63
|
+
}
|
|
64
|
+
return found;
|
|
65
|
+
}
|
|
66
|
+
function clones(inventory) {
|
|
67
|
+
return [...groups(inventory.tests, (test) => test.bodyHash)]
|
|
68
|
+
.filter(([, tests]) => tests.length > 1)
|
|
69
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
70
|
+
.map(([bodyHash, tests]) => ({ bodyHash, testIds: tests.map((test) => test.id).sort() }));
|
|
71
|
+
}
|
|
72
|
+
function changed(before, after, hashesComparable) {
|
|
73
|
+
return [...new Set([...Object.keys(before), ...Object.keys(after)])]
|
|
74
|
+
.filter((key) => {
|
|
75
|
+
if (LOCATION.has(key) || (!hashesComparable && ['bodyHash', 'dependencyHash'].includes(key)))
|
|
76
|
+
return false;
|
|
77
|
+
if (key === 'tags')
|
|
78
|
+
return stable([...before.tags].sort()) !== stable([...after.tags].sort());
|
|
79
|
+
if (key === 'annotations' || key === 'steps') {
|
|
80
|
+
const content = (test) => test[key].map((item) => Object.fromEntries(Object.entries(item).filter(([name]) => name !== 'lineStart')));
|
|
81
|
+
return stable(content(before)) !== stable(content(after));
|
|
82
|
+
}
|
|
83
|
+
return stable(before[key]) !== stable(after[key]);
|
|
84
|
+
})
|
|
85
|
+
.sort();
|
|
86
|
+
}
|
|
87
|
+
function kindsOf(before, after, fields) {
|
|
88
|
+
const kinds = [];
|
|
89
|
+
if (fields.includes('relativeFilePath'))
|
|
90
|
+
kinds.push('moved');
|
|
91
|
+
if (before.title !== after.title || stable(before.suitePath) !== stable(after.suitePath))
|
|
92
|
+
kinds.push('renamed');
|
|
93
|
+
if (fields.includes('bodyHash'))
|
|
94
|
+
kinds.push('bodyChanged');
|
|
95
|
+
if (fields.includes('dependencyHash'))
|
|
96
|
+
kinds.push('dependenciesChanged');
|
|
97
|
+
const disabled = (test) => ['skip', 'fixme', 'todo'].includes(test.state);
|
|
98
|
+
const runnable = (test) => ['active', 'expectedToFail'].includes(test.state);
|
|
99
|
+
if (runnable(before) && disabled(after))
|
|
100
|
+
kinds.push('newlySkipped');
|
|
101
|
+
if (disabled(before) && runnable(after))
|
|
102
|
+
kinds.push('reEnabled');
|
|
103
|
+
if (fields.includes('state'))
|
|
104
|
+
kinds.push('stateChanged');
|
|
105
|
+
if (fields.includes('tags'))
|
|
106
|
+
kinds.push('tagsChanged');
|
|
107
|
+
if (fields.some((field) => !CLASSIFIED.has(field)))
|
|
108
|
+
kinds.push('metadataChanged');
|
|
109
|
+
return kinds;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Compares complete inventories without mutating them. Match ids first, then mutually unique body hashes, narrowing
|
|
113
|
+
* ambiguous hashes by file, suite and dependencies. Remaining ambiguities stay additions and removals. Hashes from
|
|
114
|
+
* different tool versions are not compared; scan both revisions with one version for rename and body detection.
|
|
115
|
+
*/
|
|
116
|
+
export function diffInventories(before, after) {
|
|
117
|
+
checkInventory(before, 'before');
|
|
118
|
+
checkInventory(after, 'after');
|
|
119
|
+
if (before.framework !== after.framework)
|
|
120
|
+
throw new OptionsError('before and after must use the same framework. Scan both revisions with the same --framework.');
|
|
121
|
+
const hashesComparable = before.tool.version === after.tool.version;
|
|
122
|
+
const left = new Set(before.tests);
|
|
123
|
+
const right = new Set(after.tests);
|
|
124
|
+
const pairs = [];
|
|
125
|
+
const pair = (method, keyOf) => {
|
|
126
|
+
const old = groups(left, keyOf);
|
|
127
|
+
const next = groups(right, keyOf);
|
|
128
|
+
for (const [key, tests] of old) {
|
|
129
|
+
const other = next.get(key);
|
|
130
|
+
if (tests.length !== 1 || other?.length !== 1)
|
|
131
|
+
continue;
|
|
132
|
+
pairs.push({ before: tests[0], after: other[0], match: method });
|
|
133
|
+
left.delete(tests[0]);
|
|
134
|
+
right.delete(other[0]);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
pair('id', (test) => test.id);
|
|
138
|
+
if (hashesComparable) {
|
|
139
|
+
pair('bodyHash', (test) => test.bodyHash);
|
|
140
|
+
const withHash = (test, keys) => test.bodyHash === null ? null : stable([test.bodyHash, ...keys]);
|
|
141
|
+
pair('bodyHashAndFile', (test) => withHash(test, [test.relativeFilePath]));
|
|
142
|
+
pair('bodyHashAndSuite', (test) => withHash(test, [test.relativeFilePath, test.suitePath]));
|
|
143
|
+
pair('bodyHashAndDependencies', (test) => withHash(test, [test.dependencies.filter((file) => file !== test.relativeFilePath)]));
|
|
144
|
+
}
|
|
145
|
+
const summary = Object.fromEntries([...KINDS, 'changed', 'unchanged'].map((kind) => [kind, 0]));
|
|
146
|
+
const changes = [];
|
|
147
|
+
for (const { before, after, match } of pairs) {
|
|
148
|
+
const changedFields = changed(before, after, hashesComparable);
|
|
149
|
+
const kinds = kindsOf(before, after, changedFields);
|
|
150
|
+
if (kinds.length === 0)
|
|
151
|
+
summary.unchanged++;
|
|
152
|
+
else {
|
|
153
|
+
summary.changed++;
|
|
154
|
+
changes.push({ kinds, match, before, after, changedFields });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (const test of left)
|
|
158
|
+
changes.push({ kinds: ['removed'], match: null, before: test, after: null, changedFields: [] });
|
|
159
|
+
for (const test of right)
|
|
160
|
+
changes.push({ kinds: ['added'], match: null, before: null, after: test, changedFields: [] });
|
|
161
|
+
for (const change of changes)
|
|
162
|
+
for (const kind of change.kinds)
|
|
163
|
+
summary[kind]++;
|
|
164
|
+
changes.sort((a, b) => {
|
|
165
|
+
const key = (change) => {
|
|
166
|
+
const test = change.after ?? change.before;
|
|
167
|
+
return stable([test.relativeFilePath, test.fullName, test.id, change.kinds]);
|
|
168
|
+
};
|
|
169
|
+
return key(a) < key(b) ? -1 : 1;
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
schemaVersion: 1,
|
|
173
|
+
tool: { name: 'test-inventory', version: toolVersion },
|
|
174
|
+
framework: before.framework,
|
|
175
|
+
beforeToolVersion: before.tool.version,
|
|
176
|
+
afterToolVersion: after.tool.version,
|
|
177
|
+
hashesComparable,
|
|
178
|
+
summary,
|
|
179
|
+
changes,
|
|
180
|
+
clones: { before: clones(before), after: clones(after) },
|
|
181
|
+
warnings: [
|
|
182
|
+
...(!hashesComparable
|
|
183
|
+
? [
|
|
184
|
+
'Tool versions differ: hash comparisons and rename matching are disabled. Scan both revisions with one test-inventory version.',
|
|
185
|
+
]
|
|
186
|
+
: []),
|
|
187
|
+
...([before, after].some((inventory) => inventory.diagnostics.some((diagnostic) => diagnostic.level === 'error'))
|
|
188
|
+
? ['At least one scan has errors; missing tests may appear as additions or removals. Check its diagnostics.']
|
|
189
|
+
: []),
|
|
190
|
+
],
|
|
191
|
+
};
|
|
192
|
+
}
|
package/dist/extract.js
CHANGED
|
@@ -699,7 +699,7 @@ class Walker {
|
|
|
699
699
|
case 'invalid': {
|
|
700
700
|
// Code that runs after the file loads, or only when a condition holds, can't be sure to stop it loading.
|
|
701
701
|
const afterLoad = context.test !== null || context.hookScope !== null || context.helper !== null || context.isInCondition;
|
|
702
|
-
this.report(
|
|
702
|
+
this.report({ ...api.problem, afterLoad: afterLoad || api.problem.afterLoad, scope: context.scope });
|
|
703
703
|
// Under a condition, the call either never runs or fails the file, so it declares nothing either way.
|
|
704
704
|
return api.declaration && !context.isInCondition ? this.handle(call, api.declaration, context) : true;
|
|
705
705
|
}
|
|
@@ -1300,10 +1300,7 @@ class Walker {
|
|
|
1300
1300
|
this.declaredIn.set(test, context.declaredIn);
|
|
1301
1301
|
this.cut(context.scope, call);
|
|
1302
1302
|
// A function declared in the file and passed by name runs as the test body too.
|
|
1303
|
-
|
|
1304
|
-
if (body) {
|
|
1305
|
-
if (!declaration.fn)
|
|
1306
|
-
this.walkedAtCall.add(body);
|
|
1303
|
+
this.withDeclarationBody(declaration, call, (body) => {
|
|
1307
1304
|
this.withCase(body, args, () => {
|
|
1308
1305
|
this.visitCallback(body, {
|
|
1309
1306
|
...context,
|
|
@@ -1316,7 +1313,29 @@ class Walker {
|
|
|
1316
1313
|
helper: null,
|
|
1317
1314
|
});
|
|
1318
1315
|
});
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
/** Named callbacks keep their lexical scopes and use the same traversal bounds as directly called helpers. */
|
|
1319
|
+
withDeclarationBody(declaration, call, walk) {
|
|
1320
|
+
const fn = declaration.fn ?? declaration.hashed;
|
|
1321
|
+
if (!fn)
|
|
1322
|
+
return;
|
|
1323
|
+
if (declaration.fn) {
|
|
1324
|
+
walk(fn);
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
this.walkedAtCall.add(fn);
|
|
1328
|
+
if (this.callStack.includes(fn) || this.callStack.length >= MAX_DEPTH) {
|
|
1329
|
+
this.report(problem('test-in-function', call, 'The named callback recurses or exceeds the helper depth limit, so its nested tests are not followed here.'));
|
|
1330
|
+
return;
|
|
1319
1331
|
}
|
|
1332
|
+
if (!this.withinLimit({ fn, frame: this.frame }, call))
|
|
1333
|
+
return;
|
|
1334
|
+
const saved = this.scopes.splice(0, this.scopes.length, ...this.scopeChain(fn));
|
|
1335
|
+
this.callStack.push(fn);
|
|
1336
|
+
walk(fn);
|
|
1337
|
+
this.callStack.pop();
|
|
1338
|
+
this.scopes.splice(0, this.scopes.length, ...saved);
|
|
1320
1339
|
}
|
|
1321
1340
|
/** Runs `walk` with a case's arguments bound to the parameters of its callback, as the runner calls it. */
|
|
1322
1341
|
withCase(fn, args, walk) {
|
|
@@ -1366,8 +1385,7 @@ class Walker {
|
|
|
1366
1385
|
this.suites.push(suite);
|
|
1367
1386
|
this.cut(context.scope, call);
|
|
1368
1387
|
this.suiteFrames.set(suite, this.frame);
|
|
1369
|
-
|
|
1370
|
-
if (fn) {
|
|
1388
|
+
this.withDeclarationBody(declaration, call, (fn) => {
|
|
1371
1389
|
this.withCase(fn, args, () => {
|
|
1372
1390
|
this.visitCallback(fn, {
|
|
1373
1391
|
...context,
|
|
@@ -1385,7 +1403,7 @@ class Walker {
|
|
|
1385
1403
|
expandedAt: this.expandedAt(context, index === null ? null : call.start),
|
|
1386
1404
|
});
|
|
1387
1405
|
});
|
|
1388
|
-
}
|
|
1406
|
+
});
|
|
1389
1407
|
}
|
|
1390
1408
|
/** The statement a call forms, such as `test(...);`, or the call itself when it is part of a larger expression. */
|
|
1391
1409
|
statement(call) {
|
|
@@ -115,6 +115,7 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
115
115
|
// `undefined` given as the function is no function, as when none is given.
|
|
116
116
|
const body = written?.type === 'Identifier' && written.name === 'undefined' ? undefined : written;
|
|
117
117
|
const fn = isFunctionNode(body) ? body : null;
|
|
118
|
+
const callback = fn ?? namedFunction(this.file, context.scopes, body ?? undefined);
|
|
118
119
|
const line = this.file.source.line(call.start);
|
|
119
120
|
// A spec without a function is pending, unless it is focused: `fit` needs one.
|
|
120
121
|
const isSkipped = flags.has('skip') || (kind === 'test' && body === undefined);
|
|
@@ -127,7 +128,7 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
127
128
|
mode: null,
|
|
128
129
|
details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
|
|
129
130
|
fn,
|
|
130
|
-
hashed:
|
|
131
|
+
hashed: callback,
|
|
131
132
|
isParameterized: false,
|
|
132
133
|
caseCount: null,
|
|
133
134
|
cases: null,
|
|
@@ -168,16 +169,16 @@ export class JasmineAdapter extends SuiteAdapter {
|
|
|
168
169
|
const refusal = this.refusal('test-without-body', call, `${callee}() has no function`, context);
|
|
169
170
|
return refused(call, refusal, context, () => declared);
|
|
170
171
|
}
|
|
171
|
-
if (
|
|
172
|
-
const refusal = this.refusal('async-describe',
|
|
172
|
+
if (callback?.async) {
|
|
173
|
+
const refusal = this.refusal('async-describe', callback, 'The describe callback is async, which Jasmine refuses', context);
|
|
173
174
|
return refused(call, refusal, context, () => declared);
|
|
174
175
|
}
|
|
175
|
-
if (
|
|
176
|
-
const refusal = this.refusal('describe-throws',
|
|
176
|
+
if (callback && declaresNothing(callback)) {
|
|
177
|
+
const refusal = this.refusal('describe-throws', callback, 'The describe declares no spec or describe, which Jasmine refuses', context);
|
|
177
178
|
return refused(call, refusal, context, () => declared);
|
|
178
179
|
}
|
|
179
|
-
if (
|
|
180
|
-
const refusal = this.refusal('describe-throws',
|
|
180
|
+
if (callback && functionLength(callback) > 0) {
|
|
181
|
+
const refusal = this.refusal('describe-throws', callback, 'The describe callback takes arguments, which Jasmine refuses', context);
|
|
181
182
|
return refused(call, refusal, context, () => declared);
|
|
182
183
|
}
|
|
183
184
|
return declared;
|
package/dist/frameworks/jest.js
CHANGED
|
@@ -156,6 +156,7 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
156
156
|
const spread = args.some((arg) => arg.type === 'SpreadElement');
|
|
157
157
|
const body = spread ? undefined : args.at(1);
|
|
158
158
|
const fn = isFunctionNode(body) ? body : null;
|
|
159
|
+
const callback = fn ?? namedFunction(this.file, context.scopes, body);
|
|
159
160
|
const table = links.find((link) => link.name === 'each') ?? null;
|
|
160
161
|
const line = this.file.source.line(call.start);
|
|
161
162
|
const declared = (given = fn) => {
|
|
@@ -166,7 +167,7 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
166
167
|
mode: flags.has('concurrent') && !flags.has('skip') ? 'parallel' : null,
|
|
167
168
|
details: { tags: [], annotations: [], locks: [], meta: null, run: {} },
|
|
168
169
|
fn: given,
|
|
169
|
-
hashed: given ??
|
|
170
|
+
hashed: given ?? callback,
|
|
170
171
|
isParameterized: table !== null,
|
|
171
172
|
caseCount: table ? this.caseCount(table, context, problems) : null,
|
|
172
173
|
cases: table ? this.tableCases(table, title, context) : null,
|
|
@@ -211,12 +212,12 @@ export class JestAdapter extends SuiteAdapter {
|
|
|
211
212
|
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);
|
|
212
213
|
return refused(call, refusal, context, declared);
|
|
213
214
|
}
|
|
214
|
-
if (kind === 'describe' &&
|
|
215
|
-
const refusal = problem('async-describe',
|
|
215
|
+
if (kind === 'describe' && callback?.async) {
|
|
216
|
+
const refusal = problem('async-describe', callback, 'The describe callback is async, and Jest throws when a describe returns a promise, so it fails the file.');
|
|
216
217
|
return refused(call, refusal, context, declared);
|
|
217
218
|
}
|
|
218
|
-
if (kind === 'describe' &&
|
|
219
|
-
const returned = describeReturns(
|
|
219
|
+
if (kind === 'describe' && callback) {
|
|
220
|
+
const returned = describeReturns(callback);
|
|
220
221
|
if (returned) {
|
|
221
222
|
const refusal = problem(returned === 'promise' ? 'async-describe' : 'describe-throws', call, returned === 'promise'
|
|
222
223
|
? 'The describe callback returns a promise, and Jest throws when a describe returns one, so it fails the file.'
|
|
@@ -47,8 +47,10 @@ export declare class PlaywrightAdapter implements Adapter {
|
|
|
47
47
|
* destructured one works as it does on the object; a test object built with a destructured `extend` is not followed.
|
|
48
48
|
*/
|
|
49
49
|
private alias;
|
|
50
|
-
/** The members of `test` a value holds: none for a test object, or those of a
|
|
50
|
+
/** The members of `test` a value holds: none for a test object, or those of a declaring function. */
|
|
51
51
|
private members;
|
|
52
|
+
/** Function-valued branches stay distinct until a logical fallback rules out non-functions. */
|
|
53
|
+
private choices;
|
|
52
54
|
/** Follows the import of `name` once, and reports it once when it can't be followed and `report` is set. */
|
|
53
55
|
private follow;
|
|
54
56
|
/** Whether an argument is, or works out to, a string, as a title is. Spread arguments are handled before. */
|
|
@@ -22,6 +22,7 @@ const STATES = new Map([
|
|
|
22
22
|
['fail', 'expectedToFail'],
|
|
23
23
|
['fail.only', 'expectedToFail'],
|
|
24
24
|
]);
|
|
25
|
+
const TEST_DECLARATIONS = new Set(['', 'only', ...STATES.keys()]);
|
|
25
26
|
/** Members of `test` that are known but don't declare or modify tests. */
|
|
26
27
|
const OTHER_MEMBERS = new Set(['use', 'slow', 'setTimeout', 'extend']);
|
|
27
28
|
/** Members that set how the tests run where they are called. */
|
|
@@ -118,9 +119,20 @@ class PlaywrightBindings {
|
|
|
118
119
|
(followsCalls && this.holdsTestObject(node.name)));
|
|
119
120
|
case 'MemberExpression':
|
|
120
121
|
return propertyName(node) === 'test' && this.isModule(node.object);
|
|
121
|
-
case 'ConditionalExpression':
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
case 'ConditionalExpression': {
|
|
123
|
+
const branches = [node.consequent, node.alternate].map((expression) => ({
|
|
124
|
+
expression,
|
|
125
|
+
isObject: this.isTestObject(expression, followsCalls),
|
|
126
|
+
}));
|
|
127
|
+
// Keep inference through unknown factories, but a known member such as describe or skip is not an object.
|
|
128
|
+
return (branches.some((branch) => branch.isObject) &&
|
|
129
|
+
branches.every(({ expression, isObject }) => {
|
|
130
|
+
if (isObject)
|
|
131
|
+
return true;
|
|
132
|
+
const chain = readChain(expression);
|
|
133
|
+
return !chain || chain.links.length === 0 || !this.isTestObject(chain.base, followsCalls);
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
124
136
|
case 'CallExpression': {
|
|
125
137
|
const callee = unwrap(node.callee);
|
|
126
138
|
if (callee.type === 'MemberExpression' && propertyName(callee) === 'extend') {
|
|
@@ -250,7 +262,7 @@ export class PlaywrightAdapter {
|
|
|
250
262
|
if (links.some((link) => link.args ?? link.template)) {
|
|
251
263
|
return this.invalid(call, names, "is not part of Playwright's API", context);
|
|
252
264
|
}
|
|
253
|
-
if (key
|
|
265
|
+
if (TEST_DECLARATIONS.has(key)) {
|
|
254
266
|
return this.testCall(call, key, context);
|
|
255
267
|
}
|
|
256
268
|
const describe = DESCRIBES.get(key);
|
|
@@ -296,6 +308,10 @@ export class PlaywrightAdapter {
|
|
|
296
308
|
...members.map((name) => ({ name, args: null, template: null })),
|
|
297
309
|
...links,
|
|
298
310
|
];
|
|
311
|
+
if (base.type === 'ConditionalExpression' || base.type === 'LogicalExpression') {
|
|
312
|
+
const members = this.members(base, lookup);
|
|
313
|
+
return members && withMembers(members);
|
|
314
|
+
}
|
|
299
315
|
if (base.type === 'Identifier') {
|
|
300
316
|
// A local variable or parameter with the same name, such as `(test) => test.result()`, is not Playwright's.
|
|
301
317
|
const declaration = this.file.values.declarationOf(base.name, scopes);
|
|
@@ -389,20 +405,43 @@ export class PlaywrightAdapter {
|
|
|
389
405
|
}
|
|
390
406
|
return members && [...members, ...destructured];
|
|
391
407
|
}
|
|
392
|
-
/** The members of `test` a value holds: none for a test object, or those of a
|
|
408
|
+
/** The members of `test` a value holds: none for a test object, or those of a declaring function. */
|
|
393
409
|
members(expression, lookup) {
|
|
410
|
+
const choices = this.choices(expression, lookup);
|
|
411
|
+
if (!choices || choices.mayBeOther || choices.members.length === 0)
|
|
412
|
+
return null;
|
|
413
|
+
return choices.members.slice(1).reduce(sharedMembers, choices.members[0]);
|
|
414
|
+
}
|
|
415
|
+
/** Function-valued branches stay distinct until a logical fallback rules out non-functions. */
|
|
416
|
+
choices(expression, lookup) {
|
|
394
417
|
const node = unwrap(expression);
|
|
395
418
|
if (node.type === 'ConditionalExpression') {
|
|
396
|
-
|
|
397
|
-
|
|
419
|
+
const [yes, no] = [this.choices(node.consequent, lookup), this.choices(node.alternate, lookup)];
|
|
420
|
+
if (!yes || !no)
|
|
421
|
+
return null;
|
|
422
|
+
return { members: [...yes.members, ...no.members], mayBeOther: yes.mayBeOther || no.mayBeOther };
|
|
423
|
+
}
|
|
424
|
+
if (node.type === 'LogicalExpression') {
|
|
425
|
+
const [left, right] = [this.choices(node.left, lookup), this.choices(node.right, lookup)];
|
|
426
|
+
const isFunction = left !== null && !left.mayBeOther;
|
|
427
|
+
if (node.operator === '&&')
|
|
428
|
+
return isFunction ? right : { members: right?.members ?? [], mayBeOther: true };
|
|
429
|
+
if (isFunction)
|
|
430
|
+
return left;
|
|
431
|
+
return {
|
|
432
|
+
members: [...(left?.members ?? []), ...(right?.members ?? [])],
|
|
433
|
+
mayBeOther: right?.mayBeOther ?? true,
|
|
434
|
+
};
|
|
398
435
|
}
|
|
399
436
|
if (this.bindings.isTestObject(node, false))
|
|
400
|
-
return [];
|
|
437
|
+
return { members: [[]], mayBeOther: false };
|
|
401
438
|
const chain = readChain(node);
|
|
402
439
|
if (!chain || chain.links.some((link) => link.args ?? link.template))
|
|
403
440
|
return null;
|
|
404
441
|
const members = this.testLinks(chain, [], lookup)?.map((link) => link.name);
|
|
405
|
-
return members && (members.
|
|
442
|
+
return members && (TEST_DECLARATIONS.has(members.join('.')) || DESCRIBES.has(members.join('.')))
|
|
443
|
+
? { members: [members], mayBeOther: false }
|
|
444
|
+
: null;
|
|
406
445
|
}
|
|
407
446
|
/** Follows the import of `name` once, and reports it once when it can't be followed and `report` is set. */
|
|
408
447
|
follow(name, report) {
|
|
@@ -610,7 +649,7 @@ export class PlaywrightAdapter {
|
|
|
610
649
|
const args = call.arguments;
|
|
611
650
|
if (args.length === 0)
|
|
612
651
|
return { kind: 'other' };
|
|
613
|
-
const anonymous = isFunctionNode(args[0]);
|
|
652
|
+
const anonymous = isFunctionNode(args[0]) || (args.length === 1 && namedFunction(this.file, context.scopes, args[0]) !== null);
|
|
614
653
|
const problems = [];
|
|
615
654
|
let title = null;
|
|
616
655
|
if (!anonymous) {
|
|
@@ -619,9 +658,10 @@ export class PlaywrightAdapter {
|
|
|
619
658
|
if (read.problem)
|
|
620
659
|
problems.push(read.problem);
|
|
621
660
|
}
|
|
622
|
-
const fn = anonymous ? args[0] : findFunction(args, 1);
|
|
623
|
-
|
|
624
|
-
|
|
661
|
+
const fn = anonymous ? (isFunctionNode(args[0]) ? args[0] : null) : findFunction(args, 1);
|
|
662
|
+
const callback = fn ?? namedFunction(this.file, context.scopes, args.at(-1));
|
|
663
|
+
if (callback?.async && containsAwait(callback)) {
|
|
664
|
+
problems.push(problem('async-describe', callback, 'The describe callback awaits, but Playwright does not wait for it; tests declared after the first await end up in the describe around it, or are not collected.'));
|
|
625
665
|
}
|
|
626
666
|
const line = this.file.source.line(call.start);
|
|
627
667
|
return {
|
|
@@ -634,7 +674,7 @@ export class PlaywrightAdapter {
|
|
|
634
674
|
passesDown: null,
|
|
635
675
|
details: this.details(!anonymous && args.length === 3 ? args[1] : undefined, context, problems, title?.text ?? ''),
|
|
636
676
|
fn,
|
|
637
|
-
hashed:
|
|
677
|
+
hashed: callback,
|
|
638
678
|
isParameterized: false,
|
|
639
679
|
caseCount: null,
|
|
640
680
|
cases: null,
|
|
@@ -210,7 +210,8 @@ export class VitestAdapter extends SuiteAdapter {
|
|
|
210
210
|
return !called && !removed(link);
|
|
211
211
|
return TABLES.has(link.name) ? called : CONDITIONS.has(link.name) && link.args !== null;
|
|
212
212
|
};
|
|
213
|
-
const
|
|
213
|
+
const tableIndex = links.findIndex((link) => TABLES.has(link.name) && (link.args !== null || link.template !== null));
|
|
214
|
+
const invalid = links.find((link, index) => !valid(link) || (tableIndex !== -1 && index > tableIndex));
|
|
214
215
|
if (!invalid)
|
|
215
216
|
return this.declaration(call, kind, links, context);
|
|
216
217
|
const refusal = removed(invalid)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { scan } from './scan.ts';
|
|
2
|
+
export { diffInventories } from './diff.ts';
|
|
3
|
+
export { formatDiffMarkdown } from './diff-markdown.ts';
|
|
4
|
+
export type { ChangeKind, CloneGroup, InventoryDiff, MatchMethod, TestChange } from './diff.ts';
|
|
2
5
|
export { scanSource } from './scan-source.ts';
|
|
3
6
|
export { filterInventory, pickTestFields } from './filter.ts';
|
|
4
7
|
export type { InventoryFilter, PickedInventory } from './filter.ts';
|
package/dist/index.js
CHANGED