vitest 0.0.82 → 0.0.83
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 +4 -3
- package/dist/entry.js +5 -7
- package/dist/{error-dd23da12.js → error-a65fcd00.js} +59 -15
- package/dist/{global-cae0ce06.js → global-e172af93.js} +2 -2
- package/dist/{index-9a2ee1fc.js → index-6c8eed3e.js} +1 -1
- package/dist/{index-16a06164.js → index-906ac3f9.js} +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/node.js +2 -2
- package/dist/{suite-95be5909.js → suite-0e21bf9b.js} +17 -6
- package/dist/worker.js +1 -0
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { c } from './error-
|
|
3
|
-
import { c as createVitest } from './index-
|
|
2
|
+
import { c } from './error-a65fcd00.js';
|
|
3
|
+
import { c as createVitest } from './index-6c8eed3e.js';
|
|
4
4
|
import 'fs';
|
|
5
5
|
import 'path';
|
|
6
6
|
import 'tty';
|
|
@@ -631,7 +631,7 @@ class CAC extends EventEmitter {
|
|
|
631
631
|
|
|
632
632
|
const cac = (name = "") => new CAC(name);
|
|
633
633
|
|
|
634
|
-
var version = "0.0.
|
|
634
|
+
var version = "0.0.83";
|
|
635
635
|
|
|
636
636
|
const cli = cac("vitest");
|
|
637
637
|
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("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", {
|
|
@@ -656,6 +656,7 @@ async function run(cliFilters, options) {
|
|
|
656
656
|
}
|
|
657
657
|
const ctx = await createVitest(options);
|
|
658
658
|
process.__vitest__ = ctx;
|
|
659
|
+
process.chdir(ctx.config.root);
|
|
659
660
|
try {
|
|
660
661
|
await ctx.run(cliFilters);
|
|
661
662
|
} catch (e) {
|
package/dist/entry.js
CHANGED
|
@@ -7,9 +7,9 @@ import path, { basename } from 'path';
|
|
|
7
7
|
import { r as rpc, s as send } from './rpc-7de86f29.js';
|
|
8
8
|
import { g as getNames, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
|
|
9
9
|
import fs from 'fs';
|
|
10
|
-
import { c as c$1,
|
|
10
|
+
import { c as c$1, u as unifiedDiff } from './error-a65fcd00.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
|
-
import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-
|
|
12
|
+
import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-0e21bf9b.js';
|
|
13
13
|
import { n as nanoid } from './index-9e71c815.js';
|
|
14
14
|
import 'tty';
|
|
15
15
|
import 'source-map';
|
|
@@ -3080,7 +3080,7 @@ const stringify = (object, maxDepth = 10) => {
|
|
|
3080
3080
|
const printReceived = (object) => RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
|
|
3081
3081
|
const printExpected = (value) => EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
|
|
3082
3082
|
function diff(a, b, options) {
|
|
3083
|
-
return
|
|
3083
|
+
return unifiedDiff(stringify(a), stringify(b));
|
|
3084
3084
|
}
|
|
3085
3085
|
|
|
3086
3086
|
var matcherUtils = /*#__PURE__*/Object.freeze({
|
|
@@ -3097,9 +3097,7 @@ var matcherUtils = /*#__PURE__*/Object.freeze({
|
|
|
3097
3097
|
diff: diff
|
|
3098
3098
|
});
|
|
3099
3099
|
|
|
3100
|
-
|
|
3101
|
-
var isObject = (val) => toString.call(val) === "[object Object]";
|
|
3102
|
-
|
|
3100
|
+
const isObject = (val) => toString.call(val) === "[object Object]";
|
|
3103
3101
|
function equals(a, b, customTesters, strictCheck) {
|
|
3104
3102
|
customTesters = customTesters || [];
|
|
3105
3103
|
return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
|
|
@@ -3605,7 +3603,7 @@ async function setupGlobalEnv(config) {
|
|
|
3605
3603
|
setupConsoleLogSpy();
|
|
3606
3604
|
await setupChai();
|
|
3607
3605
|
if (config.global)
|
|
3608
|
-
(await import('./global-
|
|
3606
|
+
(await import('./global-e172af93.js')).registerApiGlobally();
|
|
3609
3607
|
}
|
|
3610
3608
|
function setupConsoleLogSpy() {
|
|
3611
3609
|
const stdout = new Writable({
|
|
@@ -1266,7 +1266,7 @@ async function printError(error) {
|
|
|
1266
1266
|
const stackStr = e.stack || e.stackStr || "";
|
|
1267
1267
|
const stacks = parseStack(stackStr);
|
|
1268
1268
|
if (!stacks.length) {
|
|
1269
|
-
console.error(e);
|
|
1269
|
+
ctx.console.error(e);
|
|
1270
1270
|
} else {
|
|
1271
1271
|
const nearest = stacks.find((stack) => {
|
|
1272
1272
|
return !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file);
|
|
@@ -1279,9 +1279,38 @@ async function printError(error) {
|
|
|
1279
1279
|
}
|
|
1280
1280
|
});
|
|
1281
1281
|
}
|
|
1282
|
+
handleImportOutsideModuleError(stackStr, ctx);
|
|
1282
1283
|
if (e.showDiff)
|
|
1283
1284
|
displayDiff(e.actual, e.expected);
|
|
1284
1285
|
}
|
|
1286
|
+
const esmErrors = [
|
|
1287
|
+
"Cannot use import statement outside a module",
|
|
1288
|
+
"Unexpected token 'export'"
|
|
1289
|
+
];
|
|
1290
|
+
function handleImportOutsideModuleError(stack, ctx) {
|
|
1291
|
+
if (!esmErrors.some((e) => stack.includes(e)))
|
|
1292
|
+
return;
|
|
1293
|
+
const path = stack.split("\n")[0].trim();
|
|
1294
|
+
let name = path.split("/node_modules/").pop() || "";
|
|
1295
|
+
if (name == null ? void 0 : name.startsWith("@"))
|
|
1296
|
+
name = name.split("/").slice(0, 2).join("/");
|
|
1297
|
+
else
|
|
1298
|
+
name = name.split("/")[0];
|
|
1299
|
+
ctx.console.error(c.yellow(`Module ${path} seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package ${c.bold(`"${name}"`)} asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
|
|
1300
|
+
|
|
1301
|
+
As a temporary workaround you can try to inline the package by updating your config:
|
|
1302
|
+
|
|
1303
|
+
` + c.gray(c.dim("// vitest.config.js")) + "\n" + c.green(`export default {
|
|
1304
|
+
test: {
|
|
1305
|
+
deps: {
|
|
1306
|
+
inline: [
|
|
1307
|
+
${c.yellow(c.bold(`"${name}"`))}
|
|
1308
|
+
]
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
`)));
|
|
1313
|
+
}
|
|
1285
1314
|
async function getSourcePos(ctx, nearest) {
|
|
1286
1315
|
const mod = ctx.server.moduleGraph.getModuleById(nearest.file);
|
|
1287
1316
|
const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
|
|
@@ -1289,7 +1318,7 @@ async function getSourcePos(ctx, nearest) {
|
|
|
1289
1318
|
return pos;
|
|
1290
1319
|
}
|
|
1291
1320
|
function displayDiff(actual, expected) {
|
|
1292
|
-
console.error(c.gray(
|
|
1321
|
+
console.error(c.gray(unifiedDiff(stringify(actual), stringify(expected))));
|
|
1293
1322
|
}
|
|
1294
1323
|
function printErrorMessage(error) {
|
|
1295
1324
|
const errorName = error.name || error.nameStr || "Unknown Error";
|
|
@@ -1395,21 +1424,26 @@ function parseStack(stack) {
|
|
|
1395
1424
|
});
|
|
1396
1425
|
return stackFrames.filter(notNullish);
|
|
1397
1426
|
}
|
|
1398
|
-
function generateDiff(actual, expected) {
|
|
1399
|
-
const diffSize = 2048;
|
|
1400
|
-
if (actual.length > diffSize)
|
|
1401
|
-
actual = `${actual.substring(0, diffSize)} ... Lines skipped`;
|
|
1402
|
-
if (expected.length > diffSize)
|
|
1403
|
-
expected = `${expected.substring(0, diffSize)} ... Lines skipped`;
|
|
1404
|
-
return unifiedDiff(actual, expected);
|
|
1405
|
-
}
|
|
1406
1427
|
function unifiedDiff(actual, expected) {
|
|
1428
|
+
const diffLimit = 10;
|
|
1407
1429
|
const indent = " ";
|
|
1430
|
+
let expectedLinesCount = 0;
|
|
1431
|
+
let actualLinesCount = 0;
|
|
1408
1432
|
function cleanUp(line) {
|
|
1409
|
-
if (line[0] === "+")
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1433
|
+
if (line[0] === "+") {
|
|
1434
|
+
if (expectedLinesCount >= diffLimit)
|
|
1435
|
+
return;
|
|
1436
|
+
expectedLinesCount++;
|
|
1437
|
+
const isLastLine = expectedLinesCount === diffLimit;
|
|
1438
|
+
return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
|
|
1439
|
+
}
|
|
1440
|
+
if (line[0] === "-") {
|
|
1441
|
+
if (actualLinesCount >= diffLimit)
|
|
1442
|
+
return;
|
|
1443
|
+
actualLinesCount++;
|
|
1444
|
+
const isLastLine = actualLinesCount === diffLimit;
|
|
1445
|
+
return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
|
|
1446
|
+
}
|
|
1413
1447
|
if (line.match(/@@/))
|
|
1414
1448
|
return "--";
|
|
1415
1449
|
if (line.match(/\\ No newline/))
|
|
@@ -1424,8 +1458,18 @@ ${indent}${c.green("+ expected")}
|
|
|
1424
1458
|
|
|
1425
1459
|
${lines.map(cleanUp).filter(notBlank).join("\n")}`;
|
|
1426
1460
|
}
|
|
1461
|
+
function formatLine(line) {
|
|
1462
|
+
const lineLimitLength = 50;
|
|
1463
|
+
if (line.length > lineLimitLength)
|
|
1464
|
+
return `${line.slice(0, lineLimitLength)} ${c.dim("[...truncated]")}`;
|
|
1465
|
+
return line;
|
|
1466
|
+
}
|
|
1467
|
+
function renderTruncateMessage(indent) {
|
|
1468
|
+
return `
|
|
1469
|
+
${indent}${c.dim("[...truncated]")}`;
|
|
1470
|
+
}
|
|
1427
1471
|
function notBlank(line) {
|
|
1428
1472
|
return typeof line !== "undefined" && line !== null;
|
|
1429
1473
|
}
|
|
1430
1474
|
|
|
1431
|
-
export { F_POINTER as F, ansiStyles as a, stripAnsi as b, c, sliceAnsi as d, F_DOWN as e, F_LONG_DASH as f, F_DOWN_RIGHT as g, F_DOT as h, F_CHECK as i, F_CROSS as j, cliTruncate as k, F_RIGHT as l,
|
|
1475
|
+
export { F_POINTER as F, ansiStyles as a, stripAnsi as b, c, sliceAnsi as d, F_DOWN as e, F_LONG_DASH as f, F_DOWN_RIGHT as g, F_DOT as h, F_CHECK as i, F_CROSS as j, cliTruncate as k, F_RIGHT as l, printError as p, stringWidth as s, unifiedDiff as u };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { g as globalApis } from './constants-adef7ffb.js';
|
|
2
|
-
import { i as index } from './index-
|
|
2
|
+
import { i as index } from './index-906ac3f9.js';
|
|
3
3
|
import 'path';
|
|
4
4
|
import 'url';
|
|
5
|
-
import './suite-
|
|
5
|
+
import './suite-0e21bf9b.js';
|
|
6
6
|
import './index-9e71c815.js';
|
|
7
7
|
import 'chai';
|
|
8
8
|
import 'tinyspy';
|
|
@@ -5,7 +5,7 @@ import { promises } from 'fs';
|
|
|
5
5
|
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-adef7ffb.js';
|
|
6
6
|
import { g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-9dcc4050.js';
|
|
7
7
|
import { performance } from 'perf_hooks';
|
|
8
|
-
import { s as stringWidth, a as ansiStyles, b as stripAnsi, d as sliceAnsi, c, F as F_POINTER, e as F_DOWN, f as F_LONG_DASH, g as F_DOWN_RIGHT, h as F_DOT, i as F_CHECK, j as F_CROSS, k as cliTruncate, l as F_RIGHT, p as printError } from './error-
|
|
8
|
+
import { s as stringWidth, a as ansiStyles, b as stripAnsi, d as sliceAnsi, c, F as F_POINTER, e as F_DOWN, f as F_LONG_DASH, g as F_DOWN_RIGHT, h as F_DOT, i as F_CHECK, j as F_CROSS, k as cliTruncate, l as F_RIGHT, p as printError } from './error-a65fcd00.js';
|
|
9
9
|
import require$$0 from 'assert';
|
|
10
10
|
import require$$2 from 'events';
|
|
11
11
|
import { MessageChannel } from 'worker_threads';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-
|
|
1
|
+
import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-0e21bf9b.js';
|
|
2
2
|
import chai, { assert, should, expect } from 'chai';
|
|
3
3
|
import { spyOn, spy } from 'tinyspy';
|
|
4
4
|
|
package/dist/index.d.ts
CHANGED
|
@@ -164,7 +164,8 @@ interface Test extends TaskBase {
|
|
|
164
164
|
result?: TaskResult;
|
|
165
165
|
}
|
|
166
166
|
declare type Task = Test | Suite | File;
|
|
167
|
-
declare type
|
|
167
|
+
declare type DoneCallback = (error?: any) => void;
|
|
168
|
+
declare type TestFunction = (done: DoneCallback) => Awaitable<void>;
|
|
168
169
|
declare type TestCollectorFn = (name: string, fn: TestFunction, timeout?: number) => void;
|
|
169
170
|
interface ConcurrentCollector {
|
|
170
171
|
(name: string, fn: TestFunction, timeout?: number): void;
|
|
@@ -269,7 +270,7 @@ interface SnapshotSummary {
|
|
|
269
270
|
updated: number;
|
|
270
271
|
}
|
|
271
272
|
|
|
272
|
-
interface InlineConfig
|
|
273
|
+
interface InlineConfig {
|
|
273
274
|
/**
|
|
274
275
|
* Include globs for test files
|
|
275
276
|
*
|
|
@@ -391,7 +392,7 @@ interface InlineConfig$1 {
|
|
|
391
392
|
*/
|
|
392
393
|
api?: boolean | number;
|
|
393
394
|
}
|
|
394
|
-
interface UserConfig extends InlineConfig
|
|
395
|
+
interface UserConfig extends InlineConfig {
|
|
395
396
|
/**
|
|
396
397
|
* Path to the config file.
|
|
397
398
|
*
|
|
@@ -610,4 +611,4 @@ declare global {
|
|
|
610
611
|
}
|
|
611
612
|
}
|
|
612
613
|
|
|
613
|
-
export { ArgumentsType, Arrayable, Awaitable, ComputeMode, Environment, EnvironmentReturn, File, HookListener, InlineConfig
|
|
614
|
+
export { ArgumentsType, Arrayable, Awaitable, ComputeMode, DoneCallback, Environment, EnvironmentReturn, File, HookListener, InlineConfig, ModuleCache, Nullable, 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, it, suite, test, vitest };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { d as describe, i as it, s as suite, t as test } from './suite-
|
|
2
|
-
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-
|
|
1
|
+
export { d as describe, i as it, s as suite, t as test } from './suite-0e21bf9b.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-906ac3f9.js';
|
|
3
3
|
export { assert, default as chai, expect, should } from 'chai';
|
|
4
4
|
export { spy, spyOn } from 'tinyspy';
|
|
5
5
|
import './index-9e71c815.js';
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as createVitest } from './index-
|
|
1
|
+
export { c as createVitest } from './index-6c8eed3e.js';
|
|
2
2
|
import 'path';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'process';
|
|
@@ -7,7 +7,7 @@ import './constants-adef7ffb.js';
|
|
|
7
7
|
import 'url';
|
|
8
8
|
import './utils-9dcc4050.js';
|
|
9
9
|
import 'perf_hooks';
|
|
10
|
-
import './error-
|
|
10
|
+
import './error-a65fcd00.js';
|
|
11
11
|
import 'tty';
|
|
12
12
|
import 'source-map';
|
|
13
13
|
import 'assert';
|
|
@@ -36,6 +36,17 @@ function withTimeout(fn, _timeout) {
|
|
|
36
36
|
})]);
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
function ensureAsyncTest(fn) {
|
|
40
|
+
if (!fn.length)
|
|
41
|
+
return fn;
|
|
42
|
+
return () => new Promise((resolve, reject) => {
|
|
43
|
+
const done = (...args) => args[0] ? reject(args[0]) : resolve();
|
|
44
|
+
fn(done);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function normalizeTest(fn, timeout) {
|
|
48
|
+
return withTimeout(ensureAsyncTest(fn), timeout);
|
|
49
|
+
}
|
|
39
50
|
|
|
40
51
|
const fnMap = new WeakMap();
|
|
41
52
|
const hooksMap = new WeakMap();
|
|
@@ -136,24 +147,24 @@ function createSuiteCollector(name, factory = () => {
|
|
|
136
147
|
}
|
|
137
148
|
function createTestCollector(collectTest) {
|
|
138
149
|
function test2(name, fn, timeout) {
|
|
139
|
-
collectTest(name,
|
|
150
|
+
collectTest(name, normalizeTest(fn, timeout), "run");
|
|
140
151
|
}
|
|
141
152
|
test2.concurrent = concurrent;
|
|
142
153
|
test2.skip = skip;
|
|
143
154
|
test2.only = only;
|
|
144
155
|
test2.todo = todo;
|
|
145
156
|
function concurrent(name, fn, timeout) {
|
|
146
|
-
collectTest(name,
|
|
157
|
+
collectTest(name, normalizeTest(fn, timeout), "run", "concurrent");
|
|
147
158
|
}
|
|
148
|
-
concurrent.skip = (name, fn, timeout) => collectTest(name,
|
|
149
|
-
concurrent.only = (name, fn, timeout) => collectTest(name,
|
|
159
|
+
concurrent.skip = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "skip", "concurrent");
|
|
160
|
+
concurrent.only = (name, fn, timeout) => collectTest(name, normalizeTest(fn, timeout), "only", "concurrent");
|
|
150
161
|
concurrent.todo = todo;
|
|
151
162
|
function skip(name, fn, timeout) {
|
|
152
|
-
collectTest(name,
|
|
163
|
+
collectTest(name, normalizeTest(fn, timeout), "skip");
|
|
153
164
|
}
|
|
154
165
|
skip.concurrent = concurrent.skip;
|
|
155
166
|
function only(name, fn, timeout) {
|
|
156
|
-
collectTest(name,
|
|
167
|
+
collectTest(name, normalizeTest(fn, timeout), "only");
|
|
157
168
|
}
|
|
158
169
|
only.concurrent = concurrent.only;
|
|
159
170
|
function todo(name) {
|
package/dist/worker.js
CHANGED
|
@@ -100,6 +100,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
100
100
|
const __filename = fileURLToPath(url);
|
|
101
101
|
const context = {
|
|
102
102
|
require: createRequire(url),
|
|
103
|
+
exports,
|
|
103
104
|
__filename,
|
|
104
105
|
__dirname: dirname(__filename),
|
|
105
106
|
__vite_ssr_import__: request,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.83",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"natural-compare": "^1.4.0",
|
|
77
77
|
"picocolors": "^1.0.0",
|
|
78
78
|
"pretty-format": "^27.4.2",
|
|
79
|
+
"rollup": "^2.61.1",
|
|
79
80
|
"strip-ansi": "^7.0.1"
|
|
80
81
|
},
|
|
81
82
|
"peerDependencies": {
|