vitest 0.0.21 → 0.0.22
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/README.md +1 -1
- package/dist/cli.js +3 -3
- package/dist/entry.js +1 -1
- package/dist/node/index.d.ts +22 -0
- package/dist/{node.js → node/index.js} +24 -21
- package/dist/reporters/default.d.ts +5 -8
- package/dist/reporters/default.js +32 -35
- package/dist/run/index.d.ts +8 -0
- package/dist/{run.js → run/index.js} +95 -23
- package/dist/types.d.ts +6 -1
- package/package.json +1 -1
- package/dist/node.d.ts +0 -11
- package/dist/run.d.ts +0 -6
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
import minimist from 'minimist';
|
|
3
2
|
import c from 'picocolors';
|
|
4
3
|
import { run } from './run';
|
|
@@ -19,8 +18,9 @@ const argv = minimist(process.argv.slice(2), {
|
|
|
19
18
|
return true;
|
|
20
19
|
},
|
|
21
20
|
});
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
if (!process.__vite_node__)
|
|
22
|
+
throw new Error('Vite can only run in Vite environment, please use the CLI to start the process');
|
|
23
|
+
const server = process.__vite_node__.server;
|
|
24
24
|
const viteConfig = (server === null || server === void 0 ? void 0 : server.config) || {};
|
|
25
25
|
const testOptions = viteConfig.test || {};
|
|
26
26
|
await run(Object.assign(Object.assign(Object.assign({}, argv), testOptions), { server, updateSnapshot: argv.update, rootDir: argv.root || process.cwd(), nameFilters: argv._ }));
|
package/dist/entry.js
CHANGED
|
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'url';
|
|
|
2
2
|
import { resolve, dirname } from 'path';
|
|
3
3
|
import minimist from 'minimist';
|
|
4
4
|
import { findUp } from 'find-up';
|
|
5
|
-
import { run } from './node.js';
|
|
5
|
+
import { run } from './node/index.js';
|
|
6
6
|
process.env.VITEST = 'true';
|
|
7
7
|
const argv = minimist(process.argv.slice(2), {
|
|
8
8
|
alias: {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InlineConfig, ViteDevServer } from 'vite';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace NodeJS {
|
|
4
|
+
interface Process {
|
|
5
|
+
__vite_node__: {
|
|
6
|
+
server: ViteDevServer;
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
moduleCache: Map<string, Promise<any>>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export interface ViteNodeOptions {
|
|
14
|
+
silent?: boolean;
|
|
15
|
+
root: string;
|
|
16
|
+
files: string[];
|
|
17
|
+
_?: string[];
|
|
18
|
+
shouldExternalize?: (file: string) => boolean;
|
|
19
|
+
config?: string;
|
|
20
|
+
defaultConfig?: InlineConfig;
|
|
21
|
+
}
|
|
22
|
+
export declare function run(argv: ViteNodeOptions): Promise<void>;
|
|
@@ -5,6 +5,7 @@ import vm from 'vm';
|
|
|
5
5
|
import { createServer, mergeConfig } from 'vite';
|
|
6
6
|
import c from 'picocolors';
|
|
7
7
|
const { red, dim, yellow } = c;
|
|
8
|
+
const __pendingModules__ = new Map();
|
|
8
9
|
export async function run(argv) {
|
|
9
10
|
process.exitCode = 0;
|
|
10
11
|
const root = argv.root || process.cwd();
|
|
@@ -19,9 +20,9 @@ export async function run(argv) {
|
|
|
19
20
|
resolve: {},
|
|
20
21
|
}));
|
|
21
22
|
await server.pluginContainer.buildStart({});
|
|
22
|
-
// @ts-expect-error
|
|
23
23
|
process.__vite_node__ = {
|
|
24
24
|
server,
|
|
25
|
+
moduleCache: __pendingModules__,
|
|
25
26
|
};
|
|
26
27
|
try {
|
|
27
28
|
await execute(files, server, argv);
|
|
@@ -31,7 +32,8 @@ export async function run(argv) {
|
|
|
31
32
|
throw e;
|
|
32
33
|
}
|
|
33
34
|
finally {
|
|
34
|
-
|
|
35
|
+
if (!process.__vite_node__.watch)
|
|
36
|
+
await server.close();
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
function normalizeId(id) {
|
|
@@ -47,7 +49,9 @@ function toFilePath(id, server) {
|
|
|
47
49
|
? id.slice(4)
|
|
48
50
|
: id.startsWith(dirname(server.config.root))
|
|
49
51
|
? id
|
|
50
|
-
:
|
|
52
|
+
: id.startsWith('/')
|
|
53
|
+
? slash(resolve(server.config.root, id.slice(1)))
|
|
54
|
+
: id;
|
|
51
55
|
if (absolute.startsWith('//'))
|
|
52
56
|
absolute = absolute.slice(1);
|
|
53
57
|
if (!absolute.startsWith('/'))
|
|
@@ -55,15 +59,12 @@ function toFilePath(id, server) {
|
|
|
55
59
|
return absolute;
|
|
56
60
|
}
|
|
57
61
|
async function execute(files, server, options) {
|
|
58
|
-
const __pendingModules__ = new Map();
|
|
59
62
|
const result = [];
|
|
60
63
|
for (const file of files)
|
|
61
64
|
result.push(await cachedRequest(`/@fs/${slash(resolve(file))}`, []));
|
|
62
65
|
return result;
|
|
63
|
-
async function directRequest(
|
|
64
|
-
|
|
65
|
-
return import(rawId);
|
|
66
|
-
callstack = [...callstack, rawId];
|
|
66
|
+
async function directRequest(id, fsPath, callstack) {
|
|
67
|
+
callstack = [...callstack, id];
|
|
67
68
|
const request = async (dep) => {
|
|
68
69
|
if (callstack.includes(dep)) {
|
|
69
70
|
throw new Error(`${red('Circular dependency detected')}\nStack:\n${[...callstack, dep].reverse().map((i) => {
|
|
@@ -73,19 +74,15 @@ async function execute(files, server, options) {
|
|
|
73
74
|
}
|
|
74
75
|
return cachedRequest(dep, callstack);
|
|
75
76
|
};
|
|
76
|
-
const id = normalizeId(rawId);
|
|
77
|
-
const absolute = toFilePath(id, server);
|
|
78
|
-
if (options.shouldExternalize(absolute))
|
|
79
|
-
return import(absolute);
|
|
80
77
|
const result = await server.transformRequest(id, { ssr: true });
|
|
81
78
|
if (!result)
|
|
82
79
|
throw new Error(`failed to load ${id}`);
|
|
83
|
-
const url = pathToFileURL(
|
|
80
|
+
const url = pathToFileURL(fsPath);
|
|
84
81
|
const exports = {};
|
|
85
82
|
const context = {
|
|
86
83
|
require: createRequire(url),
|
|
87
|
-
__filename:
|
|
88
|
-
__dirname: dirname(
|
|
84
|
+
__filename: fsPath,
|
|
85
|
+
__dirname: dirname(fsPath),
|
|
89
86
|
__vite_ssr_import__: request,
|
|
90
87
|
__vite_ssr_dynamic_import__: request,
|
|
91
88
|
__vite_ssr_exports__: exports,
|
|
@@ -93,17 +90,23 @@ async function execute(files, server, options) {
|
|
|
93
90
|
__vite_ssr_import_meta__: { url },
|
|
94
91
|
};
|
|
95
92
|
const fn = vm.runInThisContext(`async (${Object.keys(context).join(',')}) => { ${result.code} }`, {
|
|
96
|
-
filename:
|
|
93
|
+
filename: fsPath,
|
|
97
94
|
lineOffset: 0,
|
|
98
95
|
});
|
|
99
96
|
await fn(...Object.values(context));
|
|
100
97
|
return exports;
|
|
101
98
|
}
|
|
102
|
-
async function cachedRequest(
|
|
103
|
-
if (
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
async function cachedRequest(rawId, callstack) {
|
|
100
|
+
if (builtinModules.includes(rawId))
|
|
101
|
+
return import(rawId);
|
|
102
|
+
const id = normalizeId(rawId);
|
|
103
|
+
const fsPath = toFilePath(id, server);
|
|
104
|
+
if (options.shouldExternalize(fsPath))
|
|
105
|
+
return import(fsPath);
|
|
106
|
+
if (__pendingModules__.has(fsPath))
|
|
107
|
+
return __pendingModules__.get(fsPath);
|
|
108
|
+
__pendingModules__.set(fsPath, directRequest(id, fsPath, callstack));
|
|
109
|
+
return await __pendingModules__.get(fsPath);
|
|
107
110
|
}
|
|
108
111
|
function exportAll(exports, sourceModule) {
|
|
109
112
|
// eslint-disable-next-line no-restricted-syntax
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import Listr from 'listr';
|
|
2
|
-
import { Reporter, RunnerContext, Task } from '../types';
|
|
2
|
+
import { File, Reporter, RunnerContext, Task } from '../types';
|
|
3
3
|
interface TaskPromise {
|
|
4
4
|
promise: Promise<void>;
|
|
5
5
|
resolve: () => void;
|
|
6
6
|
reject: (e: unknown) => void;
|
|
7
7
|
}
|
|
8
8
|
export declare class DefaultReporter implements Reporter {
|
|
9
|
-
indent: number;
|
|
10
9
|
start: number;
|
|
11
10
|
end: number;
|
|
12
11
|
listr: Listr | null;
|
|
13
12
|
listrPromise: Promise<void> | null;
|
|
14
13
|
taskMap: Map<Task, TaskPromise>;
|
|
15
|
-
|
|
16
|
-
onCollected(ctx: RunnerContext): void;
|
|
14
|
+
onCollected(files: File[]): void;
|
|
17
15
|
onTaskEnd(task: Task): void;
|
|
18
|
-
onFinished(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
private error;
|
|
16
|
+
onFinished(ctx: RunnerContext): Promise<void>;
|
|
17
|
+
onWatcherStart(ctx: RunnerContext): Promise<void>;
|
|
18
|
+
onWatcherRerun(files: string[], trigger: string): Promise<void>;
|
|
22
19
|
onSnapshotUpdate(): void;
|
|
23
20
|
}
|
|
24
21
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import { performance } from 'perf_hooks';
|
|
2
3
|
import { relative } from 'path';
|
|
3
4
|
import c from 'picocolors';
|
|
@@ -5,20 +6,16 @@ import Listr from 'listr';
|
|
|
5
6
|
const CROSS = '✖ ';
|
|
6
7
|
export class DefaultReporter {
|
|
7
8
|
constructor() {
|
|
8
|
-
this.indent = 0;
|
|
9
9
|
this.start = 0;
|
|
10
10
|
this.end = 0;
|
|
11
11
|
this.listr = null;
|
|
12
12
|
this.listrPromise = null;
|
|
13
13
|
this.taskMap = new Map();
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
this.indent = 0;
|
|
17
|
-
}
|
|
18
|
-
onCollected(ctx) {
|
|
15
|
+
onCollected(files) {
|
|
19
16
|
this.start = performance.now();
|
|
20
17
|
this.taskMap = new Map();
|
|
21
|
-
const tasks =
|
|
18
|
+
const tasks = files.reduce((acc, file) => acc.concat(file.suites.flatMap(i => i.tasks)), []);
|
|
22
19
|
tasks.forEach((t) => {
|
|
23
20
|
const obj = {};
|
|
24
21
|
obj.promise = new Promise((resolve, reject) => {
|
|
@@ -42,7 +39,7 @@ export class DefaultReporter {
|
|
|
42
39
|
const listrOptions = {
|
|
43
40
|
exitOnError: false,
|
|
44
41
|
};
|
|
45
|
-
this.listr = new Listr(
|
|
42
|
+
this.listr = new Listr(files.map((file) => {
|
|
46
43
|
return {
|
|
47
44
|
title: relative(process.cwd(), file.filepath),
|
|
48
45
|
task: () => {
|
|
@@ -67,12 +64,11 @@ export class DefaultReporter {
|
|
|
67
64
|
else
|
|
68
65
|
(_b = this.taskMap.get(task)) === null || _b === void 0 ? void 0 : _b.resolve();
|
|
69
66
|
}
|
|
70
|
-
async onFinished(
|
|
67
|
+
async onFinished(ctx) {
|
|
71
68
|
await this.listrPromise;
|
|
72
|
-
this.log();
|
|
73
69
|
this.end = performance.now();
|
|
74
|
-
|
|
75
|
-
const tasks
|
|
70
|
+
console.log();
|
|
71
|
+
const { tasks, suites, files } = ctx;
|
|
76
72
|
const failedFiles = files.filter(i => i.error);
|
|
77
73
|
const failedSuites = suites.filter(i => i.error);
|
|
78
74
|
const runable = tasks.filter(i => i.state === 'pass' || i.state === 'fail');
|
|
@@ -80,53 +76,54 @@ export class DefaultReporter {
|
|
|
80
76
|
const failed = tasks.filter(i => i.state === 'fail');
|
|
81
77
|
const skipped = tasks.filter(i => i.state === 'skip');
|
|
82
78
|
const todo = tasks.filter(i => i.state === 'todo');
|
|
83
|
-
this.indent = 0;
|
|
84
79
|
if (failedFiles.length) {
|
|
85
|
-
|
|
80
|
+
console.error(c.bold(`\nFailed to parse ${failedFiles.length} files:`));
|
|
86
81
|
failedFiles.forEach((i) => {
|
|
87
|
-
|
|
82
|
+
console.error(c.red(`\n- ${i.filepath}`));
|
|
88
83
|
console.error(i.error || 'Unknown error');
|
|
89
|
-
|
|
84
|
+
console.log();
|
|
90
85
|
});
|
|
91
86
|
}
|
|
92
87
|
if (failedSuites.length) {
|
|
93
|
-
|
|
88
|
+
console.error(c.bold(`\nFailed to run ${failedSuites.length} suites:`));
|
|
94
89
|
failedSuites.forEach((i) => {
|
|
95
90
|
var _a;
|
|
96
|
-
|
|
91
|
+
console.error(c.red(`\n- ${(_a = i.file) === null || _a === void 0 ? void 0 : _a.filepath} > ${i.name}`));
|
|
97
92
|
console.error(i.error || 'Unknown error');
|
|
98
|
-
|
|
93
|
+
console.log();
|
|
99
94
|
});
|
|
100
95
|
}
|
|
101
96
|
if (failed.length) {
|
|
102
|
-
|
|
97
|
+
console.error(c.bold(`\nFailed Tests (${failed.length})`));
|
|
103
98
|
failed.forEach((task) => {
|
|
104
99
|
var _a;
|
|
105
|
-
|
|
100
|
+
console.error(`\n${CROSS + c.inverse(c.red(' FAIL '))} ${[task.suite.name, task.name].filter(Boolean).join(' > ')} ${c.gray(c.dim(`${(_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath}`))}`);
|
|
106
101
|
console.error(task.error || 'Unknown error');
|
|
107
|
-
|
|
102
|
+
console.log();
|
|
108
103
|
});
|
|
109
104
|
}
|
|
110
|
-
|
|
105
|
+
console.log(c.bold(c.green(`Passed ${passed.length} / ${runable.length}`)));
|
|
111
106
|
if (failed.length)
|
|
112
|
-
|
|
107
|
+
console.log(c.bold(c.red(`Failed ${failed.length} / ${runable.length}`)));
|
|
113
108
|
if (skipped.length)
|
|
114
|
-
|
|
109
|
+
console.log(c.yellow(`Skipped ${skipped.length}`));
|
|
115
110
|
if (todo.length)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
getIndent(offest = 0) {
|
|
120
|
-
return ' '.repeat((this.indent + offest) * 2);
|
|
111
|
+
console.log(c.dim(`Todo ${todo.length}`));
|
|
112
|
+
console.log(`Time ${(this.end - this.start).toFixed(2)}ms`);
|
|
121
113
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
async onWatcherStart(ctx) {
|
|
115
|
+
await this.listrPromise;
|
|
116
|
+
const failed = ctx.tasks.some(i => i.state === 'fail');
|
|
117
|
+
if (failed)
|
|
118
|
+
console.log(c.red('\nTests failed. Watching for file changes...'));
|
|
119
|
+
else
|
|
120
|
+
console.log(c.green('\nWatching for file changes...'));
|
|
125
121
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
console.
|
|
122
|
+
async onWatcherRerun(files, trigger) {
|
|
123
|
+
await this.listrPromise;
|
|
124
|
+
console.log(c.blue(`File ${relative(process.cwd(), trigger)} changed, re-running tests...`));
|
|
129
125
|
}
|
|
126
|
+
// TODO:
|
|
130
127
|
onSnapshotUpdate() {
|
|
131
128
|
}
|
|
132
129
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { File, Config, Task, RunnerContext, Suite } from '../types';
|
|
2
|
+
export declare function runTask(task: Task, ctx: RunnerContext): Promise<void>;
|
|
3
|
+
export declare function collectFiles(paths: string[]): Promise<Record<string, File>>;
|
|
4
|
+
export declare function runSite(suite: Suite, ctx: RunnerContext): Promise<void>;
|
|
5
|
+
export declare function runFile(file: File, ctx: RunnerContext): Promise<void>;
|
|
6
|
+
export declare function runFiles(filesMap: Record<string, File>, ctx: RunnerContext): Promise<void>;
|
|
7
|
+
export declare function run(config: Config): Promise<void>;
|
|
8
|
+
export declare function startWatcher(ctx: RunnerContext): Promise<void>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fg from 'fast-glob';
|
|
2
|
-
import { setupChai } from '
|
|
3
|
-
import { clearContext, defaultSuite } from '
|
|
4
|
-
import { context } from '
|
|
5
|
-
import { DefaultReporter } from '
|
|
6
|
-
import { defaultIncludes, defaultExcludes } from '
|
|
7
|
-
import { getSnapshotManager } from '
|
|
2
|
+
import { setupChai } from '../integrations/chai/setup';
|
|
3
|
+
import { clearContext, defaultSuite } from '../suite';
|
|
4
|
+
import { context } from '../context';
|
|
5
|
+
import { DefaultReporter } from '../reporters/default';
|
|
6
|
+
import { defaultIncludes, defaultExcludes } from '../constants';
|
|
7
|
+
import { getSnapshotManager } from '../integrations/chai/snapshot';
|
|
8
8
|
async function callHook(suite, name, args) {
|
|
9
9
|
await Promise.all(suite.hooks[name].map(fn => fn(...args)));
|
|
10
10
|
}
|
|
@@ -36,7 +36,7 @@ export async function runTask(task, ctx) {
|
|
|
36
36
|
await ((_c = reporter.onTaskEnd) === null || _c === void 0 ? void 0 : _c.call(reporter, task, ctx));
|
|
37
37
|
}
|
|
38
38
|
export async function collectFiles(paths) {
|
|
39
|
-
const files =
|
|
39
|
+
const files = {};
|
|
40
40
|
for (const filepath of paths) {
|
|
41
41
|
const file = {
|
|
42
42
|
filepath,
|
|
@@ -58,9 +58,10 @@ export async function collectFiles(paths) {
|
|
|
58
58
|
file.collected = false;
|
|
59
59
|
process.exitCode = 1;
|
|
60
60
|
}
|
|
61
|
-
files
|
|
61
|
+
files[filepath] = file;
|
|
62
62
|
}
|
|
63
|
-
const
|
|
63
|
+
const allFiles = Object.values(files);
|
|
64
|
+
const allSuites = allFiles.reduce((suites, file) => suites.concat(file.suites), []);
|
|
64
65
|
interpretOnlyMode(allSuites);
|
|
65
66
|
allSuites.forEach((i) => {
|
|
66
67
|
if (i.mode === 'skip')
|
|
@@ -125,40 +126,111 @@ export async function runFile(file, ctx) {
|
|
|
125
126
|
}
|
|
126
127
|
await ((_b = reporter.onFileEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, file, ctx));
|
|
127
128
|
}
|
|
129
|
+
export async function runFiles(filesMap, ctx) {
|
|
130
|
+
var _a;
|
|
131
|
+
const { reporter } = ctx;
|
|
132
|
+
await ((_a = reporter.onCollected) === null || _a === void 0 ? void 0 : _a.call(reporter, Object.values(filesMap), ctx));
|
|
133
|
+
for (const file of Object.values(filesMap))
|
|
134
|
+
await runFile(file, ctx);
|
|
135
|
+
}
|
|
128
136
|
export async function run(config) {
|
|
129
|
-
var _a, _b, _c
|
|
137
|
+
var _a, _b, _c;
|
|
138
|
+
// if watch, tell `vite-node` not to end the process
|
|
139
|
+
if (config.watch)
|
|
140
|
+
process.__vite_node__.watch = true;
|
|
130
141
|
// setup chai
|
|
131
142
|
await setupChai(config);
|
|
132
143
|
// collect files
|
|
133
|
-
let
|
|
144
|
+
let testFilepaths = await fg(config.includes || defaultIncludes, {
|
|
134
145
|
absolute: true,
|
|
135
146
|
cwd: config.rootDir,
|
|
136
147
|
ignore: config.excludes || defaultExcludes,
|
|
137
148
|
});
|
|
149
|
+
// if name filters are provided by the CLI
|
|
138
150
|
if ((_a = config.nameFilters) === null || _a === void 0 ? void 0 : _a.length)
|
|
139
|
-
|
|
140
|
-
if (!
|
|
151
|
+
testFilepaths = testFilepaths.filter(i => config.nameFilters.some(f => i.includes(f)));
|
|
152
|
+
if (!testFilepaths.length) {
|
|
141
153
|
console.error('No test files found');
|
|
142
154
|
process.exitCode = 1;
|
|
143
155
|
return;
|
|
144
156
|
}
|
|
145
|
-
|
|
146
|
-
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
157
|
+
// setup envs
|
|
147
158
|
if (config.global)
|
|
148
|
-
(await import('
|
|
159
|
+
(await import('../global')).registerApiGlobally();
|
|
149
160
|
if (config.jsdom)
|
|
150
|
-
(await import('
|
|
151
|
-
const
|
|
161
|
+
(await import('../integrations/jsdom')).setupJSDOM(globalThis);
|
|
162
|
+
const reporter = new DefaultReporter();
|
|
163
|
+
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
164
|
+
const filesMap = await collectFiles(testFilepaths);
|
|
152
165
|
const ctx = {
|
|
153
|
-
|
|
166
|
+
filesMap,
|
|
167
|
+
get files() {
|
|
168
|
+
return Object.values(this.filesMap);
|
|
169
|
+
},
|
|
170
|
+
get suites() {
|
|
171
|
+
return Object.values(this.filesMap)
|
|
172
|
+
.reduce((suites, file) => suites.concat(file.suites), []);
|
|
173
|
+
},
|
|
174
|
+
get tasks() {
|
|
175
|
+
return this.suites
|
|
176
|
+
.reduce((tasks, suite) => tasks.concat(suite.tasks), []);
|
|
177
|
+
},
|
|
154
178
|
config,
|
|
155
179
|
reporter,
|
|
156
180
|
};
|
|
157
|
-
await (
|
|
158
|
-
for (const file of files)
|
|
159
|
-
await runFile(file, ctx);
|
|
181
|
+
await runFiles(filesMap, ctx);
|
|
160
182
|
const snapshot = getSnapshotManager();
|
|
161
183
|
snapshot === null || snapshot === void 0 ? void 0 : snapshot.saveSnap();
|
|
162
184
|
snapshot === null || snapshot === void 0 ? void 0 : snapshot.report();
|
|
163
|
-
await ((
|
|
185
|
+
await ((_c = reporter.onFinished) === null || _c === void 0 ? void 0 : _c.call(reporter, ctx));
|
|
186
|
+
if (config.watch)
|
|
187
|
+
startWatcher(ctx);
|
|
188
|
+
}
|
|
189
|
+
export async function startWatcher(ctx) {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
await ((_b = (_a = ctx.reporter).onWatcherStart) === null || _b === void 0 ? void 0 : _b.call(_a, ctx));
|
|
192
|
+
let timer;
|
|
193
|
+
const changedTests = new Set();
|
|
194
|
+
const seen = new Set();
|
|
195
|
+
const { server, moduleCache } = process.__vite_node__;
|
|
196
|
+
server.watcher.on('change', async (id) => {
|
|
197
|
+
getDependencyTests(id, ctx, changedTests, seen);
|
|
198
|
+
seen.forEach(i => moduleCache.delete(i));
|
|
199
|
+
seen.clear();
|
|
200
|
+
if (changedTests.size === 0)
|
|
201
|
+
return;
|
|
202
|
+
clearTimeout(timer);
|
|
203
|
+
timer = setTimeout(async () => {
|
|
204
|
+
var _a, _b, _c, _d;
|
|
205
|
+
const snapshot = getSnapshotManager();
|
|
206
|
+
const pathes = Array.from(changedTests);
|
|
207
|
+
changedTests.clear();
|
|
208
|
+
await ((_b = (_a = ctx.reporter).onWatcherRerun) === null || _b === void 0 ? void 0 : _b.call(_a, pathes, id, ctx));
|
|
209
|
+
pathes.forEach(i => moduleCache.delete(i));
|
|
210
|
+
const files = await collectFiles(pathes);
|
|
211
|
+
Object.assign(ctx.filesMap, files);
|
|
212
|
+
await runFiles(files, ctx);
|
|
213
|
+
// TODO: clear snapshot state
|
|
214
|
+
snapshot === null || snapshot === void 0 ? void 0 : snapshot.saveSnap();
|
|
215
|
+
snapshot === null || snapshot === void 0 ? void 0 : snapshot.report();
|
|
216
|
+
await ((_d = (_c = ctx.reporter).onWatcherStart) === null || _d === void 0 ? void 0 : _d.call(_c, ctx));
|
|
217
|
+
}, 100);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function getDependencyTests(id, ctx, set = new Set(), seen = new Set()) {
|
|
221
|
+
if (seen.has(id) || set.has(id))
|
|
222
|
+
return set;
|
|
223
|
+
seen.add(id);
|
|
224
|
+
if (id in ctx.filesMap) {
|
|
225
|
+
set.add(id);
|
|
226
|
+
return set;
|
|
227
|
+
}
|
|
228
|
+
const mod = process.__vite_node__.server.moduleGraph.getModuleById(id);
|
|
229
|
+
if (mod) {
|
|
230
|
+
mod.importers.forEach((i) => {
|
|
231
|
+
if (i.id)
|
|
232
|
+
getDependencyTests(i.id, ctx, set, seen);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return set;
|
|
164
236
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -78,7 +78,10 @@ export interface File {
|
|
|
78
78
|
error?: unknown;
|
|
79
79
|
}
|
|
80
80
|
export interface RunnerContext {
|
|
81
|
+
filesMap: Record<string, File>;
|
|
81
82
|
files: File[];
|
|
83
|
+
suites: Suite[];
|
|
84
|
+
tasks: Task[];
|
|
82
85
|
config: Config;
|
|
83
86
|
reporter: Reporter;
|
|
84
87
|
}
|
|
@@ -88,7 +91,7 @@ export interface GlobalContext {
|
|
|
88
91
|
}
|
|
89
92
|
export interface Reporter {
|
|
90
93
|
onStart?: (userOptions: Config) => Awaitable<void>;
|
|
91
|
-
onCollected?: (ctx: RunnerContext) => Awaitable<void>;
|
|
94
|
+
onCollected?: (files: File[], ctx: RunnerContext) => Awaitable<void>;
|
|
92
95
|
onFinished?: (ctx: RunnerContext) => Awaitable<void>;
|
|
93
96
|
onSuiteBegin?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
94
97
|
onSuiteEnd?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
@@ -96,5 +99,7 @@ export interface Reporter {
|
|
|
96
99
|
onFileEnd?: (file: File, ctx: RunnerContext) => Awaitable<void>;
|
|
97
100
|
onTaskBegin?: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
98
101
|
onTaskEnd?: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
102
|
+
onWatcherStart?: (ctx: RunnerContext) => Awaitable<void>;
|
|
103
|
+
onWatcherRerun?: (files: string[], trigger: string, ctx: RunnerContext) => Awaitable<void>;
|
|
99
104
|
onSnapshotUpdate?: () => Awaitable<void>;
|
|
100
105
|
}
|
package/package.json
CHANGED
package/dist/node.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { InlineConfig } from 'vite';
|
|
2
|
-
export interface ViteNodeOptions {
|
|
3
|
-
silent?: boolean;
|
|
4
|
-
root: string;
|
|
5
|
-
files: string[];
|
|
6
|
-
_?: string[];
|
|
7
|
-
shouldExternalize?: (file: string) => boolean;
|
|
8
|
-
config?: string;
|
|
9
|
-
defaultConfig?: InlineConfig;
|
|
10
|
-
}
|
|
11
|
-
export declare function run(argv: ViteNodeOptions): Promise<void>;
|
package/dist/run.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { File, Config, Task, RunnerContext, Suite } from './types';
|
|
2
|
-
export declare function runTask(task: Task, ctx: RunnerContext): Promise<void>;
|
|
3
|
-
export declare function collectFiles(paths: string[]): Promise<File[]>;
|
|
4
|
-
export declare function runSite(suite: Suite, ctx: RunnerContext): Promise<void>;
|
|
5
|
-
export declare function runFile(file: File, ctx: RunnerContext): Promise<void>;
|
|
6
|
-
export declare function run(config: Config): Promise<void>;
|