vitest 0.0.107 → 0.0.108
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 +7 -8
- package/dist/{constants-82dad049.js → constants-e762cbc5.js} +1 -1
- package/dist/{error-e81aa23d.js → diff-46ee5d7d.js} +50 -40
- package/dist/entry.js +20 -8
- package/dist/global-e0d00047.js +20 -0
- package/dist/{index-77f19d39.js → index-0961cf69.js} +2 -2
- package/dist/{index-84978a77.js → index-61c8686f.js} +1 -1
- package/dist/{index-1ede1cc5.js → index-9f4b9905.js} +2 -6
- package/dist/{index-8cc284f9.js → index-a7df3e65.js} +5 -5
- package/dist/index.js +5 -4
- package/dist/jest-mock-8498c46d.js +104 -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-9754296d.js +557 -0
- package/dist/worker.js +3 -3
- package/package.json +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
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
2
|
+
|
|
3
|
+
function getDefaultExportFromCjs (x) {
|
|
4
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function commonjsRequire (path) {
|
|
8
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { commonjsRequire as a, commonjsGlobal as c, getDefaultExportFromCjs as g };
|
package/dist/cli.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import require$$0 from 'readline';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { e as ensurePackageInstalled } from './utils-
|
|
4
|
-
import { c as createVitest } from './index-
|
|
3
|
+
import { e as ensurePackageInstalled } from './utils-d97bd6d9.js';
|
|
4
|
+
import { c as createVitest } from './index-a7df3e65.js';
|
|
5
5
|
import 'tty';
|
|
6
6
|
import 'local-pkg';
|
|
7
7
|
import 'path';
|
|
8
|
-
import 'chai';
|
|
9
|
-
import 'tinyspy';
|
|
10
8
|
import 'vite';
|
|
11
9
|
import 'process';
|
|
12
10
|
import 'fs';
|
|
13
11
|
import 'os';
|
|
14
12
|
import 'util';
|
|
15
13
|
import 'stream';
|
|
16
|
-
import './constants-
|
|
14
|
+
import './constants-e762cbc5.js';
|
|
17
15
|
import 'url';
|
|
18
16
|
import 'perf_hooks';
|
|
19
|
-
import './
|
|
20
|
-
import './index-
|
|
17
|
+
import './diff-46ee5d7d.js';
|
|
18
|
+
import './index-61c8686f.js';
|
|
19
|
+
import './_commonjsHelpers-c9e3b764.js';
|
|
21
20
|
import 'assert';
|
|
22
21
|
import 'worker_threads';
|
|
23
22
|
import 'tinypool';
|
|
@@ -635,7 +634,7 @@ class CAC extends EventEmitter {
|
|
|
635
634
|
|
|
636
635
|
const cac = (name = "") => new CAC(name);
|
|
637
636
|
|
|
638
|
-
var version = "0.0.
|
|
637
|
+
var version = "0.0.108";
|
|
639
638
|
|
|
640
639
|
const cli = cac("vitest");
|
|
641
640
|
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 Vitest UI").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent").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();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
|
-
import {
|
|
2
|
+
import { h as resolve } from './utils-d97bd6d9.js';
|
|
3
3
|
|
|
4
4
|
const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
|
|
5
5
|
const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync, promises } from 'fs';
|
|
2
|
-
import {
|
|
3
|
-
import { p as notNullish, c, r as relative } from './utils-92ec89d1.js';
|
|
2
|
+
import { k as notNullish, c, r as relative } from './utils-d97bd6d9.js';
|
|
4
3
|
|
|
5
4
|
function Diff() {}
|
|
6
5
|
Diff.prototype = {
|
|
@@ -4564,7 +4563,7 @@ async function getSourcePos(ctx, nearest) {
|
|
|
4564
4563
|
return pos;
|
|
4565
4564
|
}
|
|
4566
4565
|
function displayDiff(actual, expected) {
|
|
4567
|
-
console.error(c.gray(unifiedDiff(
|
|
4566
|
+
console.error(c.gray(unifiedDiff(actual, expected)) + "\n");
|
|
4568
4567
|
}
|
|
4569
4568
|
function printErrorMessage(error) {
|
|
4570
4569
|
const errorName = error.name || error.nameStr || "Unknown Error";
|
|
@@ -4672,55 +4671,66 @@ function parseStack(stack) {
|
|
|
4672
4671
|
function unifiedDiff(actual, expected) {
|
|
4673
4672
|
if (actual === expected)
|
|
4674
4673
|
return "";
|
|
4675
|
-
const diffLimit = 10;
|
|
4676
4674
|
const indent = " ";
|
|
4677
|
-
|
|
4678
|
-
|
|
4675
|
+
const diffLimit = 15;
|
|
4676
|
+
const counts = {
|
|
4677
|
+
"+": 0,
|
|
4678
|
+
"-": 0
|
|
4679
|
+
};
|
|
4680
|
+
const expectedLinesCount = 0;
|
|
4681
|
+
const actualLinesCount = 0;
|
|
4682
|
+
let previousState = null;
|
|
4683
|
+
let previousCount = 0;
|
|
4679
4684
|
function preprocess(line) {
|
|
4680
|
-
if (!line)
|
|
4685
|
+
if (!line || line.match(/\\ No newline/))
|
|
4681
4686
|
return;
|
|
4682
|
-
|
|
4683
|
-
|
|
4687
|
+
const char = line[0];
|
|
4688
|
+
if ("-+".includes(char)) {
|
|
4689
|
+
if (previousState !== char) {
|
|
4690
|
+
previousState = char;
|
|
4691
|
+
previousCount = 0;
|
|
4692
|
+
}
|
|
4693
|
+
previousCount++;
|
|
4694
|
+
counts[char]++;
|
|
4695
|
+
if (previousCount === diffLimit)
|
|
4696
|
+
return c.dim(char + " ...");
|
|
4697
|
+
else if (previousCount > diffLimit)
|
|
4684
4698
|
return;
|
|
4685
|
-
expectedLinesCount++;
|
|
4686
|
-
line = line[0] + " " + line.slice(1);
|
|
4687
|
-
const isLastLine = expectedLinesCount === diffLimit;
|
|
4688
|
-
return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
|
|
4689
4699
|
}
|
|
4700
|
+
return line;
|
|
4701
|
+
}
|
|
4702
|
+
const msg = createPatch("string", expected, actual);
|
|
4703
|
+
const lines = msg.split("\n").slice(5).map(preprocess).filter(Boolean);
|
|
4704
|
+
const isCompact = counts["+"] === 1 && counts["-"] === 1 && lines.length === 2;
|
|
4705
|
+
let formatted = lines.map((line) => {
|
|
4690
4706
|
if (line[0] === "-") {
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4707
|
+
line = formatLine(line.slice(1));
|
|
4708
|
+
if (isCompact)
|
|
4709
|
+
return c.green(line);
|
|
4710
|
+
return c.green(`- ${formatLine(line)}`);
|
|
4711
|
+
}
|
|
4712
|
+
if (line[0] === "+") {
|
|
4713
|
+
line = formatLine(line.slice(1));
|
|
4714
|
+
if (isCompact)
|
|
4715
|
+
return c.red(line);
|
|
4716
|
+
return c.red(`+ ${formatLine(line)}`);
|
|
4697
4717
|
}
|
|
4698
4718
|
if (line.match(/@@/))
|
|
4699
4719
|
return "--";
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
${indent}${c.green("- expected")} ${cleanLines[0]}
|
|
4710
|
-
${indent}${c.red("+ actual")} ${cleanLines[1]}`;
|
|
4720
|
+
return " " + line;
|
|
4721
|
+
});
|
|
4722
|
+
if (isCompact) {
|
|
4723
|
+
formatted = [
|
|
4724
|
+
`${c.green("- Expected")} ${formatted[0]}`,
|
|
4725
|
+
`${c.red("+ Received")} ${formatted[1]}`
|
|
4726
|
+
];
|
|
4727
|
+
} else {
|
|
4728
|
+
formatted.unshift(c.green("- Expected -" + expectedLinesCount), c.red("+ Received +" + actualLinesCount), "");
|
|
4711
4729
|
}
|
|
4712
|
-
return
|
|
4713
|
-
${indent}${c.green("- expected")}
|
|
4714
|
-
${indent}${c.red("+ actual")}
|
|
4715
|
-
|
|
4716
|
-
${cleanLines.join("\n")}`;
|
|
4730
|
+
return formatted.map((i) => indent + i).join("\n");
|
|
4717
4731
|
}
|
|
4718
4732
|
function formatLine(line) {
|
|
4719
|
-
return cliTruncate(line, (process.stdout.columns || 80) -
|
|
4720
|
-
}
|
|
4721
|
-
function renderTruncateMessage(indent) {
|
|
4722
|
-
return `
|
|
4723
|
-
${indent}${c.dim("[...truncated]")}`;
|
|
4733
|
+
return cliTruncate(line, (process.stdout.columns || 80) - 4);
|
|
4724
4734
|
}
|
|
4725
4735
|
|
|
4726
4736
|
export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, F_DOWN as d, F_LONG_DASH as e, F_DOWN_RIGHT as f, F_DOT as g, F_CHECK as h, F_CROSS as i, cliTruncate as j, F_RIGHT as k, printError as p, stringWidth as s, unifiedDiff as u };
|
package/dist/entry.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import fs, { promises } from 'fs';
|
|
2
|
-
import {
|
|
2
|
+
import { c as clearContext, e as defaultSuite, f as setHooks, h as getHooks, j as context, k as getFn, b as vi } from './vi-9754296d.js';
|
|
3
3
|
import { Console } from 'console';
|
|
4
4
|
import { Writable } from 'stream';
|
|
5
5
|
import { importModule } from 'local-pkg';
|
|
6
6
|
import chai$1, { expect, util } from 'chai';
|
|
7
|
+
import { a as commonjsRequire, c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
|
|
8
|
+
import { l as index, g as getNames, c as c$1, t as toArray, b as basename, o as interpretOnlyMode, p as partitionSuiteChildren, q as hasTests, j as hasFailed } from './utils-d97bd6d9.js';
|
|
7
9
|
import { r as rpc, s as send } from './rpc-7de86f29.js';
|
|
8
|
-
import { u as unifiedDiff } from './
|
|
10
|
+
import { u as unifiedDiff } from './diff-46ee5d7d.js';
|
|
9
11
|
import { performance } from 'perf_hooks';
|
|
10
|
-
import {
|
|
11
|
-
import { n as nanoid } from './index-9e71c815.js';
|
|
12
|
+
import { n as nanoid } from './jest-mock-8498c46d.js';
|
|
12
13
|
import { format as format$1 } from 'util';
|
|
13
14
|
import 'tty';
|
|
14
15
|
import 'path';
|
|
@@ -3168,14 +3169,12 @@ const stringify = (object, maxDepth = 10) => {
|
|
|
3168
3169
|
try {
|
|
3169
3170
|
result = format_1(object, {
|
|
3170
3171
|
maxDepth,
|
|
3171
|
-
min: true,
|
|
3172
3172
|
plugins: PLUGINS
|
|
3173
3173
|
});
|
|
3174
3174
|
} catch {
|
|
3175
3175
|
result = format_1(object, {
|
|
3176
3176
|
callToJSON: false,
|
|
3177
3177
|
maxDepth,
|
|
3178
|
-
min: true,
|
|
3179
3178
|
plugins: PLUGINS
|
|
3180
3179
|
});
|
|
3181
3180
|
}
|
|
@@ -3907,7 +3906,7 @@ async function setupGlobalEnv(config) {
|
|
|
3907
3906
|
setupConsoleLogSpy();
|
|
3908
3907
|
await setupChai();
|
|
3909
3908
|
if (config.global)
|
|
3910
|
-
(await import('./global-
|
|
3909
|
+
(await import('./global-e0d00047.js')).registerApiGlobally();
|
|
3911
3910
|
}
|
|
3912
3911
|
function setupConsoleLogSpy() {
|
|
3913
3912
|
const stdout = new Writable({
|
|
@@ -3957,7 +3956,7 @@ async function runSetupFiles(config) {
|
|
|
3957
3956
|
}
|
|
3958
3957
|
|
|
3959
3958
|
function serializeError(val) {
|
|
3960
|
-
if (!val)
|
|
3959
|
+
if (!val || typeof val === "string")
|
|
3961
3960
|
return val;
|
|
3962
3961
|
if (typeof val === "function")
|
|
3963
3962
|
return `Function<${val.name}>`;
|
|
@@ -3981,6 +3980,10 @@ function processError(err) {
|
|
|
3981
3980
|
err.stackStr = String(err.stack);
|
|
3982
3981
|
if (err.name)
|
|
3983
3982
|
err.nameStr = String(err.name);
|
|
3983
|
+
if (typeof err.expected !== "string")
|
|
3984
|
+
err.expected = stringify(err.expected);
|
|
3985
|
+
if (typeof err.actual !== "string")
|
|
3986
|
+
err.actual = stringify(err.actual);
|
|
3984
3987
|
return serializeError(err);
|
|
3985
3988
|
}
|
|
3986
3989
|
|
|
@@ -4135,6 +4138,15 @@ async function startTests(paths, config) {
|
|
|
4135
4138
|
await runSuites(files);
|
|
4136
4139
|
await getSnapshotClient().saveSnap();
|
|
4137
4140
|
}
|
|
4141
|
+
function clearModuleMocks() {
|
|
4142
|
+
const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config;
|
|
4143
|
+
if (restoreMocks)
|
|
4144
|
+
vi.restoreAllMocks();
|
|
4145
|
+
else if (mockReset)
|
|
4146
|
+
vi.resetAllMocks();
|
|
4147
|
+
else if (clearMocks)
|
|
4148
|
+
vi.clearAllMocks();
|
|
4149
|
+
}
|
|
4138
4150
|
|
|
4139
4151
|
async function run(files, config) {
|
|
4140
4152
|
var _a;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { g as globalApis } from './constants-e762cbc5.js';
|
|
2
|
+
import { i as index } from './index-0961cf69.js';
|
|
3
|
+
import 'url';
|
|
4
|
+
import './utils-d97bd6d9.js';
|
|
5
|
+
import 'tty';
|
|
6
|
+
import 'local-pkg';
|
|
7
|
+
import 'path';
|
|
8
|
+
import './vi-9754296d.js';
|
|
9
|
+
import './jest-mock-8498c46d.js';
|
|
10
|
+
import 'chai';
|
|
11
|
+
import 'tinyspy';
|
|
12
|
+
import './_commonjsHelpers-c9e3b764.js';
|
|
13
|
+
|
|
14
|
+
function registerApiGlobally() {
|
|
15
|
+
globalApis.forEach((api) => {
|
|
16
|
+
globalThis[api] = index[api];
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { registerApiGlobally };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it, v as vitest, b as vi } from './vi-9754296d.js';
|
|
2
2
|
import chai, { assert, should, expect } from 'chai';
|
|
3
|
-
import { s as spies, a as spyOn, f as fn
|
|
3
|
+
import { s as spies, a as spyOn, f as fn } from './jest-mock-8498c46d.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()));
|
|
@@ -2,15 +2,11 @@ import path$5 from 'path';
|
|
|
2
2
|
import fs$5 from 'fs';
|
|
3
3
|
import require$$0 from 'util';
|
|
4
4
|
import require$$0$1 from 'child_process';
|
|
5
|
-
import {
|
|
6
|
-
import { a as signalExit, b as onetime$1 } from './index-
|
|
5
|
+
import { c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
|
|
6
|
+
import { a as signalExit, b as onetime$1 } from './index-61c8686f.js';
|
|
7
7
|
import require$$0$2 from 'os';
|
|
8
8
|
import require$$0$4 from 'buffer';
|
|
9
9
|
import require$$0$3 from 'stream';
|
|
10
|
-
import 'tty';
|
|
11
|
-
import 'local-pkg';
|
|
12
|
-
import 'chai';
|
|
13
|
-
import 'tinyspy';
|
|
14
10
|
import 'assert';
|
|
15
11
|
import 'events';
|
|
16
12
|
|
|
@@ -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';
|
|
@@ -9113,7 +9113,7 @@ async function createVitest(options, viteOverrides = {}) {
|
|
|
9113
9113
|
ctx.setServer(options, server2);
|
|
9114
9114
|
haveStarted = true;
|
|
9115
9115
|
if (options.api)
|
|
9116
|
-
server2.middlewares.use((await import('./middleware-
|
|
9116
|
+
server2.middlewares.use((await import('./middleware-093a3bde.js')).default(ctx));
|
|
9117
9117
|
}
|
|
9118
9118
|
},
|
|
9119
9119
|
MocksPlugin()
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { d as describe, i as it, s as suite, t as test } from './
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './index-
|
|
1
|
+
export { d as describe, i as it, s as suite, t as test, b as vi, v as vitest } from './vi-9754296d.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach } from './index-0961cf69.js';
|
|
3
3
|
export { assert, default as chai, expect, should } from 'chai';
|
|
4
|
-
export { f as fn, s as spies, a as spyOn
|
|
5
|
-
import './
|
|
4
|
+
export { f as fn, s as spies, a as spyOn } from './jest-mock-8498c46d.js';
|
|
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,104 @@
|
|
|
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 = "";
|
|
48
|
+
Object.defineProperty(stub, "name", {
|
|
49
|
+
get: () => name
|
|
50
|
+
});
|
|
51
|
+
stub.getMockName = () => name || "vi.fn()";
|
|
52
|
+
stub.mockName = (n) => {
|
|
53
|
+
name = n;
|
|
54
|
+
return stub;
|
|
55
|
+
};
|
|
56
|
+
stub.mockClear = () => {
|
|
57
|
+
stub.reset();
|
|
58
|
+
return stub;
|
|
59
|
+
};
|
|
60
|
+
stub.mockReset = () => {
|
|
61
|
+
stub.reset();
|
|
62
|
+
implementation = () => void 0;
|
|
63
|
+
onceImplementations = [];
|
|
64
|
+
return stub;
|
|
65
|
+
};
|
|
66
|
+
stub.mockRestore = () => {
|
|
67
|
+
stub.mockReset();
|
|
68
|
+
implementation = void 0;
|
|
69
|
+
return stub;
|
|
70
|
+
};
|
|
71
|
+
stub.getMockImplementation = () => implementation;
|
|
72
|
+
stub.mockImplementation = (fn2) => {
|
|
73
|
+
implementation = fn2;
|
|
74
|
+
return stub;
|
|
75
|
+
};
|
|
76
|
+
stub.mockImplementationOnce = (fn2) => {
|
|
77
|
+
onceImplementations.push(fn2);
|
|
78
|
+
return stub;
|
|
79
|
+
};
|
|
80
|
+
stub.mockReturnThis = () => stub.mockImplementation(function() {
|
|
81
|
+
return this;
|
|
82
|
+
});
|
|
83
|
+
stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
|
|
84
|
+
stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
|
|
85
|
+
stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
|
|
86
|
+
stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
|
|
87
|
+
stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
|
|
88
|
+
stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
|
|
89
|
+
util.addProperty(stub, "mock", () => mockContext);
|
|
90
|
+
stub.willCall(function(...args) {
|
|
91
|
+
instances.push(this);
|
|
92
|
+
const impl = onceImplementations.shift() || implementation || stub.getOriginal() || (() => {
|
|
93
|
+
});
|
|
94
|
+
return impl.apply(this, args);
|
|
95
|
+
});
|
|
96
|
+
spies.add(stub);
|
|
97
|
+
return stub;
|
|
98
|
+
}
|
|
99
|
+
function fn(implementation) {
|
|
100
|
+
return enhanceSpy(tinyspy.spyOn({ fn: implementation || (() => {
|
|
101
|
+
}) }, "fn"));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
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-a7df3e65.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';
|