vitest 0.17.0 → 0.18.1
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 +1 -1
- package/dist/{chunk-api-setup.5282c6cb.mjs → chunk-api-setup.9d3f7670.mjs} +18 -9
- package/dist/{chunk-constants.511c6e9b.mjs → chunk-constants.d4406290.mjs} +1 -1
- package/dist/{chunk-env-node.dc514f41.mjs → chunk-env-node.bbba78e5.mjs} +9 -3
- package/dist/{chunk-install-pkg.3fa50769.mjs → chunk-install-pkg.2dcb2c04.mjs} +1 -1
- package/dist/chunk-integrations-globals.00b6e1ad.mjs +23 -0
- package/dist/{chunk-runtime-chain.68f305d0.mjs → chunk-runtime-chain.b60d57da.mjs} +39 -60
- package/dist/{chunk-runtime-mocker.1c207219.mjs → chunk-runtime-mocker.1d853e3a.mjs} +77 -29
- package/dist/{chunk-runtime-rpc.5e78af38.mjs → chunk-runtime-rpc.9d1f4c48.mjs} +1 -1
- package/dist/{chunk-utils-global.79a8b1cc.mjs → chunk-utils-global.0a7416cf.mjs} +70 -6
- package/dist/{chunk-utils-source-map.f52527bc.mjs → chunk-utils-source-map.c03f8bc4.mjs} +2 -2
- package/dist/{chunk-vite-node-externalize.1efbe319.mjs → chunk-vite-node-externalize.6956d2d9.mjs} +2666 -2552
- package/dist/chunk-vite-node-utils.8077cd3c.mjs +1422 -0
- package/dist/cli.mjs +13 -13
- package/dist/config.cjs +6 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.mjs +6 -1
- package/dist/entry.mjs +638 -11
- package/dist/index.d.ts +125 -52
- package/dist/index.mjs +8 -8
- package/dist/node.d.ts +126 -54
- package/dist/node.mjs +13 -13
- package/dist/spy.mjs +102 -2
- package/dist/{vendor-index.e5dc6622.mjs → vendor-index.4bf9c627.mjs} +405 -405
- package/dist/{vendor-index.98e769c1.mjs → vendor-index.de788b6a.mjs} +7 -7
- package/dist/worker.mjs +9 -9
- package/package.json +12 -12
- package/dist/chunk-integrations-globals.6bb781c7.mjs +0 -26
- package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
- package/dist/chunk-vite-node-utils.4b58ae05.mjs +0 -9192
- package/dist/vendor-entry.2edaf3e0.mjs +0 -653
package/dist/index.d.ts
CHANGED
|
@@ -207,26 +207,18 @@ interface CustomEventMap {
|
|
|
207
207
|
type InferCustomEventPayload<T extends string> =
|
|
208
208
|
T extends keyof CustomEventMap ? CustomEventMap[T] : any
|
|
209
209
|
|
|
210
|
-
type ModuleNamespace = Record<string, any> & {
|
|
211
|
-
[Symbol.toStringTag]: 'Module'
|
|
212
|
-
}
|
|
213
|
-
|
|
214
210
|
interface ViteHotContext {
|
|
215
211
|
readonly data: any
|
|
216
212
|
|
|
217
213
|
accept(): void
|
|
218
|
-
accept(cb: (mod:
|
|
219
|
-
accept(dep: string, cb: (mod:
|
|
220
|
-
accept(
|
|
221
|
-
deps: readonly string[],
|
|
222
|
-
cb: (mods: Array<ModuleNamespace | undefined>) => void
|
|
223
|
-
): void
|
|
214
|
+
accept(cb: (mod: any) => void): void
|
|
215
|
+
accept(dep: string, cb: (mod: any) => void): void
|
|
216
|
+
accept(deps: readonly string[], cb: (mods: any[]) => void): void
|
|
224
217
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
): void
|
|
218
|
+
/**
|
|
219
|
+
* @deprecated
|
|
220
|
+
*/
|
|
221
|
+
acceptDeps(): never
|
|
230
222
|
|
|
231
223
|
dispose(cb: (data: any) => void): void
|
|
232
224
|
decline(): void
|
|
@@ -380,6 +372,50 @@ interface WorkerPool {
|
|
|
380
372
|
close: () => Promise<void>;
|
|
381
373
|
}
|
|
382
374
|
|
|
375
|
+
declare class StateManager {
|
|
376
|
+
filesMap: Map<string, File>;
|
|
377
|
+
idMap: Map<string, Task>;
|
|
378
|
+
taskFileMap: WeakMap<Task, File>;
|
|
379
|
+
errorsSet: Set<unknown>;
|
|
380
|
+
catchError(err: unknown, type: string): void;
|
|
381
|
+
clearErrors(): void;
|
|
382
|
+
getUnhandledErrors(): unknown[];
|
|
383
|
+
getFiles(keys?: string[]): File[];
|
|
384
|
+
getFilepaths(): string[];
|
|
385
|
+
getFailedFilepaths(): string[];
|
|
386
|
+
collectFiles(files?: File[]): void;
|
|
387
|
+
clearFiles(paths?: string[]): void;
|
|
388
|
+
updateId(task: Task): void;
|
|
389
|
+
updateTasks(packs: TaskResultPack[]): void;
|
|
390
|
+
updateUserLog(log: UserConsoleLog): void;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
declare class Logger {
|
|
394
|
+
ctx: Vitest;
|
|
395
|
+
console: Console;
|
|
396
|
+
outputStream: NodeJS.WriteStream & {
|
|
397
|
+
fd: 1;
|
|
398
|
+
};
|
|
399
|
+
errorStream: NodeJS.WriteStream & {
|
|
400
|
+
fd: 2;
|
|
401
|
+
};
|
|
402
|
+
logUpdate: ((...text: string[]) => void) & {
|
|
403
|
+
clear(): void;
|
|
404
|
+
done(): void;
|
|
405
|
+
};
|
|
406
|
+
private _clearScreenPending;
|
|
407
|
+
constructor(ctx: Vitest, console?: Console);
|
|
408
|
+
log(...args: any[]): void;
|
|
409
|
+
error(...args: any[]): void;
|
|
410
|
+
warn(...args: any[]): void;
|
|
411
|
+
clearScreen(message: string, force?: boolean): void;
|
|
412
|
+
private _clearScreen;
|
|
413
|
+
printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
|
|
414
|
+
printNoTestFound(filters?: string[]): void;
|
|
415
|
+
printBanner(): void;
|
|
416
|
+
printUnhandledErrors(errors: unknown[]): Promise<void>;
|
|
417
|
+
}
|
|
418
|
+
|
|
383
419
|
interface SuiteResultCache {
|
|
384
420
|
failed: boolean;
|
|
385
421
|
duration: number;
|
|
@@ -389,6 +425,7 @@ declare class ResultsCache {
|
|
|
389
425
|
private cachePath;
|
|
390
426
|
private version;
|
|
391
427
|
private root;
|
|
428
|
+
getCachePath(): string | null;
|
|
392
429
|
setConfig(root: string, config: ResolvedConfig['cache']): void;
|
|
393
430
|
getResults(fsPath: string): SuiteResultCache | undefined;
|
|
394
431
|
readFromCache(): Promise<void>;
|
|
@@ -397,6 +434,13 @@ declare class ResultsCache {
|
|
|
397
434
|
writeToCache(): Promise<void>;
|
|
398
435
|
}
|
|
399
436
|
|
|
437
|
+
interface CliOptions extends UserConfig {
|
|
438
|
+
/**
|
|
439
|
+
* Override the watch mode
|
|
440
|
+
*/
|
|
441
|
+
run?: boolean;
|
|
442
|
+
}
|
|
443
|
+
|
|
400
444
|
declare type FileStatsCache = Pick<Stats, 'size'>;
|
|
401
445
|
declare class FilesStatsCache {
|
|
402
446
|
cache: Map<string, FileStatsCache>;
|
|
@@ -405,27 +449,18 @@ declare class FilesStatsCache {
|
|
|
405
449
|
removeStats(fsPath: string): void;
|
|
406
450
|
}
|
|
407
451
|
|
|
408
|
-
declare class
|
|
409
|
-
filesMap: Map<string, File>;
|
|
410
|
-
idMap: Map<string, Task>;
|
|
411
|
-
taskFileMap: WeakMap<Task, File>;
|
|
412
|
-
errorsSet: Set<unknown>;
|
|
452
|
+
declare class VitestCache {
|
|
413
453
|
results: ResultsCache;
|
|
414
454
|
stats: FilesStatsCache;
|
|
415
455
|
getFileTestResults(id: string): SuiteResultCache | undefined;
|
|
416
456
|
getFileStats(id: string): {
|
|
417
457
|
size: number;
|
|
418
458
|
} | undefined;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
getFailedFilepaths(): string[];
|
|
425
|
-
collectFiles(files?: File[]): void;
|
|
426
|
-
updateId(task: Task): void;
|
|
427
|
-
updateTasks(packs: TaskResultPack[]): void;
|
|
428
|
-
updateUserLog(log: UserConsoleLog): void;
|
|
459
|
+
static resolveCacheDir(root: string, dir: string | undefined): string;
|
|
460
|
+
static clearCache(options: CliOptions): Promise<{
|
|
461
|
+
dir: string;
|
|
462
|
+
cleared: boolean;
|
|
463
|
+
}>;
|
|
429
464
|
}
|
|
430
465
|
|
|
431
466
|
declare class Vitest {
|
|
@@ -434,15 +469,10 @@ declare class Vitest {
|
|
|
434
469
|
server: ViteDevServer;
|
|
435
470
|
state: StateManager;
|
|
436
471
|
snapshot: SnapshotManager;
|
|
472
|
+
cache: VitestCache;
|
|
437
473
|
reporters: Reporter[];
|
|
438
|
-
|
|
474
|
+
logger: Logger;
|
|
439
475
|
pool: WorkerPool | undefined;
|
|
440
|
-
outputStream: NodeJS.WriteStream & {
|
|
441
|
-
fd: 1;
|
|
442
|
-
};
|
|
443
|
-
errorStream: NodeJS.WriteStream & {
|
|
444
|
-
fd: 2;
|
|
445
|
-
};
|
|
446
476
|
vitenode: ViteNodeServer;
|
|
447
477
|
invalidates: Set<string>;
|
|
448
478
|
changedTests: Set<string>;
|
|
@@ -451,8 +481,8 @@ declare class Vitest {
|
|
|
451
481
|
isFirstRun: boolean;
|
|
452
482
|
restartsCount: number;
|
|
453
483
|
runner: ViteNodeRunner;
|
|
454
|
-
private _onRestartListeners;
|
|
455
484
|
constructor();
|
|
485
|
+
private _onRestartListeners;
|
|
456
486
|
setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
|
|
457
487
|
getSerializableConfig(): ResolvedConfig;
|
|
458
488
|
start(filters?: string[]): Promise<void>;
|
|
@@ -463,9 +493,6 @@ declare class Vitest {
|
|
|
463
493
|
changeNamePattern(pattern: string, files?: string[], trigger?: string): Promise<void>;
|
|
464
494
|
rerunFailed(): Promise<void>;
|
|
465
495
|
updateSnapshot(files?: string[]): Promise<void>;
|
|
466
|
-
log(...args: any[]): void;
|
|
467
|
-
error(...args: any[]): void;
|
|
468
|
-
clearScreen(): void;
|
|
469
496
|
private _rerunTimer;
|
|
470
497
|
private scheduleRerun;
|
|
471
498
|
private unregisterWatcher;
|
|
@@ -480,24 +507,40 @@ declare class Vitest {
|
|
|
480
507
|
globTestFiles(filters?: string[]): Promise<string[]>;
|
|
481
508
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
482
509
|
isInSourceTestFile(code: string): boolean;
|
|
483
|
-
printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
|
|
484
510
|
onServerRestarted(fn: () => void): void;
|
|
485
511
|
}
|
|
486
512
|
|
|
487
513
|
declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
|
|
488
514
|
|
|
515
|
+
interface TestSequencer {
|
|
516
|
+
/**
|
|
517
|
+
* Slicing tests into shards. Will be run before `sort`.
|
|
518
|
+
* Only run, if `shard` is defined.
|
|
519
|
+
*/
|
|
520
|
+
shard(files: string[]): Awaitable<string[]>;
|
|
521
|
+
sort(files: string[]): Awaitable<string[]>;
|
|
522
|
+
}
|
|
523
|
+
interface TestSequencerConstructor {
|
|
524
|
+
new (ctx: Vitest): TestSequencer;
|
|
525
|
+
}
|
|
526
|
+
|
|
489
527
|
declare abstract class BaseReporter implements Reporter {
|
|
490
528
|
start: number;
|
|
491
529
|
end: number;
|
|
492
530
|
watchFilters?: string[];
|
|
493
531
|
isTTY: boolean;
|
|
494
532
|
ctx: Vitest;
|
|
533
|
+
private _filesInWatchMode;
|
|
534
|
+
private _lastRunTimeout;
|
|
535
|
+
private _lastRunTimer;
|
|
536
|
+
private _lastRunCount;
|
|
495
537
|
constructor();
|
|
496
538
|
onInit(ctx: Vitest): void;
|
|
497
539
|
relative(path: string): string;
|
|
498
540
|
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
499
541
|
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
500
542
|
onWatcherStart(): Promise<void>;
|
|
543
|
+
private resetLastRunLog;
|
|
501
544
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
502
545
|
onUserConsoleLog(log: UserConsoleLog): void;
|
|
503
546
|
shouldLog(log: UserConsoleLog): boolean;
|
|
@@ -509,7 +552,7 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
509
552
|
|
|
510
553
|
interface ListRendererOptions {
|
|
511
554
|
renderSucceed?: boolean;
|
|
512
|
-
|
|
555
|
+
logger: Logger;
|
|
513
556
|
showHeap: boolean;
|
|
514
557
|
}
|
|
515
558
|
declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
|
|
@@ -815,6 +858,7 @@ interface TaskBase {
|
|
|
815
858
|
name: string;
|
|
816
859
|
mode: RunMode;
|
|
817
860
|
concurrent?: boolean;
|
|
861
|
+
shuffle?: boolean;
|
|
818
862
|
suite?: Suite;
|
|
819
863
|
file?: File;
|
|
820
864
|
result?: TaskResult;
|
|
@@ -867,22 +911,24 @@ interface EachFunction {
|
|
|
867
911
|
<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (name: string, fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>) => void;
|
|
868
912
|
<T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => Awaitable<void>) => void;
|
|
869
913
|
}
|
|
870
|
-
declare type
|
|
914
|
+
declare type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [
|
|
871
915
|
name: string,
|
|
872
916
|
fn?: TestFunction<ExtraContext>,
|
|
873
917
|
timeout?: number
|
|
874
|
-
], void
|
|
918
|
+
], void>;
|
|
919
|
+
declare type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
|
|
875
920
|
each: EachFunction;
|
|
876
|
-
skipIf(condition: any):
|
|
877
|
-
runIf(condition: any):
|
|
921
|
+
skipIf(condition: any): ChainableTestAPI<ExtraContext>;
|
|
922
|
+
runIf(condition: any): ChainableTestAPI<ExtraContext>;
|
|
878
923
|
};
|
|
879
|
-
declare type
|
|
924
|
+
declare type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [
|
|
880
925
|
name: string,
|
|
881
926
|
factory?: SuiteFactory
|
|
882
|
-
], SuiteCollector<ExtraContext
|
|
927
|
+
], SuiteCollector<ExtraContext>>;
|
|
928
|
+
declare type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI & {
|
|
883
929
|
each: EachFunction;
|
|
884
|
-
skipIf(condition: any):
|
|
885
|
-
runIf(condition: any):
|
|
930
|
+
skipIf(condition: any): ChainableSuiteAPI<ExtraContext>;
|
|
931
|
+
runIf(condition: any): ChainableSuiteAPI<ExtraContext>;
|
|
886
932
|
};
|
|
887
933
|
declare type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
|
|
888
934
|
declare type HookCleanupCallback = (() => Awaitable<unknown>) | void;
|
|
@@ -1291,6 +1337,28 @@ interface InlineConfig {
|
|
|
1291
1337
|
cache?: false | {
|
|
1292
1338
|
dir?: string;
|
|
1293
1339
|
};
|
|
1340
|
+
/**
|
|
1341
|
+
* Options for configuring the order of running tests.
|
|
1342
|
+
*/
|
|
1343
|
+
sequence?: {
|
|
1344
|
+
/**
|
|
1345
|
+
* Class that handles sorting and sharding algorithm.
|
|
1346
|
+
* If you only need to change sorting, you can extend
|
|
1347
|
+
* your custom sequencer from `BaseSequencer` from `vitest/node`.
|
|
1348
|
+
* @default BaseSequencer
|
|
1349
|
+
*/
|
|
1350
|
+
sequencer?: TestSequencerConstructor;
|
|
1351
|
+
/**
|
|
1352
|
+
* Should tests run in random order.
|
|
1353
|
+
* @default false
|
|
1354
|
+
*/
|
|
1355
|
+
shuffle?: boolean;
|
|
1356
|
+
/**
|
|
1357
|
+
* Seed for the random number generator.
|
|
1358
|
+
* @default Date.now()
|
|
1359
|
+
*/
|
|
1360
|
+
seed?: number;
|
|
1361
|
+
};
|
|
1294
1362
|
}
|
|
1295
1363
|
interface UserConfig extends InlineConfig {
|
|
1296
1364
|
/**
|
|
@@ -1330,7 +1398,7 @@ interface UserConfig extends InlineConfig {
|
|
|
1330
1398
|
*/
|
|
1331
1399
|
shard?: string;
|
|
1332
1400
|
}
|
|
1333
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache'> {
|
|
1401
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache' | 'sequence'> {
|
|
1334
1402
|
base?: string;
|
|
1335
1403
|
config?: string;
|
|
1336
1404
|
filters?: string[];
|
|
@@ -1348,6 +1416,11 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
|
|
|
1348
1416
|
cache: {
|
|
1349
1417
|
dir: string;
|
|
1350
1418
|
} | false;
|
|
1419
|
+
sequence: {
|
|
1420
|
+
sequencer: TestSequencerConstructor;
|
|
1421
|
+
shuffle?: boolean;
|
|
1422
|
+
seed?: number;
|
|
1423
|
+
};
|
|
1351
1424
|
}
|
|
1352
1425
|
|
|
1353
1426
|
declare type VitestInlineConfig = InlineConfig;
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { p as afterAll, u as afterEach, o as beforeAll, q as beforeEach, x as createExpect, k as describe, y as expect, A as getRunningMode, n as isFirstRun, B as isWatchMode, l as it, m as runOnce, j as suite, t as test, v as vi, z as vitest, w as withCallback } from './chunk-runtime-chain.b60d57da.mjs';
|
|
2
2
|
export { assert, default as chai, should } from 'chai';
|
|
3
|
-
import '
|
|
4
|
-
import './chunk-
|
|
5
|
-
import '
|
|
3
|
+
import 'util';
|
|
4
|
+
import './chunk-utils-global.0a7416cf.mjs';
|
|
5
|
+
import 'path';
|
|
6
6
|
import 'tty';
|
|
7
7
|
import 'local-pkg';
|
|
8
|
-
import '
|
|
8
|
+
import './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
9
|
+
import './chunk-runtime-rpc.9d1f4c48.mjs';
|
|
9
10
|
import 'fs';
|
|
10
|
-
import './chunk-utils-source-map.
|
|
11
|
-
import './
|
|
11
|
+
import './chunk-utils-source-map.c03f8bc4.mjs';
|
|
12
|
+
import './spy.mjs';
|
|
12
13
|
import 'tinyspy';
|
|
13
|
-
import 'util';
|
package/dist/node.d.ts
CHANGED
|
@@ -51,26 +51,18 @@ interface CustomEventMap {
|
|
|
51
51
|
type InferCustomEventPayload<T extends string> =
|
|
52
52
|
T extends keyof CustomEventMap ? CustomEventMap[T] : any
|
|
53
53
|
|
|
54
|
-
type ModuleNamespace = Record<string, any> & {
|
|
55
|
-
[Symbol.toStringTag]: 'Module'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
54
|
interface ViteHotContext {
|
|
59
55
|
readonly data: any
|
|
60
56
|
|
|
61
57
|
accept(): void
|
|
62
|
-
accept(cb: (mod:
|
|
63
|
-
accept(dep: string, cb: (mod:
|
|
64
|
-
accept(
|
|
65
|
-
deps: readonly string[],
|
|
66
|
-
cb: (mods: Array<ModuleNamespace | undefined>) => void
|
|
67
|
-
): void
|
|
58
|
+
accept(cb: (mod: any) => void): void
|
|
59
|
+
accept(dep: string, cb: (mod: any) => void): void
|
|
60
|
+
accept(deps: readonly string[], cb: (mods: any[]) => void): void
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
): void
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated
|
|
64
|
+
*/
|
|
65
|
+
acceptDeps(): never
|
|
74
66
|
|
|
75
67
|
dispose(cb: (data: any) => void): void
|
|
76
68
|
decline(): void
|
|
@@ -367,12 +359,17 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
367
359
|
watchFilters?: string[];
|
|
368
360
|
isTTY: boolean;
|
|
369
361
|
ctx: Vitest;
|
|
362
|
+
private _filesInWatchMode;
|
|
363
|
+
private _lastRunTimeout;
|
|
364
|
+
private _lastRunTimer;
|
|
365
|
+
private _lastRunCount;
|
|
370
366
|
constructor();
|
|
371
367
|
onInit(ctx: Vitest): void;
|
|
372
368
|
relative(path: string): string;
|
|
373
369
|
onFinished(files?: File[], errors?: unknown[]): Promise<void>;
|
|
374
370
|
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
375
371
|
onWatcherStart(): Promise<void>;
|
|
372
|
+
private resetLastRunLog;
|
|
376
373
|
onWatcherRerun(files: string[], trigger?: string): Promise<void>;
|
|
377
374
|
onUserConsoleLog(log: UserConsoleLog): void;
|
|
378
375
|
shouldLog(log: UserConsoleLog): boolean;
|
|
@@ -382,9 +379,35 @@ declare abstract class BaseReporter implements Reporter {
|
|
|
382
379
|
registerUnhandledRejection(): void;
|
|
383
380
|
}
|
|
384
381
|
|
|
382
|
+
declare class Logger {
|
|
383
|
+
ctx: Vitest;
|
|
384
|
+
console: Console;
|
|
385
|
+
outputStream: NodeJS.WriteStream & {
|
|
386
|
+
fd: 1;
|
|
387
|
+
};
|
|
388
|
+
errorStream: NodeJS.WriteStream & {
|
|
389
|
+
fd: 2;
|
|
390
|
+
};
|
|
391
|
+
logUpdate: ((...text: string[]) => void) & {
|
|
392
|
+
clear(): void;
|
|
393
|
+
done(): void;
|
|
394
|
+
};
|
|
395
|
+
private _clearScreenPending;
|
|
396
|
+
constructor(ctx: Vitest, console?: Console);
|
|
397
|
+
log(...args: any[]): void;
|
|
398
|
+
error(...args: any[]): void;
|
|
399
|
+
warn(...args: any[]): void;
|
|
400
|
+
clearScreen(message: string, force?: boolean): void;
|
|
401
|
+
private _clearScreen;
|
|
402
|
+
printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
|
|
403
|
+
printNoTestFound(filters?: string[]): void;
|
|
404
|
+
printBanner(): void;
|
|
405
|
+
printUnhandledErrors(errors: unknown[]): Promise<void>;
|
|
406
|
+
}
|
|
407
|
+
|
|
385
408
|
interface ListRendererOptions {
|
|
386
409
|
renderSucceed?: boolean;
|
|
387
|
-
|
|
410
|
+
logger: Logger;
|
|
388
411
|
showHeap: boolean;
|
|
389
412
|
}
|
|
390
413
|
declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions) => {
|
|
@@ -474,6 +497,18 @@ declare const ReportersMap: {
|
|
|
474
497
|
};
|
|
475
498
|
declare type BuiltinReporters = keyof typeof ReportersMap;
|
|
476
499
|
|
|
500
|
+
interface TestSequencer {
|
|
501
|
+
/**
|
|
502
|
+
* Slicing tests into shards. Will be run before `sort`.
|
|
503
|
+
* Only run, if `shard` is defined.
|
|
504
|
+
*/
|
|
505
|
+
shard(files: string[]): Awaitable<string[]>;
|
|
506
|
+
sort(files: string[]): Awaitable<string[]>;
|
|
507
|
+
}
|
|
508
|
+
interface TestSequencerConstructor {
|
|
509
|
+
new (ctx: Vitest): TestSequencer;
|
|
510
|
+
}
|
|
511
|
+
|
|
477
512
|
declare type Awaitable<T> = T | PromiseLike<T>;
|
|
478
513
|
declare type Arrayable<T> = T | Array<T>;
|
|
479
514
|
declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
|
|
@@ -657,6 +692,7 @@ interface TaskBase {
|
|
|
657
692
|
name: string;
|
|
658
693
|
mode: RunMode;
|
|
659
694
|
concurrent?: boolean;
|
|
695
|
+
shuffle?: boolean;
|
|
660
696
|
suite?: Suite;
|
|
661
697
|
file?: File;
|
|
662
698
|
result?: TaskResult;
|
|
@@ -1080,6 +1116,28 @@ interface InlineConfig {
|
|
|
1080
1116
|
cache?: false | {
|
|
1081
1117
|
dir?: string;
|
|
1082
1118
|
};
|
|
1119
|
+
/**
|
|
1120
|
+
* Options for configuring the order of running tests.
|
|
1121
|
+
*/
|
|
1122
|
+
sequence?: {
|
|
1123
|
+
/**
|
|
1124
|
+
* Class that handles sorting and sharding algorithm.
|
|
1125
|
+
* If you only need to change sorting, you can extend
|
|
1126
|
+
* your custom sequencer from `BaseSequencer` from `vitest/node`.
|
|
1127
|
+
* @default BaseSequencer
|
|
1128
|
+
*/
|
|
1129
|
+
sequencer?: TestSequencerConstructor;
|
|
1130
|
+
/**
|
|
1131
|
+
* Should tests run in random order.
|
|
1132
|
+
* @default false
|
|
1133
|
+
*/
|
|
1134
|
+
shuffle?: boolean;
|
|
1135
|
+
/**
|
|
1136
|
+
* Seed for the random number generator.
|
|
1137
|
+
* @default Date.now()
|
|
1138
|
+
*/
|
|
1139
|
+
seed?: number;
|
|
1140
|
+
};
|
|
1083
1141
|
}
|
|
1084
1142
|
interface UserConfig extends InlineConfig {
|
|
1085
1143
|
/**
|
|
@@ -1119,7 +1177,7 @@ interface UserConfig extends InlineConfig {
|
|
|
1119
1177
|
*/
|
|
1120
1178
|
shard?: string;
|
|
1121
1179
|
}
|
|
1122
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache'> {
|
|
1180
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'shard' | 'cache' | 'sequence'> {
|
|
1123
1181
|
base?: string;
|
|
1124
1182
|
config?: string;
|
|
1125
1183
|
filters?: string[];
|
|
@@ -1137,6 +1195,11 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
|
|
|
1137
1195
|
cache: {
|
|
1138
1196
|
dir: string;
|
|
1139
1197
|
} | false;
|
|
1198
|
+
sequence: {
|
|
1199
|
+
sequencer: TestSequencerConstructor;
|
|
1200
|
+
shuffle?: boolean;
|
|
1201
|
+
seed?: number;
|
|
1202
|
+
};
|
|
1140
1203
|
}
|
|
1141
1204
|
|
|
1142
1205
|
declare type VitestInlineConfig = InlineConfig;
|
|
@@ -1417,6 +1480,24 @@ interface WorkerPool {
|
|
|
1417
1480
|
close: () => Promise<void>;
|
|
1418
1481
|
}
|
|
1419
1482
|
|
|
1483
|
+
declare class StateManager {
|
|
1484
|
+
filesMap: Map<string, File>;
|
|
1485
|
+
idMap: Map<string, Task>;
|
|
1486
|
+
taskFileMap: WeakMap<Task, File>;
|
|
1487
|
+
errorsSet: Set<unknown>;
|
|
1488
|
+
catchError(err: unknown, type: string): void;
|
|
1489
|
+
clearErrors(): void;
|
|
1490
|
+
getUnhandledErrors(): unknown[];
|
|
1491
|
+
getFiles(keys?: string[]): File[];
|
|
1492
|
+
getFilepaths(): string[];
|
|
1493
|
+
getFailedFilepaths(): string[];
|
|
1494
|
+
collectFiles(files?: File[]): void;
|
|
1495
|
+
clearFiles(paths?: string[]): void;
|
|
1496
|
+
updateId(task: Task): void;
|
|
1497
|
+
updateTasks(packs: TaskResultPack[]): void;
|
|
1498
|
+
updateUserLog(log: UserConsoleLog): void;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1420
1501
|
interface SuiteResultCache {
|
|
1421
1502
|
failed: boolean;
|
|
1422
1503
|
duration: number;
|
|
@@ -1426,6 +1507,7 @@ declare class ResultsCache {
|
|
|
1426
1507
|
private cachePath;
|
|
1427
1508
|
private version;
|
|
1428
1509
|
private root;
|
|
1510
|
+
getCachePath(): string | null;
|
|
1429
1511
|
setConfig(root: string, config: ResolvedConfig['cache']): void;
|
|
1430
1512
|
getResults(fsPath: string): SuiteResultCache | undefined;
|
|
1431
1513
|
readFromCache(): Promise<void>;
|
|
@@ -1434,6 +1516,14 @@ declare class ResultsCache {
|
|
|
1434
1516
|
writeToCache(): Promise<void>;
|
|
1435
1517
|
}
|
|
1436
1518
|
|
|
1519
|
+
interface CliOptions extends UserConfig {
|
|
1520
|
+
/**
|
|
1521
|
+
* Override the watch mode
|
|
1522
|
+
*/
|
|
1523
|
+
run?: boolean;
|
|
1524
|
+
}
|
|
1525
|
+
declare function startVitest(cliFilters: string[], options: CliOptions, viteOverrides?: UserConfig$1): Promise<boolean>;
|
|
1526
|
+
|
|
1437
1527
|
declare type FileStatsCache = Pick<Stats, 'size'>;
|
|
1438
1528
|
declare class FilesStatsCache {
|
|
1439
1529
|
cache: Map<string, FileStatsCache>;
|
|
@@ -1442,27 +1532,18 @@ declare class FilesStatsCache {
|
|
|
1442
1532
|
removeStats(fsPath: string): void;
|
|
1443
1533
|
}
|
|
1444
1534
|
|
|
1445
|
-
declare class
|
|
1446
|
-
filesMap: Map<string, File>;
|
|
1447
|
-
idMap: Map<string, Task>;
|
|
1448
|
-
taskFileMap: WeakMap<Task, File>;
|
|
1449
|
-
errorsSet: Set<unknown>;
|
|
1535
|
+
declare class VitestCache {
|
|
1450
1536
|
results: ResultsCache;
|
|
1451
1537
|
stats: FilesStatsCache;
|
|
1452
1538
|
getFileTestResults(id: string): SuiteResultCache | undefined;
|
|
1453
1539
|
getFileStats(id: string): {
|
|
1454
1540
|
size: number;
|
|
1455
1541
|
} | undefined;
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
getFailedFilepaths(): string[];
|
|
1462
|
-
collectFiles(files?: File[]): void;
|
|
1463
|
-
updateId(task: Task): void;
|
|
1464
|
-
updateTasks(packs: TaskResultPack[]): void;
|
|
1465
|
-
updateUserLog(log: UserConsoleLog): void;
|
|
1542
|
+
static resolveCacheDir(root: string, dir: string | undefined): string;
|
|
1543
|
+
static clearCache(options: CliOptions): Promise<{
|
|
1544
|
+
dir: string;
|
|
1545
|
+
cleared: boolean;
|
|
1546
|
+
}>;
|
|
1466
1547
|
}
|
|
1467
1548
|
|
|
1468
1549
|
declare class Vitest {
|
|
@@ -1471,15 +1552,10 @@ declare class Vitest {
|
|
|
1471
1552
|
server: ViteDevServer;
|
|
1472
1553
|
state: StateManager;
|
|
1473
1554
|
snapshot: SnapshotManager;
|
|
1555
|
+
cache: VitestCache;
|
|
1474
1556
|
reporters: Reporter[];
|
|
1475
|
-
|
|
1557
|
+
logger: Logger;
|
|
1476
1558
|
pool: WorkerPool | undefined;
|
|
1477
|
-
outputStream: NodeJS.WriteStream & {
|
|
1478
|
-
fd: 1;
|
|
1479
|
-
};
|
|
1480
|
-
errorStream: NodeJS.WriteStream & {
|
|
1481
|
-
fd: 2;
|
|
1482
|
-
};
|
|
1483
1559
|
vitenode: ViteNodeServer;
|
|
1484
1560
|
invalidates: Set<string>;
|
|
1485
1561
|
changedTests: Set<string>;
|
|
@@ -1488,8 +1564,8 @@ declare class Vitest {
|
|
|
1488
1564
|
isFirstRun: boolean;
|
|
1489
1565
|
restartsCount: number;
|
|
1490
1566
|
runner: ViteNodeRunner;
|
|
1491
|
-
private _onRestartListeners;
|
|
1492
1567
|
constructor();
|
|
1568
|
+
private _onRestartListeners;
|
|
1493
1569
|
setServer(options: UserConfig, server: ViteDevServer): Promise<void>;
|
|
1494
1570
|
getSerializableConfig(): ResolvedConfig;
|
|
1495
1571
|
start(filters?: string[]): Promise<void>;
|
|
@@ -1500,9 +1576,6 @@ declare class Vitest {
|
|
|
1500
1576
|
changeNamePattern(pattern: string, files?: string[], trigger?: string): Promise<void>;
|
|
1501
1577
|
rerunFailed(): Promise<void>;
|
|
1502
1578
|
updateSnapshot(files?: string[]): Promise<void>;
|
|
1503
|
-
log(...args: any[]): void;
|
|
1504
|
-
error(...args: any[]): void;
|
|
1505
|
-
clearScreen(): void;
|
|
1506
1579
|
private _rerunTimer;
|
|
1507
1580
|
private scheduleRerun;
|
|
1508
1581
|
private unregisterWatcher;
|
|
@@ -1517,7 +1590,6 @@ declare class Vitest {
|
|
|
1517
1590
|
globTestFiles(filters?: string[]): Promise<string[]>;
|
|
1518
1591
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
1519
1592
|
isInSourceTestFile(code: string): boolean;
|
|
1520
|
-
printError(err: unknown, fullStack?: boolean, type?: string): Promise<void>;
|
|
1521
1593
|
onServerRestarted(fn: () => void): void;
|
|
1522
1594
|
}
|
|
1523
1595
|
|
|
@@ -1525,14 +1597,7 @@ declare function createVitest(options: UserConfig, viteOverrides?: UserConfig$1)
|
|
|
1525
1597
|
|
|
1526
1598
|
declare function VitestPlugin(options?: UserConfig, ctx?: Vitest): Promise<Plugin$1[]>;
|
|
1527
1599
|
|
|
1528
|
-
|
|
1529
|
-
/**
|
|
1530
|
-
* Override the watch mode
|
|
1531
|
-
*/
|
|
1532
|
-
run?: boolean;
|
|
1533
|
-
}
|
|
1534
|
-
declare function startVitest(cliFilters: string[], options: CliOptions, viteOverrides?: UserConfig$1): Promise<boolean>;
|
|
1535
|
-
|
|
1600
|
+
declare type Key = string | symbol;
|
|
1536
1601
|
interface ViteRunnerRequest {
|
|
1537
1602
|
(dep: string): any;
|
|
1538
1603
|
callstack: string[];
|
|
@@ -1558,7 +1623,7 @@ declare class VitestMocker {
|
|
|
1558
1623
|
normalizePath(path: string): string;
|
|
1559
1624
|
getFsPath(path: string, external: string | null): string;
|
|
1560
1625
|
resolveMockPath(mockPath: string, external: string | null): string | null;
|
|
1561
|
-
|
|
1626
|
+
mockObject(object: Record<string | symbol, any>): Record<Key, any>;
|
|
1562
1627
|
unmockPath(path: string): void;
|
|
1563
1628
|
mockPath(path: string, external: string | null, factory?: () => any): void;
|
|
1564
1629
|
importActual<T>(id: string, importer: string): Promise<T>;
|
|
@@ -1582,4 +1647,11 @@ declare class VitestRunner extends ViteNodeRunner {
|
|
|
1582
1647
|
};
|
|
1583
1648
|
}
|
|
1584
1649
|
|
|
1585
|
-
|
|
1650
|
+
declare class BaseSequencer implements TestSequencer {
|
|
1651
|
+
protected ctx: Vitest;
|
|
1652
|
+
constructor(ctx: Vitest);
|
|
1653
|
+
shard(files: string[]): Promise<string[]>;
|
|
1654
|
+
sort(files: string[]): Promise<string[]>;
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
export { BaseSequencer, ExecuteOptions, TestSequencer, TestSequencerConstructor, Vitest, VitestPlugin, VitestRunner, createVitest, startVitest };
|