vitest 0.0.120 → 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 +3 -3
- package/dist/entry.js +34 -24
- package/dist/{global-9532b920.js → global-f5814404.js} +2 -2
- package/dist/{index-df5396e4.js → index-123a18df.js} +2 -0
- package/dist/{index-ea959009.js → index-32bc2073.js} +1 -1
- package/dist/index.d.ts +76 -58
- package/dist/index.js +2 -2
- package/dist/node.d.ts +6 -1
- package/dist/node.js +1 -1
- package/dist/{vi-67a5a3b3.js → vi-db2bc738.js} +87 -13
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import { m as mergeStream, g as getStream, c as crossSpawn } from './index-6e709
|
|
|
8
8
|
import require$$0, { constants } from 'os';
|
|
9
9
|
import { s as signalExit } from './index-648e7ab2.js';
|
|
10
10
|
import { e as ensurePackageInstalled } from './index-090545ef.js';
|
|
11
|
-
import { c as createVitest } from './index-
|
|
11
|
+
import { c as createVitest } from './index-123a18df.js';
|
|
12
12
|
import './_commonjsHelpers-c9e3b764.js';
|
|
13
13
|
import 'fs';
|
|
14
14
|
import 'stream';
|
|
@@ -1700,11 +1700,11 @@ function execa(file, args, options) {
|
|
|
1700
1700
|
return mergePromise(spawned, handlePromiseOnce);
|
|
1701
1701
|
}
|
|
1702
1702
|
|
|
1703
|
-
var version = "0.0.
|
|
1703
|
+
var version = "0.0.121";
|
|
1704
1704
|
|
|
1705
1705
|
const CLOSE_TIMEOUT = 1e3;
|
|
1706
1706
|
const cli = cac("vitest");
|
|
1707
|
-
cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open UI", { default: false }).option("-t, --testNamePattern <pattern>", "run test names with the specified pattern").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
|
|
1707
|
+
cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open UI", { default: false }).option("-t, --testNamePattern <pattern>", "run test names with the specified pattern").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--findRelatedTests <filepath>", "run only tests that import specified file").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
|
|
1708
1708
|
cli.command("run [...filters]").action(run);
|
|
1709
1709
|
cli.command("watch [...filters]").action(dev);
|
|
1710
1710
|
cli.command("dev [...filters]").action(dev);
|
package/dist/entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs, { promises } from 'fs';
|
|
2
|
-
import { f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn,
|
|
2
|
+
import { b as getState, f as equals, h as iterableEquality, j as subsetEquality, k as isA, J as JestChaiExpect, l as clearContext, m as defaultSuite, n as setHooks, o as getHooks, p as context, s as setState, q as getFn, e as vi } from './vi-db2bc738.js';
|
|
3
3
|
import { Console } from 'console';
|
|
4
4
|
import { Writable } from 'stream';
|
|
5
5
|
import { importModule } from 'local-pkg';
|
|
@@ -3283,18 +3283,19 @@ const isAsyncFunction = (fn) => typeof fn === "function" && fn[Symbol.toStringTa
|
|
|
3283
3283
|
const getMatcherState = (assertion) => {
|
|
3284
3284
|
const actual = assertion._obj;
|
|
3285
3285
|
const isNot = util.flag(assertion, "negate");
|
|
3286
|
+
const promise = util.flag(assertion, "promise") || "";
|
|
3286
3287
|
const jestUtils = __spreadProps(__spreadValues({}, matcherUtils), {
|
|
3287
3288
|
iterableEquality,
|
|
3288
3289
|
subsetEquality
|
|
3289
3290
|
});
|
|
3290
|
-
const matcherState = {
|
|
3291
|
+
const matcherState = __spreadProps(__spreadValues({
|
|
3291
3292
|
isNot,
|
|
3292
3293
|
utils: jestUtils,
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3294
|
+
promise,
|
|
3295
|
+
equals
|
|
3296
|
+
}, getState()), {
|
|
3296
3297
|
suppressedErrors: []
|
|
3297
|
-
};
|
|
3298
|
+
});
|
|
3298
3299
|
return {
|
|
3299
3300
|
state: matcherState,
|
|
3300
3301
|
isNot,
|
|
@@ -3494,22 +3495,18 @@ class StringMatching extends AsymmetricMatcher {
|
|
|
3494
3495
|
}
|
|
3495
3496
|
}
|
|
3496
3497
|
const JestAsymmetricMatchers = (chai, utils) => {
|
|
3498
|
+
utils.addMethod(chai.expect, "anything", () => new Anything());
|
|
3499
|
+
utils.addMethod(chai.expect, "any", (expected) => new Any(expected));
|
|
3497
3500
|
utils.addMethod(chai.expect, "stringContaining", (expected) => new StringContaining(expected));
|
|
3498
|
-
utils.addMethod(chai.expect, "
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
}
|
|
3507
|
-
utils.addMethod(chai.expect, "arrayContaining", (expected) => {
|
|
3508
|
-
return new ArrayContaining(expected);
|
|
3509
|
-
});
|
|
3510
|
-
utils.addMethod(chai.expect, "stringMatching", (expected) => {
|
|
3511
|
-
return new StringMatching(expected);
|
|
3512
|
-
});
|
|
3501
|
+
utils.addMethod(chai.expect, "objectContaining", (expected) => new ObjectContaining(expected));
|
|
3502
|
+
utils.addMethod(chai.expect, "arrayContaining", (expected) => new ArrayContaining(expected));
|
|
3503
|
+
utils.addMethod(chai.expect, "stringMatching", (expected) => new StringMatching(expected));
|
|
3504
|
+
chai.expect.not = {
|
|
3505
|
+
stringContaining: (expected) => new StringContaining(expected, true),
|
|
3506
|
+
objectContaining: (expected) => new ObjectContaining(expected, true),
|
|
3507
|
+
arrayContaining: (expected) => new ArrayContaining(expected, true),
|
|
3508
|
+
stringMatching: (expected) => new StringMatching(expected, true)
|
|
3509
|
+
};
|
|
3513
3510
|
};
|
|
3514
3511
|
|
|
3515
3512
|
let installed = false;
|
|
@@ -3532,7 +3529,7 @@ async function setupGlobalEnv(config) {
|
|
|
3532
3529
|
setupConsoleLogSpy();
|
|
3533
3530
|
await setupChai();
|
|
3534
3531
|
if (config.global)
|
|
3535
|
-
(await import('./global-
|
|
3532
|
+
(await import('./global-f5814404.js')).registerApiGlobally();
|
|
3536
3533
|
}
|
|
3537
3534
|
function setupConsoleLogSpy() {
|
|
3538
3535
|
const stdout = new Writable({
|
|
@@ -3624,6 +3621,9 @@ function processError(err) {
|
|
|
3624
3621
|
function hash(str, length = 10) {
|
|
3625
3622
|
return createHash("md5").update(str).digest("hex").slice(0, length);
|
|
3626
3623
|
}
|
|
3624
|
+
function inModuleGraph(files) {
|
|
3625
|
+
return files.some((file) => process.__vitest_worker__.moduleCache.has(file));
|
|
3626
|
+
}
|
|
3627
3627
|
async function collectTests(paths, config) {
|
|
3628
3628
|
const files = [];
|
|
3629
3629
|
for (const filepath of paths) {
|
|
@@ -3641,6 +3641,8 @@ async function collectTests(paths, config) {
|
|
|
3641
3641
|
try {
|
|
3642
3642
|
await runSetupFiles(config);
|
|
3643
3643
|
await import(filepath);
|
|
3644
|
+
if (config.findRelatedTests && !inModuleGraph(config.findRelatedTests))
|
|
3645
|
+
continue;
|
|
3644
3646
|
const defaultTasks = await defaultSuite.collect(file);
|
|
3645
3647
|
setHooks(file, getHooks(defaultTasks));
|
|
3646
3648
|
for (const c of [...defaultTasks.tasks, ...context.tasks]) {
|
|
@@ -3755,11 +3757,19 @@ async function runTest(test) {
|
|
|
3755
3757
|
process.__vitest_worker__.current = test;
|
|
3756
3758
|
try {
|
|
3757
3759
|
await callSuiteHook(test.suite, "beforeEach", [test, test.suite]);
|
|
3758
|
-
setState({
|
|
3760
|
+
setState({
|
|
3761
|
+
assertionCalls: 0,
|
|
3762
|
+
isExpectingAssertions: false,
|
|
3763
|
+
isExpectingAssertionsError: null,
|
|
3764
|
+
expectedAssertionsNumber: null,
|
|
3765
|
+
expectedAssertionsNumberError: null
|
|
3766
|
+
});
|
|
3759
3767
|
await getFn(test)();
|
|
3760
|
-
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberError } = getState();
|
|
3768
|
+
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberError, isExpectingAssertions, isExpectingAssertionsError } = getState();
|
|
3761
3769
|
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber)
|
|
3762
3770
|
throw expectedAssertionsNumberError;
|
|
3771
|
+
if (isExpectingAssertions === true && assertionCalls === 0)
|
|
3772
|
+
throw isExpectingAssertionsError;
|
|
3763
3773
|
test.result.state = "pass";
|
|
3764
3774
|
} catch (e) {
|
|
3765
3775
|
test.result.state = "fail";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { g as globalApis } from './constants-22bbd600.js';
|
|
2
|
-
import { i as index } from './index-
|
|
2
|
+
import { i as index } from './index-32bc2073.js';
|
|
3
3
|
import 'url';
|
|
4
4
|
import './index-090545ef.js';
|
|
5
5
|
import 'tty';
|
|
6
6
|
import 'local-pkg';
|
|
7
7
|
import 'path';
|
|
8
|
-
import './vi-
|
|
8
|
+
import './vi-db2bc738.js';
|
|
9
9
|
import './_commonjsHelpers-c9e3b764.js';
|
|
10
10
|
import './jest-mock-038a01b3.js';
|
|
11
11
|
import 'chai';
|
|
@@ -7980,6 +7980,8 @@ function resolveConfig(options, viteConfig) {
|
|
|
7980
7980
|
resolved.setupFiles = Array.from(resolved.setupFiles || []).map((i) => resolve(resolved.root, i));
|
|
7981
7981
|
if (resolved.api === true)
|
|
7982
7982
|
resolved.api = defaultPort;
|
|
7983
|
+
if (options.findRelatedTests)
|
|
7984
|
+
resolved.findRelatedTests = toArray(options.findRelatedTests).map((file) => resolve(resolved.root, file));
|
|
7983
7985
|
return resolved;
|
|
7984
7986
|
}
|
|
7985
7987
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, b as getState, s as setState, c as suite, t as test, d as describe, i as it, v as vitest, e as vi } from './vi-db2bc738.js';
|
|
2
2
|
import chai, { assert, should } from 'chai';
|
|
3
3
|
import { s as spies, a as spyOn, f as fn } from './jest-mock-038a01b3.js';
|
|
4
4
|
|
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>;
|
|
@@ -677,11 +678,16 @@ interface UserConfig extends InlineConfig {
|
|
|
677
678
|
* Pass with no tests
|
|
678
679
|
*/
|
|
679
680
|
passWithNoTests?: boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Run tests that cover a list of source files
|
|
683
|
+
*/
|
|
684
|
+
findRelatedTests?: string[] | string;
|
|
680
685
|
}
|
|
681
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern'> {
|
|
686
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'findRelatedTests'> {
|
|
682
687
|
config?: string;
|
|
683
688
|
filters?: string[];
|
|
684
689
|
testNamePattern?: RegExp;
|
|
690
|
+
findRelatedTests?: string[];
|
|
685
691
|
depsInline: (string | RegExp)[];
|
|
686
692
|
depsExternal: (string | RegExp)[];
|
|
687
693
|
coverage: ResolvedC8Options;
|
|
@@ -782,6 +788,7 @@ declare type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
|
|
|
782
788
|
};
|
|
783
789
|
declare type MaybeMockedDeep<T> = T extends MockableFunction ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
|
|
784
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>;
|
|
785
792
|
interface MockWithArgs<T extends MockableFunction> extends JestMockCompatFn<ArgumentsOf<T>, ReturnType<T>> {
|
|
786
793
|
new (...args: ConstructorArgumentsOf<T>): T;
|
|
787
794
|
(...args: ArgumentsOf<T>): ReturnType<T>;
|
|
@@ -891,69 +898,80 @@ declare module 'vite' {
|
|
|
891
898
|
test?: VitestInlineConfig;
|
|
892
899
|
}
|
|
893
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
|
+
}
|
|
894
907
|
declare global {
|
|
895
908
|
namespace Chai {
|
|
896
|
-
interface ExpectStatic {
|
|
909
|
+
interface ExpectStatic extends AsymmetricMatchersContaining {
|
|
897
910
|
extend(expects: MatchersObject): void;
|
|
898
|
-
|
|
911
|
+
assertions(expected: number): void;
|
|
912
|
+
hasAssertions(): void;
|
|
899
913
|
anything(): Anything;
|
|
900
|
-
objectContaining(expected: any): ObjectContaining;
|
|
901
914
|
any(constructor: unknown): Any;
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
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;
|
|
905
965
|
}
|
|
906
|
-
|
|
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>;
|
|
907
972
|
chaiEqual(expected: any): void;
|
|
908
|
-
toMatchSnapshot(message?: string): Assertion;
|
|
909
|
-
toMatchInlineSnapshot(snapshot?: string, message?: string): Assertion;
|
|
910
|
-
matchSnapshot(message?: string): Assertion;
|
|
911
|
-
toEqual(expected: any): void;
|
|
912
|
-
toStrictEqual(expected: any): void;
|
|
913
|
-
toBe(expected: any): void;
|
|
914
|
-
toMatch(expected: string | RegExp): void;
|
|
915
|
-
toMatchObject(expected: any): void;
|
|
916
|
-
toContain(item: any): void;
|
|
917
|
-
toContainEqual(item: any): void;
|
|
918
|
-
toBeTruthy(): void;
|
|
919
|
-
toBeFalsy(): void;
|
|
920
|
-
toBeGreaterThan(num: number): void;
|
|
921
|
-
toBeGreaterThanOrEqual(num: number): void;
|
|
922
|
-
toBeLessThan(num: number): void;
|
|
923
|
-
toBeLessThanOrEqual(num: number): void;
|
|
924
|
-
toBeNaN(): void;
|
|
925
|
-
toBeUndefined(): void;
|
|
926
|
-
toBeNull(): void;
|
|
927
|
-
toBeDefined(): void;
|
|
928
|
-
toBeInstanceOf(c: any): void;
|
|
929
|
-
toBeCalledTimes(n: number): void;
|
|
930
|
-
toHaveLength(l: number): void;
|
|
931
|
-
toHaveProperty(p: string, value?: any): void;
|
|
932
|
-
toBeCloseTo(number: number, numDigits?: number): void;
|
|
933
|
-
toHaveBeenCalledTimes(n: number): void;
|
|
934
|
-
toHaveBeenCalledOnce(): void;
|
|
935
|
-
toHaveBeenCalled(): void;
|
|
936
|
-
toBeCalled(): void;
|
|
937
|
-
toHaveBeenCalledWith(...args: any[]): void;
|
|
938
|
-
toBeCalledWith(...args: any[]): void;
|
|
939
|
-
toHaveBeenNthCalledWith(n: number, ...args: any[]): void;
|
|
940
|
-
nthCalledWith(n: number, ...args: any[]): void;
|
|
941
|
-
toHaveBeenLastCalledWith(...args: any[]): void;
|
|
942
|
-
lastCalledWith(...args: any[]): void;
|
|
943
|
-
toThrow(expected?: string | RegExp): void;
|
|
944
|
-
toThrowError(expected?: string | RegExp): void;
|
|
945
|
-
toReturn(): void;
|
|
946
|
-
toHaveReturned(): void;
|
|
947
|
-
toReturnTimes(times: number): void;
|
|
948
|
-
toHaveReturnedTimes(times: number): void;
|
|
949
|
-
toReturnWith(value: any): void;
|
|
950
|
-
toHaveReturnedWith(value: any): void;
|
|
951
|
-
toHaveLastReturnedWith(value: any): void;
|
|
952
|
-
lastReturnedWith(value: any): void;
|
|
953
|
-
toHaveNthReturnedWith(nthCall: number, value: any): void;
|
|
954
|
-
nthReturnedWith(nthCall: number, value: any): void;
|
|
955
973
|
}
|
|
956
974
|
}
|
|
957
975
|
}
|
|
958
976
|
|
|
959
|
-
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, WebSocketEvents, WebSocketHandlers, 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,5 +1,5 @@
|
|
|
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-
|
|
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
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
5
|
import './index-090545ef.js';
|
package/dist/node.d.ts
CHANGED
|
@@ -386,11 +386,16 @@ interface UserConfig extends InlineConfig {
|
|
|
386
386
|
* Pass with no tests
|
|
387
387
|
*/
|
|
388
388
|
passWithNoTests?: boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Run tests that cover a list of source files
|
|
391
|
+
*/
|
|
392
|
+
findRelatedTests?: string[] | string;
|
|
389
393
|
}
|
|
390
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern'> {
|
|
394
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'findRelatedTests'> {
|
|
391
395
|
config?: string;
|
|
392
396
|
filters?: string[];
|
|
393
397
|
testNamePattern?: RegExp;
|
|
398
|
+
findRelatedTests?: string[];
|
|
394
399
|
depsInline: (string | RegExp)[];
|
|
395
400
|
depsExternal: (string | RegExp)[];
|
|
396
401
|
coverage: ResolvedC8Options;
|
package/dist/node.js
CHANGED
|
@@ -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: {}};
|