vitest 0.0.81 → 0.0.85
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/cli.js +24 -1902
- package/dist/{constants-1268ea5c.js → constants-adef7ffb.js} +1 -1
- package/dist/entry.js +95 -114
- package/dist/{error-6bb44a98.js → error-c651f5ae.js} +61 -15
- package/dist/{global-b8e9d6fe.js → global-e172af93.js} +3 -3
- package/dist/{index-16a06164.js → index-906ac3f9.js} +1 -1
- package/dist/index-c033f95e.js +1895 -0
- package/dist/index.d.ts +16 -43
- package/dist/index.js +2 -2
- package/dist/{middleware-b567041c.js → middleware-650c5fa0.js} +1 -1
- package/dist/node.js +19 -0
- package/dist/{suite-95be5909.js → suite-0e21bf9b.js} +17 -6
- package/dist/worker.js +18 -20
- package/package.json +10 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Formatter } from 'picocolors/types';
|
|
2
|
-
import { TransformResult, ViteDevServer } from 'vite';
|
|
3
2
|
import { OptionsReceived } from 'pretty-format';
|
|
4
3
|
import { MessagePort } from 'worker_threads';
|
|
5
4
|
export { assert, default as chai, expect, should } from 'chai';
|
|
@@ -110,31 +109,14 @@ declare type MatchersObject<T extends MatcherState = MatcherState> = {
|
|
|
110
109
|
[id: string]: RawMatcherFn<T>;
|
|
111
110
|
};
|
|
112
111
|
|
|
113
|
-
declare class StateManager {
|
|
114
|
-
filesMap: Record<string, File>;
|
|
115
|
-
idMap: Record<string, Task>;
|
|
116
|
-
taskFileMap: WeakMap<Task, File>;
|
|
117
|
-
getFiles(keys?: string[]): File[];
|
|
118
|
-
collectFiles(files: File[]): void;
|
|
119
|
-
updateId(task: Task): void;
|
|
120
|
-
updateTasks(packs: TaskResultPack[]): void;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
declare class SnapshotManager {
|
|
124
|
-
config: ResolvedConfig;
|
|
125
|
-
summary: SnapshotSummary;
|
|
126
|
-
constructor(config: ResolvedConfig);
|
|
127
|
-
clear(): void;
|
|
128
|
-
add(result: SnapshotResult): void;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
112
|
declare type Awaitable<T> = T | PromiseLike<T>;
|
|
132
113
|
declare type Nullable<T> = T | null | undefined;
|
|
133
114
|
declare type Arrayable<T> = T | Array<T>;
|
|
115
|
+
declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
|
|
134
116
|
interface ModuleCache {
|
|
135
117
|
promise?: Promise<any>;
|
|
136
118
|
exports?: any;
|
|
137
|
-
|
|
119
|
+
code?: string;
|
|
138
120
|
}
|
|
139
121
|
interface EnvironmentReturn {
|
|
140
122
|
teardown: (global: any) => Awaitable<void>;
|
|
@@ -143,14 +125,6 @@ interface Environment {
|
|
|
143
125
|
name: string;
|
|
144
126
|
setup(global: any): Awaitable<EnvironmentReturn>;
|
|
145
127
|
}
|
|
146
|
-
interface VitestContext {
|
|
147
|
-
config: ResolvedConfig;
|
|
148
|
-
server: ViteDevServer;
|
|
149
|
-
state: StateManager;
|
|
150
|
-
snapshot: SnapshotManager;
|
|
151
|
-
reporters: Reporter[];
|
|
152
|
-
console: Console;
|
|
153
|
-
}
|
|
154
128
|
interface UserConsoleLog {
|
|
155
129
|
content: string;
|
|
156
130
|
type: 'stdout' | 'stderr';
|
|
@@ -189,7 +163,8 @@ interface Test extends TaskBase {
|
|
|
189
163
|
result?: TaskResult;
|
|
190
164
|
}
|
|
191
165
|
declare type Task = Test | Suite | File;
|
|
192
|
-
declare type
|
|
166
|
+
declare type DoneCallback = (error?: any) => void;
|
|
167
|
+
declare type TestFunction = (done: DoneCallback) => Awaitable<void>;
|
|
193
168
|
declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
|
|
194
169
|
interface ConcurrentCollector {
|
|
195
170
|
(name: string, fn: TestFunction, timeout?: number): void;
|
|
@@ -294,7 +269,7 @@ interface SnapshotSummary {
|
|
|
294
269
|
updated: number;
|
|
295
270
|
}
|
|
296
271
|
|
|
297
|
-
interface
|
|
272
|
+
interface InlineConfig {
|
|
298
273
|
/**
|
|
299
274
|
* Include globs for test files
|
|
300
275
|
*
|
|
@@ -397,28 +372,26 @@ interface UserOptions {
|
|
|
397
372
|
* @default false
|
|
398
373
|
*/
|
|
399
374
|
silent?: boolean;
|
|
400
|
-
/**
|
|
401
|
-
* Open Vitest UI
|
|
402
|
-
*/
|
|
403
|
-
open?: boolean;
|
|
404
375
|
/**
|
|
405
376
|
* Path to setup files
|
|
406
377
|
*/
|
|
407
378
|
setupFiles?: string | string[];
|
|
379
|
+
/**
|
|
380
|
+
* Open Vitest UI
|
|
381
|
+
* @internal WIP
|
|
382
|
+
*/
|
|
383
|
+
open?: boolean;
|
|
408
384
|
/**
|
|
409
385
|
* Listen to port and serve API
|
|
410
386
|
*
|
|
411
387
|
* When set to true, the default port is 55555
|
|
412
388
|
*
|
|
389
|
+
* @internal WIP
|
|
413
390
|
* @default false
|
|
414
391
|
*/
|
|
415
392
|
api?: boolean | number;
|
|
416
393
|
}
|
|
417
|
-
interface
|
|
418
|
-
/**
|
|
419
|
-
* Filters by name
|
|
420
|
-
*/
|
|
421
|
-
cliFilters?: string[];
|
|
394
|
+
interface UserConfig extends InlineConfig {
|
|
422
395
|
/**
|
|
423
396
|
* Path to the config file.
|
|
424
397
|
*
|
|
@@ -431,7 +404,7 @@ interface CliOptions extends UserOptions {
|
|
|
431
404
|
config?: string | undefined;
|
|
432
405
|
dom?: boolean;
|
|
433
406
|
}
|
|
434
|
-
interface ResolvedConfig extends Omit<Required<
|
|
407
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'> {
|
|
435
408
|
config?: string;
|
|
436
409
|
filters?: string[];
|
|
437
410
|
depsInline: (string | RegExp)[];
|
|
@@ -446,7 +419,7 @@ interface WorkerContext {
|
|
|
446
419
|
invalidates?: string[];
|
|
447
420
|
}
|
|
448
421
|
interface RpcMap {
|
|
449
|
-
fetch: [[id: string],
|
|
422
|
+
fetch: [[id: string], string | undefined];
|
|
450
423
|
log: [[UserConsoleLog], void];
|
|
451
424
|
processExit: [[code?: number], void];
|
|
452
425
|
onCollected: [[files: File[]], void];
|
|
@@ -577,7 +550,7 @@ declare module 'vite' {
|
|
|
577
550
|
/**
|
|
578
551
|
* Options for Vitest
|
|
579
552
|
*/
|
|
580
|
-
test?:
|
|
553
|
+
test?: InlineConfig;
|
|
581
554
|
}
|
|
582
555
|
}
|
|
583
556
|
declare global {
|
|
@@ -637,4 +610,4 @@ declare global {
|
|
|
637
610
|
}
|
|
638
611
|
}
|
|
639
612
|
|
|
640
|
-
export { Arrayable, Awaitable,
|
|
613
|
+
export { ArgumentsType, Arrayable, Awaitable, ComputeMode, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, suite, test, vitest };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { d as describe, i as it, s as suite, t as test } from './suite-
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-
|
|
1
|
+
export { d as describe, i as it, s as suite, t as test } from './suite-0e21bf9b.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-906ac3f9.js';
|
|
3
3
|
export { assert, default as chai, expect, should } from 'chai';
|
|
4
4
|
export { spy, spyOn } from 'tinyspy';
|
|
5
5
|
import './index-9e71c815.js';
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { c as createVitest } from './index-c033f95e.js';
|
|
2
|
+
import 'path';
|
|
3
|
+
import 'vite';
|
|
4
|
+
import 'process';
|
|
5
|
+
import 'fs';
|
|
6
|
+
import './constants-adef7ffb.js';
|
|
7
|
+
import 'url';
|
|
8
|
+
import './utils-9dcc4050.js';
|
|
9
|
+
import 'perf_hooks';
|
|
10
|
+
import './error-c651f5ae.js';
|
|
11
|
+
import 'tty';
|
|
12
|
+
import 'source-map';
|
|
13
|
+
import 'assert';
|
|
14
|
+
import 'events';
|
|
15
|
+
import 'worker_threads';
|
|
16
|
+
import 'piscina';
|
|
17
|
+
import 'fast-glob';
|
|
18
|
+
import 'micromatch';
|
|
19
|
+
import 'readline';
|
|
@@ -36,6 +36,17 @@ function withTimeout(fn, _timeout) {
|
|
|
36
36
|
})]);
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
function ensureAsyncTest(fn) {
|
|
40
|
+
if (!fn.length)
|
|
41
|
+
return fn;
|
|
42
|
+
return () => new Promise((resolve, reject) => {
|
|
43
|
+
const done = (...args) => args[0] ? reject(args[0]) : resolve();
|
|
44
|
+
fn(done);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function normalizeTest(fn, timeout) {
|
|
48
|
+
return withTimeout(ensureAsyncTest(fn), timeout);
|
|
49
|
+
}
|
|
39
50
|
|
|
40
51
|
const fnMap = new WeakMap();
|
|
41
52
|
const hooksMap = new WeakMap();
|
|
@@ -136,24 +147,24 @@ function createSuiteCollector(name, factory = () => {
|
|
|
136
147
|
}
|
|
137
148
|
function createTestCollector(collectTest) {
|
|
138
149
|
function test2(name, fn, timeout) {
|
|
139
|
-
collectTest(name,
|
|
150
|
+
collectTest(name, normalizeTest(fn, timeout), "run");
|
|
140
151
|
}
|
|
141
152
|
test2.concurrent = concurrent;
|
|
142
153
|
test2.skip = skip;
|
|
143
154
|
test2.only = only;
|
|
144
155
|
test2.todo = todo;
|
|
145
156
|
function concurrent(name, fn, timeout) {
|
|
146
|
-
collectTest(name,
|
|
157
|
+
collectTest(name, normalizeTest(fn, timeout), "run", "concurrent");
|
|
147
158
|
}
|
|
148
|
-
concurrent.skip = (name, fn, timeout) => collectTest(name,
|
|
149
|
-
concurrent.only = (name, fn, timeout) => collectTest(name,
|
|
159
|
+
concurrent.skip = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "skip", "concurrent");
|
|
160
|
+
concurrent.only = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "only", "concurrent");
|
|
150
161
|
concurrent.todo = todo;
|
|
151
162
|
function skip(name, fn, timeout) {
|
|
152
|
-
collectTest(name,
|
|
163
|
+
collectTest(name, normalizeTest(fn, timeout), "skip");
|
|
153
164
|
}
|
|
154
165
|
skip.concurrent = concurrent.skip;
|
|
155
166
|
function only(name, fn, timeout) {
|
|
156
|
-
collectTest(name,
|
|
167
|
+
collectTest(name, normalizeTest(fn, timeout), "only");
|
|
157
168
|
}
|
|
158
169
|
only.concurrent = concurrent.only;
|
|
159
170
|
function todo(name) {
|
package/dist/worker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve, dirname } from 'path';
|
|
2
2
|
import { n as nanoid } from './index-9e71c815.js';
|
|
3
|
-
import {
|
|
3
|
+
import { c as distDir } from './constants-adef7ffb.js';
|
|
4
4
|
import { builtinModules, createRequire } from 'module';
|
|
5
5
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
6
6
|
import vm from 'vm';
|
|
@@ -19,7 +19,8 @@ const defaultInline = [
|
|
|
19
19
|
/\.(es|esm|esm-browser|esm-bundler|es6).js$/
|
|
20
20
|
];
|
|
21
21
|
const depsExternal = [
|
|
22
|
-
/\.cjs.js
|
|
22
|
+
/\.cjs.js$/,
|
|
23
|
+
/\.mjs$/
|
|
23
24
|
];
|
|
24
25
|
const isWindows = process.platform === "win32";
|
|
25
26
|
const stubRequests = {
|
|
@@ -54,18 +55,6 @@ async function interpretedImport(path, interpretDefault) {
|
|
|
54
55
|
}
|
|
55
56
|
return mod;
|
|
56
57
|
}
|
|
57
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
58
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
59
|
-
async function withInlineSourcemap(result) {
|
|
60
|
-
const { code, map } = result;
|
|
61
|
-
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
62
|
-
return result;
|
|
63
|
-
if (map)
|
|
64
|
-
result.code = `${code}
|
|
65
|
-
|
|
66
|
-
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}`;
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
58
|
async function executeInViteNode(options) {
|
|
70
59
|
const { moduleCache, root, files, fetch } = options;
|
|
71
60
|
const externaled = new Set(builtinModules);
|
|
@@ -89,17 +78,26 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
89
78
|
};
|
|
90
79
|
if (id in stubRequests)
|
|
91
80
|
return stubRequests[id];
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
81
|
+
const transformed = await fetch(id);
|
|
82
|
+
if (!transformed)
|
|
94
83
|
throw new Error(`failed to load ${id}`);
|
|
95
|
-
if (process.env.NODE_V8_COVERAGE)
|
|
96
|
-
withInlineSourcemap(result2);
|
|
97
84
|
const url = pathToFileURL(fsPath).href;
|
|
98
85
|
const exports = {};
|
|
99
|
-
setCache(fsPath, {
|
|
86
|
+
setCache(fsPath, { code: transformed, exports });
|
|
100
87
|
const __filename = fileURLToPath(url);
|
|
88
|
+
const moduleProxy = {
|
|
89
|
+
set exports(value) {
|
|
90
|
+
exportAll(exports, value);
|
|
91
|
+
exports.default = value;
|
|
92
|
+
},
|
|
93
|
+
get exports() {
|
|
94
|
+
return exports.default;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
101
97
|
const context = {
|
|
102
98
|
require: createRequire(url),
|
|
99
|
+
exports,
|
|
100
|
+
module: moduleProxy,
|
|
103
101
|
__filename,
|
|
104
102
|
__dirname: dirname(__filename),
|
|
105
103
|
__vite_ssr_import__: request,
|
|
@@ -108,7 +106,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
108
106
|
__vite_ssr_exportAll__: (obj) => exportAll(exports, obj),
|
|
109
107
|
__vite_ssr_import_meta__: { url }
|
|
110
108
|
};
|
|
111
|
-
const fn = vm.runInThisContext(`async (${Object.keys(context).join(",")})=>{${
|
|
109
|
+
const fn = vm.runInThisContext(`async (${Object.keys(context).join(",")})=>{${transformed}
|
|
112
110
|
}`, {
|
|
113
111
|
filename: fsPath,
|
|
114
112
|
lineOffset: 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.85",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
"import": "./dist/index.js",
|
|
26
26
|
"types": "./dist/index.d.ts"
|
|
27
27
|
},
|
|
28
|
+
"./node": {
|
|
29
|
+
"import": "./dist/node.js",
|
|
30
|
+
"types": "./dist/node.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./global": {
|
|
33
|
+
"types": "./global.d.ts"
|
|
34
|
+
},
|
|
28
35
|
"./*": "./*"
|
|
29
36
|
},
|
|
30
37
|
"main": "./dist/index.js",
|
|
@@ -49,7 +56,7 @@
|
|
|
49
56
|
"micromatch": "^4.0.4",
|
|
50
57
|
"piscina": "^3.2.0",
|
|
51
58
|
"source-map": "^0.7.3",
|
|
52
|
-
"tinyspy": "^0.0.
|
|
59
|
+
"tinyspy": "^0.0.13"
|
|
53
60
|
},
|
|
54
61
|
"devDependencies": {
|
|
55
62
|
"@types/diff": "^5.0.1",
|
|
@@ -69,6 +76,7 @@
|
|
|
69
76
|
"natural-compare": "^1.4.0",
|
|
70
77
|
"picocolors": "^1.0.0",
|
|
71
78
|
"pretty-format": "^27.4.2",
|
|
79
|
+
"rollup": "^2.61.1",
|
|
72
80
|
"strip-ansi": "^7.0.1"
|
|
73
81
|
},
|
|
74
82
|
"peerDependencies": {
|