vitest 0.0.73 → 0.0.74
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 +29 -12
- package/dist/entry.js +1 -1
- package/dist/{error-5a04e54b.js → error-48107470.js} +35 -21
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import require$$2, { EventEmitter } from 'events';
|
|
2
|
-
import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, d as c, F as F_POINTER, e as F_DOWN, f as
|
|
2
|
+
import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, d as 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-48107470.js';
|
|
3
3
|
import { performance } from 'perf_hooks';
|
|
4
4
|
import path, { isAbsolute, relative, dirname, basename, resolve } from 'path';
|
|
5
5
|
import { g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-9dcc4050.js';
|
|
@@ -632,7 +632,7 @@ const cac = (name = "") => new CAC(name);
|
|
|
632
632
|
|
|
633
633
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
634
634
|
|
|
635
|
-
var version = "0.0.
|
|
635
|
+
var version = "0.0.74";
|
|
636
636
|
|
|
637
637
|
const ESC = '\u001B[';
|
|
638
638
|
const OSC = '\u001B]';
|
|
@@ -1451,6 +1451,20 @@ const spinnerMap = new WeakMap();
|
|
|
1451
1451
|
const outputMap = new WeakMap();
|
|
1452
1452
|
const pointer = c.yellow(F_POINTER);
|
|
1453
1453
|
const skipped = c.yellow(F_DOWN);
|
|
1454
|
+
function divider(text, left, right) {
|
|
1455
|
+
const length = process.stdout.columns || 10;
|
|
1456
|
+
if (text) {
|
|
1457
|
+
const textLength = stripAnsi(text).length;
|
|
1458
|
+
if (left == null && right != null) {
|
|
1459
|
+
left = length - textLength - right;
|
|
1460
|
+
} else {
|
|
1461
|
+
left = left ?? Math.floor((length - textLength) / 2);
|
|
1462
|
+
right = length - textLength - left;
|
|
1463
|
+
}
|
|
1464
|
+
return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
|
|
1465
|
+
}
|
|
1466
|
+
return F_LONG_DASH.repeat(length);
|
|
1467
|
+
}
|
|
1454
1468
|
function formatTestPath(root, path) {
|
|
1455
1469
|
var _a;
|
|
1456
1470
|
if (isAbsolute(path))
|
|
@@ -1603,7 +1617,7 @@ const createRenderer = (_tasks) => {
|
|
|
1603
1617
|
};
|
|
1604
1618
|
};
|
|
1605
1619
|
function getFullName(task) {
|
|
1606
|
-
return getNames(task).join(c.
|
|
1620
|
+
return getNames(task).join(c.dim(" > "));
|
|
1607
1621
|
}
|
|
1608
1622
|
const spinnerFrames = process.platform === "win32" ? ["-", "\\", "|", "/"] : ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1609
1623
|
function elegantSpinner() {
|
|
@@ -1663,24 +1677,27 @@ class DefaultReporter {
|
|
|
1663
1677
|
var _a2;
|
|
1664
1678
|
return ((_a2 = i.result) == null ? void 0 : _a2.state) === "fail";
|
|
1665
1679
|
});
|
|
1680
|
+
const failedTotal = failedSuites.length + failedTests.length;
|
|
1681
|
+
let current = 1;
|
|
1682
|
+
const errorDivider = () => console.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
1683
|
+
`);
|
|
1666
1684
|
if (failedSuites.length) {
|
|
1667
|
-
console.error(c.bold(c.
|
|
1668
|
-
|
|
1685
|
+
console.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
1686
|
+
console.error();
|
|
1669
1687
|
for (const suite of failedSuites) {
|
|
1670
1688
|
console.error(c.red(`
|
|
1671
1689
|
- ${getFullName(suite)}`));
|
|
1672
1690
|
await printError((_a = suite.result) == null ? void 0 : _a.error);
|
|
1673
|
-
|
|
1691
|
+
errorDivider();
|
|
1674
1692
|
}
|
|
1675
1693
|
}
|
|
1676
1694
|
if (failedTests.length) {
|
|
1677
|
-
console.error(c.bold(c.
|
|
1678
|
-
|
|
1695
|
+
console.error(c.red(divider(c.bold(c.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
1696
|
+
console.error();
|
|
1679
1697
|
for (const test of failedTests) {
|
|
1680
|
-
console.error(`${c.red(`
|
|
1681
|
-
${c.inverse(" FAIL ")}`)} ${getFullName(test)}`);
|
|
1698
|
+
console.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
|
|
1682
1699
|
await printError((_b = test.result) == null ? void 0 : _b.error);
|
|
1683
|
-
|
|
1700
|
+
errorDivider();
|
|
1684
1701
|
}
|
|
1685
1702
|
}
|
|
1686
1703
|
const executionTime = this.end - this.start;
|
|
@@ -1738,7 +1755,7 @@ ${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")
|
|
|
1738
1755
|
var _a;
|
|
1739
1756
|
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
1740
1757
|
const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
|
|
1741
|
-
console.log(c.gray(
|
|
1758
|
+
console.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
|
|
1742
1759
|
process[log.type].write(`${log.content}
|
|
1743
1760
|
`);
|
|
1744
1761
|
}
|
package/dist/entry.js
CHANGED
|
@@ -7,7 +7,7 @@ import Subset from 'chai-subset';
|
|
|
7
7
|
import path, { basename } from 'path';
|
|
8
8
|
import { g as getNames, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
|
|
9
9
|
import fs from 'fs';
|
|
10
|
-
import { d as c$1,
|
|
10
|
+
import { d as c$1, m as generateDiff } from './error-48107470.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
12
|
import { j as setHooks, c as createSuiteHooks, h as clearContext, d as defaultSuite, k as context, l as getHooks, m as getFn } from './suite-819c135e.js';
|
|
13
13
|
import { n as nanoid } from './index-6427e0f2.js';
|
|
@@ -1246,12 +1246,12 @@ function cliTruncate(text, columns, options) {
|
|
|
1246
1246
|
|
|
1247
1247
|
const F_RIGHT = "\u2192";
|
|
1248
1248
|
const F_DOWN = "\u2193";
|
|
1249
|
-
const F_UP = "\u2191";
|
|
1250
1249
|
const F_DOWN_RIGHT = "\u21B3";
|
|
1251
1250
|
const F_POINTER = "\u276F";
|
|
1252
1251
|
const F_DOT = "\xB7";
|
|
1253
1252
|
const F_CHECK = "\u221A";
|
|
1254
1253
|
const F_CROSS = "\xD7";
|
|
1254
|
+
const F_LONG_DASH = "\u23AF";
|
|
1255
1255
|
|
|
1256
1256
|
async function printError(error) {
|
|
1257
1257
|
const { server } = process.__vitest__;
|
|
@@ -1263,17 +1263,18 @@ async function printError(error) {
|
|
|
1263
1263
|
};
|
|
1264
1264
|
}
|
|
1265
1265
|
let codeFramePrinted = false;
|
|
1266
|
-
const
|
|
1266
|
+
const stackStr = e.stack || e.stackStr || "";
|
|
1267
|
+
const stacks = parseStack(stackStr);
|
|
1267
1268
|
const nearest = stacks.find((stack) => !stack.file.includes("vitest/dist") && server.moduleGraph.getModuleById(stack.file));
|
|
1268
1269
|
if (nearest) {
|
|
1269
|
-
const
|
|
1270
|
-
const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
|
|
1271
|
-
const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
|
|
1270
|
+
const pos = await getSourcePos(server, nearest);
|
|
1272
1271
|
if (pos && existsSync(nearest.file)) {
|
|
1273
1272
|
const sourceCode = await promises.readFile(nearest.file, "utf-8");
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1273
|
+
printErrorMessage(e);
|
|
1274
|
+
await printStack(server, stacks, nearest, (s) => {
|
|
1275
|
+
if (s === nearest)
|
|
1276
|
+
console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
|
|
1277
|
+
});
|
|
1277
1278
|
codeFramePrinted = true;
|
|
1278
1279
|
}
|
|
1279
1280
|
}
|
|
@@ -1282,18 +1283,29 @@ async function printError(error) {
|
|
|
1282
1283
|
if (e.showDiff)
|
|
1283
1284
|
displayDiff(e.actual, e.expected);
|
|
1284
1285
|
}
|
|
1286
|
+
async function getSourcePos(server, nearest) {
|
|
1287
|
+
const mod = server.moduleGraph.getModuleById(nearest.file);
|
|
1288
|
+
const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
|
|
1289
|
+
const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
|
|
1290
|
+
return pos;
|
|
1291
|
+
}
|
|
1285
1292
|
function displayDiff(actual, expected) {
|
|
1286
1293
|
console.error(c.gray(generateDiff(stringify(actual), stringify(expected))));
|
|
1287
1294
|
}
|
|
1288
|
-
function
|
|
1295
|
+
function printErrorMessage(error) {
|
|
1289
1296
|
const errorName = error.name || error.nameStr || "Unknown Error";
|
|
1290
1297
|
console.error(c.red(`${c.bold(errorName)}: ${error.message}`));
|
|
1291
1298
|
}
|
|
1292
|
-
function
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1299
|
+
async function printStack(server, stack, highlight, onStack) {
|
|
1300
|
+
if (!stack.length)
|
|
1301
|
+
return;
|
|
1302
|
+
for (const frame of stack) {
|
|
1303
|
+
const pos = await getSourcePos(server, frame) || frame;
|
|
1304
|
+
const color = frame === highlight ? c.yellow : c.gray;
|
|
1305
|
+
console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${frame.file}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
|
|
1306
|
+
onStack == null ? void 0 : onStack(frame);
|
|
1307
|
+
}
|
|
1308
|
+
console.log();
|
|
1297
1309
|
}
|
|
1298
1310
|
function getOriginalPos(map, { line, column }) {
|
|
1299
1311
|
return new Promise((resolve) => {
|
|
@@ -1319,12 +1331,12 @@ function posToNumber(source, pos) {
|
|
|
1319
1331
|
start += lines[i].length + 1;
|
|
1320
1332
|
return start + column;
|
|
1321
1333
|
}
|
|
1322
|
-
function generateCodeFrame(source, start = 0, end, range = 2) {
|
|
1334
|
+
function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
|
|
1323
1335
|
start = posToNumber(source, start);
|
|
1324
1336
|
end = end || start;
|
|
1325
1337
|
const lines = source.split(splitRE);
|
|
1326
1338
|
let count = 0;
|
|
1327
|
-
|
|
1339
|
+
let res = [];
|
|
1328
1340
|
function lineNo(no = "") {
|
|
1329
1341
|
return c.gray(`${String(no).padStart(3, " ")}| `);
|
|
1330
1342
|
}
|
|
@@ -1337,15 +1349,15 @@ function generateCodeFrame(source, start = 0, end, range = 2) {
|
|
|
1337
1349
|
const lineLength = lines[j].length;
|
|
1338
1350
|
if (lineLength > 200)
|
|
1339
1351
|
return "";
|
|
1340
|
-
res.push(lineNo(j + 1) + cliTruncate(lines[j], process.stdout.columns - 5));
|
|
1352
|
+
res.push(lineNo(j + 1) + cliTruncate(lines[j], process.stdout.columns - 5 - indent));
|
|
1341
1353
|
if (j === i) {
|
|
1342
1354
|
const pad = start - (count - lineLength);
|
|
1343
1355
|
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
1344
|
-
res.push(lineNo() + " ".repeat(pad) +
|
|
1356
|
+
res.push(lineNo() + " ".repeat(pad) + c.red("^".repeat(length)));
|
|
1345
1357
|
} else if (j > i) {
|
|
1346
1358
|
if (end > count) {
|
|
1347
1359
|
const length = Math.max(1, Math.min(end - count, lineLength));
|
|
1348
|
-
res.push(lineNo() +
|
|
1360
|
+
res.push(lineNo() + c.red("^".repeat(length)));
|
|
1349
1361
|
}
|
|
1350
1362
|
count += lineLength + 1;
|
|
1351
1363
|
}
|
|
@@ -1353,13 +1365,15 @@ function generateCodeFrame(source, start = 0, end, range = 2) {
|
|
|
1353
1365
|
break;
|
|
1354
1366
|
}
|
|
1355
1367
|
}
|
|
1368
|
+
if (indent)
|
|
1369
|
+
res = res.map((line) => " ".repeat(indent) + line);
|
|
1356
1370
|
return res.join("\n");
|
|
1357
1371
|
}
|
|
1358
1372
|
function stringify(obj) {
|
|
1359
1373
|
return String(obj);
|
|
1360
1374
|
}
|
|
1361
1375
|
const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
|
|
1362
|
-
const stackBarePathRE = /at ()(.+):(\d+):(\d+)$/;
|
|
1376
|
+
const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/;
|
|
1363
1377
|
function parseStack(stack) {
|
|
1364
1378
|
const lines = stack.split("\n");
|
|
1365
1379
|
const stackFrames = lines.map((raw) => {
|
|
@@ -1412,4 +1426,4 @@ function notBlank(line) {
|
|
|
1412
1426
|
return typeof line !== "undefined" && line !== null;
|
|
1413
1427
|
}
|
|
1414
1428
|
|
|
1415
|
-
export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, c as d, F_DOWN as e,
|
|
1429
|
+
export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, c 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, generateDiff as m, printError as p, stringWidth as s };
|