vitest 0.8.3 → 0.9.0
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/{chunk-api-setup.175eacf7.js → chunk-api-setup.e8071f5b.js} +4 -4
- package/dist/{chunk-constants.6062c404.js → chunk-constants.596ee4d5.js} +1 -1
- package/dist/{chunk-defaults.e5535971.js → chunk-defaults.731639a8.js} +4 -3
- package/dist/chunk-integrations-globals.d1145578.js +23 -0
- package/dist/{chunk-runtime-chain.766f27fd.js → chunk-runtime-chain.a5280da7.js} +232 -171
- package/dist/{chunk-runtime-mocker.def94aba.js → chunk-runtime-mocker.ff55be7d.js} +32 -35
- package/dist/chunk-runtime-rpc.3f693817.js +7 -0
- package/dist/{chunk-utils-base.8408f73a.js → chunk-utils-global.35d3b35d.js} +18 -1
- package/dist/{chunk-utils-timers.7bdeea22.js → chunk-utils-timers.73950dcb.js} +13 -10
- package/dist/{chunk-vite-node-externalize.ecc58a1f.js → chunk-vite-node-externalize.2004587d.js} +233 -76
- package/dist/{chunk-vite-node-utils.3c7ce184.js → chunk-vite-node-utils.5fa30ee7.js} +1 -1
- package/dist/cli.js +7 -7
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +26 -2
- package/dist/config.js +3 -2
- package/dist/entry.js +85 -53
- package/dist/index.d.ts +29 -10
- package/dist/index.js +5 -6
- package/dist/node.d.ts +21 -4
- package/dist/node.js +7 -8
- package/dist/{jest-mock.js → spy.js} +3 -0
- package/dist/worker.js +5 -6
- package/package.json +16 -16
- package/dist/chunk-integrations-globals.ade0c248.js +0 -24
- package/dist/chunk-runtime-rpc.e8aa1ebe.js +0 -8
- package/dist/chunk-utils-global.7bcfa03c.js +0 -5
package/dist/config.js
CHANGED
|
@@ -23,7 +23,7 @@ const coverageConfigDefaults = {
|
|
|
23
23
|
allowExternal: false,
|
|
24
24
|
extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const config = {
|
|
27
27
|
allowOnly: !process.env.CI,
|
|
28
28
|
watch: !process.env.CI,
|
|
29
29
|
globals: false,
|
|
@@ -46,7 +46,8 @@ const configDefaults = Object.freeze({
|
|
|
46
46
|
uiBase: "/__vitest__/",
|
|
47
47
|
open: true,
|
|
48
48
|
coverage: coverageConfigDefaults
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
|
+
const configDefaults = Object.freeze(config);
|
|
50
51
|
|
|
51
52
|
function defineConfig(config) {
|
|
52
53
|
return config;
|
package/dist/entry.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { promises } from 'fs';
|
|
2
|
-
import { t as toArray,
|
|
2
|
+
import { g as getWorkerState, t as toArray, m as relative, D as partitionSuiteChildren, E as hasTests, q as hasFailed, p as getFullName, r as resetModules } from './chunk-utils-global.35d3b35d.js';
|
|
3
3
|
import { Console } from 'console';
|
|
4
4
|
import { Writable } from 'stream';
|
|
5
5
|
import { importModule } from 'local-pkg';
|
|
6
|
-
import { r as resetRunOnceCounter, i as index, R as RealDate, s as stringify, c as clearContext, d as defaultSuite, a as setHooks, g as getHooks, b as context, e as getSnapshotClient, f as setState, h as getFn, j as getState, v as vi } from './chunk-runtime-chain.
|
|
7
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
8
|
-
import { c as clearTimeout, s as setTimeout } from './chunk-utils-timers.
|
|
9
|
-
import {
|
|
10
|
-
import { performance } from 'perf_hooks';
|
|
11
|
-
import { t as takeCoverage } from './chunk-defaults.e5535971.js';
|
|
6
|
+
import { r as resetRunOnceCounter, i as index, R as RealDate, s as stringify, c as clearContext, d as defaultSuite, a as setHooks, g as getHooks, b as context, e as getSnapshotClient, f as setState, h as getFn, j as getState, v as vi } from './chunk-runtime-chain.a5280da7.js';
|
|
7
|
+
import { r as rpc } from './chunk-runtime-rpc.3f693817.js';
|
|
8
|
+
import { c as clearTimeout, s as setTimeout } from './chunk-utils-timers.73950dcb.js';
|
|
9
|
+
import { t as takeCoverage } from './chunk-defaults.731639a8.js';
|
|
12
10
|
import { createHash } from 'crypto';
|
|
13
11
|
import { format } from 'util';
|
|
14
12
|
import 'path';
|
|
15
13
|
import 'tty';
|
|
16
14
|
import 'chai';
|
|
17
15
|
import './vendor-_commonjsHelpers.34b404ce.js';
|
|
18
|
-
import './
|
|
16
|
+
import './spy.js';
|
|
19
17
|
import 'tinyspy';
|
|
20
18
|
import 'module';
|
|
21
19
|
import 'url';
|
|
@@ -404,69 +402,100 @@ async function setupGlobalEnv(config) {
|
|
|
404
402
|
globalSetup = true;
|
|
405
403
|
setupConsoleLogSpy();
|
|
406
404
|
if (config.globals)
|
|
407
|
-
(await import('./chunk-integrations-globals.
|
|
405
|
+
(await import('./chunk-integrations-globals.d1145578.js')).registerApiGlobally();
|
|
408
406
|
}
|
|
409
407
|
function setupDefines(defines) {
|
|
410
408
|
for (const key in defines)
|
|
411
409
|
globalThis[key] = defines[key];
|
|
412
410
|
}
|
|
413
411
|
function setupConsoleLogSpy() {
|
|
414
|
-
const stdoutBuffer =
|
|
415
|
-
const stderrBuffer =
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
timer
|
|
412
|
+
const stdoutBuffer = /* @__PURE__ */ new Map();
|
|
413
|
+
const stderrBuffer = /* @__PURE__ */ new Map();
|
|
414
|
+
const timers = /* @__PURE__ */ new Map();
|
|
415
|
+
const unknownTestId = "__vitest__unknown_test__";
|
|
416
|
+
function schedule(taskId) {
|
|
417
|
+
const timer = timers.get(taskId);
|
|
418
|
+
const { stdoutTime, stderrTime } = timer;
|
|
419
|
+
clearTimeout(timer.timer);
|
|
420
|
+
timer.timer = setTimeout(() => {
|
|
422
421
|
if (stderrTime < stdoutTime) {
|
|
423
|
-
sendStderr();
|
|
424
|
-
sendStdout();
|
|
422
|
+
sendStderr(taskId);
|
|
423
|
+
sendStdout(taskId);
|
|
425
424
|
} else {
|
|
426
|
-
sendStdout();
|
|
427
|
-
sendStderr();
|
|
425
|
+
sendStdout(taskId);
|
|
426
|
+
sendStderr(taskId);
|
|
428
427
|
}
|
|
429
428
|
});
|
|
430
429
|
}
|
|
431
|
-
function sendStdout() {
|
|
432
|
-
|
|
433
|
-
if (
|
|
430
|
+
function sendStdout(taskId) {
|
|
431
|
+
const buffer = stdoutBuffer.get(taskId);
|
|
432
|
+
if (buffer) {
|
|
433
|
+
const timer = timers.get(taskId);
|
|
434
434
|
rpc().onUserConsoleLog({
|
|
435
435
|
type: "stdout",
|
|
436
|
-
content:
|
|
437
|
-
taskId
|
|
438
|
-
time: stdoutTime || RealDate.now()
|
|
436
|
+
content: buffer.map((i) => String(i)).join(""),
|
|
437
|
+
taskId,
|
|
438
|
+
time: timer.stdoutTime || RealDate.now(),
|
|
439
|
+
size: buffer.length
|
|
439
440
|
});
|
|
441
|
+
stdoutBuffer.set(taskId, []);
|
|
442
|
+
timer.stdoutTime = 0;
|
|
440
443
|
}
|
|
441
|
-
stdoutBuffer.length = 0;
|
|
442
|
-
stdoutTime = 0;
|
|
443
444
|
}
|
|
444
|
-
function sendStderr() {
|
|
445
|
-
|
|
446
|
-
if (
|
|
445
|
+
function sendStderr(taskId) {
|
|
446
|
+
const buffer = stderrBuffer.get(taskId);
|
|
447
|
+
if (buffer) {
|
|
448
|
+
const timer = timers.get(taskId);
|
|
447
449
|
rpc().onUserConsoleLog({
|
|
448
450
|
type: "stderr",
|
|
449
|
-
content:
|
|
450
|
-
taskId
|
|
451
|
-
time: stderrTime || RealDate.now()
|
|
451
|
+
content: buffer.map((i) => String(i)).join(""),
|
|
452
|
+
taskId,
|
|
453
|
+
time: timer.stderrTime || RealDate.now(),
|
|
454
|
+
size: buffer.length
|
|
452
455
|
});
|
|
456
|
+
stderrBuffer.set(taskId, []);
|
|
457
|
+
timer.stderrTime = 0;
|
|
453
458
|
}
|
|
454
|
-
stderrBuffer.length = 0;
|
|
455
|
-
stderrTime = 0;
|
|
456
459
|
}
|
|
457
460
|
const stdout = new Writable({
|
|
458
461
|
write(data, encoding, callback) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
+
var _a, _b;
|
|
463
|
+
const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
464
|
+
let timer = timers.get(id);
|
|
465
|
+
if (timer) {
|
|
466
|
+
timer.stdoutTime = timer.stdoutTime || RealDate.now();
|
|
467
|
+
} else {
|
|
468
|
+
timer = { stdoutTime: RealDate.now(), stderrTime: RealDate.now(), timer: 0 };
|
|
469
|
+
timers.set(id, timer);
|
|
470
|
+
}
|
|
471
|
+
let buffer = stdoutBuffer.get(id);
|
|
472
|
+
if (!buffer) {
|
|
473
|
+
buffer = [];
|
|
474
|
+
stdoutBuffer.set(id, buffer);
|
|
475
|
+
}
|
|
476
|
+
buffer.push(data);
|
|
477
|
+
schedule(id);
|
|
462
478
|
callback();
|
|
463
479
|
}
|
|
464
480
|
});
|
|
465
481
|
const stderr = new Writable({
|
|
466
482
|
write(data, encoding, callback) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
483
|
+
var _a, _b;
|
|
484
|
+
const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
485
|
+
let timer = timers.get(id);
|
|
486
|
+
if (timer) {
|
|
487
|
+
timer.stderrTime = timer.stderrTime || RealDate.now();
|
|
488
|
+
} else {
|
|
489
|
+
timer = { stderrTime: RealDate.now(), stdoutTime: RealDate.now(), timer: 0 };
|
|
490
|
+
timers.set(id, timer);
|
|
491
|
+
}
|
|
492
|
+
let buffer = stderrBuffer.get(id);
|
|
493
|
+
if (!buffer) {
|
|
494
|
+
buffer = [];
|
|
495
|
+
stderrBuffer.set(id, buffer);
|
|
496
|
+
}
|
|
497
|
+
buffer.push(data);
|
|
498
|
+
schedule(id);
|
|
470
499
|
callback();
|
|
471
500
|
}
|
|
472
501
|
});
|
|
@@ -549,6 +578,7 @@ Inner error message: ${err == null ? void 0 : err.message}`));
|
|
|
549
578
|
}
|
|
550
579
|
}
|
|
551
580
|
|
|
581
|
+
const now$1 = Date.now;
|
|
552
582
|
function hash(str, length = 10) {
|
|
553
583
|
return createHash("md5").update(str).digest("hex").slice(0, length);
|
|
554
584
|
}
|
|
@@ -576,9 +606,9 @@ async function collectTests(paths, config) {
|
|
|
576
606
|
} else if (c.type === "suite") {
|
|
577
607
|
file.tasks.push(c);
|
|
578
608
|
} else {
|
|
579
|
-
const start =
|
|
609
|
+
const start = now$1();
|
|
580
610
|
const suite = await c.collect(file);
|
|
581
|
-
file.collectDuration =
|
|
611
|
+
file.collectDuration = now$1() - start;
|
|
582
612
|
if (suite.name || suite.tasks.length)
|
|
583
613
|
file.tasks.push(suite);
|
|
584
614
|
}
|
|
@@ -679,6 +709,7 @@ var __spreadValues = (a, b) => {
|
|
|
679
709
|
return a;
|
|
680
710
|
};
|
|
681
711
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
712
|
+
const now = Date.now;
|
|
682
713
|
function updateSuiteHookState(suite, name, state) {
|
|
683
714
|
var _a;
|
|
684
715
|
if (!suite.result)
|
|
@@ -727,14 +758,14 @@ async function runTest(test) {
|
|
|
727
758
|
updateTask(test);
|
|
728
759
|
return;
|
|
729
760
|
}
|
|
730
|
-
const start =
|
|
761
|
+
const start = now();
|
|
731
762
|
test.result = {
|
|
732
763
|
state: "run",
|
|
733
|
-
startTime:
|
|
764
|
+
startTime: start
|
|
734
765
|
};
|
|
735
766
|
updateTask(test);
|
|
736
767
|
clearModuleMocks();
|
|
737
|
-
getSnapshotClient().setTest(test);
|
|
768
|
+
await getSnapshotClient().setTest(test);
|
|
738
769
|
const workerState = getWorkerState();
|
|
739
770
|
workerState.current = test;
|
|
740
771
|
try {
|
|
@@ -775,7 +806,7 @@ async function runTest(test) {
|
|
|
775
806
|
}
|
|
776
807
|
}
|
|
777
808
|
getSnapshotClient().clearTest();
|
|
778
|
-
test.result.duration =
|
|
809
|
+
test.result.duration = now() - start;
|
|
779
810
|
workerState.current = void 0;
|
|
780
811
|
updateTask(test);
|
|
781
812
|
}
|
|
@@ -795,10 +826,10 @@ async function runSuite(suite) {
|
|
|
795
826
|
updateTask(suite);
|
|
796
827
|
return;
|
|
797
828
|
}
|
|
798
|
-
const start =
|
|
829
|
+
const start = now();
|
|
799
830
|
suite.result = {
|
|
800
831
|
state: "run",
|
|
801
|
-
startTime:
|
|
832
|
+
startTime: start
|
|
802
833
|
};
|
|
803
834
|
updateTask(suite);
|
|
804
835
|
if (suite.mode === "skip") {
|
|
@@ -822,7 +853,7 @@ async function runSuite(suite) {
|
|
|
822
853
|
suite.result.error = processError(e);
|
|
823
854
|
}
|
|
824
855
|
}
|
|
825
|
-
suite.result.duration =
|
|
856
|
+
suite.result.duration = now() - start;
|
|
826
857
|
if (suite.mode === "run") {
|
|
827
858
|
if (!hasTests(suite)) {
|
|
828
859
|
suite.result.state = "fail";
|
|
@@ -875,8 +906,9 @@ async function run(files, config) {
|
|
|
875
906
|
var _a;
|
|
876
907
|
await setupGlobalEnv(config);
|
|
877
908
|
const workerState = getWorkerState();
|
|
878
|
-
workerState.mockMap.clear();
|
|
879
909
|
for (const file of files) {
|
|
910
|
+
workerState.mockMap.clear();
|
|
911
|
+
resetModules();
|
|
880
912
|
const code = await promises.readFile(file, "utf-8");
|
|
881
913
|
const env = ((_a = code.match(/@(?:vitest|jest)-environment\s+?([\w-]+)\b/)) == null ? void 0 : _a[1]) || config.environment || "node";
|
|
882
914
|
if (!["node", "jsdom", "happy-dom"].includes(env))
|
package/dist/index.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ interface MatcherHintOptions {
|
|
|
108
108
|
secondArgumentColor?: Formatter;
|
|
109
109
|
}
|
|
110
110
|
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
|
111
|
-
declare const stringify: (object: unknown, maxDepth?: number) => string;
|
|
111
|
+
declare const stringify: (object: unknown, maxDepth?: number, options?: PrettyFormatOptions | undefined) => string;
|
|
112
112
|
declare const printReceived: (object: unknown) => string;
|
|
113
113
|
declare const printExpected: (value: unknown) => string;
|
|
114
114
|
interface DiffOptions {
|
|
@@ -280,11 +280,13 @@ declare class ViteNodeServer {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
declare class SnapshotManager {
|
|
283
|
-
|
|
283
|
+
options: SnapshotStateOptions;
|
|
284
284
|
summary: SnapshotSummary;
|
|
285
|
-
|
|
285
|
+
extension: string;
|
|
286
|
+
constructor(options: SnapshotStateOptions);
|
|
286
287
|
clear(): void;
|
|
287
288
|
add(result: SnapshotResult): void;
|
|
289
|
+
resolvePath(testPath: string): string;
|
|
288
290
|
}
|
|
289
291
|
|
|
290
292
|
declare type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
|
|
@@ -397,6 +399,7 @@ declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions)
|
|
|
397
399
|
declare class DefaultReporter extends BaseReporter {
|
|
398
400
|
renderer?: ReturnType<typeof createListRenderer>;
|
|
399
401
|
rendererOptions: ListRendererOptions;
|
|
402
|
+
onTestRemoved(trigger?: string): Promise<void>;
|
|
400
403
|
onCollected(): void;
|
|
401
404
|
onFinished(files?: File[]): Promise<void>;
|
|
402
405
|
onWatcherStart(): Promise<void>;
|
|
@@ -431,6 +434,7 @@ declare class JsonReporter implements Reporter {
|
|
|
431
434
|
|
|
432
435
|
declare class VerboseReporter extends DefaultReporter {
|
|
433
436
|
constructor();
|
|
437
|
+
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
434
438
|
}
|
|
435
439
|
|
|
436
440
|
declare class TapReporter implements Reporter {
|
|
@@ -505,6 +509,7 @@ interface UserConsoleLog {
|
|
|
505
509
|
type: 'stdout' | 'stderr';
|
|
506
510
|
taskId?: string;
|
|
507
511
|
time: number;
|
|
512
|
+
size: number;
|
|
508
513
|
}
|
|
509
514
|
interface Position {
|
|
510
515
|
source?: string;
|
|
@@ -774,6 +779,7 @@ interface Reporter {
|
|
|
774
779
|
onCollected?: (files?: File[]) => Awaitable<void>;
|
|
775
780
|
onFinished?: (files?: File[]) => Awaitable<void>;
|
|
776
781
|
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
|
|
782
|
+
onTestRemoved?: (trigger?: string) => Awaitable<void>;
|
|
777
783
|
onWatcherStart?: () => Awaitable<void>;
|
|
778
784
|
onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
|
|
779
785
|
onServerRestart?: () => Awaitable<void>;
|
|
@@ -786,6 +792,7 @@ interface SnapshotStateOptions {
|
|
|
786
792
|
updateSnapshot: SnapshotUpdateState;
|
|
787
793
|
expand?: boolean;
|
|
788
794
|
snapshotFormat?: OptionsReceived;
|
|
795
|
+
resolveSnapshotPath?: (path: string, extension: string) => string;
|
|
789
796
|
}
|
|
790
797
|
interface SnapshotMatchOptions {
|
|
791
798
|
testName: string;
|
|
@@ -1069,6 +1076,10 @@ interface InlineConfig {
|
|
|
1069
1076
|
* Format options for snapshot testing.
|
|
1070
1077
|
*/
|
|
1071
1078
|
snapshotFormat?: PrettyFormatOptions;
|
|
1079
|
+
/**
|
|
1080
|
+
* Resolve custom snapshot path
|
|
1081
|
+
*/
|
|
1082
|
+
resolveSnapshotPath?: (path: string, extension: string) => string;
|
|
1072
1083
|
}
|
|
1073
1084
|
interface UserConfig extends InlineConfig {
|
|
1074
1085
|
/**
|
|
@@ -1102,8 +1113,14 @@ interface UserConfig extends InlineConfig {
|
|
|
1102
1113
|
* @default 'test'
|
|
1103
1114
|
*/
|
|
1104
1115
|
mode?: string;
|
|
1116
|
+
/**
|
|
1117
|
+
* Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
|
|
1118
|
+
* Requires initialized git repository
|
|
1119
|
+
* @default false
|
|
1120
|
+
*/
|
|
1121
|
+
changed?: boolean | string;
|
|
1105
1122
|
}
|
|
1106
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters'> {
|
|
1123
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath'> {
|
|
1107
1124
|
base?: string;
|
|
1108
1125
|
config?: string;
|
|
1109
1126
|
filters?: string[];
|
|
@@ -1150,6 +1167,7 @@ interface WorkerRPC {
|
|
|
1150
1167
|
onCollected: (files: File[]) => void;
|
|
1151
1168
|
onTaskUpdate: (pack: TaskResultPack[]) => void;
|
|
1152
1169
|
snapshotSaved: (snapshot: SnapshotResult) => void;
|
|
1170
|
+
resolveSnapshotPath: (testPath: string) => string;
|
|
1153
1171
|
}
|
|
1154
1172
|
interface WorkerGlobalState {
|
|
1155
1173
|
ctx: WorkerContext;
|
|
@@ -1205,11 +1223,12 @@ interface MockResultThrow {
|
|
|
1205
1223
|
value: any;
|
|
1206
1224
|
}
|
|
1207
1225
|
declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
1208
|
-
interface
|
|
1226
|
+
interface SpyContext<TArgs, TReturns> {
|
|
1209
1227
|
calls: TArgs[];
|
|
1210
1228
|
instances: TReturns[];
|
|
1211
1229
|
invocationCallOrder: number[];
|
|
1212
1230
|
results: MockResult<TReturns>[];
|
|
1231
|
+
lastCall: TArgs | undefined;
|
|
1213
1232
|
}
|
|
1214
1233
|
declare type Procedure = (...args: any[]) => any;
|
|
1215
1234
|
declare type Methods<T> = {
|
|
@@ -1224,7 +1243,7 @@ declare type Classes<T> = {
|
|
|
1224
1243
|
interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
|
|
1225
1244
|
getMockName(): string;
|
|
1226
1245
|
mockName(n: string): this;
|
|
1227
|
-
mock:
|
|
1246
|
+
mock: SpyContext<TArgs, TReturns>;
|
|
1228
1247
|
mockClear(): this;
|
|
1229
1248
|
mockReset(): this;
|
|
1230
1249
|
mockRestore(): void;
|
|
@@ -1241,6 +1260,7 @@ interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
|
|
|
1241
1260
|
}
|
|
1242
1261
|
interface SpyInstanceFn<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, TReturns> {
|
|
1243
1262
|
(...args: TArgs): TReturns;
|
|
1263
|
+
new (...args: TArgs): TReturns;
|
|
1244
1264
|
}
|
|
1245
1265
|
declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? SpyInstanceFn<ConstructorParameters<T>, R> : T;
|
|
1246
1266
|
declare type MockedFunction<T extends Procedure> = MockWithArgs<T> & {
|
|
@@ -1264,8 +1284,6 @@ interface MockWithArgs<T extends Procedure> extends SpyInstanceFn<Parameters<T>,
|
|
|
1264
1284
|
new (...args: T extends new (...args: any) => any ? ConstructorParameters<T> : never): T;
|
|
1265
1285
|
(...args: Parameters<T>): ReturnType<T>;
|
|
1266
1286
|
}
|
|
1267
|
-
declare const spies: Set<SpyInstance<any[], any>>;
|
|
1268
|
-
declare function isMockFunction(fn: any): fn is EnhancedSpy;
|
|
1269
1287
|
declare function spyOn<T, S extends Properties<Required<T>>>(obj: T, methodName: S, accessType: 'get'): SpyInstance<[], T[S]>;
|
|
1270
1288
|
declare function spyOn<T, G extends Properties<Required<T>>>(obj: T, methodName: G, accessType: 'set'): SpyInstance<[T[G]], void>;
|
|
1271
1289
|
declare function spyOn<T, M extends (Methods<Required<T>> | Classes<Required<T>>)>(obj: T, methodName: M): Required<T>[M] extends (...args: infer A) => infer R | (new (...args: infer A) => infer R) ? SpyInstance<A, R> : never;
|
|
@@ -1359,7 +1377,8 @@ declare class VitestUtils {
|
|
|
1359
1377
|
* using jsdom/happy-dom and want to mock global variables, like
|
|
1360
1378
|
* `IntersectionObserver`.
|
|
1361
1379
|
*/
|
|
1362
|
-
stubGlobal(name: string, value: any): this;
|
|
1380
|
+
stubGlobal(name: string | symbol | number, value: any): this;
|
|
1381
|
+
resetModules(): this;
|
|
1363
1382
|
}
|
|
1364
1383
|
declare const vitest: VitestUtils;
|
|
1365
1384
|
declare const vi: VitestUtils;
|
|
@@ -1490,4 +1509,4 @@ declare global {
|
|
|
1490
1509
|
}
|
|
1491
1510
|
}
|
|
1492
1511
|
|
|
1493
|
-
export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookListener, InlineConfig, JSDOMOptions,
|
|
1512
|
+
export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookListener, InlineConfig, JSDOMOptions, MergeInsertions, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
export { q as afterAll, w as afterEach, p as beforeAll, u as beforeEach, l as describe, x as expect, z as getRunningMode, o as isFirstRun, A as isWatchMode, m as it, n as runOnce, k as suite, t as test, v as vi, y as vitest } from './chunk-runtime-chain.
|
|
2
|
-
export { fn, isMockFunction, spies, spyOn } from './jest-mock.js';
|
|
1
|
+
export { q as afterAll, w as afterEach, p as beforeAll, u as beforeEach, l as describe, x as expect, z as getRunningMode, o as isFirstRun, A as isWatchMode, m as it, n as runOnce, k as suite, t as test, v as vi, y as vitest } from './chunk-runtime-chain.a5280da7.js';
|
|
3
2
|
export { assert, default as chai, should } from 'chai';
|
|
4
3
|
import 'util';
|
|
5
|
-
import './chunk-utils-
|
|
4
|
+
import './chunk-utils-global.35d3b35d.js';
|
|
6
5
|
import 'path';
|
|
7
6
|
import 'tty';
|
|
8
7
|
import 'local-pkg';
|
|
9
|
-
import './chunk-utils-
|
|
10
|
-
import './chunk-utils-timers.7bdeea22.js';
|
|
8
|
+
import './chunk-utils-timers.73950dcb.js';
|
|
11
9
|
import './vendor-_commonjsHelpers.34b404ce.js';
|
|
12
|
-
import './chunk-runtime-rpc.
|
|
10
|
+
import './chunk-runtime-rpc.3f693817.js';
|
|
13
11
|
import 'fs';
|
|
12
|
+
import './spy.js';
|
|
14
13
|
import 'tinyspy';
|
package/dist/node.d.ts
CHANGED
|
@@ -245,6 +245,7 @@ declare const createListRenderer: (_tasks: Task[], options: ListRendererOptions)
|
|
|
245
245
|
declare class DefaultReporter extends BaseReporter {
|
|
246
246
|
renderer?: ReturnType<typeof createListRenderer>;
|
|
247
247
|
rendererOptions: ListRendererOptions;
|
|
248
|
+
onTestRemoved(trigger?: string): Promise<void>;
|
|
248
249
|
onCollected(): void;
|
|
249
250
|
onFinished(files?: File[]): Promise<void>;
|
|
250
251
|
onWatcherStart(): Promise<void>;
|
|
@@ -279,6 +280,7 @@ declare class JsonReporter implements Reporter {
|
|
|
279
280
|
|
|
280
281
|
declare class VerboseReporter extends DefaultReporter {
|
|
281
282
|
constructor();
|
|
283
|
+
onTaskUpdate(packs: TaskResultPack[]): void;
|
|
282
284
|
}
|
|
283
285
|
|
|
284
286
|
declare class TapReporter implements Reporter {
|
|
@@ -328,6 +330,7 @@ interface UserConsoleLog {
|
|
|
328
330
|
type: 'stdout' | 'stderr';
|
|
329
331
|
taskId?: string;
|
|
330
332
|
time: number;
|
|
333
|
+
size: number;
|
|
331
334
|
}
|
|
332
335
|
interface Position {
|
|
333
336
|
source?: string;
|
|
@@ -538,6 +541,7 @@ interface Reporter {
|
|
|
538
541
|
onCollected?: (files?: File[]) => Awaitable<void>;
|
|
539
542
|
onFinished?: (files?: File[]) => Awaitable<void>;
|
|
540
543
|
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
|
|
544
|
+
onTestRemoved?: (trigger?: string) => Awaitable<void>;
|
|
541
545
|
onWatcherStart?: () => Awaitable<void>;
|
|
542
546
|
onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
|
|
543
547
|
onServerRestart?: () => Awaitable<void>;
|
|
@@ -549,6 +553,7 @@ interface SnapshotStateOptions {
|
|
|
549
553
|
updateSnapshot: SnapshotUpdateState;
|
|
550
554
|
expand?: boolean;
|
|
551
555
|
snapshotFormat?: OptionsReceived;
|
|
556
|
+
resolveSnapshotPath?: (path: string, extension: string) => string;
|
|
552
557
|
}
|
|
553
558
|
interface SnapshotResult {
|
|
554
559
|
filepath: string;
|
|
@@ -824,6 +829,10 @@ interface InlineConfig {
|
|
|
824
829
|
* Format options for snapshot testing.
|
|
825
830
|
*/
|
|
826
831
|
snapshotFormat?: PrettyFormatOptions;
|
|
832
|
+
/**
|
|
833
|
+
* Resolve custom snapshot path
|
|
834
|
+
*/
|
|
835
|
+
resolveSnapshotPath?: (path: string, extension: string) => string;
|
|
827
836
|
}
|
|
828
837
|
interface UserConfig extends InlineConfig {
|
|
829
838
|
/**
|
|
@@ -857,8 +866,14 @@ interface UserConfig extends InlineConfig {
|
|
|
857
866
|
* @default 'test'
|
|
858
867
|
*/
|
|
859
868
|
mode?: string;
|
|
869
|
+
/**
|
|
870
|
+
* Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
|
|
871
|
+
* Requires initialized git repository
|
|
872
|
+
* @default false
|
|
873
|
+
*/
|
|
874
|
+
changed?: boolean | string;
|
|
860
875
|
}
|
|
861
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters'> {
|
|
876
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath'> {
|
|
862
877
|
base?: string;
|
|
863
878
|
config?: string;
|
|
864
879
|
filters?: string[];
|
|
@@ -874,11 +889,13 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
|
|
|
874
889
|
declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
|
|
875
890
|
|
|
876
891
|
declare class SnapshotManager {
|
|
877
|
-
|
|
892
|
+
options: SnapshotStateOptions;
|
|
878
893
|
summary: SnapshotSummary;
|
|
879
|
-
|
|
894
|
+
extension: string;
|
|
895
|
+
constructor(options: SnapshotStateOptions);
|
|
880
896
|
clear(): void;
|
|
881
897
|
add(result: SnapshotResult): void;
|
|
898
|
+
resolvePath(testPath: string): string;
|
|
882
899
|
}
|
|
883
900
|
|
|
884
901
|
declare type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
|
|
@@ -992,7 +1009,7 @@ declare class VitestMocker {
|
|
|
992
1009
|
normalizePath(path: string): string;
|
|
993
1010
|
getFsPath(path: string, external: string | null): string;
|
|
994
1011
|
resolveMockPath(mockPath: string, external: string | null): string | null;
|
|
995
|
-
|
|
1012
|
+
mockValue(value: any): any;
|
|
996
1013
|
unmockPath(path: string): void;
|
|
997
1014
|
mockPath(path: string, external: string | null, factory?: () => any): void;
|
|
998
1015
|
importActual<T>(id: string, importer: string): Promise<T>;
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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.2004587d.js';
|
|
2
|
+
export { V as VitestRunner } from './chunk-runtime-mocker.ff55be7d.js';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'path';
|
|
5
5
|
import 'child_process';
|
|
@@ -13,20 +13,19 @@ import 'stream';
|
|
|
13
13
|
import 'util';
|
|
14
14
|
import 'url';
|
|
15
15
|
import 'os';
|
|
16
|
-
import './chunk-utils-
|
|
16
|
+
import './chunk-utils-global.35d3b35d.js';
|
|
17
17
|
import 'tty';
|
|
18
18
|
import 'local-pkg';
|
|
19
19
|
import 'vite';
|
|
20
|
-
import './chunk-constants.
|
|
21
|
-
import './chunk-vite-node-utils.
|
|
20
|
+
import './chunk-constants.596ee4d5.js';
|
|
21
|
+
import './chunk-vite-node-utils.5fa30ee7.js';
|
|
22
22
|
import 'module';
|
|
23
23
|
import 'vm';
|
|
24
|
-
import './chunk-defaults.
|
|
24
|
+
import './chunk-defaults.731639a8.js';
|
|
25
25
|
import 'perf_hooks';
|
|
26
|
-
import './chunk-utils-timers.
|
|
26
|
+
import './chunk-utils-timers.73950dcb.js';
|
|
27
27
|
import 'worker_threads';
|
|
28
28
|
import 'tinypool';
|
|
29
29
|
import './chunk-magic-string.d5e0e473.js';
|
|
30
30
|
import 'readline';
|
|
31
31
|
import './vendor-index.ee829ed6.js';
|
|
32
|
-
import './chunk-utils-global.7bcfa03c.js';
|
package/dist/worker.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.
|
|
3
|
-
import { d as distDir } from './chunk-constants.
|
|
4
|
-
import { e as executeInViteNode } from './chunk-runtime-mocker.
|
|
5
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
6
|
-
import { g as getWorkerState } from './chunk-utils-global.7bcfa03c.js';
|
|
1
|
+
import { w as resolve, g as getWorkerState } from './chunk-utils-global.35d3b35d.js';
|
|
2
|
+
import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-utils.5fa30ee7.js';
|
|
3
|
+
import { d as distDir } from './chunk-constants.596ee4d5.js';
|
|
4
|
+
import { e as executeInViteNode } from './chunk-runtime-mocker.ff55be7d.js';
|
|
5
|
+
import { r as rpc } from './chunk-runtime-rpc.3f693817.js';
|
|
7
6
|
import 'path';
|
|
8
7
|
import 'tty';
|
|
9
8
|
import 'local-pkg';
|