vitest 0.8.2 → 0.8.5

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.
Files changed (41) hide show
  1. package/dist/chunk-api-setup.da2f55ae.js +4442 -0
  2. package/dist/chunk-constants.76cf224a.js +31 -0
  3. package/dist/chunk-defaults.e85b72aa.js +148 -0
  4. package/dist/chunk-install-pkg.7dd40977.js +0 -1
  5. package/dist/chunk-integrations-globals.3713535d.js +24 -0
  6. package/dist/chunk-magic-string.d5e0e473.js +0 -1
  7. package/dist/chunk-runtime-chain.c86f1eb0.js +7131 -0
  8. package/dist/chunk-runtime-mocker.7cc59bee.js +258 -0
  9. package/dist/chunk-runtime-rpc.5263102e.js +8 -0
  10. package/dist/chunk-utils-base.aff0a195.js +408 -0
  11. package/dist/chunk-utils-global.7bcfa03c.js +0 -1
  12. package/dist/chunk-utils-timers.5657f2a4.js +4655 -0
  13. package/dist/chunk-vite-node-externalize.e472da7d.js +13611 -0
  14. package/dist/chunk-vite-node-utils.a6890356.js +9152 -0
  15. package/dist/cli.js +7 -8
  16. package/dist/config.cjs +3 -2
  17. package/dist/config.d.ts +26 -2
  18. package/dist/config.js +3 -2
  19. package/dist/entry.js +83 -52
  20. package/dist/index.d.ts +32 -9
  21. package/dist/index.js +5 -6
  22. package/dist/node.d.ts +20 -4
  23. package/dist/node.js +7 -8
  24. package/dist/spy.js +102 -0
  25. package/dist/vendor-_commonjsHelpers.34b404ce.js +0 -1
  26. package/dist/vendor-index.87b2fc14.js +0 -1
  27. package/dist/vendor-index.ee829ed6.js +0 -1
  28. package/dist/worker.js +5 -6
  29. package/package.json +17 -17
  30. package/dist/chunk-api-setup.f537ec22.js +0 -4443
  31. package/dist/chunk-constants.6062c404.js +0 -32
  32. package/dist/chunk-defaults.e5535971.js +0 -148
  33. package/dist/chunk-integrations-globals.1039302d.js +0 -25
  34. package/dist/chunk-runtime-chain.f873402e.js +0 -7068
  35. package/dist/chunk-runtime-rpc.e8aa1ebe.js +0 -9
  36. package/dist/chunk-utils-base.8408f73a.js +0 -409
  37. package/dist/chunk-utils-path.02d3f287.js +0 -267
  38. package/dist/chunk-utils-timers.7bdeea22.js +0 -4653
  39. package/dist/chunk-vite-node-externalize.a2ee7060.js +0 -13470
  40. package/dist/chunk-vite-node-utils.386c09c4.js +0 -9153
  41. package/dist/jest-mock.js +0 -100
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
- config: ResolvedConfig;
283
+ options: SnapshotStateOptions;
284
284
  summary: SnapshotSummary;
285
- constructor(config: ResolvedConfig);
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>;
@@ -505,6 +508,7 @@ interface UserConsoleLog {
505
508
  type: 'stdout' | 'stderr';
506
509
  taskId?: string;
507
510
  time: number;
511
+ size: number;
508
512
  }
509
513
  interface Position {
510
514
  source?: string;
@@ -774,6 +778,7 @@ interface Reporter {
774
778
  onCollected?: (files?: File[]) => Awaitable<void>;
775
779
  onFinished?: (files?: File[]) => Awaitable<void>;
776
780
  onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
781
+ onTestRemoved?: (trigger?: string) => Awaitable<void>;
777
782
  onWatcherStart?: () => Awaitable<void>;
778
783
  onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
779
784
  onServerRestart?: () => Awaitable<void>;
@@ -786,6 +791,7 @@ interface SnapshotStateOptions {
786
791
  updateSnapshot: SnapshotUpdateState;
787
792
  expand?: boolean;
788
793
  snapshotFormat?: OptionsReceived;
794
+ resolveSnapshotPath?: (path: string, extension: string) => string;
789
795
  }
790
796
  interface SnapshotMatchOptions {
791
797
  testName: string;
@@ -1069,6 +1075,10 @@ interface InlineConfig {
1069
1075
  * Format options for snapshot testing.
1070
1076
  */
1071
1077
  snapshotFormat?: PrettyFormatOptions;
1078
+ /**
1079
+ * Resolve custom snapshot path
1080
+ */
1081
+ resolveSnapshotPath?: (path: string, extension: string) => string;
1072
1082
  }
1073
1083
  interface UserConfig extends InlineConfig {
1074
1084
  /**
@@ -1102,8 +1112,14 @@ interface UserConfig extends InlineConfig {
1102
1112
  * @default 'test'
1103
1113
  */
1104
1114
  mode?: string;
1115
+ /**
1116
+ * Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
1117
+ * Requires initialized git repository
1118
+ * @default false
1119
+ */
1120
+ changed?: boolean | string;
1105
1121
  }
1106
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters'> {
1122
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath'> {
1107
1123
  base?: string;
1108
1124
  config?: string;
1109
1125
  filters?: string[];
@@ -1150,6 +1166,7 @@ interface WorkerRPC {
1150
1166
  onCollected: (files: File[]) => void;
1151
1167
  onTaskUpdate: (pack: TaskResultPack[]) => void;
1152
1168
  snapshotSaved: (snapshot: SnapshotResult) => void;
1169
+ resolveSnapshotPath: (testPath: string) => string;
1153
1170
  }
1154
1171
  interface WorkerGlobalState {
1155
1172
  ctx: WorkerContext;
@@ -1205,11 +1222,12 @@ interface MockResultThrow {
1205
1222
  value: any;
1206
1223
  }
1207
1224
  declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
1208
- interface JestMockCompatContext<TArgs, TReturns> {
1225
+ interface SpyContext<TArgs, TReturns> {
1209
1226
  calls: TArgs[];
1210
1227
  instances: TReturns[];
1211
1228
  invocationCallOrder: number[];
1212
1229
  results: MockResult<TReturns>[];
1230
+ lastCall: TArgs | undefined;
1213
1231
  }
1214
1232
  declare type Procedure = (...args: any[]) => any;
1215
1233
  declare type Methods<T> = {
@@ -1224,7 +1242,7 @@ declare type Classes<T> = {
1224
1242
  interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
1225
1243
  getMockName(): string;
1226
1244
  mockName(n: string): this;
1227
- mock: JestMockCompatContext<TArgs, TReturns>;
1245
+ mock: SpyContext<TArgs, TReturns>;
1228
1246
  mockClear(): this;
1229
1247
  mockReset(): this;
1230
1248
  mockRestore(): void;
@@ -1241,6 +1259,7 @@ interface SpyInstance<TArgs extends any[] = any[], TReturns = any> {
1241
1259
  }
1242
1260
  interface SpyInstanceFn<TArgs extends any[] = any, TReturns = any> extends SpyInstance<TArgs, TReturns> {
1243
1261
  (...args: TArgs): TReturns;
1262
+ new (...args: TArgs): TReturns;
1244
1263
  }
1245
1264
  declare type MaybeMockedConstructor<T> = T extends new (...args: Array<any>) => infer R ? SpyInstanceFn<ConstructorParameters<T>, R> : T;
1246
1265
  declare type MockedFunction<T extends Procedure> = MockWithArgs<T> & {
@@ -1264,8 +1283,6 @@ interface MockWithArgs<T extends Procedure> extends SpyInstanceFn<Parameters<T>,
1264
1283
  new (...args: T extends new (...args: any) => any ? ConstructorParameters<T> : never): T;
1265
1284
  (...args: Parameters<T>): ReturnType<T>;
1266
1285
  }
1267
- declare const spies: Set<SpyInstance<any[], any>>;
1268
- declare function isMockFunction(fn: any): fn is EnhancedSpy;
1269
1286
  declare function spyOn<T, S extends Properties<Required<T>>>(obj: T, methodName: S, accessType: 'get'): SpyInstance<[], T[S]>;
1270
1287
  declare function spyOn<T, G extends Properties<Required<T>>>(obj: T, methodName: G, accessType: 'set'): SpyInstance<[T[G]], void>;
1271
1288
  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;
@@ -1354,6 +1371,12 @@ declare class VitestUtils {
1354
1371
  clearAllMocks(): this;
1355
1372
  resetAllMocks(): this;
1356
1373
  restoreAllMocks(): this;
1374
+ /**
1375
+ * Will put a value on global scope. Useful, if you are
1376
+ * using jsdom/happy-dom and want to mock global variables, like
1377
+ * `IntersectionObserver`.
1378
+ */
1379
+ stubGlobal(name: string | symbol | number, value: any): this;
1357
1380
  }
1358
1381
  declare const vitest: VitestUtils;
1359
1382
  declare const vi: VitestUtils;
@@ -1484,4 +1507,4 @@ declare global {
1484
1507
  }
1485
1508
  }
1486
1509
 
1487
- export { ApiConfig, ArgumentsType$1 as ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, C8Options, Constructable, CoverageReporter, DeepMerge, DoneCallback, EnhancedSpy, Environment, EnvironmentOptions, EnvironmentReturn, ErrorWithDiff, File, HookListener, InlineConfig, JSDOMOptions, JestMockCompatContext, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MergeInsertions, MockWithArgs, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, ModuleGraphData, MutableArray, Nullable, ParsedStack, Position, Reporter, ResolveIdFunction, ResolvedC8Options, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, 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, fn, getRunningMode, isFirstRun, isMockFunction, isWatchMode, it, runOnce, spies, spyOn, suite, test, vi, vitest };
1510
+ 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,15 +1,14 @@
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.f873402e.js';
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.c86f1eb0.js';
3
2
  export { assert, default as chai, should } from 'chai';
4
3
  import 'util';
5
- import './chunk-utils-base.8408f73a.js';
4
+ import './chunk-utils-base.aff0a195.js';
6
5
  import 'path';
7
6
  import 'tty';
8
7
  import 'local-pkg';
9
8
  import './chunk-utils-global.7bcfa03c.js';
10
- import './chunk-utils-timers.7bdeea22.js';
9
+ import './chunk-utils-timers.5657f2a4.js';
11
10
  import './vendor-_commonjsHelpers.34b404ce.js';
12
- import './chunk-runtime-rpc.e8aa1ebe.js';
11
+ import './chunk-runtime-rpc.5263102e.js';
13
12
  import 'fs';
13
+ import './spy.js';
14
14
  import 'tinyspy';
15
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7OyJ9
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>;
@@ -328,6 +329,7 @@ interface UserConsoleLog {
328
329
  type: 'stdout' | 'stderr';
329
330
  taskId?: string;
330
331
  time: number;
332
+ size: number;
331
333
  }
332
334
  interface Position {
333
335
  source?: string;
@@ -538,6 +540,7 @@ interface Reporter {
538
540
  onCollected?: (files?: File[]) => Awaitable<void>;
539
541
  onFinished?: (files?: File[]) => Awaitable<void>;
540
542
  onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>;
543
+ onTestRemoved?: (trigger?: string) => Awaitable<void>;
541
544
  onWatcherStart?: () => Awaitable<void>;
542
545
  onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
543
546
  onServerRestart?: () => Awaitable<void>;
@@ -549,6 +552,7 @@ interface SnapshotStateOptions {
549
552
  updateSnapshot: SnapshotUpdateState;
550
553
  expand?: boolean;
551
554
  snapshotFormat?: OptionsReceived;
555
+ resolveSnapshotPath?: (path: string, extension: string) => string;
552
556
  }
553
557
  interface SnapshotResult {
554
558
  filepath: string;
@@ -824,6 +828,10 @@ interface InlineConfig {
824
828
  * Format options for snapshot testing.
825
829
  */
826
830
  snapshotFormat?: PrettyFormatOptions;
831
+ /**
832
+ * Resolve custom snapshot path
833
+ */
834
+ resolveSnapshotPath?: (path: string, extension: string) => string;
827
835
  }
828
836
  interface UserConfig extends InlineConfig {
829
837
  /**
@@ -857,8 +865,14 @@ interface UserConfig extends InlineConfig {
857
865
  * @default 'test'
858
866
  */
859
867
  mode?: string;
868
+ /**
869
+ * Runs tests that are affected by the changes in the repository, or between specified branch or commit hash
870
+ * Requires initialized git repository
871
+ * @default false
872
+ */
873
+ changed?: boolean | string;
860
874
  }
861
- interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters'> {
875
+ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath'> {
862
876
  base?: string;
863
877
  config?: string;
864
878
  filters?: string[];
@@ -874,11 +888,13 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
874
888
  declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
875
889
 
876
890
  declare class SnapshotManager {
877
- config: ResolvedConfig;
891
+ options: SnapshotStateOptions;
878
892
  summary: SnapshotSummary;
879
- constructor(config: ResolvedConfig);
893
+ extension: string;
894
+ constructor(options: SnapshotStateOptions);
880
895
  clear(): void;
881
896
  add(result: SnapshotResult): void;
897
+ resolvePath(testPath: string): string;
882
898
  }
883
899
 
884
900
  declare type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<void>;
@@ -992,7 +1008,7 @@ declare class VitestMocker {
992
1008
  normalizePath(path: string): string;
993
1009
  getFsPath(path: string, external: string | null): string;
994
1010
  resolveMockPath(mockPath: string, external: string | null): string | null;
995
- mockObject(obj: any): any;
1011
+ mockValue(value: any): any;
996
1012
  unmockPath(path: string): void;
997
1013
  mockPath(path: string, external: string | null, factory?: () => any): void;
998
1014
  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.a2ee7060.js';
2
- export { V as VitestRunner } from './chunk-utils-path.02d3f287.js';
1
+ export { V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-vite-node-externalize.e472da7d.js';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.7cc59bee.js';
3
3
  import 'buffer';
4
4
  import 'path';
5
5
  import 'child_process';
@@ -13,21 +13,20 @@ import 'stream';
13
13
  import 'util';
14
14
  import 'url';
15
15
  import 'os';
16
- import './chunk-utils-base.8408f73a.js';
16
+ import './chunk-utils-base.aff0a195.js';
17
17
  import 'tty';
18
18
  import 'local-pkg';
19
19
  import 'vite';
20
- import './chunk-constants.6062c404.js';
21
- import './chunk-vite-node-utils.386c09c4.js';
20
+ import './chunk-constants.76cf224a.js';
21
+ import './chunk-vite-node-utils.a6890356.js';
22
22
  import 'module';
23
23
  import 'vm';
24
- import './chunk-defaults.e5535971.js';
24
+ import './chunk-defaults.e85b72aa.js';
25
25
  import 'perf_hooks';
26
- import './chunk-utils-timers.7bdeea22.js';
26
+ import './chunk-utils-timers.5657f2a4.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
32
  import './chunk-utils-global.7bcfa03c.js';
33
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm9kZS5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
package/dist/spy.js ADDED
@@ -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.at(-1);
40
+ }
41
+ };
42
+ let onceImplementations = [];
43
+ let name = stub.name;
44
+ stub.getMockName = () => name || "vi.fn()";
45
+ stub.mockName = (n) => {
46
+ name = n;
47
+ return stub;
48
+ };
49
+ stub.mockClear = () => {
50
+ stub.reset();
51
+ instances = [];
52
+ invocations = [];
53
+ return stub;
54
+ };
55
+ stub.mockReset = () => {
56
+ stub.mockClear();
57
+ implementation = () => void 0;
58
+ onceImplementations = [];
59
+ return stub;
60
+ };
61
+ stub.mockRestore = () => {
62
+ stub.mockReset();
63
+ implementation = void 0;
64
+ return stub;
65
+ };
66
+ stub.getMockImplementation = () => implementation;
67
+ stub.mockImplementation = (fn2) => {
68
+ implementation = fn2;
69
+ return stub;
70
+ };
71
+ stub.mockImplementationOnce = (fn2) => {
72
+ onceImplementations.push(fn2);
73
+ return stub;
74
+ };
75
+ stub.mockReturnThis = () => stub.mockImplementation(function() {
76
+ return this;
77
+ });
78
+ stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
79
+ stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
80
+ stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
81
+ stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
82
+ stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
83
+ stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
84
+ Object.defineProperty(stub, "mock", {
85
+ get: () => mockContext
86
+ });
87
+ stub.willCall(function(...args) {
88
+ instances.push(this);
89
+ invocations.push(++callOrder);
90
+ const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
91
+ });
92
+ return impl.apply(this, args);
93
+ });
94
+ spies.add(stub);
95
+ return stub;
96
+ }
97
+ function fn(implementation) {
98
+ return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
99
+ }) }, "fn"));
100
+ }
101
+
102
+ export { fn, isMockFunction, spies, spyOn };
@@ -5,4 +5,3 @@ function commonjsRequire (path) {
5
5
  }
6
6
 
7
7
  export { commonjsGlobal as a, commonjsRequire as c };
8
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVuZG9yLV9jb21tb25qc0hlbHBlcnMuMzRiNDA0Y2UuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7In0=