vitest 0.26.2 → 0.27.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/LICENSE.md +2 -54
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +15 -15
- package/dist/{chunk-api-setup.46ee0021.js → chunk-api-setup.16ac28c0.js} +13 -3
- package/dist/{chunk-install-pkg.31846bc1.js → chunk-install-pkg.6dd2bae6.js} +2 -2
- package/dist/{chunk-integrations-coverage.befed097.js → chunk-integrations-coverage.44413252.js} +19 -1
- package/dist/chunk-integrations-globals.3dfaeb99.js +27 -0
- package/dist/{chunk-typecheck-constants.e478eb98.js → chunk-mock-date.a1c85759.js} +10 -28
- package/dist/{chunk-node-git.43b341db.js → chunk-node-git.543e964a.js} +3 -4
- package/dist/{chunk-runtime-chain.198631fd.js → chunk-runtime-chain.6df5a66b.js} +1192 -1028
- package/dist/{chunk-runtime-error.12631a44.js → chunk-runtime-error.fad2c32b.js} +2 -2
- package/dist/{chunk-runtime-mocker.03096876.js → chunk-runtime-mocker.a677dd28.js} +10 -8
- package/dist/{chunk-runtime-rpc.503623e9.js → chunk-runtime-rpc.7f83c8a9.js} +2 -2
- package/dist/{chunk-runtime-setup.f79addc3.js → chunk-runtime-setup.731b2b04.js} +51 -52
- package/dist/{chunk-snapshot-manager.8c94a052.js → chunk-snapshot-manager.700322bf.js} +430 -303
- package/dist/{chunk-utils-env.4afc6329.js → chunk-utils-env.b861e3a0.js} +1 -63
- package/dist/{chunk-utils-import.dc87c88c.js → chunk-utils-import.2baa69a9.js} +38 -13
- package/dist/chunk-utils-source-map.60562959.js +408 -0
- package/dist/{chunk-utils-timers.54caa12a.js → chunk-utils-timers.52534f96.js} +2977 -3458
- package/dist/cli-wrapper.js +13 -13
- 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-40ebba2b.d.ts → index-2d10c3fd.d.ts} +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +12 -12
- package/dist/loader.js +3 -3
- package/dist/node.d.ts +6 -6
- package/dist/node.js +11 -11
- package/dist/spy.js +2 -102
- package/dist/suite.js +10 -10
- package/dist/{types-2a26f28c.d.ts → types-e1e1d1e5.d.ts} +92 -83
- package/dist/vendor-index.723a074f.js +102 -0
- package/dist/{vendor-index.62932580.js → vendor-index.7a2cebfe.js} +0 -0
- package/dist/{vendor-index.808a85a6.js → vendor-index.9c919048.js} +0 -0
- package/dist/{vendor-index.a323f2d0.js → vendor-index.b2fdde54.js} +1 -1
- package/dist/worker.js +7 -7
- package/package.json +9 -5
- package/dist/chunk-integrations-globals.5af12e76.js +0 -27
- package/dist/chunk-utils-source-map.95b8b3f0.js +0 -94
|
@@ -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,9 +237,11 @@ 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[];
|
|
244
|
+
getTestPacks(): TaskResultPack[];
|
|
237
245
|
}
|
|
238
246
|
|
|
239
247
|
type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
|
|
@@ -402,6 +410,7 @@ declare class Vitest {
|
|
|
402
410
|
*/
|
|
403
411
|
exit(force?: boolean): Promise<void>;
|
|
404
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[]>;
|
|
405
414
|
globTestFiles(filters?: string[]): Promise<string[]>;
|
|
406
415
|
isTargetFile(id: string, source?: string): Promise<boolean>;
|
|
407
416
|
isInSourceTestFile(code: string): boolean;
|
|
@@ -409,7 +418,9 @@ declare class Vitest {
|
|
|
409
418
|
onAfterSetServer(fn: OnServerRestartHandler): void;
|
|
410
419
|
}
|
|
411
420
|
|
|
412
|
-
type
|
|
421
|
+
type MockFactoryWithHelper = (importOriginal: <T = unknown>() => Promise<T>) => any;
|
|
422
|
+
type MockFactory = () => any;
|
|
423
|
+
type MockMap = Map<string, Record<string, string | null | MockFactory>>;
|
|
413
424
|
|
|
414
425
|
interface TestSequencer {
|
|
415
426
|
/**
|
|
@@ -838,17 +849,11 @@ interface UserConsoleLog {
|
|
|
838
849
|
time: number;
|
|
839
850
|
size: number;
|
|
840
851
|
}
|
|
841
|
-
interface Position {
|
|
842
|
-
source?: string;
|
|
843
|
-
line: number;
|
|
844
|
-
column: number;
|
|
845
|
-
}
|
|
846
852
|
interface ParsedStack {
|
|
847
853
|
method: string;
|
|
848
854
|
file: string;
|
|
849
855
|
line: number;
|
|
850
856
|
column: number;
|
|
851
|
-
sourcePos?: Position;
|
|
852
857
|
}
|
|
853
858
|
interface ErrorWithDiff extends Error {
|
|
854
859
|
name: string;
|
|
@@ -954,13 +959,18 @@ interface TaskBase {
|
|
|
954
959
|
result?: TaskResult;
|
|
955
960
|
retry?: number;
|
|
956
961
|
logs?: UserConsoleLog[];
|
|
962
|
+
meta?: any;
|
|
957
963
|
}
|
|
958
964
|
interface TaskResult {
|
|
959
965
|
state: TaskState;
|
|
960
966
|
duration?: number;
|
|
961
967
|
startTime?: number;
|
|
962
968
|
heap?: number;
|
|
969
|
+
/**
|
|
970
|
+
* @deprecated Use "errors" instead
|
|
971
|
+
*/
|
|
963
972
|
error?: ErrorWithDiff;
|
|
973
|
+
errors?: ErrorWithDiff[];
|
|
964
974
|
htmlError?: string;
|
|
965
975
|
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
|
966
976
|
benchmark?: BenchmarkResult;
|
|
@@ -987,10 +997,7 @@ interface Test<ExtraContext = {}> extends TaskBase {
|
|
|
987
997
|
context: TestContext & ExtraContext;
|
|
988
998
|
onFailed?: OnTestFailedHandler[];
|
|
989
999
|
}
|
|
990
|
-
|
|
991
|
-
type: 'typecheck';
|
|
992
|
-
}
|
|
993
|
-
type Task = Test | Suite | File | Benchmark | TypeCheck;
|
|
1000
|
+
type Task = Test | Suite | File | Benchmark;
|
|
994
1001
|
type DoneCallback = (error?: any) => void;
|
|
995
1002
|
type TestFunction<ExtraContext = {}> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
|
|
996
1003
|
type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
|
|
@@ -1249,7 +1256,7 @@ interface BaseCoverageOptions {
|
|
|
1249
1256
|
/**
|
|
1250
1257
|
* Clean coverage report on watch rerun
|
|
1251
1258
|
*
|
|
1252
|
-
* @default
|
|
1259
|
+
* @default true
|
|
1253
1260
|
*/
|
|
1254
1261
|
cleanOnRerun?: boolean;
|
|
1255
1262
|
/**
|
|
@@ -1969,38 +1976,11 @@ declare module 'vite' {
|
|
|
1969
1976
|
}
|
|
1970
1977
|
}
|
|
1971
1978
|
|
|
1972
|
-
|
|
1979
|
+
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
|
|
1980
|
+
maxLength?: number;
|
|
1981
|
+
}): string;
|
|
1973
1982
|
|
|
1974
|
-
|
|
1975
|
-
comment?: string;
|
|
1976
|
-
expectedColor?: Formatter;
|
|
1977
|
-
isDirectExpectCall?: boolean;
|
|
1978
|
-
isNot?: boolean;
|
|
1979
|
-
promise?: string;
|
|
1980
|
-
receivedColor?: Formatter;
|
|
1981
|
-
secondArgument?: string;
|
|
1982
|
-
secondArgumentColor?: Formatter;
|
|
1983
|
-
}
|
|
1984
|
-
interface DiffOptions {
|
|
1985
|
-
aAnnotation?: string;
|
|
1986
|
-
aColor?: Formatter;
|
|
1987
|
-
aIndicator?: string;
|
|
1988
|
-
bAnnotation?: string;
|
|
1989
|
-
bColor?: Formatter;
|
|
1990
|
-
bIndicator?: string;
|
|
1991
|
-
changeColor?: Formatter;
|
|
1992
|
-
changeLineTrailingSpaceColor?: Formatter;
|
|
1993
|
-
commonColor?: Formatter;
|
|
1994
|
-
commonIndicator?: string;
|
|
1995
|
-
commonLineTrailingSpaceColor?: Formatter;
|
|
1996
|
-
contextLines?: number;
|
|
1997
|
-
emptyFirstOrLastLinePlaceholder?: string;
|
|
1998
|
-
expand?: boolean;
|
|
1999
|
-
includeChangeCounts?: boolean;
|
|
2000
|
-
omitAnnotationLines?: boolean;
|
|
2001
|
-
patchColor?: Formatter;
|
|
2002
|
-
compareKeys?: any;
|
|
2003
|
-
}
|
|
1983
|
+
type Formatter = (input: string | number | null | undefined) => string;
|
|
2004
1984
|
|
|
2005
1985
|
declare const EXPECTED_COLOR: Formatter;
|
|
2006
1986
|
declare const RECEIVED_COLOR: Formatter;
|
|
@@ -2008,37 +1988,97 @@ declare const INVERTED_COLOR: Formatter;
|
|
|
2008
1988
|
declare const BOLD_WEIGHT: Formatter;
|
|
2009
1989
|
declare const DIM_COLOR: Formatter;
|
|
2010
1990
|
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
|
2011
|
-
declare function stringify(object: unknown, maxDepth?: number, { maxLength, ...options }?: PrettyFormatOptions & {
|
|
2012
|
-
maxLength?: number;
|
|
2013
|
-
}): string;
|
|
2014
1991
|
declare const printReceived: (object: unknown) => string;
|
|
2015
1992
|
declare const printExpected: (value: unknown) => string;
|
|
2016
1993
|
declare function diff(a: any, b: any, options?: DiffOptions): string;
|
|
2017
1994
|
|
|
1995
|
+
declare const jestMatcherUtils_stringify: typeof stringify;
|
|
2018
1996
|
declare const jestMatcherUtils_EXPECTED_COLOR: typeof EXPECTED_COLOR;
|
|
2019
1997
|
declare const jestMatcherUtils_RECEIVED_COLOR: typeof RECEIVED_COLOR;
|
|
2020
1998
|
declare const jestMatcherUtils_INVERTED_COLOR: typeof INVERTED_COLOR;
|
|
2021
1999
|
declare const jestMatcherUtils_BOLD_WEIGHT: typeof BOLD_WEIGHT;
|
|
2022
2000
|
declare const jestMatcherUtils_DIM_COLOR: typeof DIM_COLOR;
|
|
2023
2001
|
declare const jestMatcherUtils_matcherHint: typeof matcherHint;
|
|
2024
|
-
declare const jestMatcherUtils_stringify: typeof stringify;
|
|
2025
2002
|
declare const jestMatcherUtils_printReceived: typeof printReceived;
|
|
2026
2003
|
declare const jestMatcherUtils_printExpected: typeof printExpected;
|
|
2027
2004
|
declare const jestMatcherUtils_diff: typeof diff;
|
|
2028
2005
|
declare namespace jestMatcherUtils {
|
|
2029
2006
|
export {
|
|
2007
|
+
jestMatcherUtils_stringify as stringify,
|
|
2030
2008
|
jestMatcherUtils_EXPECTED_COLOR as EXPECTED_COLOR,
|
|
2031
2009
|
jestMatcherUtils_RECEIVED_COLOR as RECEIVED_COLOR,
|
|
2032
2010
|
jestMatcherUtils_INVERTED_COLOR as INVERTED_COLOR,
|
|
2033
2011
|
jestMatcherUtils_BOLD_WEIGHT as BOLD_WEIGHT,
|
|
2034
2012
|
jestMatcherUtils_DIM_COLOR as DIM_COLOR,
|
|
2035
2013
|
jestMatcherUtils_matcherHint as matcherHint,
|
|
2036
|
-
jestMatcherUtils_stringify as stringify,
|
|
2037
2014
|
jestMatcherUtils_printReceived as printReceived,
|
|
2038
2015
|
jestMatcherUtils_printExpected as printExpected,
|
|
2039
2016
|
jestMatcherUtils_diff as diff,
|
|
2040
2017
|
};
|
|
2041
2018
|
}
|
|
2019
|
+
type Tester = (a: any, b: any) => boolean | undefined;
|
|
2020
|
+
interface MatcherHintOptions {
|
|
2021
|
+
comment?: string;
|
|
2022
|
+
expectedColor?: Formatter;
|
|
2023
|
+
isDirectExpectCall?: boolean;
|
|
2024
|
+
isNot?: boolean;
|
|
2025
|
+
promise?: string;
|
|
2026
|
+
receivedColor?: Formatter;
|
|
2027
|
+
secondArgument?: string;
|
|
2028
|
+
secondArgumentColor?: Formatter;
|
|
2029
|
+
}
|
|
2030
|
+
interface DiffOptions {
|
|
2031
|
+
aAnnotation?: string;
|
|
2032
|
+
aColor?: Formatter;
|
|
2033
|
+
aIndicator?: string;
|
|
2034
|
+
bAnnotation?: string;
|
|
2035
|
+
bColor?: Formatter;
|
|
2036
|
+
bIndicator?: string;
|
|
2037
|
+
changeColor?: Formatter;
|
|
2038
|
+
changeLineTrailingSpaceColor?: Formatter;
|
|
2039
|
+
commonColor?: Formatter;
|
|
2040
|
+
commonIndicator?: string;
|
|
2041
|
+
commonLineTrailingSpaceColor?: Formatter;
|
|
2042
|
+
contextLines?: number;
|
|
2043
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
|
2044
|
+
expand?: boolean;
|
|
2045
|
+
includeChangeCounts?: boolean;
|
|
2046
|
+
omitAnnotationLines?: boolean;
|
|
2047
|
+
patchColor?: Formatter;
|
|
2048
|
+
compareKeys?: any;
|
|
2049
|
+
}
|
|
2050
|
+
interface MatcherState$1 {
|
|
2051
|
+
assertionCalls: number;
|
|
2052
|
+
currentTestName?: string;
|
|
2053
|
+
dontThrow?: () => void;
|
|
2054
|
+
error?: Error;
|
|
2055
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
2056
|
+
expand?: boolean;
|
|
2057
|
+
expectedAssertionsNumber?: number | null;
|
|
2058
|
+
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
2059
|
+
isExpectingAssertions?: boolean;
|
|
2060
|
+
isExpectingAssertionsError?: Error | null;
|
|
2061
|
+
isNot: boolean;
|
|
2062
|
+
promise: string;
|
|
2063
|
+
suppressedErrors: Array<Error>;
|
|
2064
|
+
testPath?: string;
|
|
2065
|
+
utils: typeof jestMatcherUtils & {
|
|
2066
|
+
iterableEquality: Tester;
|
|
2067
|
+
subsetEquality: Tester;
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
2070
|
+
interface SyncExpectationResult {
|
|
2071
|
+
pass: boolean;
|
|
2072
|
+
message: () => string;
|
|
2073
|
+
actual?: any;
|
|
2074
|
+
expected?: any;
|
|
2075
|
+
}
|
|
2076
|
+
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
2077
|
+
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
2078
|
+
interface RawMatcherFn<T extends MatcherState$1 = MatcherState$1> {
|
|
2079
|
+
(this: T, received: any, expected: any, options?: any): ExpectationResult;
|
|
2080
|
+
}
|
|
2081
|
+
type MatchersObject<T extends MatcherState$1 = MatcherState$1> = Record<string, RawMatcherFn<T>>;
|
|
2042
2082
|
|
|
2043
2083
|
/**
|
|
2044
2084
|
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
@@ -2087,41 +2127,10 @@ declare class SnapshotState {
|
|
|
2087
2127
|
pack(): Promise<SnapshotResult>;
|
|
2088
2128
|
}
|
|
2089
2129
|
|
|
2090
|
-
|
|
2091
|
-
interface MatcherState {
|
|
2092
|
-
assertionCalls: number;
|
|
2093
|
-
currentTestName?: string;
|
|
2094
|
-
dontThrow?: () => void;
|
|
2095
|
-
error?: Error;
|
|
2096
|
-
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
2097
|
-
expand?: boolean;
|
|
2098
|
-
expectedAssertionsNumber?: number | null;
|
|
2099
|
-
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
2100
|
-
isExpectingAssertions?: boolean;
|
|
2101
|
-
isExpectingAssertionsError?: Error | null;
|
|
2102
|
-
isNot: boolean;
|
|
2130
|
+
interface MatcherState extends MatcherState$1 {
|
|
2103
2131
|
environment: VitestEnvironment;
|
|
2104
|
-
promise: string;
|
|
2105
2132
|
snapshotState: SnapshotState;
|
|
2106
|
-
suppressedErrors: Array<Error>;
|
|
2107
|
-
testPath?: string;
|
|
2108
|
-
utils: typeof jestMatcherUtils & {
|
|
2109
|
-
iterableEquality: Tester;
|
|
2110
|
-
subsetEquality: Tester;
|
|
2111
|
-
};
|
|
2112
|
-
}
|
|
2113
|
-
interface SyncExpectationResult {
|
|
2114
|
-
pass: boolean;
|
|
2115
|
-
message: () => string;
|
|
2116
|
-
actual?: any;
|
|
2117
|
-
expected?: any;
|
|
2118
|
-
}
|
|
2119
|
-
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
2120
|
-
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
2121
|
-
interface RawMatcherFn<T extends MatcherState = MatcherState> {
|
|
2122
|
-
(this: T, received: any, expected: any, options?: any): ExpectationResult;
|
|
2123
2133
|
}
|
|
2124
|
-
type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
|
|
2125
2134
|
|
|
2126
2135
|
type Promisify<O> = {
|
|
2127
2136
|
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? O extends R ? Promisify<O[K]> : (...args: A) => Promise<R> : O[K];
|
|
@@ -2248,4 +2257,4 @@ type Context = RootAndTarget & {
|
|
|
2248
2257
|
lastActivePath?: string;
|
|
2249
2258
|
};
|
|
2250
2259
|
|
|
2251
|
-
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,
|
|
2260
|
+
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 };
|
|
@@ -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 };
|
|
File without changes
|
|
File without changes
|
|
@@ -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.7a2cebfe.js';
|
|
6
6
|
import url from 'node:url';
|
|
7
7
|
import { constants } from 'os';
|
|
8
8
|
import os from 'node:os';
|
package/dist/worker.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { b as resolve,
|
|
1
|
+
import { b as resolve, f as distDir } from './chunk-utils-env.b861e3a0.js';
|
|
2
2
|
import { c as createBirpc } from './vendor-index.783e7f3e.js';
|
|
3
3
|
import { workerId } from 'tinypool';
|
|
4
4
|
import { ModuleCacheMap } from 'vite-node/client';
|
|
5
|
-
import { g as getWorkerState } from './chunk-
|
|
6
|
-
import { e as executeInViteNode } from './chunk-runtime-mocker.
|
|
7
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
8
|
-
import { p as processError } from './chunk-runtime-error.
|
|
9
|
-
import 'tty';
|
|
5
|
+
import { g as getWorkerState } from './chunk-mock-date.a1c85759.js';
|
|
6
|
+
import { e as executeInViteNode } from './chunk-runtime-mocker.a677dd28.js';
|
|
7
|
+
import { r as rpc } from './chunk-runtime-rpc.7f83c8a9.js';
|
|
8
|
+
import { p as processError } from './chunk-runtime-error.fad2c32b.js';
|
|
10
9
|
import 'node:url';
|
|
11
10
|
import 'path';
|
|
12
11
|
import 'node:path';
|
|
12
|
+
import 'picocolors';
|
|
13
13
|
import 'local-pkg';
|
|
14
14
|
import 'vite-node/utils';
|
|
15
15
|
import 'vite';
|
|
@@ -22,7 +22,7 @@ import 'fs';
|
|
|
22
22
|
import 'module';
|
|
23
23
|
import 'assert';
|
|
24
24
|
import 'util';
|
|
25
|
-
import './chunk-utils-timers.
|
|
25
|
+
import './chunk-utils-timers.52534f96.js';
|
|
26
26
|
import 'chai';
|
|
27
27
|
|
|
28
28
|
let _viteNode;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.0",
|
|
5
5
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"test",
|
|
23
23
|
"jest"
|
|
24
24
|
],
|
|
25
|
+
"sideEffects": false,
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
28
|
"require": {
|
|
@@ -105,16 +106,18 @@
|
|
|
105
106
|
"@types/node": "*",
|
|
106
107
|
"acorn": "^8.8.1",
|
|
107
108
|
"acorn-walk": "^8.2.0",
|
|
109
|
+
"cac": "^6.7.14",
|
|
108
110
|
"chai": "^4.3.7",
|
|
109
111
|
"debug": "^4.3.4",
|
|
110
112
|
"local-pkg": "^0.4.2",
|
|
113
|
+
"picocolors": "^1.0.0",
|
|
111
114
|
"source-map": "^0.6.1",
|
|
112
115
|
"strip-literal": "^1.0.0",
|
|
113
116
|
"tinybench": "^2.3.1",
|
|
114
117
|
"tinypool": "^0.3.0",
|
|
115
118
|
"tinyspy": "^1.0.2",
|
|
116
119
|
"vite": "^3.0.0 || ^4.0.0",
|
|
117
|
-
"vite-node": "0.
|
|
120
|
+
"vite-node": "0.27.0"
|
|
118
121
|
},
|
|
119
122
|
"devDependencies": {
|
|
120
123
|
"@antfu/install-pkg": "^0.1.1",
|
|
@@ -127,7 +130,6 @@
|
|
|
127
130
|
"@types/prompts": "^2.4.2",
|
|
128
131
|
"@types/sinonjs__fake-timers": "^8.1.2",
|
|
129
132
|
"birpc": "^0.2.3",
|
|
130
|
-
"cac": "^6.7.14",
|
|
131
133
|
"chai-subset": "^1.6.0",
|
|
132
134
|
"cli-truncate": "^3.1.0",
|
|
133
135
|
"diff": "^5.1.0",
|
|
@@ -147,7 +149,6 @@
|
|
|
147
149
|
"natural-compare": "^1.4.0",
|
|
148
150
|
"p-limit": "^4.0.0",
|
|
149
151
|
"pathe": "^0.2.0",
|
|
150
|
-
"picocolors": "^1.0.0",
|
|
151
152
|
"pkg-types": "^1.0.1",
|
|
152
153
|
"pretty-format": "^27.5.1",
|
|
153
154
|
"prompts": "^2.4.2",
|
|
@@ -155,7 +156,10 @@
|
|
|
155
156
|
"strip-ansi": "^7.0.1",
|
|
156
157
|
"typescript": "^4.9.4",
|
|
157
158
|
"ws": "^8.11.0",
|
|
158
|
-
"@vitest/
|
|
159
|
+
"@vitest/expect": "0.27.0",
|
|
160
|
+
"@vitest/utils": "0.27.0",
|
|
161
|
+
"@vitest/spy": "0.27.0",
|
|
162
|
+
"@vitest/ui": "0.27.0"
|
|
159
163
|
},
|
|
160
164
|
"scripts": {
|
|
161
165
|
"build": "rimraf dist && rollup -c",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { m as globalApis } from './chunk-utils-env.4afc6329.js';
|
|
2
|
-
import { i as index } from './chunk-utils-import.dc87c88c.js';
|
|
3
|
-
import 'tty';
|
|
4
|
-
import 'node:url';
|
|
5
|
-
import 'path';
|
|
6
|
-
import './chunk-runtime-chain.198631fd.js';
|
|
7
|
-
import 'util';
|
|
8
|
-
import 'chai';
|
|
9
|
-
import './chunk-typecheck-constants.e478eb98.js';
|
|
10
|
-
import 'node:path';
|
|
11
|
-
import 'local-pkg';
|
|
12
|
-
import './vendor-_commonjsHelpers.addc3445.js';
|
|
13
|
-
import './chunk-runtime-rpc.503623e9.js';
|
|
14
|
-
import './chunk-utils-timers.54caa12a.js';
|
|
15
|
-
import 'node:fs';
|
|
16
|
-
import './chunk-utils-source-map.95b8b3f0.js';
|
|
17
|
-
import 'fs';
|
|
18
|
-
import './spy.js';
|
|
19
|
-
import 'tinyspy';
|
|
20
|
-
|
|
21
|
-
function registerApiGlobally() {
|
|
22
|
-
globalApis.forEach((api) => {
|
|
23
|
-
globalThis[api] = index[api];
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { registerApiGlobally };
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { b as resolve } from './chunk-utils-env.4afc6329.js';
|
|
2
|
-
import { k as notNullish } from './chunk-typecheck-constants.e478eb98.js';
|
|
3
|
-
|
|
4
|
-
const lineSplitRE = /\r?\n/;
|
|
5
|
-
const stackIgnorePatterns = [
|
|
6
|
-
"node:internal",
|
|
7
|
-
"/vitest/dist/",
|
|
8
|
-
"/vitest/src/",
|
|
9
|
-
"/vite-node/dist/",
|
|
10
|
-
"/vite-node/src/",
|
|
11
|
-
"/node_modules/chai/",
|
|
12
|
-
"/node_modules/tinypool/",
|
|
13
|
-
"/node_modules/tinyspy/"
|
|
14
|
-
];
|
|
15
|
-
function extractLocation(urlLike) {
|
|
16
|
-
if (!urlLike.includes(":"))
|
|
17
|
-
return [urlLike];
|
|
18
|
-
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
19
|
-
const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
|
|
20
|
-
if (!parts)
|
|
21
|
-
return [urlLike];
|
|
22
|
-
return [parts[1], parts[2] || void 0, parts[3] || void 0];
|
|
23
|
-
}
|
|
24
|
-
function parseStacktrace(e, full = false) {
|
|
25
|
-
if (!e)
|
|
26
|
-
return [];
|
|
27
|
-
if (e.stacks)
|
|
28
|
-
return e.stacks;
|
|
29
|
-
const stackStr = e.stack || e.stackStr || "";
|
|
30
|
-
const stackFrames = stackStr.split("\n").map((raw) => {
|
|
31
|
-
let line = raw.trim();
|
|
32
|
-
if (line.includes("(eval "))
|
|
33
|
-
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
34
|
-
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
35
|
-
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
36
|
-
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
37
|
-
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
38
|
-
let method = location && sanitizedLine || "";
|
|
39
|
-
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
|
40
|
-
if (!file || !lineNumber || !columnNumber)
|
|
41
|
-
return null;
|
|
42
|
-
if (method.startsWith("async "))
|
|
43
|
-
method = method.slice(6);
|
|
44
|
-
if (file.startsWith("file://"))
|
|
45
|
-
file = file.slice(7);
|
|
46
|
-
file = resolve(file);
|
|
47
|
-
if (!full && stackIgnorePatterns.some((p) => file && file.includes(p)))
|
|
48
|
-
return null;
|
|
49
|
-
return {
|
|
50
|
-
method,
|
|
51
|
-
file,
|
|
52
|
-
line: parseInt(lineNumber),
|
|
53
|
-
column: parseInt(columnNumber)
|
|
54
|
-
};
|
|
55
|
-
}).filter(notNullish);
|
|
56
|
-
e.stacks = stackFrames;
|
|
57
|
-
return stackFrames;
|
|
58
|
-
}
|
|
59
|
-
function posToNumber(source, pos) {
|
|
60
|
-
if (typeof pos === "number")
|
|
61
|
-
return pos;
|
|
62
|
-
const lines = source.split(lineSplitRE);
|
|
63
|
-
const { line, column } = pos;
|
|
64
|
-
let start = 0;
|
|
65
|
-
if (line > lines.length)
|
|
66
|
-
return source.length;
|
|
67
|
-
for (let i = 0; i < line - 1; i++)
|
|
68
|
-
start += lines[i].length + 1;
|
|
69
|
-
return start + column;
|
|
70
|
-
}
|
|
71
|
-
function numberToPos(source, offset) {
|
|
72
|
-
if (typeof offset !== "number")
|
|
73
|
-
return offset;
|
|
74
|
-
if (offset > source.length) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
`offset is longer than source length! offset ${offset} > length ${source.length}`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
const lines = source.split(lineSplitRE);
|
|
80
|
-
let counted = 0;
|
|
81
|
-
let line = 0;
|
|
82
|
-
let column = 0;
|
|
83
|
-
for (; line < lines.length; line++) {
|
|
84
|
-
const lineLength = lines[line].length + 1;
|
|
85
|
-
if (counted + lineLength >= offset) {
|
|
86
|
-
column = offset - counted + 1;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
counted += lineLength;
|
|
90
|
-
}
|
|
91
|
-
return { line: line + 1, column };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { posToNumber as a, lineSplitRE as l, numberToPos as n, parseStacktrace as p };
|