vitest 0.9.4 → 0.10.2
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 +7 -0
- package/dist/{chunk-api-setup.49283db8.js → chunk-api-setup.b55307fb.js} +41 -18
- package/dist/{chunk-constants.c8f1d38c.js → chunk-constants.90075174.js} +1 -1
- package/dist/{chunk-defaults.43e746f3.js → chunk-defaults.fd5b939d.js} +1 -1
- package/dist/{chunk-install-pkg.cbf3a38b.js → chunk-install-pkg.73b84ae1.js} +113 -115
- package/dist/chunk-integrations-globals.16d9702f.js +29 -0
- package/dist/chunk-integrations-spy.f036df6f.js +102 -0
- package/dist/{chunk-runtime-chain.701cffd8.js → chunk-runtime-chain.6292a3de.js} +941 -901
- package/dist/{chunk-runtime-mocker.e802beae.js → chunk-runtime-mocker.ca5ecf98.js} +5 -21
- package/dist/{chunk-runtime-rpc.c47f2233.js → chunk-runtime-rpc.8e14ae4f.js} +1 -1
- package/dist/{chunk-utils-global.a3293dce.js → chunk-utils-global.9b434e81.js} +42 -10
- package/dist/{chunk-utils-timers.b26e7c5c.js → chunk-utils-timers.c50fec92.js} +1406 -1057
- package/dist/{chunk-vite-node-externalize.1c19fc5e.js → chunk-vite-node-externalize.4255f25f.js} +661 -548
- package/dist/{chunk-vite-node-utils.b4debb0b.js → chunk-vite-node-utils.c160b239.js} +73 -71
- package/dist/cli.js +12 -12
- package/dist/entry.js +15 -919
- package/dist/index.d.ts +112 -31
- package/dist/index.js +8 -8
- package/dist/node.d.ts +40 -12
- package/dist/node.js +11 -11
- package/dist/spy.js +2 -102
- package/dist/vendor-_commonjsHelpers.addc3445.js +3 -0
- package/dist/vendor-entry.17835032.js +991 -0
- package/dist/vendor-index.405e58ef.js +6291 -0
- package/dist/{vendor-index.bd255bc8.js → vendor-index.40be925a.js} +173 -158
- package/dist/worker.js +9 -6
- package/package.json +9 -10
- package/vitest.mjs +1 -1
- package/dist/chunk-integrations-globals.b4a20711.js +0 -23
- package/dist/vendor-_commonjsHelpers.34b404ce.js +0 -7
- package/dist/vendor-index.13468339.js +0 -5707
package/dist/index.d.ts
CHANGED
|
@@ -202,6 +202,36 @@ declare class ModuleCacheMap extends Map<string, ModuleCache$1> {
|
|
|
202
202
|
get(fsPath: string): ModuleCache$1 | undefined;
|
|
203
203
|
delete(fsPath: string): boolean;
|
|
204
204
|
}
|
|
205
|
+
declare class ViteNodeRunner {
|
|
206
|
+
options: ViteNodeRunnerOptions;
|
|
207
|
+
root: string;
|
|
208
|
+
debug: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Holds the cache of modules
|
|
211
|
+
* Keys of the map are filepaths, or plain package names
|
|
212
|
+
*/
|
|
213
|
+
moduleCache: ModuleCacheMap;
|
|
214
|
+
constructor(options: ViteNodeRunnerOptions);
|
|
215
|
+
executeFile(file: string): Promise<any>;
|
|
216
|
+
executeId(id: string): Promise<any>;
|
|
217
|
+
/** @internal */
|
|
218
|
+
cachedRequest(rawId: string, callstack: string[]): Promise<any>;
|
|
219
|
+
/** @internal */
|
|
220
|
+
directRequest(id: string, fsPath: string, _callstack: string[]): Promise<any>;
|
|
221
|
+
prepareContext(context: Record<string, any>): Record<string, any>;
|
|
222
|
+
shouldResolveId(dep: string): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Define if a module should be interop-ed
|
|
225
|
+
* This function mostly for the ability to override by subclass
|
|
226
|
+
*/
|
|
227
|
+
shouldInterop(path: string, mod: any): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Import a module and interop it
|
|
230
|
+
*/
|
|
231
|
+
interopedImport(path: string): Promise<any>;
|
|
232
|
+
hasNestedDefault(target: any): any;
|
|
233
|
+
private debugLog;
|
|
234
|
+
}
|
|
205
235
|
|
|
206
236
|
interface DepsHandlingOptions {
|
|
207
237
|
external?: (string | RegExp)[];
|
|
@@ -229,11 +259,22 @@ interface FetchResult {
|
|
|
229
259
|
map?: RawSourceMap;
|
|
230
260
|
}
|
|
231
261
|
declare type FetchFunction = (id: string) => Promise<FetchResult>;
|
|
262
|
+
declare type ResolveIdFunction$1 = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
|
|
232
263
|
interface ModuleCache$1 {
|
|
233
264
|
promise?: Promise<any>;
|
|
234
265
|
exports?: any;
|
|
235
266
|
code?: string;
|
|
236
267
|
}
|
|
268
|
+
interface ViteNodeRunnerOptions {
|
|
269
|
+
root: string;
|
|
270
|
+
fetchModule: FetchFunction;
|
|
271
|
+
resolveId?: ResolveIdFunction$1;
|
|
272
|
+
base?: string;
|
|
273
|
+
moduleCache?: ModuleCacheMap;
|
|
274
|
+
interopDefault?: boolean;
|
|
275
|
+
requestStubs?: Record<string, any>;
|
|
276
|
+
debug?: boolean;
|
|
277
|
+
}
|
|
237
278
|
interface ViteNodeResolveId {
|
|
238
279
|
external?: boolean | 'absolute' | 'relative';
|
|
239
280
|
id: string;
|
|
@@ -300,6 +341,10 @@ declare class StateManager {
|
|
|
300
341
|
filesMap: Map<string, File>;
|
|
301
342
|
idMap: Map<string, Task>;
|
|
302
343
|
taskFileMap: WeakMap<Task, File>;
|
|
344
|
+
errorsSet: Set<unknown>;
|
|
345
|
+
catchError(err: unknown, type: string): void;
|
|
346
|
+
clearErrors(): void;
|
|
347
|
+
getUnhandledErrors(): unknown[];
|
|
303
348
|
getFiles(keys?: string[]): File[];
|
|
304
349
|
getFilepaths(): string[];
|
|
305
350
|
getFailedFilepaths(): string[];
|
|
@@ -331,6 +376,7 @@ declare class Vitest {
|
|
|
331
376
|
closingPromise?: Promise<void>;
|
|
332
377
|
isFirstRun: boolean;
|
|
333
378
|
restartsCount: number;
|
|
379
|
+
runner: ViteNodeRunner;
|
|
334
380
|
private _onRestartListeners;
|
|
335
381
|
constructor();
|
|
336
382
|
setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
|
|
@@ -360,7 +406,7 @@ declare class Vitest {
|
|
|
360
406
|
globTestFiles(filters?: string[]): Promise<string[]>;
|
|
361
407
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
362
408
|
isInSourceTestFile(code: string): boolean;
|
|
363
|
-
printError(err: unknown): Promise<void>;
|
|
409
|
+
printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
|
|
364
410
|
onServerRestarted(fn: () => void): void;
|
|
365
411
|
}
|
|
366
412
|
|
|
@@ -375,7 +421,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
375
421
|
constructor();
|
|
376
422
|
onInit(ctx: Vitest): void;
|
|
377
423
|
relative(path: string): string;
|
|
378
|
-
onFinished(files?: File[]): Promise<void>;
|
|
424
|
+
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
379
425
|
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
380
426
|
onWatcherStart(): Promise<void>;
|
|
381
427
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
@@ -389,6 +435,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
389
435
|
interface ListRendererOptions {
|
|
390
436
|
renderSucceed?: boolean;
|
|
391
437
|
outputStream: NodeJS.WritableStream;
|
|
438
|
+
showHeap: boolean;
|
|
392
439
|
}
|
|
393
440
|
declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
|
|
394
441
|
start(): any;
|
|
@@ -402,7 +449,7 @@ declare class DefaultReporter extends BaseReporter {
|
|
|
402
449
|
rendererOptions: ListRendererOptions;
|
|
403
450
|
onTestRemoved(trigger?: string): Promise<void>;
|
|
404
451
|
onCollected(): void;
|
|
405
|
-
onFinished(files?: File[]): Promise<void>;
|
|
452
|
+
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
406
453
|
onWatcherStart(): Promise<void>;
|
|
407
454
|
stopListRender(): Promise<void>;
|
|
408
455
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
@@ -412,7 +459,7 @@ declare class DefaultReporter extends BaseReporter {
|
|
|
412
459
|
declare class DotReporter extends BaseReporter {
|
|
413
460
|
renderer?: ReturnType<typeof createListRenderer>;
|
|
414
461
|
onCollected(): void;
|
|
415
|
-
onFinished(files?: File[]): Promise<void>;
|
|
462
|
+
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
416
463
|
onWatcherStart(): Promise<void>;
|
|
417
464
|
stopListRender(): Promise<void>;
|
|
418
465
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
@@ -534,6 +581,7 @@ interface ErrorWithDiff extends Error {
|
|
|
534
581
|
actual?: any;
|
|
535
582
|
expected?: any;
|
|
536
583
|
operator?: string;
|
|
584
|
+
type?: string;
|
|
537
585
|
}
|
|
538
586
|
interface ModuleGraphData {
|
|
539
587
|
graph: Record<string, string[]>;
|
|
@@ -700,6 +748,7 @@ interface TaskResult {
|
|
|
700
748
|
state: TaskState;
|
|
701
749
|
duration?: number;
|
|
702
750
|
startTime?: number;
|
|
751
|
+
heap?: number;
|
|
703
752
|
error?: ErrorWithDiff;
|
|
704
753
|
htmlError?: string;
|
|
705
754
|
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
|
@@ -713,15 +762,16 @@ interface File extends Suite {
|
|
|
713
762
|
filepath: string;
|
|
714
763
|
collectDuration?: number;
|
|
715
764
|
}
|
|
716
|
-
interface Test extends TaskBase {
|
|
765
|
+
interface Test<ExtraContext = {}> extends TaskBase {
|
|
717
766
|
type: 'test';
|
|
718
767
|
suite: Suite;
|
|
719
768
|
result?: TaskResult;
|
|
720
769
|
fails?: boolean;
|
|
770
|
+
context: TestContext & ExtraContext;
|
|
721
771
|
}
|
|
722
772
|
declare type Task = Test | Suite | File;
|
|
723
773
|
declare type DoneCallback = (error?: any) => void;
|
|
724
|
-
declare type TestFunction = (
|
|
774
|
+
declare type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<void>;
|
|
725
775
|
declare type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
|
|
726
776
|
1: [T[0]];
|
|
727
777
|
2: [T[0], T[1]];
|
|
@@ -736,36 +786,41 @@ declare type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
|
|
|
736
786
|
fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
|
|
737
787
|
}[T extends Readonly<[any]> ? 1 : T extends Readonly<[any, any]> ? 2 : T extends Readonly<[any, any, any]> ? 3 : T extends Readonly<[any, any, any, any]> ? 4 : T extends Readonly<[any, any, any, any, any]> ? 5 : T extends Readonly<[any, any, any, any, any, any]> ? 6 : T extends Readonly<[any, any, any, any, any, any, any]> ? 7 : T extends Readonly<[any, any, any, any, any, any, any, any]> ? 8 : T extends Readonly<[any, any, any, any, any, any, any, any, any]> ? 9 : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]> ? 10 : 'fallback'];
|
|
738
788
|
interface EachFunction {
|
|
739
|
-
<T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => void) => void;
|
|
740
|
-
<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => void) => void;
|
|
741
|
-
<T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => void) => void;
|
|
789
|
+
<T extends any[] | [any]>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T) => Awaitable<void>) => void;
|
|
790
|
+
<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>) => void;
|
|
791
|
+
<T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>) => void;
|
|
742
792
|
}
|
|
743
|
-
declare type TestAPI = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
|
|
793
|
+
declare type TestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
|
|
744
794
|
name: string,
|
|
745
|
-
fn?: TestFunction
|
|
795
|
+
fn?: TestFunction<ExtraContext>,
|
|
746
796
|
timeout?: number
|
|
747
797
|
], void> & {
|
|
748
798
|
each: EachFunction;
|
|
799
|
+
skipIf(condition: any): TestAPI<ExtraContext>;
|
|
800
|
+
runIf(condition: any): TestAPI<ExtraContext>;
|
|
749
801
|
};
|
|
750
|
-
declare type SuiteAPI = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo', [
|
|
802
|
+
declare type SuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo', [
|
|
751
803
|
name: string,
|
|
752
804
|
factory?: SuiteFactory
|
|
753
|
-
], SuiteCollector
|
|
805
|
+
], SuiteCollector<ExtraContext>> & {
|
|
754
806
|
each: EachFunction;
|
|
807
|
+
skipIf(condition: any): SuiteAPI<ExtraContext>;
|
|
808
|
+
runIf(condition: any): SuiteAPI<ExtraContext>;
|
|
755
809
|
};
|
|
756
|
-
declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
|
|
810
|
+
declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
|
|
757
811
|
interface SuiteHooks {
|
|
758
|
-
beforeAll: HookListener<[Suite]
|
|
812
|
+
beforeAll: HookListener<[Suite], () => Awaitable<void>>[];
|
|
759
813
|
afterAll: HookListener<[Suite]>[];
|
|
760
|
-
beforeEach: HookListener<[
|
|
761
|
-
afterEach: HookListener<[
|
|
814
|
+
beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
|
|
815
|
+
afterEach: HookListener<[TestContext, Suite]>[];
|
|
762
816
|
}
|
|
763
|
-
|
|
817
|
+
declare type HookCleanupCallback = (() => Awaitable<void>) | void;
|
|
818
|
+
interface SuiteCollector<ExtraContext = {}> {
|
|
764
819
|
readonly name: string;
|
|
765
820
|
readonly mode: RunMode;
|
|
766
821
|
type: 'collector';
|
|
767
|
-
test: TestAPI
|
|
768
|
-
tasks: (Suite | Test | SuiteCollector)[];
|
|
822
|
+
test: TestAPI<ExtraContext>;
|
|
823
|
+
tasks: (Suite | Test | SuiteCollector<ExtraContext>)[];
|
|
769
824
|
collect: (file?: File) => Promise<Suite>;
|
|
770
825
|
clear: () => void;
|
|
771
826
|
on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
|
|
@@ -775,11 +830,25 @@ interface RuntimeContext {
|
|
|
775
830
|
tasks: (SuiteCollector | Test)[];
|
|
776
831
|
currentSuite: SuiteCollector | null;
|
|
777
832
|
}
|
|
833
|
+
interface TestContext {
|
|
834
|
+
/**
|
|
835
|
+
* @deprecated Use promise instead
|
|
836
|
+
*/
|
|
837
|
+
(error?: any): void;
|
|
838
|
+
/**
|
|
839
|
+
* Metadata of the current test
|
|
840
|
+
*/
|
|
841
|
+
meta: Readonly<Test>;
|
|
842
|
+
/**
|
|
843
|
+
* A expect instance bound to the test
|
|
844
|
+
*/
|
|
845
|
+
expect: Vi.ExpectStatic;
|
|
846
|
+
}
|
|
778
847
|
|
|
779
848
|
interface Reporter {
|
|
780
849
|
onInit?(ctx: Vitest): void;
|
|
781
850
|
onCollected?: (files?: File[]) => Awaitable<void>;
|
|
782
|
-
onFinished?: (files?: File[]) => Awaitable<void>;
|
|
851
|
+
onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
|
|
783
852
|
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
|
|
784
853
|
onTestRemoved?: (trigger?: string) => Awaitable<void>;
|
|
785
854
|
onWatcherStart?: () => Awaitable<void>;
|
|
@@ -939,9 +1008,10 @@ interface InlineConfig {
|
|
|
939
1008
|
*/
|
|
940
1009
|
root?: string;
|
|
941
1010
|
/**
|
|
942
|
-
* Custom reporter for output
|
|
1011
|
+
* Custom reporter for output. Can contain one or more built-in report names, reporter instances,
|
|
1012
|
+
* and/or paths to custom reporters
|
|
943
1013
|
*/
|
|
944
|
-
reporters?: Arrayable<BuiltinReporters | Reporter
|
|
1014
|
+
reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>;
|
|
945
1015
|
/**
|
|
946
1016
|
* diff output length
|
|
947
1017
|
*/
|
|
@@ -1083,6 +1153,10 @@ interface InlineConfig {
|
|
|
1083
1153
|
* Resolve custom snapshot path
|
|
1084
1154
|
*/
|
|
1085
1155
|
resolveSnapshotPath?: (path: string, extension: string) => string;
|
|
1156
|
+
/**
|
|
1157
|
+
* Show heap usage after each test. Usefull for debugging memory leaks.
|
|
1158
|
+
*/
|
|
1159
|
+
logHeapUsage?: boolean;
|
|
1086
1160
|
}
|
|
1087
1161
|
interface UserConfig extends InlineConfig {
|
|
1088
1162
|
/**
|
|
@@ -1164,9 +1238,10 @@ interface WorkerRPC {
|
|
|
1164
1238
|
fetch: FetchFunction;
|
|
1165
1239
|
resolveId: ResolveIdFunction;
|
|
1166
1240
|
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
|
|
1167
|
-
onFinished: (files: File[]) => void;
|
|
1241
|
+
onFinished: (files: File[], errors?: unknown[]) => void;
|
|
1168
1242
|
onWorkerExit: (code?: number) => void;
|
|
1169
1243
|
onUserConsoleLog: (log: UserConsoleLog) => void;
|
|
1244
|
+
onUnhandledRejection: (err: unknown) => void;
|
|
1170
1245
|
onCollected: (files: File[]) => void;
|
|
1171
1246
|
onTaskUpdate: (pack: TaskResultPack[]) => void;
|
|
1172
1247
|
snapshotSaved: (snapshot: SnapshotResult) => void;
|
|
@@ -1182,16 +1257,21 @@ interface WorkerGlobalState {
|
|
|
1182
1257
|
mockMap: MockMap;
|
|
1183
1258
|
}
|
|
1184
1259
|
|
|
1185
|
-
declare const suite: SuiteAPI
|
|
1186
|
-
declare const test: TestAPI
|
|
1187
|
-
declare const describe: SuiteAPI
|
|
1188
|
-
declare const it: TestAPI
|
|
1260
|
+
declare const suite: SuiteAPI<{}>;
|
|
1261
|
+
declare const test: TestAPI<{}>;
|
|
1262
|
+
declare const describe: SuiteAPI<{}>;
|
|
1263
|
+
declare const it: TestAPI<{}>;
|
|
1189
1264
|
|
|
1190
1265
|
declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
|
|
1191
1266
|
declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
|
|
1192
1267
|
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
|
|
1193
1268
|
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
|
|
1194
1269
|
|
|
1270
|
+
/**
|
|
1271
|
+
* A simple wrapper for converting callback style to promise
|
|
1272
|
+
*/
|
|
1273
|
+
declare function withCallback(fn: (done: DoneCallback) => void): Promise<void>;
|
|
1274
|
+
|
|
1195
1275
|
/**
|
|
1196
1276
|
* This utils allows computational intensive tasks to only be ran once
|
|
1197
1277
|
* across test reruns to improve the watch mode performance.
|
|
@@ -1211,8 +1291,6 @@ declare function runOnce<T>(fn: (() => T), key?: string): T;
|
|
|
1211
1291
|
*/
|
|
1212
1292
|
declare function isFirstRun(): boolean;
|
|
1213
1293
|
|
|
1214
|
-
declare const expect: Vi.ExpectStatic;
|
|
1215
|
-
|
|
1216
1294
|
interface MockResultReturn<T> {
|
|
1217
1295
|
type: 'return';
|
|
1218
1296
|
value: T;
|
|
@@ -1293,6 +1371,9 @@ declare function spyOn<T, M extends (Methods<Required<T>> | Classes<Required<T>>
|
|
|
1293
1371
|
declare function fn<TArgs extends any[] = any[], R = any>(): SpyInstanceFn<TArgs, R>;
|
|
1294
1372
|
declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): SpyInstanceFn<TArgs, R>;
|
|
1295
1373
|
|
|
1374
|
+
declare function createExpect(test?: Test): Vi.ExpectStatic;
|
|
1375
|
+
declare const expect: Vi.ExpectStatic;
|
|
1376
|
+
|
|
1296
1377
|
declare class VitestUtils {
|
|
1297
1378
|
private _timers;
|
|
1298
1379
|
private _mockedDate;
|
|
@@ -1513,4 +1594,4 @@ declare global {
|
|
|
1513
1594
|
}
|
|
1514
1595
|
}
|
|
1515
1596
|
|
|
1516
|
-
export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyContext, SpyInstance, SpyInstanceFn, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestFunction, TransformResultWithSource, UncheckedSnapshot, UserConfig, UserConsoleLog, Vitest, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerGlobalState, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest };
|
|
1597
|
+
export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookCleanupCallback, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, MockedFunction, MockedObject, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, SpyContext, SpyInstance, SpyInstanceFn, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TransformResultWithSource, UncheckedSnapshot, UserConfig, UserConsoleLog, Vitest, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerGlobalState, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, createExpect, describe, expect, getRunningMode, isFirstRun, isWatchMode, it, runOnce, suite, test, vi, vitest, withCallback };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { c as afterAll, f as afterEach, b as beforeAll, e as beforeEach, g as createExpect, d as describe, h as expect, k as getRunningMode, a as isFirstRun, l as isWatchMode, i as it, r as runOnce, s as suite, t as test, j as vi, v as vitest, w as withCallback } from './chunk-runtime-chain.6292a3de.js';
|
|
2
2
|
export { assert, default as chai, should } from 'chai';
|
|
3
|
-
import '
|
|
4
|
-
import './chunk-
|
|
5
|
-
import '
|
|
3
|
+
import './vendor-_commonjsHelpers.addc3445.js';
|
|
4
|
+
import './chunk-runtime-rpc.8e14ae4f.js';
|
|
5
|
+
import './chunk-utils-global.9b434e81.js';
|
|
6
6
|
import 'tty';
|
|
7
7
|
import 'local-pkg';
|
|
8
|
-
import '
|
|
9
|
-
import './vendor-_commonjsHelpers.34b404ce.js';
|
|
10
|
-
import './chunk-runtime-rpc.c47f2233.js';
|
|
8
|
+
import 'path';
|
|
11
9
|
import 'fs';
|
|
12
|
-
import './
|
|
10
|
+
import './chunk-utils-timers.c50fec92.js';
|
|
11
|
+
import './chunk-integrations-spy.f036df6f.js';
|
|
13
12
|
import 'tinyspy';
|
|
13
|
+
import 'util';
|
package/dist/node.d.ts
CHANGED
|
@@ -220,7 +220,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
220
220
|
constructor();
|
|
221
221
|
onInit(ctx: Vitest): void;
|
|
222
222
|
relative(path: string): string;
|
|
223
|
-
onFinished(files?: File[]): Promise<void>;
|
|
223
|
+
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
224
224
|
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
225
225
|
onWatcherStart(): Promise<void>;
|
|
226
226
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
@@ -234,6 +234,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
234
234
|
interface ListRendererOptions {
|
|
235
235
|
renderSucceed?: boolean;
|
|
236
236
|
outputStream: NodeJS.WritableStream;
|
|
237
|
+
showHeap: boolean;
|
|
237
238
|
}
|
|
238
239
|
declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
|
|
239
240
|
start(): any;
|
|
@@ -247,7 +248,7 @@ declare class DefaultReporter extends BaseReporter {
|
|
|
247
248
|
rendererOptions: ListRendererOptions;
|
|
248
249
|
onTestRemoved(trigger?: string): Promise<void>;
|
|
249
250
|
onCollected(): void;
|
|
250
|
-
onFinished(files?: File[]): Promise<void>;
|
|
251
|
+
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
251
252
|
onWatcherStart(): Promise<void>;
|
|
252
253
|
stopListRender(): Promise<void>;
|
|
253
254
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
@@ -257,7 +258,7 @@ declare class DefaultReporter extends BaseReporter {
|
|
|
257
258
|
declare class DotReporter extends BaseReporter {
|
|
258
259
|
renderer?: ReturnType<typeof createListRenderer>;
|
|
259
260
|
onCollected(): void;
|
|
260
|
-
onFinished(files?: File[]): Promise<void>;
|
|
261
|
+
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
261
262
|
onWatcherStart(): Promise<void>;
|
|
262
263
|
stopListRender(): Promise<void>;
|
|
263
264
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
@@ -354,6 +355,7 @@ interface ErrorWithDiff extends Error {
|
|
|
354
355
|
actual?: any;
|
|
355
356
|
expected?: any;
|
|
356
357
|
operator?: string;
|
|
358
|
+
type?: string;
|
|
357
359
|
}
|
|
358
360
|
|
|
359
361
|
declare type CoverageReporter = 'clover' | 'cobertura' | 'html-spa' | 'html' | 'json-summary' | 'json' | 'lcov' | 'lcovonly' | 'none' | 'teamcity' | 'text-lcov' | 'text-summary' | 'text';
|
|
@@ -509,6 +511,7 @@ interface TaskResult {
|
|
|
509
511
|
state: TaskState;
|
|
510
512
|
duration?: number;
|
|
511
513
|
startTime?: number;
|
|
514
|
+
heap?: number;
|
|
512
515
|
error?: ErrorWithDiff;
|
|
513
516
|
htmlError?: string;
|
|
514
517
|
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
|
@@ -522,25 +525,40 @@ interface File extends Suite {
|
|
|
522
525
|
filepath: string;
|
|
523
526
|
collectDuration?: number;
|
|
524
527
|
}
|
|
525
|
-
interface Test extends TaskBase {
|
|
528
|
+
interface Test<ExtraContext = {}> extends TaskBase {
|
|
526
529
|
type: 'test';
|
|
527
530
|
suite: Suite;
|
|
528
531
|
result?: TaskResult;
|
|
529
532
|
fails?: boolean;
|
|
533
|
+
context: TestContext & ExtraContext;
|
|
530
534
|
}
|
|
531
535
|
declare type Task = Test | Suite | File;
|
|
532
|
-
declare type HookListener<T extends any[]> = (...args: T) => Awaitable<void>;
|
|
536
|
+
declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return | void>;
|
|
533
537
|
interface SuiteHooks {
|
|
534
|
-
beforeAll: HookListener<[Suite]
|
|
538
|
+
beforeAll: HookListener<[Suite], () => Awaitable<void>>[];
|
|
535
539
|
afterAll: HookListener<[Suite]>[];
|
|
536
|
-
beforeEach: HookListener<[
|
|
537
|
-
afterEach: HookListener<[
|
|
540
|
+
beforeEach: HookListener<[TestContext, Suite], () => Awaitable<void>>[];
|
|
541
|
+
afterEach: HookListener<[TestContext, Suite]>[];
|
|
542
|
+
}
|
|
543
|
+
interface TestContext {
|
|
544
|
+
/**
|
|
545
|
+
* @deprecated Use promise instead
|
|
546
|
+
*/
|
|
547
|
+
(error?: any): void;
|
|
548
|
+
/**
|
|
549
|
+
* Metadata of the current test
|
|
550
|
+
*/
|
|
551
|
+
meta: Readonly<Test>;
|
|
552
|
+
/**
|
|
553
|
+
* A expect instance bound to the test
|
|
554
|
+
*/
|
|
555
|
+
expect: Vi.ExpectStatic;
|
|
538
556
|
}
|
|
539
557
|
|
|
540
558
|
interface Reporter {
|
|
541
559
|
onInit?(ctx: Vitest): void;
|
|
542
560
|
onCollected?: (files?: File[]) => Awaitable<void>;
|
|
543
|
-
onFinished?: (files?: File[]) => Awaitable<void>;
|
|
561
|
+
onFinished?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
|
|
544
562
|
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
|
|
545
563
|
onTestRemoved?: (trigger?: string) => Awaitable<void>;
|
|
546
564
|
onWatcherStart?: () => Awaitable<void>;
|
|
@@ -691,9 +709,10 @@ interface InlineConfig {
|
|
|
691
709
|
*/
|
|
692
710
|
root?: string;
|
|
693
711
|
/**
|
|
694
|
-
* Custom reporter for output
|
|
712
|
+
* Custom reporter for output. Can contain one or more built-in report names, reporter instances,
|
|
713
|
+
* and/or paths to custom reporters
|
|
695
714
|
*/
|
|
696
|
-
reporters?: Arrayable<BuiltinReporters | Reporter
|
|
715
|
+
reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>;
|
|
697
716
|
/**
|
|
698
717
|
* diff output length
|
|
699
718
|
*/
|
|
@@ -835,6 +854,10 @@ interface InlineConfig {
|
|
|
835
854
|
* Resolve custom snapshot path
|
|
836
855
|
*/
|
|
837
856
|
resolveSnapshotPath?: (path: string, extension: string) => string;
|
|
857
|
+
/**
|
|
858
|
+
* Show heap usage after each test. Usefull for debugging memory leaks.
|
|
859
|
+
*/
|
|
860
|
+
logHeapUsage?: boolean;
|
|
838
861
|
}
|
|
839
862
|
interface UserConfig extends InlineConfig {
|
|
840
863
|
/**
|
|
@@ -911,6 +934,10 @@ declare class StateManager {
|
|
|
911
934
|
filesMap: Map<string, File>;
|
|
912
935
|
idMap: Map<string, Task>;
|
|
913
936
|
taskFileMap: WeakMap<Task, File>;
|
|
937
|
+
errorsSet: Set<unknown>;
|
|
938
|
+
catchError(err: unknown, type: string): void;
|
|
939
|
+
clearErrors(): void;
|
|
940
|
+
getUnhandledErrors(): unknown[];
|
|
914
941
|
getFiles(keys?: string[]): File[];
|
|
915
942
|
getFilepaths(): string[];
|
|
916
943
|
getFailedFilepaths(): string[];
|
|
@@ -942,6 +969,7 @@ declare class Vitest {
|
|
|
942
969
|
closingPromise?: Promise<void>;
|
|
943
970
|
isFirstRun: boolean;
|
|
944
971
|
restartsCount: number;
|
|
972
|
+
runner: ViteNodeRunner;
|
|
945
973
|
private _onRestartListeners;
|
|
946
974
|
constructor();
|
|
947
975
|
setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
|
|
@@ -971,7 +999,7 @@ declare class Vitest {
|
|
|
971
999
|
globTestFiles(filters?: string[]): Promise<string[]>;
|
|
972
1000
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
973
1001
|
isInSourceTestFile(code: string): boolean;
|
|
974
|
-
printError(err: unknown): Promise<void>;
|
|
1002
|
+
printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
|
|
975
1003
|
onServerRestarted(fn: () => void): void;
|
|
976
1004
|
}
|
|
977
1005
|
|
package/dist/node.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.
|
|
2
|
-
export { V as VitestRunner } from './chunk-runtime-mocker.
|
|
1
|
+
export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.4255f25f.js';
|
|
2
|
+
export { V as VitestRunner } from './chunk-runtime-mocker.ca5ecf98.js';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'path';
|
|
5
5
|
import 'child_process';
|
|
6
6
|
import 'process';
|
|
7
|
-
import './vendor-index.
|
|
8
|
-
import './vendor-_commonjsHelpers.
|
|
7
|
+
import './vendor-index.40be925a.js';
|
|
8
|
+
import './vendor-_commonjsHelpers.addc3445.js';
|
|
9
9
|
import 'fs';
|
|
10
10
|
import 'assert';
|
|
11
11
|
import 'events';
|
|
@@ -13,19 +13,19 @@ import 'stream';
|
|
|
13
13
|
import 'util';
|
|
14
14
|
import 'url';
|
|
15
15
|
import 'os';
|
|
16
|
-
import './chunk-utils-global.
|
|
16
|
+
import './chunk-utils-global.9b434e81.js';
|
|
17
17
|
import 'tty';
|
|
18
18
|
import 'local-pkg';
|
|
19
19
|
import 'vite';
|
|
20
|
-
import './chunk-constants.
|
|
20
|
+
import './chunk-constants.90075174.js';
|
|
21
21
|
import 'readline';
|
|
22
|
-
import './chunk-vite-node-utils.
|
|
22
|
+
import './chunk-vite-node-utils.c160b239.js';
|
|
23
23
|
import 'module';
|
|
24
24
|
import 'vm';
|
|
25
|
-
import './chunk-defaults.
|
|
26
|
-
import 'perf_hooks';
|
|
27
|
-
import './chunk-utils-timers.b26e7c5c.js';
|
|
25
|
+
import './chunk-defaults.fd5b939d.js';
|
|
28
26
|
import 'worker_threads';
|
|
29
27
|
import 'tinypool';
|
|
28
|
+
import 'perf_hooks';
|
|
29
|
+
import './chunk-utils-timers.c50fec92.js';
|
|
30
30
|
import './chunk-magic-string.d5e0e473.js';
|
|
31
|
-
import './vendor-index.
|
|
31
|
+
import './vendor-index.405e58ef.js';
|
package/dist/spy.js
CHANGED
|
@@ -1,102 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const spies = /* @__PURE__ */ new Set();
|
|
4
|
-
function isMockFunction(fn2) {
|
|
5
|
-
return typeof fn2 === "function" && "_isMockFunction" in fn2 && fn2._isMockFunction;
|
|
6
|
-
}
|
|
7
|
-
function spyOn(obj, method, accessType) {
|
|
8
|
-
const dictionary = {
|
|
9
|
-
get: "getter",
|
|
10
|
-
set: "setter"
|
|
11
|
-
};
|
|
12
|
-
const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
|
|
13
|
-
const stub = tinyspy.spyOn(obj, objMethod);
|
|
14
|
-
return enhanceSpy(stub);
|
|
15
|
-
}
|
|
16
|
-
let callOrder = 0;
|
|
17
|
-
function enhanceSpy(spy) {
|
|
18
|
-
const stub = spy;
|
|
19
|
-
let implementation;
|
|
20
|
-
let instances = [];
|
|
21
|
-
let invocations = [];
|
|
22
|
-
const mockContext = {
|
|
23
|
-
get calls() {
|
|
24
|
-
return stub.calls;
|
|
25
|
-
},
|
|
26
|
-
get instances() {
|
|
27
|
-
return instances;
|
|
28
|
-
},
|
|
29
|
-
get invocationCallOrder() {
|
|
30
|
-
return invocations;
|
|
31
|
-
},
|
|
32
|
-
get results() {
|
|
33
|
-
return stub.results.map(([callType, value]) => {
|
|
34
|
-
const type = callType === "error" ? "throw" : "return";
|
|
35
|
-
return { type, value };
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
get lastCall() {
|
|
39
|
-
return stub.calls.at(-1);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
let onceImplementations = [];
|
|
43
|
-
let name = stub.name;
|
|
44
|
-
stub.getMockName = () => name || "vi.fn()";
|
|
45
|
-
stub.mockName = (n) => {
|
|
46
|
-
name = n;
|
|
47
|
-
return stub;
|
|
48
|
-
};
|
|
49
|
-
stub.mockClear = () => {
|
|
50
|
-
stub.reset();
|
|
51
|
-
instances = [];
|
|
52
|
-
invocations = [];
|
|
53
|
-
return stub;
|
|
54
|
-
};
|
|
55
|
-
stub.mockReset = () => {
|
|
56
|
-
stub.mockClear();
|
|
57
|
-
implementation = () => void 0;
|
|
58
|
-
onceImplementations = [];
|
|
59
|
-
return stub;
|
|
60
|
-
};
|
|
61
|
-
stub.mockRestore = () => {
|
|
62
|
-
stub.mockReset();
|
|
63
|
-
implementation = void 0;
|
|
64
|
-
return stub;
|
|
65
|
-
};
|
|
66
|
-
stub.getMockImplementation = () => implementation;
|
|
67
|
-
stub.mockImplementation = (fn2) => {
|
|
68
|
-
implementation = fn2;
|
|
69
|
-
return stub;
|
|
70
|
-
};
|
|
71
|
-
stub.mockImplementationOnce = (fn2) => {
|
|
72
|
-
onceImplementations.push(fn2);
|
|
73
|
-
return stub;
|
|
74
|
-
};
|
|
75
|
-
stub.mockReturnThis = () => stub.mockImplementation(function() {
|
|
76
|
-
return this;
|
|
77
|
-
});
|
|
78
|
-
stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
|
|
79
|
-
stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
|
|
80
|
-
stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
|
|
81
|
-
stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
|
|
82
|
-
stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
|
|
83
|
-
stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
|
|
84
|
-
Object.defineProperty(stub, "mock", {
|
|
85
|
-
get: () => mockContext
|
|
86
|
-
});
|
|
87
|
-
stub.willCall(function(...args) {
|
|
88
|
-
instances.push(this);
|
|
89
|
-
invocations.push(++callOrder);
|
|
90
|
-
const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
|
|
91
|
-
});
|
|
92
|
-
return impl.apply(this, args);
|
|
93
|
-
});
|
|
94
|
-
spies.add(stub);
|
|
95
|
-
return stub;
|
|
96
|
-
}
|
|
97
|
-
function fn(implementation) {
|
|
98
|
-
return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
|
|
99
|
-
}) }, "fn"));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { fn, isMockFunction, spies, spyOn };
|
|
1
|
+
export { f as fn, i as isMockFunction, a as spies, s as spyOn } from './chunk-integrations-spy.f036df6f.js';
|
|
2
|
+
import 'tinyspy';
|