vitest 0.0.125 → 0.0.129
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 +10 -10
- package/dist/{constants-8b3a9b31.js → constants-868b9a2e.js} +2 -2
- package/dist/{diff-3adb959a.js → diff-be830986.js} +1 -1
- package/dist/entry.js +32 -23
- package/dist/{global-3b7dd162.js → global-0254dd68.js} +6 -6
- package/dist/{index-7f52a6d6.js → index-06712022.js} +3 -2
- package/dist/{index-9fdde2e8.js → index-42a3a132.js} +2 -2
- package/dist/{index-ce49e384.js → index-42d44ee5.js} +2 -2
- package/dist/{index-fa899e66.js → index-93dcb598.js} +0 -0
- package/dist/{index-e909c175.js → index-a73f33e0.js} +0 -0
- package/dist/{index-648e7ab2.js → index-cb02ee01.js} +0 -0
- package/dist/{index-6e709f57.js → index-cce5de77.js} +0 -0
- package/dist/{index-37193236.js → index-d30b5ed0.js} +870 -721
- package/dist/index.d.ts +20 -18
- package/dist/index.js +4 -4
- package/dist/{jest-mock-038a01b3.js → jest-mock-30625866.js} +4 -1
- package/dist/{magic-string.es-94000aea.js → magic-string.es-98a8bfa0.js} +0 -0
- package/dist/node.d.ts +17 -16
- package/dist/node.js +8 -8
- package/dist/{setup-b0d2ca33.js → setup-6e09a65a.js} +4 -4
- package/dist/{vi-56df0b20.js → vi-fe26a646.js} +54 -37
- package/dist/worker.js +5 -5
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OptionsReceived, Plugin } from 'pretty-format';
|
|
2
2
|
import { Formatter } from 'picocolors/types';
|
|
3
|
-
import { ViteDevServer } from 'vite';
|
|
3
|
+
import { ViteDevServer, CommonServerOptions } from 'vite';
|
|
4
4
|
import { RawSourceMap } from 'source-map-js';
|
|
5
5
|
import { MessagePort } from 'worker_threads';
|
|
6
6
|
import { SpyImpl } from 'tinyspy';
|
|
@@ -511,6 +511,7 @@ interface SnapshotSummary {
|
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom';
|
|
514
|
+
declare type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
|
|
514
515
|
interface InlineConfig {
|
|
515
516
|
/**
|
|
516
517
|
* Include globs for test files
|
|
@@ -647,24 +648,10 @@ interface InlineConfig {
|
|
|
647
648
|
* Coverage options
|
|
648
649
|
*/
|
|
649
650
|
coverage?: C8Options;
|
|
650
|
-
/**
|
|
651
|
-
* Open Vitest UI
|
|
652
|
-
* @internal WIP
|
|
653
|
-
*/
|
|
654
|
-
open?: boolean;
|
|
655
651
|
/**
|
|
656
652
|
* run test names with the specified pattern
|
|
657
653
|
*/
|
|
658
654
|
testNamePattern?: string | RegExp;
|
|
659
|
-
/**
|
|
660
|
-
* Listen to port and serve API
|
|
661
|
-
*
|
|
662
|
-
* When set to true, the default port is 55555
|
|
663
|
-
*
|
|
664
|
-
* @internal WIP
|
|
665
|
-
* @default false
|
|
666
|
-
*/
|
|
667
|
-
api?: boolean | number;
|
|
668
655
|
/**
|
|
669
656
|
* Will call `.mockClear()` on all spies before each test
|
|
670
657
|
* @default false
|
|
@@ -680,6 +667,19 @@ interface InlineConfig {
|
|
|
680
667
|
* @default false
|
|
681
668
|
*/
|
|
682
669
|
restoreMocks?: boolean;
|
|
670
|
+
/**
|
|
671
|
+
* Serve API options.
|
|
672
|
+
*
|
|
673
|
+
* When set to true, the default port is 51204.
|
|
674
|
+
*
|
|
675
|
+
* @default false
|
|
676
|
+
*/
|
|
677
|
+
api?: boolean | number | ApiConfig;
|
|
678
|
+
/**
|
|
679
|
+
* Open Vitest UI
|
|
680
|
+
* @internal WIP
|
|
681
|
+
*/
|
|
682
|
+
open?: boolean;
|
|
683
683
|
}
|
|
684
684
|
interface UserConfig extends InlineConfig {
|
|
685
685
|
/**
|
|
@@ -709,7 +709,7 @@ interface UserConfig extends InlineConfig {
|
|
|
709
709
|
*/
|
|
710
710
|
related?: string[] | string;
|
|
711
711
|
}
|
|
712
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related'> {
|
|
712
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api'> {
|
|
713
713
|
config?: string;
|
|
714
714
|
filters?: string[];
|
|
715
715
|
testNamePattern?: RegExp;
|
|
@@ -720,6 +720,7 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
|
|
|
720
720
|
interpretDefault: boolean;
|
|
721
721
|
coverage: ResolvedC8Options;
|
|
722
722
|
snapshotOptions: SnapshotStateOptions;
|
|
723
|
+
api?: ApiConfig;
|
|
723
724
|
}
|
|
724
725
|
|
|
725
726
|
interface WorkerContext {
|
|
@@ -822,6 +823,7 @@ interface MockWithArgs<T extends MockableFunction> extends JestMockCompatFn<Argu
|
|
|
822
823
|
(...args: ArgumentsOf<T>): ReturnType<T>;
|
|
823
824
|
}
|
|
824
825
|
declare const spies: Set<JestMockCompat<any[], any>>;
|
|
826
|
+
declare function isMockFunction(fn: any): fn is EnhancedSpy;
|
|
825
827
|
declare function spyOn<T, K extends keyof T>(obj: T, method: K, accessType?: 'get' | 'set'): T[K] extends (...args: infer TArgs) => infer TReturnValue ? JestMockCompat<TArgs, TReturnValue> : JestMockCompat;
|
|
826
828
|
declare type Awaited<T> = T extends Promise<infer R> ? R : never;
|
|
827
829
|
declare function fn<TArgs extends any[] = any[], R = any>(): JestMockCompatFn<TArgs, R>;
|
|
@@ -899,7 +901,7 @@ declare class VitestUtils {
|
|
|
899
901
|
*/
|
|
900
902
|
mocked<T>(item: T, deep?: false): MaybeMocked<T>;
|
|
901
903
|
mocked<T>(item: T, deep: true): MaybeMockedDeep<T>;
|
|
902
|
-
isMockFunction(fn: any):
|
|
904
|
+
isMockFunction(fn: any): fn is EnhancedSpy;
|
|
903
905
|
clearAllMocks(): this;
|
|
904
906
|
resetAllMocks(): this;
|
|
905
907
|
restoreAllMocks(): this;
|
|
@@ -1011,4 +1013,4 @@ declare global {
|
|
|
1011
1013
|
}
|
|
1012
1014
|
}
|
|
1013
1015
|
|
|
1014
|
-
export { ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ConstructorArgumentsOf, DoneCallback, EnhancedSpy, Environment, EnvironmentReturn, ErrorWithDiff, 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 };
|
|
1016
|
+
export { ApiConfig, ArgumentsOf, ArgumentsType, Arrayable, Awaitable, BuiltinEnvironment, ConstructorArgumentsOf, DoneCallback, EnhancedSpy, Environment, EnvironmentReturn, ErrorWithDiff, 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, isMockFunction, 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-fe26a646.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-06712022.js';
|
|
3
|
+
export { f as fn, i as isMockFunction, s as spies, a as spyOn } from './jest-mock-30625866.js';
|
|
4
4
|
export { assert, default as chai, should } from 'chai';
|
|
5
|
-
import './index-
|
|
5
|
+
import './index-42a3a132.js';
|
|
6
6
|
import 'url';
|
|
7
7
|
import 'tty';
|
|
8
8
|
import 'local-pkg';
|
|
@@ -2,6 +2,9 @@ import { util } from 'chai';
|
|
|
2
2
|
import * as tinyspy from 'tinyspy';
|
|
3
3
|
|
|
4
4
|
const spies = new Set();
|
|
5
|
+
function isMockFunction(fn2) {
|
|
6
|
+
return typeof fn2 === "function" && "__isSpy" in fn2 && fn2.__isSpy;
|
|
7
|
+
}
|
|
5
8
|
function spyOn(obj, method, accessType) {
|
|
6
9
|
const dictionary = {
|
|
7
10
|
get: "getter",
|
|
@@ -87,4 +90,4 @@ function fn(implementation) {
|
|
|
87
90
|
}) }, "fn"));
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
export { spyOn as a, fn as f, spies as s };
|
|
93
|
+
export { spyOn as a, fn as f, isMockFunction as i, spies as s };
|
|
File without changes
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ViteDevServer, UserConfig as UserConfig$1 } from 'vite';
|
|
1
|
+
import { CommonServerOptions, ViteDevServer, UserConfig as UserConfig$1 } from 'vite';
|
|
2
2
|
import { RawSourceMap } from 'source-map-js';
|
|
3
3
|
import { OptionsReceived } from 'pretty-format';
|
|
4
4
|
|
|
@@ -227,6 +227,7 @@ interface SnapshotSummary {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
declare type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom';
|
|
230
|
+
declare type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'>;
|
|
230
231
|
interface InlineConfig {
|
|
231
232
|
/**
|
|
232
233
|
* Include globs for test files
|
|
@@ -363,24 +364,10 @@ interface InlineConfig {
|
|
|
363
364
|
* Coverage options
|
|
364
365
|
*/
|
|
365
366
|
coverage?: C8Options;
|
|
366
|
-
/**
|
|
367
|
-
* Open Vitest UI
|
|
368
|
-
* @internal WIP
|
|
369
|
-
*/
|
|
370
|
-
open?: boolean;
|
|
371
367
|
/**
|
|
372
368
|
* run test names with the specified pattern
|
|
373
369
|
*/
|
|
374
370
|
testNamePattern?: string | RegExp;
|
|
375
|
-
/**
|
|
376
|
-
* Listen to port and serve API
|
|
377
|
-
*
|
|
378
|
-
* When set to true, the default port is 55555
|
|
379
|
-
*
|
|
380
|
-
* @internal WIP
|
|
381
|
-
* @default false
|
|
382
|
-
*/
|
|
383
|
-
api?: boolean | number;
|
|
384
371
|
/**
|
|
385
372
|
* Will call `.mockClear()` on all spies before each test
|
|
386
373
|
* @default false
|
|
@@ -396,6 +383,19 @@ interface InlineConfig {
|
|
|
396
383
|
* @default false
|
|
397
384
|
*/
|
|
398
385
|
restoreMocks?: boolean;
|
|
386
|
+
/**
|
|
387
|
+
* Serve API options.
|
|
388
|
+
*
|
|
389
|
+
* When set to true, the default port is 51204.
|
|
390
|
+
*
|
|
391
|
+
* @default false
|
|
392
|
+
*/
|
|
393
|
+
api?: boolean | number | ApiConfig;
|
|
394
|
+
/**
|
|
395
|
+
* Open Vitest UI
|
|
396
|
+
* @internal WIP
|
|
397
|
+
*/
|
|
398
|
+
open?: boolean;
|
|
399
399
|
}
|
|
400
400
|
interface UserConfig extends InlineConfig {
|
|
401
401
|
/**
|
|
@@ -425,7 +425,7 @@ interface UserConfig extends InlineConfig {
|
|
|
425
425
|
*/
|
|
426
426
|
related?: string[] | string;
|
|
427
427
|
}
|
|
428
|
-
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related'> {
|
|
428
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'coverage' | 'testNamePattern' | 'related' | 'api'> {
|
|
429
429
|
config?: string;
|
|
430
430
|
filters?: string[];
|
|
431
431
|
testNamePattern?: RegExp;
|
|
@@ -436,6 +436,7 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters'
|
|
|
436
436
|
interpretDefault: boolean;
|
|
437
437
|
coverage: ResolvedC8Options;
|
|
438
438
|
snapshotOptions: SnapshotStateOptions;
|
|
439
|
+
api?: ApiConfig;
|
|
439
440
|
}
|
|
440
441
|
|
|
441
442
|
declare class SnapshotManager {
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { c as createVitest } from './index-
|
|
1
|
+
export { c as createVitest } from './index-d30b5ed0.js';
|
|
2
2
|
import 'fs';
|
|
3
|
-
import './index-
|
|
3
|
+
import './index-42a3a132.js';
|
|
4
4
|
import 'url';
|
|
5
5
|
import 'tty';
|
|
6
6
|
import 'local-pkg';
|
|
@@ -11,14 +11,14 @@ import 'os';
|
|
|
11
11
|
import 'util';
|
|
12
12
|
import 'stream';
|
|
13
13
|
import 'events';
|
|
14
|
-
import './constants-8b3a9b31.js';
|
|
15
|
-
import './magic-string.es-94000aea.js';
|
|
16
|
-
import 'perf_hooks';
|
|
17
|
-
import './diff-3adb959a.js';
|
|
18
|
-
import './index-648e7ab2.js';
|
|
19
14
|
import './_commonjsHelpers-c9e3b764.js';
|
|
15
|
+
import './constants-868b9a2e.js';
|
|
16
|
+
import './magic-string.es-98a8bfa0.js';
|
|
17
|
+
import 'perf_hooks';
|
|
18
|
+
import './diff-be830986.js';
|
|
19
|
+
import './index-cb02ee01.js';
|
|
20
20
|
import 'assert';
|
|
21
21
|
import 'module';
|
|
22
22
|
import 'worker_threads';
|
|
23
23
|
import 'tinypool';
|
|
24
|
-
import './index-
|
|
24
|
+
import './index-a73f33e0.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promises } from 'fs';
|
|
2
|
-
import { c as createBirpc } from './index-
|
|
2
|
+
import { c as createBirpc } from './index-a73f33e0.js';
|
|
3
3
|
import require$$0$1 from 'stream';
|
|
4
4
|
import require$$0 from 'zlib';
|
|
5
5
|
import require$$3 from 'net';
|
|
@@ -9,10 +9,10 @@ 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-
|
|
12
|
+
import { A as API_PATH } from './constants-868b9a2e.js';
|
|
13
13
|
import { s as shouldExternalize } from './externalize-2f63779d.js';
|
|
14
|
-
import { o as interpretSourcePos, n as parseStacktrace } from './diff-
|
|
15
|
-
import './index-
|
|
14
|
+
import { o as interpretSourcePos, n as parseStacktrace } from './diff-be830986.js';
|
|
15
|
+
import './index-42a3a132.js';
|
|
16
16
|
import 'tty';
|
|
17
17
|
import 'local-pkg';
|
|
18
18
|
import 'path';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as noop, i as isObject } from './index-
|
|
1
|
+
import { n as noop, i as isObject } from './index-42a3a132.js';
|
|
2
|
+
import { i as isMockFunction, a as spyOn, f as fn, s as spies } from './jest-mock-30625866.js';
|
|
2
3
|
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-038a01b3.js';
|
|
4
4
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defProps = Object.defineProperties;
|
|
@@ -2808,6 +2808,20 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2808
2808
|
def("chaiEqual", function(...args) {
|
|
2809
2809
|
return chaiEqual.apply(this, args);
|
|
2810
2810
|
});
|
|
2811
|
+
["throw", "throws", "Throw"].forEach((m) => {
|
|
2812
|
+
utils.overwriteMethod(chai.Assertion.prototype, m, (_super) => {
|
|
2813
|
+
return function(...args) {
|
|
2814
|
+
const promise = utils.flag(this, "promise");
|
|
2815
|
+
const object = utils.flag(this, "object");
|
|
2816
|
+
if (promise === "rejects") {
|
|
2817
|
+
utils.flag(this, "object", () => {
|
|
2818
|
+
throw object;
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
_super.apply(this, args);
|
|
2822
|
+
};
|
|
2823
|
+
});
|
|
2824
|
+
});
|
|
2811
2825
|
utils.overwriteMethod(chai.Assertion.prototype, "equal", (_super) => {
|
|
2812
2826
|
return function(...args) {
|
|
2813
2827
|
const expected = args[0];
|
|
@@ -2861,12 +2875,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2861
2875
|
def("toContainEqual", function(expected) {
|
|
2862
2876
|
const obj = utils.flag(this, "object");
|
|
2863
2877
|
const index = Array.from(obj).findIndex((item) => {
|
|
2864
|
-
|
|
2865
|
-
chai.assert.deepEqual(item, expected);
|
|
2866
|
-
} catch {
|
|
2867
|
-
return false;
|
|
2868
|
-
}
|
|
2869
|
-
return true;
|
|
2878
|
+
return equals(item, expected);
|
|
2870
2879
|
});
|
|
2871
2880
|
this.assert(index !== -1, "expected #{this} to deep equally contain #{exp}", "expected #{this} to not deep equally contain #{exp}", expected);
|
|
2872
2881
|
});
|
|
@@ -2915,15 +2924,24 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2915
2924
|
def("toHaveProperty", function(...args) {
|
|
2916
2925
|
return this.have.deep.nested.property(...args);
|
|
2917
2926
|
});
|
|
2918
|
-
def("toBeCloseTo", function(
|
|
2919
|
-
|
|
2920
|
-
|
|
2927
|
+
def("toBeCloseTo", function(received, precision = 2) {
|
|
2928
|
+
const expected = this._obj;
|
|
2929
|
+
let pass = false;
|
|
2930
|
+
let expectedDiff = 0;
|
|
2931
|
+
let receivedDiff = 0;
|
|
2932
|
+
if (received === Infinity && expected === Infinity) {
|
|
2933
|
+
pass = true;
|
|
2934
|
+
} else if (received === -Infinity && expected === -Infinity) {
|
|
2935
|
+
pass = true;
|
|
2936
|
+
} else {
|
|
2937
|
+
expectedDiff = Math.pow(10, -precision) / 2;
|
|
2938
|
+
receivedDiff = Math.abs(expected - received);
|
|
2939
|
+
pass = receivedDiff < expectedDiff;
|
|
2940
|
+
}
|
|
2941
|
+
return this.assert(pass, `expected #{this} to be close to #{exp}, recieved difference is ${receivedDiff}, but expected ${expectedDiff}`, `expected #{this} to not be close to #{exp}, recieved difference is ${receivedDiff}, but expected ${expectedDiff}`, received, expected);
|
|
2921
2942
|
});
|
|
2922
|
-
function isSpy(putativeSpy) {
|
|
2923
|
-
return typeof putativeSpy === "function" && "__isSpy" in putativeSpy && putativeSpy.__isSpy;
|
|
2924
|
-
}
|
|
2925
2943
|
const assertIsMock = (assertion) => {
|
|
2926
|
-
if (!
|
|
2944
|
+
if (!isMockFunction(assertion._obj))
|
|
2927
2945
|
throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
|
|
2928
2946
|
};
|
|
2929
2947
|
const getSpy = (assertion) => {
|
|
@@ -2933,23 +2951,26 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2933
2951
|
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
|
|
2934
2952
|
const spy = getSpy(this);
|
|
2935
2953
|
const spyName = spy.getMockName();
|
|
2936
|
-
|
|
2954
|
+
const callCount = spy.mock.calls.length;
|
|
2955
|
+
return this.assert(callCount === number, `expected "${spyName}" to be called #{exp} times`, `expected "${spyName}" to not be called #{exp} times`, number, callCount);
|
|
2937
2956
|
});
|
|
2938
2957
|
def("toHaveBeenCalledOnce", function() {
|
|
2939
2958
|
const spy = getSpy(this);
|
|
2940
2959
|
const spyName = spy.getMockName();
|
|
2941
|
-
|
|
2960
|
+
const callCount = spy.mock.calls.length;
|
|
2961
|
+
return this.assert(callCount === 1, `expected "${spyName}" to be called once`, `expected "${spyName}" to not be called once`, 1, callCount);
|
|
2942
2962
|
});
|
|
2943
2963
|
def(["toHaveBeenCalled", "toBeCalled"], function() {
|
|
2944
2964
|
const spy = getSpy(this);
|
|
2945
2965
|
const spyName = spy.getMockName();
|
|
2946
|
-
|
|
2966
|
+
const called = spy.mock.calls.length > 0;
|
|
2967
|
+
return this.assert(called, `expected "${spyName}" to be called at least once`, `expected "${spyName}" to not be called at all`, true, called);
|
|
2947
2968
|
});
|
|
2948
2969
|
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
|
|
2949
2970
|
const spy = getSpy(this);
|
|
2950
2971
|
const spyName = spy.getMockName();
|
|
2951
|
-
const pass = spy.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
|
|
2952
|
-
return this.assert(pass, `expected "${spyName}" to be called with arguments: #{exp}`, `expected "${spyName}" to not be called with arguments: #{exp}`, args, spy.calls);
|
|
2972
|
+
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
|
|
2973
|
+
return this.assert(pass, `expected "${spyName}" to be called with arguments: #{exp}`, `expected "${spyName}" to not be called with arguments: #{exp}`, args, spy.mock.calls);
|
|
2953
2974
|
});
|
|
2954
2975
|
const ordinalOf = (i) => {
|
|
2955
2976
|
const j = i % 10;
|
|
@@ -2965,44 +2986,40 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
2965
2986
|
def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
|
|
2966
2987
|
const spy = getSpy(this);
|
|
2967
2988
|
const spyName = spy.getMockName();
|
|
2968
|
-
const nthCall = spy.calls[times - 1];
|
|
2989
|
+
const nthCall = spy.mock.calls[times - 1];
|
|
2969
2990
|
this.assert(equals(nthCall, args, [iterableEquality]), `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);
|
|
2970
2991
|
});
|
|
2971
2992
|
def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
|
|
2972
2993
|
const spy = getSpy(this);
|
|
2973
2994
|
const spyName = spy.getMockName();
|
|
2974
|
-
const lastCall = spy.calls[spy.calls.length - 1];
|
|
2995
|
+
const lastCall = spy.mock.calls[spy.calls.length - 1];
|
|
2975
2996
|
this.assert(equals(lastCall, args, [iterableEquality]), `expected last "${spyName}" call to have been called with #{exp}`, `expected last "${spyName}" call to not have been called with #{exp}`, args, lastCall);
|
|
2976
2997
|
});
|
|
2977
2998
|
def(["toThrow", "toThrowError"], function(expected) {
|
|
2978
|
-
|
|
2979
|
-
if (negate)
|
|
2980
|
-
this.not.to.throw(expected);
|
|
2981
|
-
else
|
|
2982
|
-
this.to.throw(expected);
|
|
2999
|
+
return this.to.throw(expected);
|
|
2983
3000
|
});
|
|
2984
3001
|
def(["toHaveReturned", "toReturn"], function() {
|
|
2985
3002
|
const spy = getSpy(this);
|
|
2986
3003
|
const spyName = spy.getMockName();
|
|
2987
|
-
const calledAndNotThrew = spy.
|
|
3004
|
+
const calledAndNotThrew = spy.mock.calls.length > 0 && !spy.mock.results.some(({ type }) => type === "throw");
|
|
2988
3005
|
this.assert(calledAndNotThrew, `expected "${spyName}" to be successfully called at least once`, `expected "${spyName}" to not be successfully called`, calledAndNotThrew, !calledAndNotThrew);
|
|
2989
3006
|
});
|
|
2990
3007
|
def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
|
|
2991
3008
|
const spy = getSpy(this);
|
|
2992
3009
|
const spyName = spy.getMockName();
|
|
2993
|
-
const successfullReturns = spy.results.reduce((success,
|
|
3010
|
+
const successfullReturns = spy.mock.results.reduce((success, { type }) => type === "throw" ? success : ++success, 0);
|
|
2994
3011
|
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}`);
|
|
2995
3012
|
});
|
|
2996
3013
|
def(["toHaveReturnedWith", "toReturnWith"], function(value) {
|
|
2997
3014
|
const spy = getSpy(this);
|
|
2998
3015
|
const spyName = spy.getMockName();
|
|
2999
|
-
const pass = spy.results.some((
|
|
3016
|
+
const pass = spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result));
|
|
3000
3017
|
this.assert(pass, `expected "${spyName}" to be successfully called with #{exp}`, `expected "${spyName}" to not be successfully called with #{exp}`, value);
|
|
3001
3018
|
});
|
|
3002
3019
|
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
|
|
3003
3020
|
const spy = getSpy(this);
|
|
3004
3021
|
const spyName = spy.getMockName();
|
|
3005
|
-
const lastResult = spy.
|
|
3022
|
+
const { value: lastResult } = spy.mock.results[spy.returns.length - 1];
|
|
3006
3023
|
const pass = equals(lastResult, value);
|
|
3007
3024
|
this.assert(pass, `expected last "${spyName}" call to return #{exp}`, `expected last "${spyName}" call to not return #{exp}`, value, lastResult);
|
|
3008
3025
|
});
|
|
@@ -3010,9 +3027,9 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
3010
3027
|
const spy = getSpy(this);
|
|
3011
3028
|
const spyName = spy.getMockName();
|
|
3012
3029
|
const isNot = utils.flag(this, "negate");
|
|
3013
|
-
const
|
|
3030
|
+
const { type: callType, value: callResult } = spy.mock.results[nthCall - 1];
|
|
3014
3031
|
const ordinalCall = `${ordinalOf(nthCall)} call`;
|
|
3015
|
-
if (!isNot && callType === "
|
|
3032
|
+
if (!isNot && callType === "throw")
|
|
3016
3033
|
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
|
|
3017
3034
|
const nthCallReturn = equals(callResult, value);
|
|
3018
3035
|
this.assert(nthCallReturn, `expected ${ordinalCall} "${spyName}" call to return #{exp}`, `expected ${ordinalCall} "${spyName}" call to not return #{exp}`, value, callResult);
|
|
@@ -3030,7 +3047,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
3030
3047
|
utils.flag(this, "object", value);
|
|
3031
3048
|
return result.call(this, ...args);
|
|
3032
3049
|
}, (err) => {
|
|
3033
|
-
throw new Error(`promise rejected ${err} instead of resolving`);
|
|
3050
|
+
throw new Error(`promise rejected "${err}" instead of resolving`);
|
|
3034
3051
|
});
|
|
3035
3052
|
};
|
|
3036
3053
|
}
|
|
@@ -3048,7 +3065,7 @@ const JestChaiExpect = (chai, utils) => {
|
|
|
3048
3065
|
return result instanceof chai.Assertion ? proxy : result;
|
|
3049
3066
|
return async (...args) => {
|
|
3050
3067
|
return wrapper.then((value) => {
|
|
3051
|
-
throw new Error(`promise resolved ${value} instead of rejecting`);
|
|
3068
|
+
throw new Error(`promise resolved "${value}" instead of rejecting`);
|
|
3052
3069
|
}, (err) => {
|
|
3053
3070
|
utils.flag(this, "object", err);
|
|
3054
3071
|
return result.call(this, ...args);
|
|
@@ -3362,7 +3379,7 @@ class FakeTimers {
|
|
|
3362
3379
|
this._setInterval,
|
|
3363
3380
|
this._clearTimeout,
|
|
3364
3381
|
this._clearInterval
|
|
3365
|
-
], 'timers are not mocked. try calling "
|
|
3382
|
+
], 'timers are not mocked. try calling "vi.useFakeTimers()" first');
|
|
3366
3383
|
}
|
|
3367
3384
|
}
|
|
3368
3385
|
|
|
@@ -3419,7 +3436,7 @@ class VitestUtils {
|
|
|
3419
3436
|
return item;
|
|
3420
3437
|
}
|
|
3421
3438
|
isMockFunction(fn2) {
|
|
3422
|
-
return
|
|
3439
|
+
return isMockFunction(fn2);
|
|
3423
3440
|
}
|
|
3424
3441
|
clearAllMocks() {
|
|
3425
3442
|
__vitest__clearMocks__({ clearMocks: true });
|
package/dist/worker.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { d as dirname, b as basename, k as resolve, p as mergeSlashes, q as join, s as slash, m as toFilePath } from './index-
|
|
2
|
-
import { c as createBirpc } from './index-
|
|
3
|
-
import { c as distDir } from './constants-
|
|
1
|
+
import { d as dirname, b as basename, k as resolve, p as mergeSlashes, q as join, s as slash, m as toFilePath } from './index-42a3a132.js';
|
|
2
|
+
import { c as createBirpc } from './index-a73f33e0.js';
|
|
3
|
+
import { c as distDir } from './constants-868b9a2e.js';
|
|
4
4
|
import { builtinModules, createRequire } from 'module';
|
|
5
5
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
6
6
|
import vm from 'vm';
|
|
7
7
|
import { s as shouldExternalize } from './externalize-2f63779d.js';
|
|
8
8
|
import { existsSync, readdirSync } from 'fs';
|
|
9
|
-
import { a as spyOn, s as spies } from './jest-mock-
|
|
9
|
+
import { a as spyOn, s as spies } from './jest-mock-30625866.js';
|
|
10
10
|
import { r as rpc } from './rpc-8c7cc374.js';
|
|
11
11
|
import 'tty';
|
|
12
12
|
import 'local-pkg';
|
|
@@ -383,7 +383,7 @@ async function startViteNode(ctx) {
|
|
|
383
383
|
return _viteNode;
|
|
384
384
|
}
|
|
385
385
|
function init(ctx) {
|
|
386
|
-
if (process.__vitest_worker__ && ctx.config.threads)
|
|
386
|
+
if (process.__vitest_worker__ && ctx.config.threads && ctx.config.isolate)
|
|
387
387
|
throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${process.__vitest_worker__.ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
|
|
388
388
|
process.stdout.write("\0");
|
|
389
389
|
const { config, port } = ctx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.129",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"strip-ansi": "^7.0.1",
|
|
92
92
|
"typescript": "^4.5.4",
|
|
93
93
|
"ws": "^8.4.0",
|
|
94
|
-
"@vitest/ui": "0.0.
|
|
94
|
+
"@vitest/ui": "0.0.129"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"c8": "*",
|