vitest 0.0.74 → 0.0.75
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 +82 -50
- package/dist/entry.js +12 -6
- package/dist/{error-48107470.js → error-eb493046.js} +13 -11
- package/dist/index.d.ts +19 -0
- 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 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-
|
|
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-eb493046.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.75";
|
|
636
636
|
|
|
637
637
|
const ESC = '\u001B[';
|
|
638
638
|
const OSC = '\u001B]';
|
|
@@ -1441,7 +1441,7 @@ function createLogUpdate(stream, {showCursor = false} = {}) {
|
|
|
1441
1441
|
return render;
|
|
1442
1442
|
}
|
|
1443
1443
|
|
|
1444
|
-
|
|
1444
|
+
createLogUpdate(process$2.stdout);
|
|
1445
1445
|
|
|
1446
1446
|
createLogUpdate(process$2.stderr);
|
|
1447
1447
|
|
|
@@ -1452,7 +1452,9 @@ const outputMap = new WeakMap();
|
|
|
1452
1452
|
const pointer = c.yellow(F_POINTER);
|
|
1453
1453
|
const skipped = c.yellow(F_DOWN);
|
|
1454
1454
|
function divider(text, left, right) {
|
|
1455
|
-
|
|
1455
|
+
let length = process.stdout.columns;
|
|
1456
|
+
if (!length || isNaN(length))
|
|
1457
|
+
length = 10;
|
|
1456
1458
|
if (text) {
|
|
1457
1459
|
const textLength = stripAnsi(text).length;
|
|
1458
1460
|
if (left == null && right != null) {
|
|
@@ -1461,6 +1463,8 @@ function divider(text, left, right) {
|
|
|
1461
1463
|
left = left ?? Math.floor((length - textLength) / 2);
|
|
1462
1464
|
right = length - textLength - left;
|
|
1463
1465
|
}
|
|
1466
|
+
left = Math.max(0, left);
|
|
1467
|
+
right = Math.max(0, right);
|
|
1464
1468
|
return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
|
|
1465
1469
|
}
|
|
1466
1470
|
return F_LONG_DASH.repeat(length);
|
|
@@ -1587,8 +1591,10 @@ function renderTree(tasks, level = 0) {
|
|
|
1587
1591
|
const createRenderer = (_tasks) => {
|
|
1588
1592
|
let tasks = _tasks;
|
|
1589
1593
|
let timer;
|
|
1594
|
+
const stdout = process.stdout;
|
|
1595
|
+
const log = createLogUpdate(stdout);
|
|
1590
1596
|
function update() {
|
|
1591
|
-
|
|
1597
|
+
log(renderTree(tasks));
|
|
1592
1598
|
}
|
|
1593
1599
|
return {
|
|
1594
1600
|
start() {
|
|
@@ -1607,12 +1613,13 @@ const createRenderer = (_tasks) => {
|
|
|
1607
1613
|
clearInterval(timer);
|
|
1608
1614
|
timer = void 0;
|
|
1609
1615
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1616
|
+
log.clear();
|
|
1617
|
+
stdout.write(`${renderTree(tasks)}
|
|
1618
|
+
`);
|
|
1612
1619
|
return this;
|
|
1613
1620
|
},
|
|
1614
1621
|
clear() {
|
|
1615
|
-
|
|
1622
|
+
log.clear();
|
|
1616
1623
|
}
|
|
1617
1624
|
};
|
|
1618
1625
|
};
|
|
@@ -1634,11 +1641,23 @@ class DefaultReporter {
|
|
|
1634
1641
|
this.ctx = ctx;
|
|
1635
1642
|
this.start = 0;
|
|
1636
1643
|
this.end = 0;
|
|
1644
|
+
this.console = globalThis.console;
|
|
1645
|
+
this.isFirstWatchRun = true;
|
|
1637
1646
|
const mode = ctx.config.watch ? c.yellow(" DEV ") : c.cyan(" RUN ");
|
|
1638
|
-
|
|
1647
|
+
this.log(`${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
1639
1648
|
`);
|
|
1640
1649
|
this.start = performance.now();
|
|
1641
1650
|
}
|
|
1651
|
+
log(...args) {
|
|
1652
|
+
if (this.ctx.config.silent)
|
|
1653
|
+
return;
|
|
1654
|
+
this.console.log(...args);
|
|
1655
|
+
}
|
|
1656
|
+
error(...args) {
|
|
1657
|
+
if (this.ctx.config.silent)
|
|
1658
|
+
return;
|
|
1659
|
+
this.console.error(...args);
|
|
1660
|
+
}
|
|
1642
1661
|
relative(path) {
|
|
1643
1662
|
return relative(this.ctx.config.root, path);
|
|
1644
1663
|
}
|
|
@@ -1657,16 +1676,16 @@ class DefaultReporter {
|
|
|
1657
1676
|
return;
|
|
1658
1677
|
const task = this.ctx.state.idMap[pack[0]];
|
|
1659
1678
|
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
1660
|
-
|
|
1679
|
+
this.log(` ${getStateSymbol(task)} ${getFullName(task)}`);
|
|
1661
1680
|
if (task.result.state === "fail")
|
|
1662
|
-
|
|
1681
|
+
this.log(c.red(` ${F_RIGHT} ${(_c = task.result.error) == null ? void 0 : _c.message}`));
|
|
1663
1682
|
}
|
|
1664
1683
|
}
|
|
1665
1684
|
async onFinished(files = this.ctx.state.getFiles()) {
|
|
1666
1685
|
var _a, _b;
|
|
1667
1686
|
this.end = performance.now();
|
|
1668
1687
|
await this.stopListRender();
|
|
1669
|
-
|
|
1688
|
+
this.log();
|
|
1670
1689
|
const suites = getSuites(files);
|
|
1671
1690
|
const tests = getTests(files);
|
|
1672
1691
|
const failedSuites = suites.filter((i) => {
|
|
@@ -1679,23 +1698,23 @@ class DefaultReporter {
|
|
|
1679
1698
|
});
|
|
1680
1699
|
const failedTotal = failedSuites.length + failedTests.length;
|
|
1681
1700
|
let current = 1;
|
|
1682
|
-
const errorDivider = () =>
|
|
1701
|
+
const errorDivider = () => this.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
1683
1702
|
`);
|
|
1684
1703
|
if (failedSuites.length) {
|
|
1685
|
-
|
|
1686
|
-
|
|
1704
|
+
this.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
1705
|
+
this.error();
|
|
1687
1706
|
for (const suite of failedSuites) {
|
|
1688
|
-
|
|
1707
|
+
this.error(c.red(`
|
|
1689
1708
|
- ${getFullName(suite)}`));
|
|
1690
1709
|
await printError((_a = suite.result) == null ? void 0 : _a.error);
|
|
1691
1710
|
errorDivider();
|
|
1692
1711
|
}
|
|
1693
1712
|
}
|
|
1694
1713
|
if (failedTests.length) {
|
|
1695
|
-
|
|
1696
|
-
|
|
1714
|
+
this.error(c.red(divider(c.bold(c.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
1715
|
+
this.error();
|
|
1697
1716
|
for (const test of failedTests) {
|
|
1698
|
-
|
|
1717
|
+
this.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
|
|
1699
1718
|
await printError((_b = test.result) == null ? void 0 : _b.error);
|
|
1700
1719
|
errorDivider();
|
|
1701
1720
|
}
|
|
@@ -1713,17 +1732,17 @@ class DefaultReporter {
|
|
|
1713
1732
|
};
|
|
1714
1733
|
const snapshotOutput = renderSnapshotSummary(this.ctx.config.root, this.ctx.snapshot.summary);
|
|
1715
1734
|
if (snapshotOutput.length) {
|
|
1716
|
-
|
|
1735
|
+
this.log(snapshotOutput.map((t, i) => i === 0 ? `${padTitle("Snapshots")} ${t}` : `${padTitle("")} ${t}`).join("\n"));
|
|
1717
1736
|
if (snapshotOutput.length > 1)
|
|
1718
|
-
|
|
1737
|
+
this.log();
|
|
1719
1738
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1739
|
+
this.log(padTitle("Test Files"), getStateString(files));
|
|
1740
|
+
this.log(padTitle("Tests"), getStateString(tests));
|
|
1722
1741
|
if (this.watchFilters)
|
|
1723
|
-
|
|
1742
|
+
this.log(padTitle("Time"), time(threadTime));
|
|
1724
1743
|
else
|
|
1725
|
-
|
|
1726
|
-
|
|
1744
|
+
this.log(padTitle("Time"), time(executionTime) + c.gray(` (in thread ${time(threadTime)}, ${(executionTime / threadTime * 100).toFixed(2)}%)`));
|
|
1745
|
+
this.log();
|
|
1727
1746
|
}
|
|
1728
1747
|
async onWatcherStart() {
|
|
1729
1748
|
await this.stopListRender();
|
|
@@ -1732,30 +1751,34 @@ class DefaultReporter {
|
|
|
1732
1751
|
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
1733
1752
|
});
|
|
1734
1753
|
if (failed.length)
|
|
1735
|
-
|
|
1754
|
+
this.log(`
|
|
1736
1755
|
${c.bold(c.inverse(c.red(" FAIL ")))}${c.red(` ${failed.length} tests failed. Watching for file changes...`)}`);
|
|
1737
1756
|
else
|
|
1738
|
-
|
|
1757
|
+
this.log(`
|
|
1739
1758
|
${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")}`);
|
|
1759
|
+
if (this.isFirstWatchRun) {
|
|
1760
|
+
this.isFirstWatchRun = false;
|
|
1761
|
+
this.log(c.gray("press any key to exit..."));
|
|
1762
|
+
}
|
|
1740
1763
|
}
|
|
1741
1764
|
async onWatcherRerun(files, trigger) {
|
|
1742
1765
|
await this.stopListRender();
|
|
1743
1766
|
this.watchFilters = files;
|
|
1744
|
-
console.clear();
|
|
1745
|
-
|
|
1767
|
+
this.console.clear();
|
|
1768
|
+
this.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
|
|
1746
1769
|
`));
|
|
1747
1770
|
}
|
|
1748
1771
|
async stopListRender() {
|
|
1749
1772
|
var _a;
|
|
1750
1773
|
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
1751
1774
|
this.renderer = void 0;
|
|
1752
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
1775
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1753
1776
|
}
|
|
1754
1777
|
onUserConsoleLog(log) {
|
|
1755
1778
|
var _a;
|
|
1756
1779
|
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
1757
1780
|
const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
|
|
1758
|
-
|
|
1781
|
+
this.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
|
|
1759
1782
|
process[log.type].write(`${log.content}
|
|
1760
1783
|
`);
|
|
1761
1784
|
}
|
|
@@ -2286,6 +2309,7 @@ async function startWatcher(ctx, pool) {
|
|
|
2286
2309
|
let timer;
|
|
2287
2310
|
const changedTests = new Set();
|
|
2288
2311
|
const seen = new Set();
|
|
2312
|
+
let isFirstRun = true;
|
|
2289
2313
|
let promise;
|
|
2290
2314
|
server.watcher.on("change", (id) => {
|
|
2291
2315
|
id = slash(id);
|
|
@@ -2317,6 +2341,7 @@ async function startWatcher(ctx, pool) {
|
|
|
2317
2341
|
seen.clear();
|
|
2318
2342
|
return;
|
|
2319
2343
|
}
|
|
2344
|
+
isFirstRun = false;
|
|
2320
2345
|
ctx.state.getFiles().forEach((file) => {
|
|
2321
2346
|
var _a2;
|
|
2322
2347
|
if (((_a2 = file.result) == null ? void 0 : _a2.state) === "fail")
|
|
@@ -2326,7 +2351,9 @@ async function startWatcher(ctx, pool) {
|
|
|
2326
2351
|
const tests = Array.from(changedTests);
|
|
2327
2352
|
changedTests.clear();
|
|
2328
2353
|
seen.clear();
|
|
2329
|
-
promise = start(tests, id, invalidates)
|
|
2354
|
+
promise = start(tests, id, invalidates).then(() => {
|
|
2355
|
+
promise = void 0;
|
|
2356
|
+
});
|
|
2330
2357
|
await promise;
|
|
2331
2358
|
}, WATCHER_DEBOUNCE);
|
|
2332
2359
|
}
|
|
@@ -2337,8 +2364,18 @@ async function startWatcher(ctx, pool) {
|
|
|
2337
2364
|
await ((_b = reporter.onFinished) == null ? void 0 : _b.call(reporter, ctx.state.getFiles(tests)));
|
|
2338
2365
|
await ((_c = reporter.onWatcherStart) == null ? void 0 : _c.call(reporter));
|
|
2339
2366
|
}
|
|
2340
|
-
if (process.stdin.isTTY)
|
|
2341
|
-
|
|
2367
|
+
if (process.stdin.isTTY) {
|
|
2368
|
+
readline.emitKeypressEvents(process.stdin);
|
|
2369
|
+
process.stdin.setRawMode(true);
|
|
2370
|
+
process.stdin.on("keypress", (str) => {
|
|
2371
|
+
if (str === "" || str === "")
|
|
2372
|
+
process.exit();
|
|
2373
|
+
if (promise)
|
|
2374
|
+
return;
|
|
2375
|
+
if (isFirstRun)
|
|
2376
|
+
process.exit();
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2342
2379
|
await new Promise(() => {
|
|
2343
2380
|
});
|
|
2344
2381
|
}
|
|
@@ -2359,16 +2396,6 @@ function getAffectedTests(ctx, id, set = new Set(), seen = new Set()) {
|
|
|
2359
2396
|
}
|
|
2360
2397
|
return set;
|
|
2361
2398
|
}
|
|
2362
|
-
function listenToKeybard() {
|
|
2363
|
-
readline.emitKeypressEvents(process.stdin);
|
|
2364
|
-
process.stdin.setRawMode(true);
|
|
2365
|
-
process.stdin.on("keypress", (str, key) => {
|
|
2366
|
-
if (str === "" || str === "")
|
|
2367
|
-
process.exit();
|
|
2368
|
-
if (str === "\r")
|
|
2369
|
-
process.exit();
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
2399
|
|
|
2373
2400
|
async function start(ctx) {
|
|
2374
2401
|
var _a, _b;
|
|
@@ -2445,7 +2472,7 @@ var __spreadValues = (a, b) => {
|
|
|
2445
2472
|
};
|
|
2446
2473
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
2447
2474
|
const cli = cac("vitest");
|
|
2448
|
-
cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", {
|
|
2475
|
+
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("--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", {
|
|
2449
2476
|
default: "node"
|
|
2450
2477
|
}).help();
|
|
2451
2478
|
cli.command("run [...filters]").action(run);
|
|
@@ -2454,20 +2481,25 @@ cli.command("dev [...filters]").action(dev);
|
|
|
2454
2481
|
cli.command("[...filters]").action(dev);
|
|
2455
2482
|
cli.parse();
|
|
2456
2483
|
async function dev(cliFilters, argv) {
|
|
2457
|
-
argv.watch
|
|
2484
|
+
if (argv.watch == null)
|
|
2485
|
+
argv.watch = !process.env.CI && !process.env.NODE_V8_COVERAGE;
|
|
2458
2486
|
await run(cliFilters, argv);
|
|
2459
2487
|
}
|
|
2460
2488
|
async function run(cliFilters, argv) {
|
|
2461
2489
|
process.env.VITEST = "true";
|
|
2462
|
-
|
|
2463
|
-
|
|
2490
|
+
process.env.NODE_ENV = "test";
|
|
2491
|
+
if (!argv.silent) {
|
|
2492
|
+
console.log(c.magenta(c.bold("\nVitest is in closed beta exclusively for Sponsors")));
|
|
2493
|
+
console.log(c.yellow("Learn more at https://vitest.dev\n"));
|
|
2494
|
+
}
|
|
2464
2495
|
const { config, server } = await initViteServer(__spreadProps(__spreadValues({}, argv), { cliFilters }));
|
|
2465
2496
|
const ctx = process.__vitest__ = {
|
|
2466
2497
|
server,
|
|
2467
2498
|
config,
|
|
2468
2499
|
state: new StateManager(),
|
|
2469
2500
|
snapshot: new SnapshotManager(config),
|
|
2470
|
-
reporter: config.reporter
|
|
2501
|
+
reporter: config.reporter,
|
|
2502
|
+
console: globalThis.console
|
|
2471
2503
|
};
|
|
2472
2504
|
ctx.reporter = ctx.reporter || new DefaultReporter(ctx);
|
|
2473
2505
|
try {
|
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, m as generateDiff } from './error-
|
|
10
|
+
import { d as c$1, m as generateDiff } from './error-eb493046.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';
|
|
@@ -2831,7 +2831,7 @@ class SnapshotState {
|
|
|
2831
2831
|
this._uncheckedKeys.delete(key);
|
|
2832
2832
|
const receivedSerialized = addExtraLineBreaks(serialize(received, void 0, this._snapshotFormat));
|
|
2833
2833
|
const expected = isInline ? inlineSnapshot : this._snapshotData[key];
|
|
2834
|
-
const pass = expected === receivedSerialized;
|
|
2834
|
+
const pass = (expected == null ? void 0 : expected.trim()) === (receivedSerialized == null ? void 0 : receivedSerialized.trim());
|
|
2835
2835
|
const hasSnapshot = expected !== void 0;
|
|
2836
2836
|
const snapshotIsPersisted = isInline || fs.existsSync(this._snapshotPath);
|
|
2837
2837
|
if (pass && !isInline) {
|
|
@@ -2909,13 +2909,15 @@ class SnapshotClient {
|
|
|
2909
2909
|
clearTest() {
|
|
2910
2910
|
this.test = void 0;
|
|
2911
2911
|
}
|
|
2912
|
-
assert(received, message) {
|
|
2912
|
+
assert(received, message, inlineSnapshot) {
|
|
2913
2913
|
if (!this.test)
|
|
2914
|
-
throw new Error("Snapshot
|
|
2914
|
+
throw new Error("Snapshot cannot be used outside of test");
|
|
2915
|
+
const testName = getNames(this.test).slice(1).join(" > ");
|
|
2915
2916
|
const { actual, expected, key, pass } = this.snapshotState.match({
|
|
2916
|
-
testName
|
|
2917
|
+
testName,
|
|
2917
2918
|
received,
|
|
2918
|
-
isInline:
|
|
2919
|
+
isInline: !!inlineSnapshot,
|
|
2920
|
+
inlineSnapshot: inlineSnapshot == null ? void 0 : inlineSnapshot.trim()
|
|
2919
2921
|
});
|
|
2920
2922
|
if (!pass) {
|
|
2921
2923
|
expect(actual.trim()).equals(expected ? expected.trim() : "", message || `Snapshot name: \`${key}\``);
|
|
@@ -2970,6 +2972,10 @@ function SnapshotPlugin() {
|
|
|
2970
2972
|
getSnapshotClient().assert(expected, message);
|
|
2971
2973
|
});
|
|
2972
2974
|
}
|
|
2975
|
+
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function(inlineSnapshot, message) {
|
|
2976
|
+
const expected = utils.flag(this, "object");
|
|
2977
|
+
getSnapshotClient().assert(expected, message, inlineSnapshot);
|
|
2978
|
+
});
|
|
2973
2979
|
};
|
|
2974
2980
|
}
|
|
2975
2981
|
|
|
@@ -1254,7 +1254,7 @@ const F_CROSS = "\xD7";
|
|
|
1254
1254
|
const F_LONG_DASH = "\u23AF";
|
|
1255
1255
|
|
|
1256
1256
|
async function printError(error) {
|
|
1257
|
-
const
|
|
1257
|
+
const ctx = process.__vitest__;
|
|
1258
1258
|
let e = error;
|
|
1259
1259
|
if (typeof error === "string") {
|
|
1260
1260
|
e = {
|
|
@@ -1265,15 +1265,15 @@ async function printError(error) {
|
|
|
1265
1265
|
let codeFramePrinted = false;
|
|
1266
1266
|
const stackStr = e.stack || e.stackStr || "";
|
|
1267
1267
|
const stacks = parseStack(stackStr);
|
|
1268
|
-
const nearest = stacks.find((stack) => !stack.file.includes("vitest/dist") && server.moduleGraph.getModuleById(stack.file));
|
|
1268
|
+
const nearest = stacks.find((stack) => !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file));
|
|
1269
1269
|
if (nearest) {
|
|
1270
|
-
const pos = await getSourcePos(
|
|
1270
|
+
const pos = await getSourcePos(ctx, nearest);
|
|
1271
1271
|
if (pos && existsSync(nearest.file)) {
|
|
1272
1272
|
const sourceCode = await promises.readFile(nearest.file, "utf-8");
|
|
1273
1273
|
printErrorMessage(e);
|
|
1274
|
-
await printStack(
|
|
1274
|
+
await printStack(ctx, stacks, nearest, (s) => {
|
|
1275
1275
|
if (s === nearest)
|
|
1276
|
-
console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
|
|
1276
|
+
ctx.console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
|
|
1277
1277
|
});
|
|
1278
1278
|
codeFramePrinted = true;
|
|
1279
1279
|
}
|
|
@@ -1283,8 +1283,8 @@ async function printError(error) {
|
|
|
1283
1283
|
if (e.showDiff)
|
|
1284
1284
|
displayDiff(e.actual, e.expected);
|
|
1285
1285
|
}
|
|
1286
|
-
async function getSourcePos(
|
|
1287
|
-
const mod = server.moduleGraph.getModuleById(nearest.file);
|
|
1286
|
+
async function getSourcePos(ctx, nearest) {
|
|
1287
|
+
const mod = ctx.server.moduleGraph.getModuleById(nearest.file);
|
|
1288
1288
|
const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
|
|
1289
1289
|
const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
|
|
1290
1290
|
return pos;
|
|
@@ -1296,16 +1296,18 @@ function printErrorMessage(error) {
|
|
|
1296
1296
|
const errorName = error.name || error.nameStr || "Unknown Error";
|
|
1297
1297
|
console.error(c.red(`${c.bold(errorName)}: ${error.message}`));
|
|
1298
1298
|
}
|
|
1299
|
-
async function printStack(
|
|
1299
|
+
async function printStack(ctx, stack, highlight, onStack) {
|
|
1300
1300
|
if (!stack.length)
|
|
1301
1301
|
return;
|
|
1302
1302
|
for (const frame of stack) {
|
|
1303
|
-
const pos = await getSourcePos(
|
|
1303
|
+
const pos = await getSourcePos(ctx, frame) || frame;
|
|
1304
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(" ")}`));
|
|
1305
|
+
ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${frame.file}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
|
|
1306
1306
|
onStack == null ? void 0 : onStack(frame);
|
|
1307
|
+
if (frame.file in ctx.state.filesMap)
|
|
1308
|
+
break;
|
|
1307
1309
|
}
|
|
1308
|
-
console.log();
|
|
1310
|
+
ctx.console.log();
|
|
1309
1311
|
}
|
|
1310
1312
|
function getOriginalPos(map, { line, column }) {
|
|
1311
1313
|
return new Promise((resolve) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -149,6 +149,7 @@ interface VitestContext {
|
|
|
149
149
|
state: StateManager;
|
|
150
150
|
snapshot: SnapshotManager;
|
|
151
151
|
reporter: Reporter;
|
|
152
|
+
console: Console;
|
|
152
153
|
}
|
|
153
154
|
interface UserConsoleLog {
|
|
154
155
|
content: string;
|
|
@@ -378,8 +379,25 @@ interface UserOptions {
|
|
|
378
379
|
*/
|
|
379
380
|
minThreads?: number;
|
|
380
381
|
interpretDefault?: boolean;
|
|
382
|
+
/**
|
|
383
|
+
* Default timeout of a test in milliseconds
|
|
384
|
+
*
|
|
385
|
+
* @default 5000
|
|
386
|
+
*/
|
|
381
387
|
testTimeout?: number;
|
|
388
|
+
/**
|
|
389
|
+
* Default timeout of a hook in milliseconds
|
|
390
|
+
*
|
|
391
|
+
* @default 5000
|
|
392
|
+
*/
|
|
382
393
|
hookTimeout?: number;
|
|
394
|
+
/**
|
|
395
|
+
* Silent mode
|
|
396
|
+
* TODO: implement this
|
|
397
|
+
*
|
|
398
|
+
* @default false
|
|
399
|
+
*/
|
|
400
|
+
silent?: boolean;
|
|
383
401
|
}
|
|
384
402
|
interface CliOptions extends UserOptions {
|
|
385
403
|
/**
|
|
@@ -558,6 +576,7 @@ declare global {
|
|
|
558
576
|
}
|
|
559
577
|
interface Assertion {
|
|
560
578
|
toMatchSnapshot(message?: string): Assertion;
|
|
579
|
+
toMatchInlineSnapshot(snapshot?: string, message?: string): Assertion;
|
|
561
580
|
matchSnapshot(message?: string): Assertion;
|
|
562
581
|
toEqual(expected: any): void;
|
|
563
582
|
toStrictEqual(expected: any): void;
|