vitest 0.0.111 → 0.0.115
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/LICENSE.md +34 -5
- package/dist/cli.js +1110 -32
- package/dist/{constants-2b0310b7.js → constants-5968a78c.js} +2 -2
- package/dist/{diff-66d6bb83.js → diff-67678e1f.js} +3299 -3298
- package/dist/entry.js +84 -26
- package/dist/{global-201fd559.js → global-bc40af7c.js} +6 -6
- package/dist/{index-61c8686f.js → index-648e7ab2.js} +62 -62
- package/dist/index-6e709f57.js +781 -0
- package/dist/{utils-cb6b1266.js → index-7c024e16.js} +35 -2
- package/dist/{index-2bb9fd4d.js → index-7f57c252.js} +2 -2
- package/dist/{index-8ab26d25.js → index-b4f86684.js} +216 -1181
- package/dist/{index-9f4b9905.js → index-ce49e384.js} +33 -800
- package/dist/index-e909c175.js +62 -0
- package/dist/index.d.ts +102 -26
- package/dist/index.js +5 -4
- package/dist/{jest-mock-a57b745c.js → jest-mock-4a754991.js} +1 -12
- package/dist/magic-string.es-94000aea.js +1360 -0
- package/dist/{middleware-2028dfa0.js → middleware-647438b9.js} +2 -2
- package/dist/node.d.ts +79 -6
- package/dist/node.js +9 -6
- package/dist/rpc-8c7cc374.js +5 -0
- package/dist/utils.js +3 -2
- package/dist/{vi-cb9e4e4e.js → vi-2115c609.js} +14 -4
- package/dist/worker.js +23 -37
- package/package.json +3 -1
- package/vitest.mjs +1 -20
- package/dist/rpc-7de86f29.js +0 -10
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
function createBirpc({
|
|
2
|
+
functions,
|
|
3
|
+
post,
|
|
4
|
+
on,
|
|
5
|
+
eventNames = [],
|
|
6
|
+
serialize = (i) => i,
|
|
7
|
+
deserialize = (i) => i
|
|
8
|
+
}) {
|
|
9
|
+
const rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
10
|
+
on(async (data) => {
|
|
11
|
+
const msg = deserialize(data);
|
|
12
|
+
if (msg.t === "q") {
|
|
13
|
+
const { m: method, a: args } = msg;
|
|
14
|
+
let result, error;
|
|
15
|
+
try {
|
|
16
|
+
result = await functions[method](...args);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
error = e;
|
|
19
|
+
}
|
|
20
|
+
if (msg.i)
|
|
21
|
+
post(serialize({ t: "s", i: msg.i, r: result, e: error }));
|
|
22
|
+
} else {
|
|
23
|
+
const { i: ack, r: result, e: error } = msg;
|
|
24
|
+
const promise = rpcPromiseMap.get(ack);
|
|
25
|
+
if (error)
|
|
26
|
+
promise?.reject(error);
|
|
27
|
+
else
|
|
28
|
+
promise?.resolve(result);
|
|
29
|
+
rpcPromiseMap.delete(ack);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return new Proxy({}, {
|
|
33
|
+
get(_, method) {
|
|
34
|
+
const sendEvent = (...args) => {
|
|
35
|
+
post(serialize({ m: method, a: args, t: "q" }));
|
|
36
|
+
};
|
|
37
|
+
if (eventNames.includes(method)) {
|
|
38
|
+
sendEvent.asEvent = sendEvent;
|
|
39
|
+
return sendEvent;
|
|
40
|
+
}
|
|
41
|
+
const sendCall = (...args) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const id = nanoid();
|
|
44
|
+
rpcPromiseMap.set(id, { resolve, reject });
|
|
45
|
+
post(serialize({ m: method, a: args, i: id, t: "q" }));
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
sendCall.asEvent = sendEvent;
|
|
49
|
+
return sendCall;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
54
|
+
function nanoid(size = 21) {
|
|
55
|
+
let id = "";
|
|
56
|
+
let i = size;
|
|
57
|
+
while (i--)
|
|
58
|
+
id += urlAlphabet[Math.random() * 64 | 0];
|
|
59
|
+
return id;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { createBirpc as c };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Formatter } from 'picocolors/types';
|
|
2
2
|
import { ViteDevServer } from 'vite';
|
|
3
|
+
import { RawSourceMap } from 'source-map-js';
|
|
3
4
|
import { OptionsReceived } from 'pretty-format';
|
|
5
|
+
import { Arrayable as Arrayable$1 } from 'vitest';
|
|
4
6
|
import { MessagePort } from 'worker_threads';
|
|
5
7
|
export { Spy, SpyFn } from 'tinyspy';
|
|
6
8
|
export { assert, default as chai, should } from 'chai';
|
|
@@ -193,14 +195,21 @@ declare class Vitest {
|
|
|
193
195
|
reporters: Reporter[];
|
|
194
196
|
console: Console;
|
|
195
197
|
pool: WorkerPool | undefined;
|
|
198
|
+
outputStream: NodeJS.WriteStream & {
|
|
199
|
+
fd: 1;
|
|
200
|
+
};
|
|
201
|
+
errorStream: NodeJS.WriteStream & {
|
|
202
|
+
fd: 2;
|
|
203
|
+
};
|
|
196
204
|
invalidates: Set<string>;
|
|
197
205
|
changedTests: Set<string>;
|
|
206
|
+
visitedFilesMap: Map<string, RawSourceMap>;
|
|
198
207
|
runningPromise?: Promise<void>;
|
|
199
208
|
isFirstRun: boolean;
|
|
200
209
|
restartsCount: number;
|
|
201
210
|
private _onRestartListeners;
|
|
202
211
|
constructor();
|
|
203
|
-
setServer(options: UserConfig, server: ViteDevServer): void
|
|
212
|
+
setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
|
|
204
213
|
start(filters?: string[]): Promise<void>;
|
|
205
214
|
runFiles(files: string[]): Promise<void>;
|
|
206
215
|
log(...args: any[]): void;
|
|
@@ -218,12 +227,12 @@ declare class Vitest {
|
|
|
218
227
|
}
|
|
219
228
|
|
|
220
229
|
declare abstract class BaseReporter implements Reporter {
|
|
221
|
-
ctx: Vitest;
|
|
222
230
|
start: number;
|
|
223
231
|
end: number;
|
|
224
232
|
watchFilters?: string[];
|
|
225
233
|
isTTY: boolean;
|
|
226
|
-
|
|
234
|
+
ctx: Vitest;
|
|
235
|
+
onInit(ctx: Vitest): void;
|
|
227
236
|
relative(path: string): string;
|
|
228
237
|
onFinished(files?: File[]): Promise<void>;
|
|
229
238
|
onTaskUpdate(pack: TaskResultPack): void;
|
|
@@ -233,12 +242,14 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
233
242
|
onUserConsoleLog(log: UserConsoleLog): void;
|
|
234
243
|
onServerRestart(): void;
|
|
235
244
|
reportSummary(files: File[]): Promise<void>;
|
|
245
|
+
private printTaskErrors;
|
|
236
246
|
}
|
|
237
247
|
|
|
238
248
|
interface ListRendererOptions {
|
|
239
249
|
renderSucceed?: boolean;
|
|
250
|
+
outputStream: NodeJS.WritableStream;
|
|
240
251
|
}
|
|
241
|
-
declare const createListRenderer: (_tasks: Task[], options
|
|
252
|
+
declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
|
|
242
253
|
start(): any;
|
|
243
254
|
update(_tasks: Task[]): any;
|
|
244
255
|
stop(): Promise<any>;
|
|
@@ -267,7 +278,7 @@ declare class DotReporter extends BaseReporter {
|
|
|
267
278
|
}
|
|
268
279
|
|
|
269
280
|
declare class VerboseReporter extends DefaultReporter {
|
|
270
|
-
constructor(
|
|
281
|
+
constructor();
|
|
271
282
|
}
|
|
272
283
|
|
|
273
284
|
declare const ReportersMap: {
|
|
@@ -277,6 +288,56 @@ declare const ReportersMap: {
|
|
|
277
288
|
};
|
|
278
289
|
declare type BuiltinReporters = keyof typeof ReportersMap;
|
|
279
290
|
|
|
291
|
+
declare type Reporter$1 = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
|
|
292
|
+
interface C8Options {
|
|
293
|
+
/**
|
|
294
|
+
* Enable coverage, pass `--coverage` to enable
|
|
295
|
+
*
|
|
296
|
+
* @default false
|
|
297
|
+
*/
|
|
298
|
+
enabled?: boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Directory to write coverage report to
|
|
301
|
+
*/
|
|
302
|
+
reportsDirectory?: string;
|
|
303
|
+
/**
|
|
304
|
+
* Clean coverage before running tests
|
|
305
|
+
*
|
|
306
|
+
* @default true
|
|
307
|
+
*/
|
|
308
|
+
clean?: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Clean coverage report on watch rerun
|
|
311
|
+
*
|
|
312
|
+
* @default false
|
|
313
|
+
*/
|
|
314
|
+
cleanOnRerun?: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Allow files from outside of your cwd.
|
|
317
|
+
*
|
|
318
|
+
* @default false
|
|
319
|
+
*/
|
|
320
|
+
allowExternal?: any;
|
|
321
|
+
/**
|
|
322
|
+
* Reporters
|
|
323
|
+
*
|
|
324
|
+
* @default 'text'
|
|
325
|
+
*/
|
|
326
|
+
reporter?: Arrayable$1<Reporter$1>;
|
|
327
|
+
/**
|
|
328
|
+
* Exclude coverage under /node_modules/
|
|
329
|
+
*
|
|
330
|
+
* @default true
|
|
331
|
+
*/
|
|
332
|
+
excludeNodeModules?: boolean;
|
|
333
|
+
exclude?: string[];
|
|
334
|
+
include?: string[];
|
|
335
|
+
skipFull?: boolean;
|
|
336
|
+
}
|
|
337
|
+
interface ResolvedC8Options extends Required<C8Options> {
|
|
338
|
+
tempDirectory: string;
|
|
339
|
+
}
|
|
340
|
+
|
|
280
341
|
declare type Awaitable<T> = T | PromiseLike<T>;
|
|
281
342
|
declare type Nullable<T> = T | null | undefined;
|
|
282
343
|
declare type Arrayable<T> = T | Array<T>;
|
|
@@ -298,6 +359,16 @@ interface UserConsoleLog {
|
|
|
298
359
|
type: 'stdout' | 'stderr';
|
|
299
360
|
taskId?: string;
|
|
300
361
|
}
|
|
362
|
+
interface Position {
|
|
363
|
+
line: number;
|
|
364
|
+
column: number;
|
|
365
|
+
}
|
|
366
|
+
interface ParsedStack {
|
|
367
|
+
method: string;
|
|
368
|
+
file: string;
|
|
369
|
+
line: number;
|
|
370
|
+
column: number;
|
|
371
|
+
}
|
|
301
372
|
|
|
302
373
|
declare type ChainableFunction<T extends string, Args extends any[], R = any> = {
|
|
303
374
|
(...args: Args): R;
|
|
@@ -369,6 +440,7 @@ interface RuntimeContext {
|
|
|
369
440
|
}
|
|
370
441
|
|
|
371
442
|
interface Reporter {
|
|
443
|
+
onInit(ctx: Vitest): void;
|
|
372
444
|
onStart?: (files?: string[]) => Awaitable<void>;
|
|
373
445
|
onFinished?: (files?: File[]) => Awaitable<void>;
|
|
374
446
|
onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
|
|
@@ -538,6 +610,16 @@ interface InlineConfig {
|
|
|
538
610
|
* @default ['**\/node_modules\/**', '**\/dist/**']
|
|
539
611
|
*/
|
|
540
612
|
watchIgnore?: (string | RegExp)[];
|
|
613
|
+
/**
|
|
614
|
+
* Isolate environment for each test file
|
|
615
|
+
*
|
|
616
|
+
* @default true
|
|
617
|
+
*/
|
|
618
|
+
isolate?: boolean;
|
|
619
|
+
/**
|
|
620
|
+
* Coverage options
|
|
621
|
+
*/
|
|
622
|
+
coverage?: C8Options;
|
|
541
623
|
/**
|
|
542
624
|
* Open Vitest UI
|
|
543
625
|
* @internal WIP
|
|
@@ -592,11 +674,12 @@ interface UserConfig extends InlineConfig {
|
|
|
592
674
|
*/
|
|
593
675
|
passWithNoTests?: boolean;
|
|
594
676
|
}
|
|
595
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'> {
|
|
677
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage'> {
|
|
596
678
|
config?: string;
|
|
597
679
|
filters?: string[];
|
|
598
680
|
depsInline: (string | RegExp)[];
|
|
599
681
|
depsExternal: (string | RegExp)[];
|
|
682
|
+
coverage: ResolvedC8Options;
|
|
600
683
|
snapshotOptions: SnapshotStateOptions;
|
|
601
684
|
}
|
|
602
685
|
|
|
@@ -606,26 +689,19 @@ interface WorkerContext {
|
|
|
606
689
|
files: string[];
|
|
607
690
|
invalidates?: string[];
|
|
608
691
|
}
|
|
609
|
-
interface
|
|
610
|
-
fetch:
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
onTaskUpdate:
|
|
616
|
-
snapshotSaved:
|
|
617
|
-
}
|
|
618
|
-
declare type RpcCall = <T extends keyof RpcMap>(method: T, ...args: RpcMap[T][0]) => Promise<RpcMap[T][1]>;
|
|
619
|
-
declare type RpcSend = <T extends keyof RpcMap>(method: T, ...args: RpcMap[T][0]) => void;
|
|
620
|
-
declare type RpcPayload<T extends keyof RpcMap = keyof RpcMap> = {
|
|
621
|
-
id: string;
|
|
622
|
-
method: T;
|
|
623
|
-
args: RpcMap[T][0];
|
|
624
|
-
};
|
|
692
|
+
interface WorkerRPC {
|
|
693
|
+
fetch: (id: string) => Promise<string | undefined>;
|
|
694
|
+
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
|
|
695
|
+
onWorkerExit: (code?: number) => void;
|
|
696
|
+
onUserLog: (log: UserConsoleLog) => void;
|
|
697
|
+
onCollected: (files: File[]) => void;
|
|
698
|
+
onTaskUpdate: (pack: TaskResultPack) => void;
|
|
699
|
+
snapshotSaved: (snapshot: SnapshotResult) => void;
|
|
700
|
+
}
|
|
625
701
|
|
|
626
|
-
declare const suite: ChainableFunction<"
|
|
702
|
+
declare const suite: ChainableFunction<"concurrent" | "skip" | "only" | "todo", [name: string, factory?: TestFactory | undefined], SuiteCollector>;
|
|
627
703
|
declare const test: TestCollector;
|
|
628
|
-
declare const describe: ChainableFunction<"
|
|
704
|
+
declare const describe: ChainableFunction<"concurrent" | "skip" | "only" | "todo", [name: string, factory?: TestFactory | undefined], SuiteCollector>;
|
|
629
705
|
declare const it: TestCollector;
|
|
630
706
|
|
|
631
707
|
declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
|
|
@@ -633,7 +709,7 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
|
|
|
633
709
|
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
|
|
634
710
|
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
|
|
635
711
|
|
|
636
|
-
declare const expect:
|
|
712
|
+
declare const expect: Chai.ExpectStatic;
|
|
637
713
|
|
|
638
714
|
interface MockResultReturn<T> {
|
|
639
715
|
type: 'return';
|
|
@@ -866,4 +942,4 @@ declare global {
|
|
|
866
942
|
}
|
|
867
943
|
}
|
|
868
944
|
|
|
869
|
-
export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, ConstructorArgumentsOf, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable,
|
|
945
|
+
export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, ConstructorArgumentsOf, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable, ParsedStack, Position, PropertyKeysOf, Reporter, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export { d as describe, i as it, c as suite, t as test, e as vi, v as vitest } from './vi-
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-
|
|
3
|
-
export { f as fn, s as spies, a as spyOn } from './jest-mock-
|
|
1
|
+
export { d as describe, i as it, c as suite, t as test, e as vi, v as vitest } from './vi-2115c609.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-7f57c252.js';
|
|
3
|
+
export { f as fn, s as spies, a as spyOn } from './jest-mock-4a754991.js';
|
|
4
4
|
export { assert, default as chai, should } from 'chai';
|
|
5
|
-
import './
|
|
5
|
+
import './index-7c024e16.js';
|
|
6
|
+
import 'url';
|
|
6
7
|
import 'tty';
|
|
7
8
|
import 'local-pkg';
|
|
8
9
|
import 'path';
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { util } from 'chai';
|
|
2
2
|
import * as tinyspy from 'tinyspy';
|
|
3
3
|
|
|
4
|
-
let urlAlphabet =
|
|
5
|
-
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
6
|
-
let nanoid = (size = 21) => {
|
|
7
|
-
let id = '';
|
|
8
|
-
let i = size;
|
|
9
|
-
while (i--) {
|
|
10
|
-
id += urlAlphabet[(Math.random() * 64) | 0];
|
|
11
|
-
}
|
|
12
|
-
return id
|
|
13
|
-
};
|
|
14
|
-
|
|
15
4
|
const spies = /* @__PURE__ */ new Set();
|
|
16
5
|
function spyOn(obj, method, accessType) {
|
|
17
6
|
const dictionary = {
|
|
@@ -98,4 +87,4 @@ function fn(implementation) {
|
|
|
98
87
|
}) }, "fn"));
|
|
99
88
|
}
|
|
100
89
|
|
|
101
|
-
export { spyOn as a, fn as f,
|
|
90
|
+
export { spyOn as a, fn as f, spies as s };
|