@quiesco/vitest 0.7.0 → 0.8.0
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/dist/list.d.ts +5 -0
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +22 -2
- package/dist/list.js.map +1 -1
- package/package.json +2 -2
- package/src/list.ts +22 -2
package/dist/list.d.ts
CHANGED
|
@@ -6,5 +6,10 @@ export interface ListArgs {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function parseListArgs(argv: readonly string[]): ListArgs;
|
|
8
8
|
export declare function listVitestTests(args: Omit<ListArgs, 'out'>): Promise<TestList>;
|
|
9
|
+
/** Whether the call at `location` (1-based line and column, in the original source) is a hook call. */
|
|
10
|
+
export declare function isHookCall(lines: readonly string[] | null, location: {
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
} | undefined): boolean;
|
|
9
14
|
export declare function listMain(argv: readonly string[]): Promise<void>;
|
|
10
15
|
//# sourceMappingURL=list.d.ts.map
|
package/dist/list.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../src/list.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../src/list.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAW,MAAM,eAAe,CAAC;AAKvD,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,CAU/D;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiBpF;AAaD,uGAAuG;AACvG,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GAAG,OAAO,CAI3H;AAMD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAWrE"}
|
package/dist/list.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A static parse (`parseSpecifications`): no globalSetup, setup files, module code or fixtures run
|
|
7
7
|
* (findings P0). `test.each` is listed once; skipped and todo tests are listed too. Ids are Vitest's own
|
|
8
|
-
* test ids, as the reporter sends them.
|
|
8
|
+
* test ids, as the reporter sends them. The static parse takes every `test.<x>(…)` call for a test, so
|
|
9
|
+
* hook calls through the test function (`test.beforeEach(reset)`, #55) are dropped by their source.
|
|
9
10
|
*/
|
|
10
11
|
import fs from 'node:fs';
|
|
11
12
|
import { createVitest } from 'vitest/node';
|
|
@@ -34,8 +35,10 @@ export async function listVitestTests(args) {
|
|
|
34
35
|
const tests = [];
|
|
35
36
|
const errors = [];
|
|
36
37
|
for (const m of modules) {
|
|
38
|
+
const lines = sourceLines(m.moduleId);
|
|
37
39
|
for (const t of m.children.allTests())
|
|
38
|
-
|
|
40
|
+
if (!isHookCall(lines, t.location))
|
|
41
|
+
tests.push(testRef(t, root));
|
|
39
42
|
for (const e of m.errors())
|
|
40
43
|
errors.push({ file: testRefFile(root, m.moduleId), message: e.message });
|
|
41
44
|
}
|
|
@@ -45,6 +48,23 @@ export async function listVitestTests(args) {
|
|
|
45
48
|
await vitest.close();
|
|
46
49
|
}
|
|
47
50
|
}
|
|
51
|
+
/** Hooks a test function also has (`test.beforeEach`, `it.afterAll`, …): calls of these are not tests. */
|
|
52
|
+
const HOOK_CALL = /^[\w$]+(?:\.[\w$]+)*\.(?:beforeEach|afterEach|beforeAll|afterAll|aroundEach|aroundAll|onTestFailed|onTestFinished)\s*\(/;
|
|
53
|
+
function sourceLines(file) {
|
|
54
|
+
try {
|
|
55
|
+
return fs.readFileSync(file, 'utf8').split('\n');
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Whether the call at `location` (1-based line and column, in the original source) is a hook call. */
|
|
62
|
+
export function isHookCall(lines, location) {
|
|
63
|
+
if (lines === null || location === undefined)
|
|
64
|
+
return false;
|
|
65
|
+
const line = lines[location.line - 1];
|
|
66
|
+
return line !== undefined && HOOK_CALL.test(line.slice(location.column - 1));
|
|
67
|
+
}
|
|
48
68
|
function testRefFile(root, file) {
|
|
49
69
|
return file.startsWith(`${root}/`) ? file.slice(root.length + 1) : file;
|
|
50
70
|
}
|
package/dist/list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../src/list.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../src/list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAQxC,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,MAAM,IAAI,GAAa,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAW,CAAC;QAC5B,IAAI,CAAC,KAAK,OAAO;YAAE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAA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AAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAY;IAC7C,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAuB;IACpD,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,IAAc,CAAC;IACnB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAG,CAAW,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;IACjG,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,IAAI,CAAC,GAAG,KAAK,EAAE;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;;QAClD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiesco/vitest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Quiesco for Vitest: one session for the run, `app` as a test fixture, a reset before every test",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "h2nology",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"src"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@quiesco/core": "0.
|
|
55
|
+
"@quiesco/core": "0.8.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"vitest": ">=5.1"
|
package/src/list.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A static parse (`parseSpecifications`): no globalSetup, setup files, module code or fixtures run
|
|
7
7
|
* (findings P0). `test.each` is listed once; skipped and todo tests are listed too. Ids are Vitest's own
|
|
8
|
-
* test ids, as the reporter sends them.
|
|
8
|
+
* test ids, as the reporter sends them. The static parse takes every `test.<x>(…)` call for a test, so
|
|
9
|
+
* hook calls through the test function (`test.beforeEach(reset)`, #55) are dropped by their source.
|
|
9
10
|
*/
|
|
10
11
|
import fs from 'node:fs';
|
|
11
12
|
|
|
@@ -41,7 +42,8 @@ export async function listVitestTests(args: Omit<ListArgs, 'out'>): Promise<Test
|
|
|
41
42
|
const tests: TestRef[] = [];
|
|
42
43
|
const errors: { file?: string; message: string }[] = [];
|
|
43
44
|
for (const m of modules) {
|
|
44
|
-
|
|
45
|
+
const lines = sourceLines(m.moduleId);
|
|
46
|
+
for (const t of m.children.allTests()) if (!isHookCall(lines, t.location)) tests.push(testRef(t, root));
|
|
45
47
|
for (const e of m.errors()) errors.push({ file: testRefFile(root, m.moduleId), message: e.message });
|
|
46
48
|
}
|
|
47
49
|
return { runner: 'vitest', files: specifications.map((s) => testRefFile(root, s.moduleId)), tests, errors };
|
|
@@ -50,6 +52,24 @@ export async function listVitestTests(args: Omit<ListArgs, 'out'>): Promise<Test
|
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
/** Hooks a test function also has (`test.beforeEach`, `it.afterAll`, …): calls of these are not tests. */
|
|
56
|
+
const HOOK_CALL = /^[\w$]+(?:\.[\w$]+)*\.(?:beforeEach|afterEach|beforeAll|afterAll|aroundEach|aroundAll|onTestFailed|onTestFinished)\s*\(/;
|
|
57
|
+
|
|
58
|
+
function sourceLines(file: string): string[] | null {
|
|
59
|
+
try {
|
|
60
|
+
return fs.readFileSync(file, 'utf8').split('\n');
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Whether the call at `location` (1-based line and column, in the original source) is a hook call. */
|
|
67
|
+
export function isHookCall(lines: readonly string[] | null, location: { line: number; column: number } | undefined): boolean {
|
|
68
|
+
if (lines === null || location === undefined) return false;
|
|
69
|
+
const line = lines[location.line - 1];
|
|
70
|
+
return line !== undefined && HOOK_CALL.test(line.slice(location.column - 1));
|
|
71
|
+
}
|
|
72
|
+
|
|
53
73
|
function testRefFile(root: string, file: string): string {
|
|
54
74
|
return file.startsWith(`${root}/`) ? file.slice(root.length + 1) : file;
|
|
55
75
|
}
|