vitest 0.0.117 → 0.0.121
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/cli.js +28 -10
- package/dist/{constants-080f26e8.js → constants-22bbd600.js} +1 -1
- package/dist/{diff-80c47cfa.js → diff-a295cb37.js} +1 -1
- package/dist/entry.js +81 -32
- package/dist/{global-d95ee155.js → global-f5814404.js} +5 -5
- package/dist/{index-bf29f0e6.js → index-090545ef.js} +1 -19
- package/dist/{index-33d800eb.js → index-123a18df.js} +60 -36
- package/dist/{index-2b1f526f.js → index-32bc2073.js} +2 -2
- package/dist/index.d.ts +93 -60
- package/dist/index.js +4 -4
- package/dist/{jest-mock-4a754991.js → jest-mock-038a01b3.js} +1 -1
- package/dist/node.d.ts +14 -3
- package/dist/node.js +4 -4
- package/dist/{setup-95b119ff.js → setup-c9c7cb5b.js} +3 -3
- package/dist/utils.js +1 -1
- package/dist/{vi-39f06eb7.js → vi-db2bc738.js} +104 -24
- package/dist/worker.js +36 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ViteDevServer } from 'vite';
|
|
|
3
3
|
import { RawSourceMap } from 'source-map-js';
|
|
4
4
|
import { OptionsReceived } from 'pretty-format';
|
|
5
5
|
import { MessagePort } from 'worker_threads';
|
|
6
|
+
import { SpyImpl } from 'tinyspy';
|
|
6
7
|
export { Spy, SpyFn } from 'tinyspy';
|
|
7
8
|
export { assert, default as chai, should } from 'chai';
|
|
8
9
|
|
|
@@ -85,9 +86,9 @@ declare type MatcherState = {
|
|
|
85
86
|
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
86
87
|
expand?: boolean;
|
|
87
88
|
expectedAssertionsNumber?: number | null;
|
|
88
|
-
expectedAssertionsNumberError?: Error;
|
|
89
|
+
expectedAssertionsNumberError?: Error | null;
|
|
89
90
|
isExpectingAssertions?: boolean;
|
|
90
|
-
isExpectingAssertionsError?: Error;
|
|
91
|
+
isExpectingAssertionsError?: Error | null;
|
|
91
92
|
isNot: boolean;
|
|
92
93
|
promise: string;
|
|
93
94
|
suppressedErrors: Array<Error>;
|
|
@@ -177,8 +178,8 @@ interface WorkerPool {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
declare class StateManager {
|
|
180
|
-
filesMap:
|
|
181
|
-
idMap:
|
|
181
|
+
filesMap: Map<string, File>;
|
|
182
|
+
idMap: Map<string, Task>;
|
|
182
183
|
taskFileMap: WeakMap<Task, File>;
|
|
183
184
|
getFiles(keys?: string[]): File[];
|
|
184
185
|
collectFiles(files?: File[]): void;
|
|
@@ -204,6 +205,7 @@ declare class Vitest {
|
|
|
204
205
|
changedTests: Set<string>;
|
|
205
206
|
visitedFilesMap: Map<string, RawSourceMap>;
|
|
206
207
|
runningPromise?: Promise<void>;
|
|
208
|
+
closingPromise?: Promise<void>;
|
|
207
209
|
isFirstRun: boolean;
|
|
208
210
|
restartsCount: number;
|
|
209
211
|
private _onRestartListeners;
|
|
@@ -624,6 +626,10 @@ interface InlineConfig {
|
|
|
624
626
|
* @internal WIP
|
|
625
627
|
*/
|
|
626
628
|
open?: boolean;
|
|
629
|
+
/**
|
|
630
|
+
* run test names with the specified pattern
|
|
631
|
+
*/
|
|
632
|
+
testNamePattern?: string | RegExp;
|
|
627
633
|
/**
|
|
628
634
|
* Listen to port and serve API
|
|
629
635
|
*
|
|
@@ -672,10 +678,16 @@ interface UserConfig extends InlineConfig {
|
|
|
672
678
|
* Pass with no tests
|
|
673
679
|
*/
|
|
674
680
|
passWithNoTests?: boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Run tests that cover a list of source files
|
|
683
|
+
*/
|
|
684
|
+
findRelatedTests?: string[] | string;
|
|
675
685
|
}
|
|
676
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage'> {
|
|
686
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'findRelatedTests'> {
|
|
677
687
|
config?: string;
|
|
678
688
|
filters?: string[];
|
|
689
|
+
testNamePattern?: RegExp;
|
|
690
|
+
findRelatedTests?: string[];
|
|
679
691
|
depsInline: (string | RegExp)[];
|
|
680
692
|
depsExternal: (string | RegExp)[];
|
|
681
693
|
coverage: ResolvedC8Options;
|
|
@@ -776,6 +788,7 @@ declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
|
|
|
776
788
|
};
|
|
777
789
|
declare type MaybeMockedDeep<T> = T extends MockableFunction ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
|
|
778
790
|
declare type MaybeMocked<T> = T extends MockableFunction ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
|
|
791
|
+
declare type EnhancedSpy<TArgs extends any[] = any[], TReturns = any> = JestMockCompat<TArgs, TReturns> & SpyImpl<TArgs, TReturns>;
|
|
779
792
|
interface MockWithArgs<T extends MockableFunction> extends JestMockCompatFn<ArgumentsOf<T>, ReturnType<T>> {
|
|
780
793
|
new (...args: ConstructorArgumentsOf<T>): T;
|
|
781
794
|
(...args: ArgumentsOf<T>): ReturnType<T>;
|
|
@@ -866,6 +879,15 @@ declare class VitestUtils {
|
|
|
866
879
|
declare const vitest: VitestUtils;
|
|
867
880
|
declare const vi: VitestUtils;
|
|
868
881
|
|
|
882
|
+
interface WebSocketHandlers {
|
|
883
|
+
getFiles(): File[];
|
|
884
|
+
getConfig(): ResolvedConfig;
|
|
885
|
+
getSourceCode(id: string): Promise<string>;
|
|
886
|
+
rerun(files: string[]): Promise<void>;
|
|
887
|
+
}
|
|
888
|
+
interface WebSocketEvents extends Pick<Reporter, 'onCollected' | 'onTaskUpdate'> {
|
|
889
|
+
}
|
|
890
|
+
|
|
869
891
|
declare type VitestInlineConfig = InlineConfig;
|
|
870
892
|
|
|
871
893
|
declare module 'vite' {
|
|
@@ -876,69 +898,80 @@ declare module 'vite' {
|
|
|
876
898
|
test?: VitestInlineConfig;
|
|
877
899
|
}
|
|
878
900
|
}
|
|
901
|
+
interface AsymmetricMatchersContaining {
|
|
902
|
+
stringContaining(expected: string): void;
|
|
903
|
+
objectContaining(expected: any): ObjectContaining;
|
|
904
|
+
arrayContaining(expected: unknown[]): ArrayContaining;
|
|
905
|
+
stringMatching(expected: string | RegExp): StringMatching;
|
|
906
|
+
}
|
|
879
907
|
declare global {
|
|
880
908
|
namespace Chai {
|
|
881
|
-
interface ExpectStatic {
|
|
909
|
+
interface ExpectStatic extends AsymmetricMatchersContaining {
|
|
882
910
|
extend(expects: MatchersObject): void;
|
|
883
|
-
|
|
911
|
+
assertions(expected: number): void;
|
|
912
|
+
hasAssertions(): void;
|
|
884
913
|
anything(): Anything;
|
|
885
|
-
objectContaining(expected: any): ObjectContaining;
|
|
886
914
|
any(constructor: unknown): Any;
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
915
|
+
not: AsymmetricMatchersContaining;
|
|
916
|
+
}
|
|
917
|
+
interface JestAssertions<T = void> {
|
|
918
|
+
toMatchSnapshot(message?: string): T;
|
|
919
|
+
toMatchInlineSnapshot(snapshot?: string, message?: string): T;
|
|
920
|
+
matchSnapshot(message?: string): T;
|
|
921
|
+
toEqual(expected: any): T;
|
|
922
|
+
toStrictEqual(expected: any): T;
|
|
923
|
+
toBe(expected: any): T;
|
|
924
|
+
toMatch(expected: string | RegExp): T;
|
|
925
|
+
toMatchObject(expected: any): T;
|
|
926
|
+
toContain(item: any): T;
|
|
927
|
+
toContainEqual(item: any): T;
|
|
928
|
+
toBeTruthy(): T;
|
|
929
|
+
toBeFalsy(): T;
|
|
930
|
+
toBeGreaterThan(num: number): T;
|
|
931
|
+
toBeGreaterThanOrEqual(num: number): T;
|
|
932
|
+
toBeLessThan(num: number): T;
|
|
933
|
+
toBeLessThanOrEqual(num: number): T;
|
|
934
|
+
toBeNaN(): T;
|
|
935
|
+
toBeUndefined(): T;
|
|
936
|
+
toBeNull(): T;
|
|
937
|
+
toBeDefined(): T;
|
|
938
|
+
toBeInstanceOf(c: any): T;
|
|
939
|
+
toBeCalledTimes(n: number): T;
|
|
940
|
+
toHaveLength(l: number): T;
|
|
941
|
+
toHaveProperty(p: string, value?: any): T;
|
|
942
|
+
toBeCloseTo(number: number, numDigits?: number): T;
|
|
943
|
+
toHaveBeenCalledTimes(n: number): T;
|
|
944
|
+
toHaveBeenCalledOnce(): T;
|
|
945
|
+
toHaveBeenCalled(): T;
|
|
946
|
+
toBeCalled(): T;
|
|
947
|
+
toHaveBeenCalledWith(...args: any[]): T;
|
|
948
|
+
toBeCalledWith(...args: any[]): T;
|
|
949
|
+
toHaveBeenNthCalledWith(n: number, ...args: any[]): T;
|
|
950
|
+
nthCalledWith(n: number, ...args: any[]): T;
|
|
951
|
+
toHaveBeenLastCalledWith(...args: any[]): T;
|
|
952
|
+
lastCalledWith(...args: any[]): T;
|
|
953
|
+
toThrow(expected?: string | RegExp): T;
|
|
954
|
+
toThrowError(expected?: string | RegExp): T;
|
|
955
|
+
toReturn(): T;
|
|
956
|
+
toHaveReturned(): T;
|
|
957
|
+
toReturnTimes(times: number): T;
|
|
958
|
+
toHaveReturnedTimes(times: number): T;
|
|
959
|
+
toReturnWith(value: any): T;
|
|
960
|
+
toHaveReturnedWith(value: any): T;
|
|
961
|
+
toHaveLastReturnedWith(value: any): T;
|
|
962
|
+
lastReturnedWith(value: any): T;
|
|
963
|
+
toHaveNthReturnedWith(nthCall: number, value: any): T;
|
|
964
|
+
nthReturnedWith(nthCall: number, value: any): T;
|
|
890
965
|
}
|
|
891
|
-
|
|
966
|
+
type Promisify<O> = {
|
|
967
|
+
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? O extends R ? Promisify<O[K]> : (...args: A) => Promise<R> : O[K];
|
|
968
|
+
};
|
|
969
|
+
interface Assertion extends JestAssertions {
|
|
970
|
+
resolves: Promisify<Assertion>;
|
|
971
|
+
rejects: Promisify<Assertion>;
|
|
892
972
|
chaiEqual(expected: any): void;
|
|
893
|
-
toMatchSnapshot(message?: string): Assertion;
|
|
894
|
-
toMatchInlineSnapshot(snapshot?: string, message?: string): Assertion;
|
|
895
|
-
matchSnapshot(message?: string): Assertion;
|
|
896
|
-
toEqual(expected: any): void;
|
|
897
|
-
toStrictEqual(expected: any): void;
|
|
898
|
-
toBe(expected: any): void;
|
|
899
|
-
toMatch(expected: string | RegExp): void;
|
|
900
|
-
toMatchObject(expected: any): void;
|
|
901
|
-
toContain(item: any): void;
|
|
902
|
-
toContainEqual(item: any): void;
|
|
903
|
-
toBeTruthy(): void;
|
|
904
|
-
toBeFalsy(): void;
|
|
905
|
-
toBeGreaterThan(num: number): void;
|
|
906
|
-
toBeGreaterThanOrEqual(num: number): void;
|
|
907
|
-
toBeLessThan(num: number): void;
|
|
908
|
-
toBeLessThanOrEqual(num: number): void;
|
|
909
|
-
toBeNaN(): void;
|
|
910
|
-
toBeUndefined(): void;
|
|
911
|
-
toBeNull(): void;
|
|
912
|
-
toBeDefined(): void;
|
|
913
|
-
toBeInstanceOf(c: any): void;
|
|
914
|
-
toBeCalledTimes(n: number): void;
|
|
915
|
-
toHaveLength(l: number): void;
|
|
916
|
-
toHaveProperty(p: string, value?: any): void;
|
|
917
|
-
toBeCloseTo(number: number, numDigits?: number): void;
|
|
918
|
-
toHaveBeenCalledTimes(n: number): void;
|
|
919
|
-
toHaveBeenCalledOnce(): void;
|
|
920
|
-
toHaveBeenCalled(): void;
|
|
921
|
-
toBeCalled(): void;
|
|
922
|
-
toHaveBeenCalledWith(...args: any[]): void;
|
|
923
|
-
toBeCalledWith(...args: any[]): void;
|
|
924
|
-
toHaveBeenNthCalledWith(n: number, ...args: any[]): void;
|
|
925
|
-
nthCalledWith(n: number, ...args: any[]): void;
|
|
926
|
-
toHaveBeenLastCalledWith(...args: any[]): void;
|
|
927
|
-
lastCalledWith(...args: any[]): void;
|
|
928
|
-
toThrow(expected?: string | RegExp): void;
|
|
929
|
-
toThrowError(expected?: string | RegExp): void;
|
|
930
|
-
toReturn(): void;
|
|
931
|
-
toHaveReturned(): void;
|
|
932
|
-
toReturnTimes(times: number): void;
|
|
933
|
-
toHaveReturnedTimes(times: number): void;
|
|
934
|
-
toReturnWith(value: any): void;
|
|
935
|
-
toHaveReturnedWith(value: any): void;
|
|
936
|
-
toHaveLastReturnedWith(value: any): void;
|
|
937
|
-
lastReturnedWith(value: any): void;
|
|
938
|
-
toHaveNthReturnedWith(nthCall: number, value: any): void;
|
|
939
|
-
nthReturnedWith(nthCall: number, value: any): void;
|
|
940
973
|
}
|
|
941
974
|
}
|
|
942
975
|
}
|
|
943
976
|
|
|
944
|
-
export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, ConstructorArgumentsOf, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable, ParsedStack, Position, PropertyKeysOf, Reporter, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
|
|
977
|
+
export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ComputeMode, ConstructorArgumentsOf, DoneCallback, EnhancedSpy, Environment, EnvironmentReturn, File, HookListener, InlineConfig, JestMockCompat, JestMockCompatContext, JestMockCompatFn, MaybeMocked, MaybeMockedConstructor, MaybeMockedDeep, MethodKeysOf, MockWithArgs, MockableFunction, MockedFunction, MockedFunctionDeep, MockedObject, MockedObjectDeep, ModuleCache, Nullable, ParsedStack, Position, PropertyKeysOf, Reporter, ResolvedConfig, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WebSocketEvents, WebSocketHandlers, WorkerContext, WorkerRPC, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { d as describe, i as it, c as suite, t as test, e as vi, v as vitest } from './vi-
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-
|
|
3
|
-
export { f as fn, s as spies, a as spyOn } from './jest-mock-
|
|
1
|
+
export { d as describe, i as it, c as suite, t as test, e as vi, v as vitest } from './vi-db2bc738.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-32bc2073.js';
|
|
3
|
+
export { f as fn, s as spies, a as spyOn } from './jest-mock-038a01b3.js';
|
|
4
4
|
export { assert, default as chai, should } from 'chai';
|
|
5
|
-
import './index-
|
|
5
|
+
import './index-090545ef.js';
|
|
6
6
|
import 'url';
|
|
7
7
|
import 'tty';
|
|
8
8
|
import 'local-pkg';
|
package/dist/node.d.ts
CHANGED
|
@@ -334,6 +334,10 @@ interface InlineConfig {
|
|
|
334
334
|
* @internal WIP
|
|
335
335
|
*/
|
|
336
336
|
open?: boolean;
|
|
337
|
+
/**
|
|
338
|
+
* run test names with the specified pattern
|
|
339
|
+
*/
|
|
340
|
+
testNamePattern?: string | RegExp;
|
|
337
341
|
/**
|
|
338
342
|
* Listen to port and serve API
|
|
339
343
|
*
|
|
@@ -382,10 +386,16 @@ interface UserConfig extends InlineConfig {
|
|
|
382
386
|
* Pass with no tests
|
|
383
387
|
*/
|
|
384
388
|
passWithNoTests?: boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Run tests that cover a list of source files
|
|
391
|
+
*/
|
|
392
|
+
findRelatedTests?: string[] | string;
|
|
385
393
|
}
|
|
386
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage'> {
|
|
394
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'findRelatedTests'> {
|
|
387
395
|
config?: string;
|
|
388
396
|
filters?: string[];
|
|
397
|
+
testNamePattern?: RegExp;
|
|
398
|
+
findRelatedTests?: string[];
|
|
389
399
|
depsInline: (string | RegExp)[];
|
|
390
400
|
depsExternal: (string | RegExp)[];
|
|
391
401
|
coverage: ResolvedC8Options;
|
|
@@ -408,8 +418,8 @@ interface WorkerPool {
|
|
|
408
418
|
}
|
|
409
419
|
|
|
410
420
|
declare class StateManager {
|
|
411
|
-
filesMap:
|
|
412
|
-
idMap:
|
|
421
|
+
filesMap: Map<string, File>;
|
|
422
|
+
idMap: Map<string, Task>;
|
|
413
423
|
taskFileMap: WeakMap<Task, File>;
|
|
414
424
|
getFiles(keys?: string[]): File[];
|
|
415
425
|
collectFiles(files?: File[]): void;
|
|
@@ -435,6 +445,7 @@ declare class Vitest {
|
|
|
435
445
|
changedTests: Set<string>;
|
|
436
446
|
visitedFilesMap: Map<string, RawSourceMap>;
|
|
437
447
|
runningPromise?: Promise<void>;
|
|
448
|
+
closingPromise?: Promise<void>;
|
|
438
449
|
isFirstRun: boolean;
|
|
439
450
|
restartsCount: number;
|
|
440
451
|
private _onRestartListeners;
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { c as createVitest } from './index-
|
|
2
|
-
import './index-
|
|
1
|
+
export { c as createVitest } from './index-123a18df.js';
|
|
2
|
+
import './index-090545ef.js';
|
|
3
3
|
import 'url';
|
|
4
4
|
import 'tty';
|
|
5
5
|
import 'local-pkg';
|
|
@@ -11,10 +11,10 @@ import 'os';
|
|
|
11
11
|
import 'util';
|
|
12
12
|
import 'stream';
|
|
13
13
|
import 'events';
|
|
14
|
-
import './constants-
|
|
14
|
+
import './constants-22bbd600.js';
|
|
15
15
|
import './magic-string.es-94000aea.js';
|
|
16
16
|
import 'perf_hooks';
|
|
17
|
-
import './diff-
|
|
17
|
+
import './diff-a295cb37.js';
|
|
18
18
|
import './index-648e7ab2.js';
|
|
19
19
|
import './_commonjsHelpers-c9e3b764.js';
|
|
20
20
|
import 'assert';
|
|
@@ -9,8 +9,8 @@ import require$$2 from 'events';
|
|
|
9
9
|
import require$$1 from 'https';
|
|
10
10
|
import require$$2$1 from 'http';
|
|
11
11
|
import require$$7 from 'url';
|
|
12
|
-
import { A as API_PATH } from './constants-
|
|
13
|
-
import './index-
|
|
12
|
+
import { A as API_PATH } from './constants-22bbd600.js';
|
|
13
|
+
import './index-090545ef.js';
|
|
14
14
|
import 'tty';
|
|
15
15
|
import 'local-pkg';
|
|
16
16
|
import 'path';
|
|
@@ -4248,7 +4248,7 @@ function abortHandshake(socket, code, message, headers) {
|
|
|
4248
4248
|
function setup(ctx) {
|
|
4249
4249
|
var _a;
|
|
4250
4250
|
const wss = new websocketServer({ noServer: true });
|
|
4251
|
-
const clients =
|
|
4251
|
+
const clients = new Map();
|
|
4252
4252
|
(_a = ctx.server.httpServer) == null ? void 0 : _a.on("upgrade", (request, socket, head) => {
|
|
4253
4253
|
if (!request.url)
|
|
4254
4254
|
return;
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { l as deepMerge, e as ensurePackageInstalled, g as getFullName,
|
|
1
|
+
export { l as deepMerge, e as ensurePackageInstalled, g as getFullName, v as getNames, f as getSuites, z as getTasks, j as getTests, h as hasFailed, x as hasTests, i as isObject, y as isWindows, p as mergeSlashes, n as noop, o as notNullish, w as partitionSuiteChildren, k as resolvePath, s as slash, t as toArray, m as toFilePath } from './index-090545ef.js';
|
|
2
2
|
import 'url';
|
|
3
3
|
import 'tty';
|
|
4
4
|
import 'local-pkg';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as noop, i as isObject } from './index-
|
|
1
|
+
import { n as noop, i as isObject } from './index-090545ef.js';
|
|
2
2
|
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-c9e3b764.js';
|
|
3
|
-
import { a as spyOn, f as fn, s as spies } from './jest-mock-
|
|
3
|
+
import { a as spyOn, f as fn, s as spies } from './jest-mock-038a01b3.js';
|
|
4
4
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defProps = Object.defineProperties;
|
|
@@ -86,8 +86,8 @@ function normalizeTest(fn, timeout) {
|
|
|
86
86
|
return withTimeout(ensureAsyncTest(fn), timeout);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const fnMap =
|
|
90
|
-
const hooksMap =
|
|
89
|
+
const fnMap = new WeakMap();
|
|
90
|
+
const hooksMap = new WeakMap();
|
|
91
91
|
function setFn(key, fn) {
|
|
92
92
|
fnMap.set(key, fn);
|
|
93
93
|
}
|
|
@@ -206,7 +206,7 @@ function equals(a, b, customTesters, strictCheck) {
|
|
|
206
206
|
function isAsymmetric(obj) {
|
|
207
207
|
return !!obj && isA("Function", obj.asymmetricMatch);
|
|
208
208
|
}
|
|
209
|
-
function hasAsymmetric(obj, seen =
|
|
209
|
+
function hasAsymmetric(obj, seen = new Set()) {
|
|
210
210
|
if (seen.has(obj))
|
|
211
211
|
return false;
|
|
212
212
|
seen.add(obj);
|
|
@@ -410,7 +410,7 @@ const hasPropertyInObject = (object, key) => {
|
|
|
410
410
|
};
|
|
411
411
|
const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
|
|
412
412
|
const subsetEquality = (object, subset) => {
|
|
413
|
-
const subsetEqualityWithContext = (seenReferences =
|
|
413
|
+
const subsetEqualityWithContext = (seenReferences = new WeakMap()) => (object2, subset2) => {
|
|
414
414
|
if (!isObjectWithKeys(subset2))
|
|
415
415
|
return void 0;
|
|
416
416
|
return Object.keys(subset2).every((key) => {
|
|
@@ -459,6 +459,8 @@ const MATCHERS_OBJECT = Symbol.for("matchers-object");
|
|
|
459
459
|
if (!Object.prototype.hasOwnProperty.call(global, MATCHERS_OBJECT)) {
|
|
460
460
|
const defaultState = {
|
|
461
461
|
assertionCalls: 0,
|
|
462
|
+
isExpectingAssertions: false,
|
|
463
|
+
isExpectingAssertionsError: null,
|
|
462
464
|
expectedAssertionsNumber: null,
|
|
463
465
|
expectedAssertionsNumberError: null
|
|
464
466
|
};
|
|
@@ -502,7 +504,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
502
504
|
const expected = args[0];
|
|
503
505
|
const actual = utils.flag(this, "object");
|
|
504
506
|
if (hasAsymmetric(expected)) {
|
|
505
|
-
this.assert(equals(actual, expected), "not match with #{exp}", "should not match with #{exp}",
|
|
507
|
+
this.assert(equals(actual, expected), "not match with #{exp}", "should not match with #{exp}", expected, actual);
|
|
506
508
|
} else {
|
|
507
509
|
_super.apply(this, args);
|
|
508
510
|
}
|
|
@@ -512,7 +514,14 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
512
514
|
return this.eql(expected);
|
|
513
515
|
});
|
|
514
516
|
def("toStrictEqual", function(expected) {
|
|
515
|
-
|
|
517
|
+
const obj = utils.flag(this, "object");
|
|
518
|
+
const equal = equals(obj, expected, [
|
|
519
|
+
iterableEquality,
|
|
520
|
+
typeEquality,
|
|
521
|
+
sparseArrayEquality,
|
|
522
|
+
arrayBufferEquality
|
|
523
|
+
], true);
|
|
524
|
+
return this.assert(equal, "expected #{this} to strictly equal #{exp}", "expected #{this} to not strictly equal #{exp}", expected, obj);
|
|
516
525
|
});
|
|
517
526
|
def("toBe", function(expected) {
|
|
518
527
|
return this.equal(expected);
|
|
@@ -571,6 +580,10 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
571
580
|
return this.be.null;
|
|
572
581
|
});
|
|
573
582
|
def("toBeDefined", function() {
|
|
583
|
+
const negate = utils.flag(this, "negate");
|
|
584
|
+
utils.flag(this, "negate", false);
|
|
585
|
+
if (negate)
|
|
586
|
+
return this.be.undefined;
|
|
574
587
|
return this.not.be.undefined;
|
|
575
588
|
});
|
|
576
589
|
def("toBeInstanceOf", function(obj) {
|
|
@@ -599,20 +612,24 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
599
612
|
};
|
|
600
613
|
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
|
|
601
614
|
const spy = getSpy(this);
|
|
602
|
-
|
|
615
|
+
const spyName = spy.getMockName();
|
|
616
|
+
return this.assert(spy.callCount === number, `expected "${spyName}" to be called #{exp} times`, `expected "${spyName}" to not be called #{exp} times`, number, spy.callCount);
|
|
603
617
|
});
|
|
604
618
|
def("toHaveBeenCalledOnce", function() {
|
|
605
619
|
const spy = getSpy(this);
|
|
606
|
-
|
|
620
|
+
const spyName = spy.getMockName();
|
|
621
|
+
return this.assert(spy.callCount === 1, `expected "${spyName}" to be called once`, `expected "${spyName}" to not be called once`, 1, spy.callCount);
|
|
607
622
|
});
|
|
608
623
|
def(["toHaveBeenCalled", "toBeCalled"], function() {
|
|
609
624
|
const spy = getSpy(this);
|
|
610
|
-
|
|
625
|
+
const spyName = spy.getMockName();
|
|
626
|
+
return this.assert(spy.called, `expected "${spyName}" to be called at least once`, `expected "${spyName}" to not be called at all`, true, spy.called);
|
|
611
627
|
});
|
|
612
628
|
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
|
613
629
|
const spy = getSpy(this);
|
|
630
|
+
const spyName = spy.getMockName();
|
|
614
631
|
const pass = spy.calls.some((callArg) => equals(callArg, args));
|
|
615
|
-
return this.assert(pass,
|
|
632
|
+
return this.assert(pass, `expected "${spyName}" to be called with arguments: #{exp}`, `expected "${spyName}" to not be called with arguments: #{exp}`, args, spy.calls);
|
|
616
633
|
});
|
|
617
634
|
const ordinalOf = (i) => {
|
|
618
635
|
const j = i % 10;
|
|
@@ -627,13 +644,15 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
627
644
|
};
|
|
628
645
|
def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
|
|
629
646
|
const spy = getSpy(this);
|
|
647
|
+
const spyName = spy.getMockName();
|
|
630
648
|
const nthCall = spy.calls[times - 1];
|
|
631
|
-
this.assert(equals(nthCall, args), `expected ${ordinalOf(times)}
|
|
649
|
+
this.assert(equals(nthCall, args), `expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`, `expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`, args, nthCall);
|
|
632
650
|
});
|
|
633
651
|
def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
|
|
634
652
|
const spy = getSpy(this);
|
|
653
|
+
const spyName = spy.getMockName();
|
|
635
654
|
const lastCall = spy.calls[spy.calls.length - 1];
|
|
636
|
-
this.assert(equals(lastCall, args),
|
|
655
|
+
this.assert(equals(lastCall, args), `expected last "${spyName}" call to have been called with #{exp}`, `expected last "${spyName}" call to not have been called with #{exp}`, args, lastCall);
|
|
637
656
|
});
|
|
638
657
|
def(["toThrow", "toThrowError"], function(expected) {
|
|
639
658
|
const negate = utils.flag(this, "negate");
|
|
@@ -644,34 +663,80 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
644
663
|
});
|
|
645
664
|
def(["toHaveReturned", "toReturn"], function() {
|
|
646
665
|
const spy = getSpy(this);
|
|
666
|
+
const spyName = spy.getMockName();
|
|
647
667
|
const calledAndNotThrew = spy.called && !spy.results.some(([type]) => type === "error");
|
|
648
|
-
this.assert(calledAndNotThrew,
|
|
668
|
+
this.assert(calledAndNotThrew, `expected "${spyName}" to be successfully called at least once`, `expected "${spyName}" to not be successfully called`, calledAndNotThrew, !calledAndNotThrew);
|
|
649
669
|
});
|
|
650
670
|
def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
|
|
651
671
|
const spy = getSpy(this);
|
|
672
|
+
const spyName = spy.getMockName();
|
|
652
673
|
const successfullReturns = spy.results.reduce((success, [type]) => type === "error" ? success : ++success, 0);
|
|
653
|
-
this.assert(successfullReturns === times, `expected
|
|
674
|
+
this.assert(successfullReturns === times, `expected "${spyName}" to be successfully called ${times} times`, `expected "${spyName}" to not be successfully called ${times} times`, `expected number of returns: ${times}`, `received number of returns: ${successfullReturns}`);
|
|
654
675
|
});
|
|
655
676
|
def(["toHaveReturnedWith", "toReturnWith"], function(value) {
|
|
656
677
|
const spy = getSpy(this);
|
|
678
|
+
const spyName = spy.getMockName();
|
|
657
679
|
const pass = spy.results.some(([type, result]) => type === "ok" && equals(value, result));
|
|
658
|
-
this.assert(pass,
|
|
680
|
+
this.assert(pass, `expected "${spyName}" to be successfully called with #{exp}`, `expected "${spyName}" to not be successfully called with #{exp}`, value);
|
|
659
681
|
});
|
|
660
682
|
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
|
661
683
|
const spy = getSpy(this);
|
|
684
|
+
const spyName = spy.getMockName();
|
|
662
685
|
const lastResult = spy.returns[spy.returns.length - 1];
|
|
663
686
|
const pass = equals(lastResult, value);
|
|
664
|
-
this.assert(pass,
|
|
687
|
+
this.assert(pass, `expected last "${spyName}" call to return #{exp}`, `expected last "${spyName}" call to not return #{exp}`, value, lastResult);
|
|
665
688
|
});
|
|
666
689
|
def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
|
|
667
690
|
const spy = getSpy(this);
|
|
691
|
+
const spyName = spy.getMockName();
|
|
668
692
|
const isNot = utils.flag(this, "negate");
|
|
669
693
|
const [callType, callResult] = spy.results[nthCall - 1];
|
|
670
694
|
const ordinalCall = `${ordinalOf(nthCall)} call`;
|
|
671
695
|
if (!isNot && callType === "error")
|
|
672
696
|
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
|
|
673
697
|
const nthCallReturn = equals(callResult, value);
|
|
674
|
-
this.assert(nthCallReturn, `expected ${ordinalCall}
|
|
698
|
+
this.assert(nthCallReturn, `expected ${ordinalCall} "${spyName}" call to return #{exp}`, `expected ${ordinalCall} "${spyName}" call to not return #{exp}`, value, callResult);
|
|
699
|
+
});
|
|
700
|
+
utils.addProperty(chai.Assertion.prototype, "resolves", function() {
|
|
701
|
+
utils.flag(this, "promise", "resolves");
|
|
702
|
+
const obj = utils.flag(this, "object");
|
|
703
|
+
const proxy = new Proxy(this, {
|
|
704
|
+
get: (target, key, reciever) => {
|
|
705
|
+
const result = Reflect.get(target, key, reciever);
|
|
706
|
+
if (typeof result !== "function")
|
|
707
|
+
return result instanceof chai.Assertion ? proxy : result;
|
|
708
|
+
return async (...args) => {
|
|
709
|
+
return obj.then((value) => {
|
|
710
|
+
utils.flag(this, "object", value);
|
|
711
|
+
return result.call(this, ...args);
|
|
712
|
+
}, (err) => {
|
|
713
|
+
throw new Error(`promise rejected ${err} instead of resolving`);
|
|
714
|
+
});
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
return proxy;
|
|
719
|
+
});
|
|
720
|
+
utils.addProperty(chai.Assertion.prototype, "rejects", function() {
|
|
721
|
+
utils.flag(this, "promise", "rejects");
|
|
722
|
+
const obj = utils.flag(this, "object");
|
|
723
|
+
const wrapper = typeof obj === "function" ? obj() : obj;
|
|
724
|
+
const proxy = new Proxy(this, {
|
|
725
|
+
get: (target, key, reciever) => {
|
|
726
|
+
const result = Reflect.get(target, key, reciever);
|
|
727
|
+
if (typeof result !== "function")
|
|
728
|
+
return result instanceof chai.Assertion ? proxy : result;
|
|
729
|
+
return async (...args) => {
|
|
730
|
+
return wrapper.then((value) => {
|
|
731
|
+
throw new Error(`promise resolved ${value} instead of rejecting`);
|
|
732
|
+
}, (err) => {
|
|
733
|
+
utils.flag(this, "object", err);
|
|
734
|
+
return result.call(this, ...args);
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
return proxy;
|
|
675
740
|
});
|
|
676
741
|
utils.addMethod(chai.expect, "assertions", function assertions(expected) {
|
|
677
742
|
const error = new Error(`expected number of assertions to be ${expected}, but got ${getState().assertionCalls}`);
|
|
@@ -682,6 +747,15 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
682
747
|
expectedAssertionsNumberError: error
|
|
683
748
|
});
|
|
684
749
|
});
|
|
750
|
+
utils.addMethod(chai.expect, "hasAssertions", function hasAssertions() {
|
|
751
|
+
const error = new Error("expected any number of assertion, but got none");
|
|
752
|
+
if (Error.captureStackTrace)
|
|
753
|
+
Error.captureStackTrace(error, hasAssertions);
|
|
754
|
+
setState({
|
|
755
|
+
isExpectingAssertions: true,
|
|
756
|
+
isExpectingAssertionsError: error
|
|
757
|
+
});
|
|
758
|
+
});
|
|
685
759
|
};
|
|
686
760
|
|
|
687
761
|
var mockdate$1 = {exports: {}};
|
|
@@ -797,6 +871,12 @@ const originalSetInterval = global.setInterval;
|
|
|
797
871
|
const originalClearTimeout = global.clearTimeout;
|
|
798
872
|
const originalClearInterval = global.clearInterval;
|
|
799
873
|
const MAX_LOOPS = 1e4;
|
|
874
|
+
var QueueTaskType;
|
|
875
|
+
(function(QueueTaskType2) {
|
|
876
|
+
QueueTaskType2["Interval"] = "interval";
|
|
877
|
+
QueueTaskType2["Timeout"] = "timeout";
|
|
878
|
+
QueueTaskType2["Immediate"] = "immediate";
|
|
879
|
+
})(QueueTaskType || (QueueTaskType = {}));
|
|
800
880
|
const assertEvery = (assertions, message) => {
|
|
801
881
|
if (assertions.some((a) => !a))
|
|
802
882
|
throw new Error(message);
|
|
@@ -841,8 +921,8 @@ class FakeTimers {
|
|
|
841
921
|
return resultBuilder(id, cb);
|
|
842
922
|
};
|
|
843
923
|
};
|
|
844
|
-
this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory(
|
|
845
|
-
this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory(
|
|
924
|
+
this._setTimeout = spyOn(global, "setTimeout").mockImplementation(spyFactory(QueueTaskType.Timeout, getNodeTimeout));
|
|
925
|
+
this._setInterval = spyOn(global, "setInterval").mockImplementation(spyFactory(QueueTaskType.Interval, getNodeTimeout));
|
|
846
926
|
const clearTimerFactory = (spyType) => (id) => {
|
|
847
927
|
if (id === void 0)
|
|
848
928
|
return;
|
|
@@ -850,8 +930,8 @@ class FakeTimers {
|
|
|
850
930
|
if (index !== -1)
|
|
851
931
|
this._tasksQueue.splice(index, 1);
|
|
852
932
|
};
|
|
853
|
-
this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory(
|
|
854
|
-
this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory(
|
|
933
|
+
this._clearTimeout = spyOn(global, "clearTimeout").mockImplementation(clearTimerFactory(QueueTaskType.Timeout));
|
|
934
|
+
this._clearInterval = spyOn(global, "clearInterval").mockImplementation(clearTimerFactory(QueueTaskType.Interval));
|
|
855
935
|
}
|
|
856
936
|
useRealTimers() {
|
|
857
937
|
this._isMocked = false;
|
|
@@ -947,7 +1027,7 @@ class FakeTimers {
|
|
|
947
1027
|
this._tasksQueue.sort((t1, t2) => {
|
|
948
1028
|
const diff = t1.call.nestedMs - t2.call.nestedMs;
|
|
949
1029
|
if (diff === 0) {
|
|
950
|
-
if (t1.type ===
|
|
1030
|
+
if (t1.type === QueueTaskType.Immediate && t2.type !== QueueTaskType.Immediate)
|
|
951
1031
|
return 1;
|
|
952
1032
|
return 0;
|
|
953
1033
|
}
|