vitest 0.0.106 → 0.0.110
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/_commonjsHelpers-c9e3b764.js +11 -0
- package/dist/cli.js +8 -9
- package/dist/{constants-82dad049.js → constants-e762cbc5.js} +1 -1
- package/dist/{error-e81aa23d.js → diff-46ee5d7d.js} +50 -40
- package/dist/entry.js +37 -456
- package/dist/global-b8ab5632.js +20 -0
- package/dist/{index-84978a77.js → index-61c8686f.js} +1 -1
- package/dist/{index-1ede1cc5.js → index-9f4b9905.js} +2 -6
- package/dist/{index-77f19d39.js → index-a90f376d.js} +12 -5
- package/dist/{index-8cc284f9.js → index-b183bb20.js} +100 -30
- package/dist/index.d.ts +59 -4
- package/dist/index.js +6 -5
- package/dist/jest-mock-a57b745c.js +101 -0
- package/dist/{middleware-0c8d46aa.js → middleware-093a3bde.js} +2 -4
- package/dist/node.js +6 -7
- package/dist/utils-d97bd6d9.js +349 -0
- package/dist/utils.js +1 -3
- package/dist/vi-aedc8539.js +1018 -0
- package/dist/worker.js +139 -72
- package/package.json +3 -3
- package/vitest.mjs +1 -1
- package/dist/global-0f4da031.js +0 -19
- package/dist/index-9e71c815.js +0 -12
- package/dist/suite-ff89a82e.js +0 -201
- package/dist/utils-92ec89d1.js +0 -814
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './
|
|
2
|
-
import chai, { assert, should
|
|
3
|
-
import { s as spies, a as spyOn, f as fn
|
|
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-aedc8539.js';
|
|
2
|
+
import chai, { assert, should } from 'chai';
|
|
3
|
+
import { s as spies, a as spyOn, f as fn } from './jest-mock-a57b745c.js';
|
|
4
4
|
|
|
5
5
|
const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
6
6
|
const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
7
7
|
const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
8
8
|
const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
|
|
9
9
|
|
|
10
|
+
const expect = (value, message) => {
|
|
11
|
+
const { assertionCalls } = getState();
|
|
12
|
+
setState({ assertionCalls: assertionCalls + 1 });
|
|
13
|
+
return chai.expect(value, message);
|
|
14
|
+
};
|
|
15
|
+
Object.assign(expect, chai.expect);
|
|
16
|
+
|
|
10
17
|
var index = /*#__PURE__*/Object.freeze({
|
|
11
18
|
__proto__: null,
|
|
12
19
|
suite: suite,
|
|
@@ -19,8 +26,8 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
19
26
|
afterEach: afterEach,
|
|
20
27
|
assert: assert,
|
|
21
28
|
should: should,
|
|
22
|
-
expect: expect,
|
|
23
29
|
chai: chai,
|
|
30
|
+
expect: expect,
|
|
24
31
|
spies: spies,
|
|
25
32
|
spyOn: spyOn,
|
|
26
33
|
fn: fn,
|
|
@@ -28,4 +35,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
28
35
|
vi: vi
|
|
29
36
|
});
|
|
30
37
|
|
|
31
|
-
export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, index as i };
|
|
38
|
+
export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, expect as e, index as i };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c, g as getNames,
|
|
1
|
+
import { c, g as getNames, s as slash$1, a as getTests, i as isAbsolute, r as relative, d as dirname, b as basename, f as getSuites, h as resolve, n as noop$1, t as toArray, j as hasFailed } from './utils-d97bd6d9.js';
|
|
2
2
|
import { createServer, mergeConfig } from 'vite';
|
|
3
3
|
import path$a from 'path';
|
|
4
4
|
import process$1 from 'process';
|
|
@@ -7,10 +7,10 @@ import require$$0 from 'os';
|
|
|
7
7
|
import require$$0$1 from 'util';
|
|
8
8
|
import require$$0$2 from 'stream';
|
|
9
9
|
import require$$2 from 'events';
|
|
10
|
-
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-
|
|
10
|
+
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-e762cbc5.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
|
-
import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, F as F_POINTER, d as F_DOWN, e as F_LONG_DASH, f as F_DOWN_RIGHT, g as F_DOT, h as F_CHECK, i as F_CROSS, j as cliTruncate, k as F_RIGHT, p as printError } from './
|
|
13
|
-
import { o as onetime, s as signalExit } from './index-
|
|
12
|
+
import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, F as F_POINTER, d as F_DOWN, e as F_LONG_DASH, f as F_DOWN_RIGHT, g as F_DOT, h as F_CHECK, i as F_CROSS, j as cliTruncate, k as F_RIGHT, p as printError } from './diff-46ee5d7d.js';
|
|
13
|
+
import { o as onetime, s as signalExit } from './index-61c8686f.js';
|
|
14
14
|
import { MessageChannel } from 'worker_threads';
|
|
15
15
|
import { pathToFileURL } from 'url';
|
|
16
16
|
import { Tinypool } from 'tinypool';
|
|
@@ -7242,23 +7242,27 @@ const spinnerMap = /* @__PURE__ */ new WeakMap();
|
|
|
7242
7242
|
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
7243
7243
|
const pointer = c.yellow(F_POINTER);
|
|
7244
7244
|
const skipped = c.yellow(F_DOWN);
|
|
7245
|
-
function
|
|
7245
|
+
function getCols(delta = 0) {
|
|
7246
7246
|
let length = process.stdout.columns;
|
|
7247
7247
|
if (!length || isNaN(length))
|
|
7248
|
-
length =
|
|
7248
|
+
length = 30;
|
|
7249
|
+
return Math.max(length + delta, 0);
|
|
7250
|
+
}
|
|
7251
|
+
function divider(text, left, right) {
|
|
7252
|
+
const cols = getCols();
|
|
7249
7253
|
if (text) {
|
|
7250
7254
|
const textLength = stripAnsi(text).length;
|
|
7251
7255
|
if (left == null && right != null) {
|
|
7252
|
-
left =
|
|
7256
|
+
left = cols - textLength - right;
|
|
7253
7257
|
} else {
|
|
7254
|
-
left = left ?? Math.floor((
|
|
7255
|
-
right =
|
|
7258
|
+
left = left ?? Math.floor((cols - textLength) / 2);
|
|
7259
|
+
right = cols - textLength - left;
|
|
7256
7260
|
}
|
|
7257
7261
|
left = Math.max(0, left);
|
|
7258
7262
|
right = Math.max(0, right);
|
|
7259
7263
|
return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
|
|
7260
7264
|
}
|
|
7261
|
-
return F_LONG_DASH.repeat(
|
|
7265
|
+
return F_LONG_DASH.repeat(cols);
|
|
7262
7266
|
}
|
|
7263
7267
|
function formatTestPath(root, path) {
|
|
7264
7268
|
var _a;
|
|
@@ -7344,6 +7348,15 @@ function getStateSymbol(task) {
|
|
|
7344
7348
|
}
|
|
7345
7349
|
return " ";
|
|
7346
7350
|
}
|
|
7351
|
+
function formatFilepath(path) {
|
|
7352
|
+
const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
|
|
7353
|
+
const basename2 = path.slice(lastSlash);
|
|
7354
|
+
let firstDot = basename2.indexOf(".");
|
|
7355
|
+
if (firstDot < 0)
|
|
7356
|
+
firstDot = basename2.length;
|
|
7357
|
+
firstDot += lastSlash;
|
|
7358
|
+
return c.dim(path.slice(0, lastSlash)) + path.slice(lastSlash, firstDot) + c.dim(path.slice(firstDot));
|
|
7359
|
+
}
|
|
7347
7360
|
function renderTree(tasks, level = 0) {
|
|
7348
7361
|
var _a, _b, _c, _d;
|
|
7349
7362
|
let output = [];
|
|
@@ -7359,7 +7372,10 @@ function renderTree(tasks, level = 0) {
|
|
|
7359
7372
|
if (duration > DURATION_LONG)
|
|
7360
7373
|
suffix += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
|
|
7361
7374
|
}
|
|
7362
|
-
|
|
7375
|
+
let name = task.name;
|
|
7376
|
+
if (level === 0)
|
|
7377
|
+
name = formatFilepath(name);
|
|
7378
|
+
output.push(" ".repeat(level) + prefix + name + suffix);
|
|
7363
7379
|
if (((_b = task.result) == null ? void 0 : _b.state) !== "pass" && outputMap.get(task) != null) {
|
|
7364
7380
|
let data = outputMap.get(task);
|
|
7365
7381
|
if (typeof data === "string") {
|
|
@@ -7369,7 +7385,7 @@ function renderTree(tasks, level = 0) {
|
|
|
7369
7385
|
}
|
|
7370
7386
|
if (data != null) {
|
|
7371
7387
|
const out = `${" ".repeat(level)}${F_RIGHT} ${data}`;
|
|
7372
|
-
output.push(` ${c.gray(cliTruncate(out,
|
|
7388
|
+
output.push(` ${c.gray(cliTruncate(out, getCols(-3)))}`);
|
|
7373
7389
|
}
|
|
7374
7390
|
}
|
|
7375
7391
|
if ((((_c = task.result) == null ? void 0 : _c.state) === "fail" || ((_d = task.result) == null ? void 0 : _d.state) === "run") && task.type === "suite" && task.tasks.length > 0)
|
|
@@ -7483,8 +7499,9 @@ ${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
|
7483
7499
|
this.ctx.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
7484
7500
|
this.ctx.error();
|
|
7485
7501
|
for (const suite of failedSuites) {
|
|
7502
|
+
const filepath = (suite == null ? void 0 : suite.filepath) || "";
|
|
7486
7503
|
this.ctx.error(c.red(`
|
|
7487
|
-
- ${getFullName(suite)}`));
|
|
7504
|
+
- ${getFullName(suite)} ${c.dim(`[ ${this.relative(filepath)} ]`)}`));
|
|
7488
7505
|
await printError((_a = suite.result) == null ? void 0 : _a.error, this.ctx);
|
|
7489
7506
|
errorDivider();
|
|
7490
7507
|
}
|
|
@@ -8641,16 +8658,68 @@ MagicString.prototype.trimStart = function trimStart (charType) {
|
|
|
8641
8658
|
return this;
|
|
8642
8659
|
};
|
|
8643
8660
|
|
|
8644
|
-
const mockRegexp = /\b(?:vitest|vi)\s*.\s*
|
|
8661
|
+
const mockRegexp = /\b((?:vitest|vi)\s*.\s*mock\(["`'\s](.*[@\w_-]+)["`'\s])[),]{1}/;
|
|
8662
|
+
const pathRegexp = /\b(?:vitest|vi)\s*.\s*(unmock|importActual|importMock)\(["`'\s](.*[@\w_-]+)["`'\s]\);?/mg;
|
|
8663
|
+
const isComment = (line) => {
|
|
8664
|
+
const commentStarts = ["//", "/*", "*"];
|
|
8665
|
+
line = line.trim();
|
|
8666
|
+
return commentStarts.some((cmt) => line.startsWith(cmt));
|
|
8667
|
+
};
|
|
8668
|
+
const parseMocks = (code) => {
|
|
8669
|
+
const splitted = code.split("\n");
|
|
8670
|
+
const mockCalls = {};
|
|
8671
|
+
let mockCall = 0;
|
|
8672
|
+
let lineIndex = -1;
|
|
8673
|
+
while (lineIndex < splitted.length) {
|
|
8674
|
+
lineIndex++;
|
|
8675
|
+
const line = splitted[lineIndex];
|
|
8676
|
+
if (!line)
|
|
8677
|
+
break;
|
|
8678
|
+
const mock = mockCalls[mockCall] || {
|
|
8679
|
+
code: "",
|
|
8680
|
+
declaraton: "",
|
|
8681
|
+
path: ""
|
|
8682
|
+
};
|
|
8683
|
+
if (!mock.code) {
|
|
8684
|
+
const started = mockRegexp.exec(line);
|
|
8685
|
+
if (!started || isComment(line))
|
|
8686
|
+
continue;
|
|
8687
|
+
mock.code += `${line}
|
|
8688
|
+
`;
|
|
8689
|
+
mock.declaraton = started[1];
|
|
8690
|
+
mock.path = started[2];
|
|
8691
|
+
mockCalls[mockCall] = mock;
|
|
8692
|
+
if (line.includes(");")) {
|
|
8693
|
+
mockCall++;
|
|
8694
|
+
continue;
|
|
8695
|
+
}
|
|
8696
|
+
continue;
|
|
8697
|
+
}
|
|
8698
|
+
mock.code += `${line}
|
|
8699
|
+
`;
|
|
8700
|
+
mockCalls[mockCall] = mock;
|
|
8701
|
+
const startNumber = (mock.code.match(/{/g) || []).length;
|
|
8702
|
+
const endNumber = (mock.code.match(/}/g) || []).length;
|
|
8703
|
+
if (line.includes(");")) {
|
|
8704
|
+
if (startNumber === endNumber || startNumber === 0 && endNumber === 0)
|
|
8705
|
+
mockCall++;
|
|
8706
|
+
}
|
|
8707
|
+
}
|
|
8708
|
+
return Object.values(mockCalls);
|
|
8709
|
+
};
|
|
8710
|
+
const getMethodCall = (method, actualPath, importPath) => {
|
|
8711
|
+
let nodeModule = "null";
|
|
8712
|
+
if (actualPath.includes("/node_modules/"))
|
|
8713
|
+
nodeModule = `"${importPath}"`;
|
|
8714
|
+
return `__vitest__${method}__("${actualPath}", ${nodeModule}`;
|
|
8715
|
+
};
|
|
8645
8716
|
const MocksPlugin = () => {
|
|
8646
8717
|
return {
|
|
8647
8718
|
name: "vitest:mock-plugin",
|
|
8648
8719
|
enforce: "post",
|
|
8649
8720
|
async transform(code, id) {
|
|
8650
8721
|
let m;
|
|
8651
|
-
const matchAll =
|
|
8652
|
-
if (!matchAll.length)
|
|
8653
|
-
return;
|
|
8722
|
+
const matchAll = code.matchAll(pathRegexp);
|
|
8654
8723
|
for (const match of matchAll) {
|
|
8655
8724
|
const [line, method, modulePath] = match;
|
|
8656
8725
|
const filepath = await this.resolve(modulePath, id);
|
|
@@ -8658,18 +8727,19 @@ const MocksPlugin = () => {
|
|
|
8658
8727
|
m ?? (m = new MagicString(code));
|
|
8659
8728
|
const start = match.index || 0;
|
|
8660
8729
|
const end = start + line.length;
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8730
|
+
const overwrite = `${getMethodCall(method, filepath.id, modulePath)});`;
|
|
8731
|
+
m.overwrite(start, end, overwrite);
|
|
8732
|
+
}
|
|
8733
|
+
}
|
|
8734
|
+
if (mockRegexp.exec(code)) {
|
|
8735
|
+
const mocks = parseMocks((m == null ? void 0 : m.toString()) || code);
|
|
8736
|
+
for (const mock of mocks) {
|
|
8737
|
+
const filepath = await this.resolve(mock.path, id);
|
|
8738
|
+
if (!filepath)
|
|
8739
|
+
continue;
|
|
8740
|
+
m ?? (m = new MagicString(code));
|
|
8741
|
+
const overwrite = getMethodCall("mock", filepath.id, mock.path);
|
|
8742
|
+
m.prepend(mock.code.replace(mock.declaraton, overwrite));
|
|
8673
8743
|
}
|
|
8674
8744
|
}
|
|
8675
8745
|
if (m) {
|
|
@@ -9113,7 +9183,7 @@ async function createVitest(options, viteOverrides = {}) {
|
|
|
9113
9183
|
ctx.setServer(options, server2);
|
|
9114
9184
|
haveStarted = true;
|
|
9115
9185
|
if (options.api)
|
|
9116
|
-
server2.middlewares.use((await import('./middleware-
|
|
9186
|
+
server2.middlewares.use((await import('./middleware-093a3bde.js')).default(ctx));
|
|
9117
9187
|
}
|
|
9118
9188
|
},
|
|
9119
9189
|
MocksPlugin()
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Formatter } from 'picocolors/types';
|
|
2
2
|
import { OptionsReceived } from 'pretty-format';
|
|
3
3
|
import { MessagePort } from 'worker_threads';
|
|
4
|
-
export {
|
|
4
|
+
export { Spy, SpyFn } from 'tinyspy';
|
|
5
|
+
export { assert, default as chai, should } from 'chai';
|
|
5
6
|
|
|
6
7
|
declare const EXPECTED_COLOR: Formatter;
|
|
7
8
|
declare const RECEIVED_COLOR: Formatter;
|
|
@@ -116,6 +117,7 @@ interface AsymmetricMatcherInterface {
|
|
|
116
117
|
declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
|
|
117
118
|
protected sample: T;
|
|
118
119
|
protected inverse: boolean;
|
|
120
|
+
$$typeof: symbol;
|
|
119
121
|
constructor(sample: T, inverse?: boolean);
|
|
120
122
|
protected getMatcherContext(): State;
|
|
121
123
|
abstract asymmetricMatch(other: unknown): boolean;
|
|
@@ -527,6 +529,8 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
|
|
|
527
529
|
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
|
|
528
530
|
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
|
|
529
531
|
|
|
532
|
+
declare const expect: (value: any, message?: string | undefined) => Chai.Assertion;
|
|
533
|
+
|
|
530
534
|
interface MockResultReturn<T> {
|
|
531
535
|
type: 'return';
|
|
532
536
|
value: T;
|
|
@@ -619,10 +623,60 @@ declare class VitestUtils {
|
|
|
619
623
|
getMockedDate(): string | number | Date | null;
|
|
620
624
|
spyOn: typeof spyOn;
|
|
621
625
|
fn: typeof fn;
|
|
622
|
-
|
|
626
|
+
/**
|
|
627
|
+
* Makes all `imports` to passed module to be mocked.
|
|
628
|
+
* - If there is a factory, will return it's result. The call to `vi.mock` is hoisted to the top of the file,
|
|
629
|
+
* so you don't have access to variables declared in the global file scope, if you didn't put them before imports!
|
|
630
|
+
* - If `__mocks__` folder with file of the same name exist, all imports will
|
|
631
|
+
* return it.
|
|
632
|
+
* - If there is no `__mocks__` folder or a file with the same name inside, will call original
|
|
633
|
+
* module and mock it.
|
|
634
|
+
* @param path Path to the module. Can be aliased, if your config suppors it
|
|
635
|
+
* @param factory Factory for the mocked module. Has the highest priority.
|
|
636
|
+
*/
|
|
637
|
+
mock(path: string, factory?: () => any): void;
|
|
638
|
+
/**
|
|
639
|
+
* Removes module from mocked registry. All subsequent calls to import will
|
|
640
|
+
* return original module even if it was mocked.
|
|
641
|
+
* @param path Path to the module. Can be aliased, if your config suppors it
|
|
642
|
+
*/
|
|
623
643
|
unmock(path: string): void;
|
|
644
|
+
/**
|
|
645
|
+
* Imports module, bypassing all checks if it should be mocked.
|
|
646
|
+
* Can be useful if you want to mock module partially.
|
|
647
|
+
* @example
|
|
648
|
+
* vi.mock('./example', async () => {
|
|
649
|
+
* const axios = await vi.importActual('./example')
|
|
650
|
+
*
|
|
651
|
+
* return { ...axios, get: vi.fn() }
|
|
652
|
+
* })
|
|
653
|
+
* @param path Path to the module. Can be aliased, if your config suppors it
|
|
654
|
+
* @returns Actual module without spies
|
|
655
|
+
*/
|
|
624
656
|
importActual<T>(path: string): Promise<T>;
|
|
625
|
-
|
|
657
|
+
/**
|
|
658
|
+
* Imports a module with all of its properties and nested properties mocked.
|
|
659
|
+
* For the rules applied, see docs.
|
|
660
|
+
* @param path Path to the module. Can be aliased, if your config suppors it
|
|
661
|
+
* @returns Fully mocked module
|
|
662
|
+
*/
|
|
663
|
+
importMock<T>(path: string): Promise<MaybeMockedDeep<T>>;
|
|
664
|
+
/**
|
|
665
|
+
* Type helpers for TypeScript. In reality just returns the object that was passed.
|
|
666
|
+
* @example
|
|
667
|
+
* import example from './example'
|
|
668
|
+
* vi.mock('./example')
|
|
669
|
+
*
|
|
670
|
+
* test('1+1 equals 2' async () => {
|
|
671
|
+
* vi.mocked(example.calc).mockRestore()
|
|
672
|
+
*
|
|
673
|
+
* const res = example.calc(1, '+', 1)
|
|
674
|
+
*
|
|
675
|
+
* expect(res).toBe(2)
|
|
676
|
+
* })
|
|
677
|
+
* @param item Anything that can be mocked
|
|
678
|
+
* @param deep If the object is deeply mocked
|
|
679
|
+
*/
|
|
626
680
|
mocked<T>(item: T, deep?: false): MaybeMocked<T>;
|
|
627
681
|
mocked<T>(item: T, deep: true): MaybeMockedDeep<T>;
|
|
628
682
|
isMockFunction(fn: any): any;
|
|
@@ -653,6 +707,7 @@ declare global {
|
|
|
653
707
|
any(constructor: unknown): Any;
|
|
654
708
|
arrayContaining(expected: any): ArrayContaining;
|
|
655
709
|
stringMatching(expected: RegExp): StringMatching;
|
|
710
|
+
assertions(expected: number): void;
|
|
656
711
|
}
|
|
657
712
|
interface Assertion {
|
|
658
713
|
chaiEqual(expected: any): void;
|
|
@@ -707,4 +762,4 @@ declare global {
|
|
|
707
762
|
}
|
|
708
763
|
}
|
|
709
764
|
|
|
710
|
-
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, PropertyKeysOf, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, fn, it, spies, spyOn, suite, test, vi, vitest };
|
|
765
|
+
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, PropertyKeysOf, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConfig, UserConsoleLog, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, expect, fn, it, spies, spyOn, suite, test, vi, vitest };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { d as describe, i as it,
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './index-
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
import './
|
|
1
|
+
export { d as describe, i as it, c as suite, t as test, e as vi, v as vitest } from './vi-aedc8539.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, e as expect } from './index-a90f376d.js';
|
|
3
|
+
export { f as fn, s as spies, a as spyOn } from './jest-mock-a57b745c.js';
|
|
4
|
+
export { assert, default as chai, should } from 'chai';
|
|
5
|
+
import './utils-d97bd6d9.js';
|
|
6
6
|
import 'tty';
|
|
7
7
|
import 'local-pkg';
|
|
8
8
|
import 'path';
|
|
9
|
+
import './_commonjsHelpers-c9e3b764.js';
|
|
9
10
|
import 'tinyspy';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { util } from 'chai';
|
|
2
|
+
import * as tinyspy from 'tinyspy';
|
|
3
|
+
|
|
4
|
+
let urlAlphabet =
|
|
5
|
+
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
6
|
+
let nanoid = (size = 21) => {
|
|
7
|
+
let id = '';
|
|
8
|
+
let i = size;
|
|
9
|
+
while (i--) {
|
|
10
|
+
id += urlAlphabet[(Math.random() * 64) | 0];
|
|
11
|
+
}
|
|
12
|
+
return id
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const spies = /* @__PURE__ */ new Set();
|
|
16
|
+
function spyOn(obj, method, accessType) {
|
|
17
|
+
const dictionary = {
|
|
18
|
+
get: "getter",
|
|
19
|
+
set: "setter"
|
|
20
|
+
};
|
|
21
|
+
const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
|
|
22
|
+
const stub = tinyspy.spyOn(obj, objMethod);
|
|
23
|
+
return enhanceSpy(stub);
|
|
24
|
+
}
|
|
25
|
+
function enhanceSpy(spy) {
|
|
26
|
+
const stub = spy;
|
|
27
|
+
let implementation;
|
|
28
|
+
const instances = [];
|
|
29
|
+
const mockContext = {
|
|
30
|
+
get calls() {
|
|
31
|
+
return stub.calls;
|
|
32
|
+
},
|
|
33
|
+
get instances() {
|
|
34
|
+
return instances;
|
|
35
|
+
},
|
|
36
|
+
get invocationCallOrder() {
|
|
37
|
+
return [];
|
|
38
|
+
},
|
|
39
|
+
get results() {
|
|
40
|
+
return stub.results.map(([callType, value]) => {
|
|
41
|
+
const type = callType === "error" ? "throw" : "return";
|
|
42
|
+
return { type, value };
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
let onceImplementations = [];
|
|
47
|
+
let name = stub.name;
|
|
48
|
+
stub.getMockName = () => name || "vi.fn()";
|
|
49
|
+
stub.mockName = (n) => {
|
|
50
|
+
name = n;
|
|
51
|
+
return stub;
|
|
52
|
+
};
|
|
53
|
+
stub.mockClear = () => {
|
|
54
|
+
stub.reset();
|
|
55
|
+
return stub;
|
|
56
|
+
};
|
|
57
|
+
stub.mockReset = () => {
|
|
58
|
+
stub.reset();
|
|
59
|
+
implementation = () => void 0;
|
|
60
|
+
onceImplementations = [];
|
|
61
|
+
return stub;
|
|
62
|
+
};
|
|
63
|
+
stub.mockRestore = () => {
|
|
64
|
+
stub.mockReset();
|
|
65
|
+
implementation = void 0;
|
|
66
|
+
return stub;
|
|
67
|
+
};
|
|
68
|
+
stub.getMockImplementation = () => implementation;
|
|
69
|
+
stub.mockImplementation = (fn2) => {
|
|
70
|
+
implementation = fn2;
|
|
71
|
+
return stub;
|
|
72
|
+
};
|
|
73
|
+
stub.mockImplementationOnce = (fn2) => {
|
|
74
|
+
onceImplementations.push(fn2);
|
|
75
|
+
return stub;
|
|
76
|
+
};
|
|
77
|
+
stub.mockReturnThis = () => stub.mockImplementation(function() {
|
|
78
|
+
return this;
|
|
79
|
+
});
|
|
80
|
+
stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
|
|
81
|
+
stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
|
|
82
|
+
stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
|
|
83
|
+
stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
|
|
84
|
+
stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
|
|
85
|
+
stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
|
|
86
|
+
util.addProperty(stub, "mock", () => mockContext);
|
|
87
|
+
stub.willCall(function(...args) {
|
|
88
|
+
instances.push(this);
|
|
89
|
+
const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
|
|
90
|
+
});
|
|
91
|
+
return impl.apply(this, args);
|
|
92
|
+
});
|
|
93
|
+
spies.add(stub);
|
|
94
|
+
return stub;
|
|
95
|
+
}
|
|
96
|
+
function fn(implementation) {
|
|
97
|
+
return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
|
|
98
|
+
}) }, "fn"));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { spyOn as a, fn as f, nanoid as n, spies as s };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { A as API_PATH } from './constants-
|
|
1
|
+
import { A as API_PATH } from './constants-e762cbc5.js';
|
|
2
2
|
import 'url';
|
|
3
|
-
import './utils-
|
|
3
|
+
import './utils-d97bd6d9.js';
|
|
4
4
|
import 'tty';
|
|
5
5
|
import 'local-pkg';
|
|
6
6
|
import 'path';
|
|
7
|
-
import 'chai';
|
|
8
|
-
import 'tinyspy';
|
|
9
7
|
|
|
10
8
|
/*! (c) 2020 Andrea Giammarchi */
|
|
11
9
|
|
package/dist/node.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
export { c as createVitest } from './index-
|
|
2
|
-
import './utils-
|
|
1
|
+
export { c as createVitest } from './index-b183bb20.js';
|
|
2
|
+
import './utils-d97bd6d9.js';
|
|
3
3
|
import 'tty';
|
|
4
4
|
import 'local-pkg';
|
|
5
5
|
import 'path';
|
|
6
|
-
import 'chai';
|
|
7
|
-
import 'tinyspy';
|
|
8
6
|
import 'vite';
|
|
9
7
|
import 'process';
|
|
10
8
|
import 'fs';
|
|
@@ -12,11 +10,12 @@ import 'os';
|
|
|
12
10
|
import 'util';
|
|
13
11
|
import 'stream';
|
|
14
12
|
import 'events';
|
|
15
|
-
import './constants-
|
|
13
|
+
import './constants-e762cbc5.js';
|
|
16
14
|
import 'url';
|
|
17
15
|
import 'perf_hooks';
|
|
18
|
-
import './
|
|
19
|
-
import './index-
|
|
16
|
+
import './diff-46ee5d7d.js';
|
|
17
|
+
import './index-61c8686f.js';
|
|
18
|
+
import './_commonjsHelpers-c9e3b764.js';
|
|
20
19
|
import 'assert';
|
|
21
20
|
import 'worker_threads';
|
|
22
21
|
import 'tinypool';
|