vitest 0.26.3 → 0.27.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 +15 -66
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +15 -15
- package/dist/{chunk-api-setup.47a09f0f.js → chunk-api-setup.2be3cc38.js} +60 -31
- package/dist/{chunk-install-pkg.6dd2bae6.js → chunk-install-pkg.7b006b3e.js} +8 -8
- package/dist/{chunk-integrations-coverage.befed097.js → chunk-integrations-coverage.44413252.js} +19 -1
- package/dist/chunk-integrations-globals.02f1259c.js +27 -0
- package/dist/{chunk-typecheck-constants.06e1fe5b.js → chunk-mock-date.149ed990.js} +19 -32
- package/dist/{chunk-node-git.a90c0582.js → chunk-node-git.125c9008.js} +3 -4
- package/dist/{chunk-runtime-chain.f51aa930.js → chunk-runtime-chain.4e2aa823.js} +1193 -1029
- package/dist/{chunk-runtime-error.f5c8aaf2.js → chunk-runtime-error.97854396.js} +2 -2
- package/dist/{chunk-runtime-mocker.887bf8c8.js → chunk-runtime-mocker.4755840f.js} +10 -8
- package/dist/{chunk-runtime-rpc.54d72169.js → chunk-runtime-rpc.25cc9413.js} +2 -2
- package/dist/{chunk-runtime-setup.a06d5c72.js → chunk-runtime-setup.56d71d30.js} +51 -52
- package/dist/{chunk-snapshot-manager.70695b70.js → chunk-snapshot-manager.1a2dbf96.js} +468 -302
- package/dist/{chunk-utils-env.3fdc1793.js → chunk-utils-env.f4a39d2c.js} +8 -70
- package/dist/{chunk-utils-import.e7f64637.js → chunk-utils-import.16d9fb0d.js} +22 -8
- package/dist/chunk-utils-source-map.4e9b891d.js +408 -0
- package/dist/{chunk-utils-timers.715da787.js → chunk-utils-timers.52534f96.js} +2977 -3458
- package/dist/cli-wrapper.js +15 -15
- package/dist/cli.js +15 -627
- package/dist/config.cjs +2 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -1
- package/dist/entry.js +14 -14
- package/dist/environments.d.ts +1 -1
- package/dist/{index-761e769b.d.ts → index-1cfc7f58.d.ts} +4 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/loader.js +9 -10
- package/dist/node.d.ts +2 -2
- package/dist/node.js +14 -12
- package/dist/spy.js +2 -102
- package/dist/suite.js +10 -10
- package/dist/{types-bae746aa.d.ts → types-5617096e.d.ts} +97 -77
- package/dist/{vendor-index.b2fdde54.js → vendor-index.451e37bc.js} +1 -1
- package/dist/vendor-index.723a074f.js +102 -0
- package/dist/vendor-index.b0346fe4.js +395 -0
- package/dist/{vendor-index.7a2cebfe.js → vendor-index.e6c27006.js} +12 -12
- package/dist/worker.js +24 -19
- package/package.json +13 -8
- package/dist/chunk-integrations-globals.ee28730b.js +0 -27
- package/dist/chunk-utils-source-map.5278ee22.js +0 -86
- package/dist/vendor-index.2e96c50b.js +0 -215
|
@@ -173,6 +173,10 @@ interface ParsedFile extends File {
|
|
|
173
173
|
start: number;
|
|
174
174
|
end: number;
|
|
175
175
|
}
|
|
176
|
+
interface ParsedTest extends Test {
|
|
177
|
+
start: number;
|
|
178
|
+
end: number;
|
|
179
|
+
}
|
|
176
180
|
interface ParsedSuite extends Suite {
|
|
177
181
|
start: number;
|
|
178
182
|
end: number;
|
|
@@ -181,9 +185,9 @@ interface LocalCallDefinition {
|
|
|
181
185
|
start: number;
|
|
182
186
|
end: number;
|
|
183
187
|
name: string;
|
|
184
|
-
type:
|
|
188
|
+
type: 'suite' | 'test';
|
|
185
189
|
mode: 'run' | 'skip' | 'only' | 'todo';
|
|
186
|
-
task: ParsedSuite | ParsedFile;
|
|
190
|
+
task: ParsedSuite | ParsedFile | ParsedTest;
|
|
187
191
|
}
|
|
188
192
|
interface FileInformation {
|
|
189
193
|
file: File;
|
|
@@ -213,12 +217,14 @@ declare class Typechecker {
|
|
|
213
217
|
private _result;
|
|
214
218
|
private _tests;
|
|
215
219
|
private tempConfigPath?;
|
|
220
|
+
private allowJs?;
|
|
216
221
|
private process;
|
|
217
222
|
constructor(ctx: Vitest, files: string[]);
|
|
218
223
|
onParseStart(fn: Callback): void;
|
|
219
224
|
onParseEnd(fn: Callback<[ErrorsCache]>): void;
|
|
220
225
|
onWatcherRerun(fn: Callback): void;
|
|
221
226
|
protected collectFileTests(filepath: string): Promise<FileInformation | null>;
|
|
227
|
+
protected getFiles(): string[];
|
|
222
228
|
collectTests(): Promise<Record<string, FileInformation>>;
|
|
223
229
|
protected prepareResults(output: string): Promise<{
|
|
224
230
|
files: File[];
|
|
@@ -231,6 +237,7 @@ declare class Typechecker {
|
|
|
231
237
|
clear(): Promise<void>;
|
|
232
238
|
stop(): Promise<void>;
|
|
233
239
|
protected ensurePackageInstalled(root: string, checker: string): Promise<void>;
|
|
240
|
+
prepare(): Promise<void>;
|
|
234
241
|
start(): Promise<void>;
|
|
235
242
|
getResult(): ErrorsCache;
|
|
236
243
|
getTestFiles(): File[];
|
|
@@ -403,6 +410,7 @@ declare class Vitest {
|
|
|
403
410
|
*/
|
|
404
411
|
exit(force?: boolean): Promise<void>;
|
|
405
412
|
report<T extends keyof Reporter>(name: T, ...args: ArgumentsType$1<Reporter[T]>): Promise<void>;
|
|
413
|
+
globFiles(filters: string[], include: string[], exclude: string[]): Promise<string[]>;
|
|
406
414
|
globTestFiles(filters?: string[]): Promise<string[]>;
|
|
407
415
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
408
416
|
isInSourceTestFile(code: string): boolean;
|
|
@@ -545,6 +553,12 @@ declare class TapFlatReporter extends TapReporter {
|
|
|
545
553
|
onFinished(files?: File[]): Promise<void>;
|
|
546
554
|
}
|
|
547
555
|
|
|
556
|
+
declare class HangingProcessReporter implements Reporter {
|
|
557
|
+
whyRunning: (() => void) | undefined;
|
|
558
|
+
onInit(): void;
|
|
559
|
+
onProcessTimeout(): void;
|
|
560
|
+
}
|
|
561
|
+
|
|
548
562
|
declare class JsonReporter implements Reporter {
|
|
549
563
|
start: number;
|
|
550
564
|
ctx: Vitest;
|
|
@@ -598,6 +612,7 @@ declare const ReportersMap: {
|
|
|
598
612
|
tap: typeof TapReporter;
|
|
599
613
|
'tap-flat': typeof TapFlatReporter;
|
|
600
614
|
junit: typeof JUnitReporter;
|
|
615
|
+
'hanging-process': typeof HangingProcessReporter;
|
|
601
616
|
};
|
|
602
617
|
type BuiltinReporters = keyof typeof ReportersMap;
|
|
603
618
|
|
|
@@ -951,13 +966,18 @@ interface TaskBase {
|
|
|
951
966
|
result?: TaskResult;
|
|
952
967
|
retry?: number;
|
|
953
968
|
logs?: UserConsoleLog[];
|
|
969
|
+
meta?: any;
|
|
954
970
|
}
|
|
955
971
|
interface TaskResult {
|
|
956
972
|
state: TaskState;
|
|
957
973
|
duration?: number;
|
|
958
974
|
startTime?: number;
|
|
959
975
|
heap?: number;
|
|
976
|
+
/**
|
|
977
|
+
* @deprecated Use "errors" instead
|
|
978
|
+
*/
|
|
960
979
|
error?: ErrorWithDiff;
|
|
980
|
+
errors?: ErrorWithDiff[];
|
|
961
981
|
htmlError?: string;
|
|
962
982
|
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
|
963
983
|
benchmark?: BenchmarkResult;
|
|
@@ -984,10 +1004,7 @@ interface Test<ExtraContext = {}> extends TaskBase {
|
|
|
984
1004
|
context: TestContext & ExtraContext;
|
|
985
1005
|
onFailed?: OnTestFailedHandler[];
|
|
986
1006
|
}
|
|
987
|
-
|
|
988
|
-
type: 'typecheck';
|
|
989
|
-
}
|
|
990
|
-
type Task = Test | Suite | File | Benchmark | TypeCheck;
|
|
1007
|
+
type Task = Test | Suite | File | Benchmark;
|
|
991
1008
|
type DoneCallback = (error?: any) => void;
|
|
992
1009
|
type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
|
|
993
1010
|
type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
|
|
@@ -1156,7 +1173,7 @@ interface WorkerRPC {
|
|
|
1156
1173
|
resolveId: ResolveIdFunction;
|
|
1157
1174
|
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
|
|
1158
1175
|
onFinished: (files: File[], errors?: unknown[]) => void;
|
|
1159
|
-
onWorkerExit: (code?: number) => void;
|
|
1176
|
+
onWorkerExit: (error: unknown, code?: number) => void;
|
|
1160
1177
|
onPathsCollected: (paths: string[]) => void;
|
|
1161
1178
|
onUserConsoleLog: (log: UserConsoleLog) => void;
|
|
1162
1179
|
onUnhandledRejection: (err: unknown) => void;
|
|
@@ -1246,7 +1263,7 @@ interface BaseCoverageOptions {
|
|
|
1246
1263
|
/**
|
|
1247
1264
|
* Clean coverage report on watch rerun
|
|
1248
1265
|
*
|
|
1249
|
-
* @default
|
|
1266
|
+
* @default true
|
|
1250
1267
|
*/
|
|
1251
1268
|
cleanOnRerun?: boolean;
|
|
1252
1269
|
/**
|
|
@@ -1435,6 +1452,7 @@ interface Reporter {
|
|
|
1435
1452
|
onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
|
|
1436
1453
|
onServerRestart?: (reason?: string) => Awaitable<void>;
|
|
1437
1454
|
onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
|
|
1455
|
+
onProcessTimeout?: () => Awaitable<void>;
|
|
1438
1456
|
}
|
|
1439
1457
|
|
|
1440
1458
|
type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
|
|
@@ -1966,38 +1984,11 @@ declare module 'vite' {
|
|
|
1966
1984
|
}
|
|
1967
1985
|
}
|
|
1968
1986
|
|
|
1969
|
-
|
|
1987
|
+
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
|
|
1988
|
+
maxLength?: number;
|
|
1989
|
+
}): string;
|
|
1970
1990
|
|
|
1971
|
-
|
|
1972
|
-
comment?: string;
|
|
1973
|
-
expectedColor?: Formatter;
|
|
1974
|
-
isDirectExpectCall?: boolean;
|
|
1975
|
-
isNot?: boolean;
|
|
1976
|
-
promise?: string;
|
|
1977
|
-
receivedColor?: Formatter;
|
|
1978
|
-
secondArgument?: string;
|
|
1979
|
-
secondArgumentColor?: Formatter;
|
|
1980
|
-
}
|
|
1981
|
-
interface DiffOptions {
|
|
1982
|
-
aAnnotation?: string;
|
|
1983
|
-
aColor?: Formatter;
|
|
1984
|
-
aIndicator?: string;
|
|
1985
|
-
bAnnotation?: string;
|
|
1986
|
-
bColor?: Formatter;
|
|
1987
|
-
bIndicator?: string;
|
|
1988
|
-
changeColor?: Formatter;
|
|
1989
|
-
changeLineTrailingSpaceColor?: Formatter;
|
|
1990
|
-
commonColor?: Formatter;
|
|
1991
|
-
commonIndicator?: string;
|
|
1992
|
-
commonLineTrailingSpaceColor?: Formatter;
|
|
1993
|
-
contextLines?: number;
|
|
1994
|
-
emptyFirstOrLastLinePlaceholder?: string;
|
|
1995
|
-
expand?: boolean;
|
|
1996
|
-
includeChangeCounts?: boolean;
|
|
1997
|
-
omitAnnotationLines?: boolean;
|
|
1998
|
-
patchColor?: Formatter;
|
|
1999
|
-
compareKeys?: any;
|
|
2000
|
-
}
|
|
1991
|
+
type Formatter = (input: string | number | null | undefined) => string;
|
|
2001
1992
|
|
|
2002
1993
|
declare const EXPECTED_COLOR: Formatter;
|
|
2003
1994
|
declare const RECEIVED_COLOR: Formatter;
|
|
@@ -2005,37 +1996,97 @@ declare const INVERTED_COLOR: Formatter;
|
|
|
2005
1996
|
declare const BOLD_WEIGHT: Formatter;
|
|
2006
1997
|
declare const DIM_COLOR: Formatter;
|
|
2007
1998
|
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
|
2008
|
-
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
|
|
2009
|
-
maxLength?: number;
|
|
2010
|
-
}): string;
|
|
2011
1999
|
declare const printReceived: (object: unknown) => string;
|
|
2012
2000
|
declare const printExpected: (value: unknown) => string;
|
|
2013
2001
|
declare function diff(a: any, b: any, options?: DiffOptions): string;
|
|
2014
2002
|
|
|
2003
|
+
declare const jestMatcherUtils_stringify: typeof stringify;
|
|
2015
2004
|
declare const jestMatcherUtils_EXPECTED_COLOR: typeof EXPECTED_COLOR;
|
|
2016
2005
|
declare const jestMatcherUtils_RECEIVED_COLOR: typeof RECEIVED_COLOR;
|
|
2017
2006
|
declare const jestMatcherUtils_INVERTED_COLOR: typeof INVERTED_COLOR;
|
|
2018
2007
|
declare const jestMatcherUtils_BOLD_WEIGHT: typeof BOLD_WEIGHT;
|
|
2019
2008
|
declare const jestMatcherUtils_DIM_COLOR: typeof DIM_COLOR;
|
|
2020
2009
|
declare const jestMatcherUtils_matcherHint: typeof matcherHint;
|
|
2021
|
-
declare const jestMatcherUtils_stringify: typeof stringify;
|
|
2022
2010
|
declare const jestMatcherUtils_printReceived: typeof printReceived;
|
|
2023
2011
|
declare const jestMatcherUtils_printExpected: typeof printExpected;
|
|
2024
2012
|
declare const jestMatcherUtils_diff: typeof diff;
|
|
2025
2013
|
declare namespace jestMatcherUtils {
|
|
2026
2014
|
export {
|
|
2015
|
+
jestMatcherUtils_stringify as stringify,
|
|
2027
2016
|
jestMatcherUtils_EXPECTED_COLOR as EXPECTED_COLOR,
|
|
2028
2017
|
jestMatcherUtils_RECEIVED_COLOR as RECEIVED_COLOR,
|
|
2029
2018
|
jestMatcherUtils_INVERTED_COLOR as INVERTED_COLOR,
|
|
2030
2019
|
jestMatcherUtils_BOLD_WEIGHT as BOLD_WEIGHT,
|
|
2031
2020
|
jestMatcherUtils_DIM_COLOR as DIM_COLOR,
|
|
2032
2021
|
jestMatcherUtils_matcherHint as matcherHint,
|
|
2033
|
-
jestMatcherUtils_stringify as stringify,
|
|
2034
2022
|
jestMatcherUtils_printReceived as printReceived,
|
|
2035
2023
|
jestMatcherUtils_printExpected as printExpected,
|
|
2036
2024
|
jestMatcherUtils_diff as diff,
|
|
2037
2025
|
};
|
|
2038
2026
|
}
|
|
2027
|
+
type Tester = (a: any, b: any) => boolean | undefined;
|
|
2028
|
+
interface MatcherHintOptions {
|
|
2029
|
+
comment?: string;
|
|
2030
|
+
expectedColor?: Formatter;
|
|
2031
|
+
isDirectExpectCall?: boolean;
|
|
2032
|
+
isNot?: boolean;
|
|
2033
|
+
promise?: string;
|
|
2034
|
+
receivedColor?: Formatter;
|
|
2035
|
+
secondArgument?: string;
|
|
2036
|
+
secondArgumentColor?: Formatter;
|
|
2037
|
+
}
|
|
2038
|
+
interface DiffOptions {
|
|
2039
|
+
aAnnotation?: string;
|
|
2040
|
+
aColor?: Formatter;
|
|
2041
|
+
aIndicator?: string;
|
|
2042
|
+
bAnnotation?: string;
|
|
2043
|
+
bColor?: Formatter;
|
|
2044
|
+
bIndicator?: string;
|
|
2045
|
+
changeColor?: Formatter;
|
|
2046
|
+
changeLineTrailingSpaceColor?: Formatter;
|
|
2047
|
+
commonColor?: Formatter;
|
|
2048
|
+
commonIndicator?: string;
|
|
2049
|
+
commonLineTrailingSpaceColor?: Formatter;
|
|
2050
|
+
contextLines?: number;
|
|
2051
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
|
2052
|
+
expand?: boolean;
|
|
2053
|
+
includeChangeCounts?: boolean;
|
|
2054
|
+
omitAnnotationLines?: boolean;
|
|
2055
|
+
patchColor?: Formatter;
|
|
2056
|
+
compareKeys?: any;
|
|
2057
|
+
}
|
|
2058
|
+
interface MatcherState$1 {
|
|
2059
|
+
assertionCalls: number;
|
|
2060
|
+
currentTestName?: string;
|
|
2061
|
+
dontThrow?: () => void;
|
|
2062
|
+
error?: Error;
|
|
2063
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
2064
|
+
expand?: boolean;
|
|
2065
|
+
expectedAssertionsNumber?: number | null;
|
|
2066
|
+
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
2067
|
+
isExpectingAssertions?: boolean;
|
|
2068
|
+
isExpectingAssertionsError?: Error | null;
|
|
2069
|
+
isNot: boolean;
|
|
2070
|
+
promise: string;
|
|
2071
|
+
suppressedErrors: Array<Error>;
|
|
2072
|
+
testPath?: string;
|
|
2073
|
+
utils: typeof jestMatcherUtils & {
|
|
2074
|
+
iterableEquality: Tester;
|
|
2075
|
+
subsetEquality: Tester;
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
interface SyncExpectationResult {
|
|
2079
|
+
pass: boolean;
|
|
2080
|
+
message: () => string;
|
|
2081
|
+
actual?: any;
|
|
2082
|
+
expected?: any;
|
|
2083
|
+
}
|
|
2084
|
+
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
2085
|
+
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
2086
|
+
interface RawMatcherFn<T extends MatcherState$1 = MatcherState$1> {
|
|
2087
|
+
(this: T, received: any, expected: any, options?: any): ExpectationResult;
|
|
2088
|
+
}
|
|
2089
|
+
type MatchersObject<T extends MatcherState$1 = MatcherState$1> = Record<string, RawMatcherFn<T>>;
|
|
2039
2090
|
|
|
2040
2091
|
/**
|
|
2041
2092
|
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
@@ -2084,41 +2135,10 @@ declare class SnapshotState {
|
|
|
2084
2135
|
pack(): Promise<SnapshotResult>;
|
|
2085
2136
|
}
|
|
2086
2137
|
|
|
2087
|
-
|
|
2088
|
-
interface MatcherState {
|
|
2089
|
-
assertionCalls: number;
|
|
2090
|
-
currentTestName?: string;
|
|
2091
|
-
dontThrow?: () => void;
|
|
2092
|
-
error?: Error;
|
|
2093
|
-
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
2094
|
-
expand?: boolean;
|
|
2095
|
-
expectedAssertionsNumber?: number | null;
|
|
2096
|
-
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
2097
|
-
isExpectingAssertions?: boolean;
|
|
2098
|
-
isExpectingAssertionsError?: Error | null;
|
|
2099
|
-
isNot: boolean;
|
|
2138
|
+
interface MatcherState extends MatcherState$1 {
|
|
2100
2139
|
environment: VitestEnvironment;
|
|
2101
|
-
promise: string;
|
|
2102
2140
|
snapshotState: SnapshotState;
|
|
2103
|
-
suppressedErrors: Array<Error>;
|
|
2104
|
-
testPath?: string;
|
|
2105
|
-
utils: typeof jestMatcherUtils & {
|
|
2106
|
-
iterableEquality: Tester;
|
|
2107
|
-
subsetEquality: Tester;
|
|
2108
|
-
};
|
|
2109
|
-
}
|
|
2110
|
-
interface SyncExpectationResult {
|
|
2111
|
-
pass: boolean;
|
|
2112
|
-
message: () => string;
|
|
2113
|
-
actual?: any;
|
|
2114
|
-
expected?: any;
|
|
2115
|
-
}
|
|
2116
|
-
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
2117
|
-
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
2118
|
-
interface RawMatcherFn<T extends MatcherState = MatcherState> {
|
|
2119
|
-
(this: T, received: any, expected: any, options?: any): ExpectationResult;
|
|
2120
2141
|
}
|
|
2121
|
-
type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
|
|
2122
2142
|
|
|
2123
2143
|
type Promisify<O> = {
|
|
2124
2144
|
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? O extends R ? Promisify<O[K]> : (...args: A) => Promise<R> : O[K];
|
|
@@ -2245,4 +2265,4 @@ type Context = RootAndTarget & {
|
|
|
2245
2265
|
lastActivePath?: string;
|
|
2246
2266
|
};
|
|
2247
2267
|
|
|
2248
|
-
export {
|
|
2268
|
+
export { WorkerContext as $, ApiConfig as A, BuiltinEnvironment as B, CollectLineNumbers as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, SuiteFactory as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, RuntimeContext as K, TestContext as L, MockFactoryWithHelper as M, Vitest as N, OnTestFailedHandler as O, SnapshotData as P, SnapshotUpdateState as Q, RuntimeConfig as R, SequenceHooks as S, TaskResultPack as T, UserConfig as U, VitestEnvironment as V, SnapshotStateOptions as W, SnapshotMatchOptions as X, SnapshotResult as Y, UncheckedSnapshot as Z, SnapshotSummary as _, File as a, ResolveIdFunction as a0, AfterSuiteRunMeta as a1, WorkerRPC as a2, WorkerGlobalState as a3, Awaitable as a4, Nullable as a5, Arrayable as a6, ArgumentsType$1 as a7, MergeInsertions as a8, DeepMerge as a9, TestSequencerConstructor as aA, MutableArray as aa, Constructable as ab, ModuleCache as ac, EnvironmentReturn as ad, Environment as ae, UserConsoleLog as af, ParsedStack as ag, ErrorWithDiff as ah, OnServerRestartHandler as ai, CoverageProvider as aj, CoverageProviderModule as ak, CoverageReporter as al, CoverageOptions as am, ResolvedCoverageOptions as an, BaseCoverageOptions as ao, CoverageIstanbulOptions as ap, CoverageC8Options as aq, BenchmarkUserOptions as ar, Benchmark as as, BenchmarkResult as at, BenchFunction as au, BenchmarkAPI as av, MockFactory as aw, MockMap as ax, TestSequencer as ay, startVitest as az, ResolvedConfig as b, ModuleGraphData as c, Reporter as d, RawErrsMap as e, TscErrorInfo as f, CollectLines as g, RootAndTarget as h, Context as i, CSSModuleScopeStrategy as j, VitestRunMode as k, TypecheckConfig as l, RunMode as m, TaskState as n, TaskBase as o, TaskResult as p, Suite as q, Test as r, Task as s, TestFunction as t, TestOptions as u, TestAPI as v, SuiteAPI as w, HookCleanupCallback as x, SuiteHooks as y, SuiteCollector as z };
|
|
@@ -2,7 +2,7 @@ import { Buffer } from 'node:buffer';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import childProcess from 'node:child_process';
|
|
4
4
|
import process$1 from 'node:process';
|
|
5
|
-
import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn } from './vendor-index.
|
|
5
|
+
import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn } from './vendor-index.e6c27006.js';
|
|
6
6
|
import url from 'node:url';
|
|
7
7
|
import { constants } from 'os';
|
|
8
8
|
import os from 'node:os';
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as tinyspy from 'tinyspy';
|
|
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[stub.calls.length - 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 { spies as a, fn as f, isMockFunction as i, spyOn as s };
|