vitest 0.0.73 → 0.0.77
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 +133 -71
- package/dist/{constants-d4c70610.js → constants-2435fa16.js} +11 -1
- package/dist/entry.js +58 -24
- package/dist/{error-5a04e54b.js → error-c9295525.js} +47 -31
- package/dist/{global-e40b54d6.js → global-38c2f902.js} +4 -4
- package/dist/index-6feda5ef.js +33 -0
- package/dist/{index-6427e0f2.js → index-9e71c815.js} +0 -0
- package/dist/index.d.ts +42 -14
- package/dist/index.js +3 -3
- package/dist/middleware-37267df8.js +34 -0
- package/dist/{suite-819c135e.js → suite-95be5909.js} +42 -41
- package/dist/worker.js +3 -2
- package/package.json +9 -37
- package/README.gh.md +0 -105
- package/README.npm.md +0 -9
- package/dist/index-e37648e9.js +0 -31
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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-c9295525.js';
|
|
3
3
|
import { performance } from 'perf_hooks';
|
|
4
4
|
import path, { isAbsolute, relative, dirname, basename, resolve } from 'path';
|
|
5
|
-
import { g as getNames, s as slash, a as getTests, b as getSuites,
|
|
5
|
+
import { g as getNames, s as slash, a as getTests, b as getSuites, h as hasFailed } from './utils-9dcc4050.js';
|
|
6
6
|
import process$2 from 'process';
|
|
7
7
|
import require$$0 from 'assert';
|
|
8
8
|
import { promises } from 'fs';
|
|
9
9
|
import { createServer } from 'vite';
|
|
10
|
-
import { d as defaultIncludes, a as defaultExcludes, b as distDir } from './constants-
|
|
10
|
+
import { d as defaultIncludes, a as defaultExcludes, b as defaultPort, c as configFiles, e as distDir } from './constants-2435fa16.js';
|
|
11
11
|
import { MessageChannel } from 'worker_threads';
|
|
12
12
|
import { pathToFileURL } from 'url';
|
|
13
13
|
import Piscina from 'piscina';
|
|
@@ -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.77";
|
|
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
|
|
|
@@ -1451,6 +1451,24 @@ 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
|
+
let length = process.stdout.columns;
|
|
1456
|
+
if (!length || isNaN(length))
|
|
1457
|
+
length = 10;
|
|
1458
|
+
if (text) {
|
|
1459
|
+
const textLength = stripAnsi(text).length;
|
|
1460
|
+
if (left == null && right != null) {
|
|
1461
|
+
left = length - textLength - right;
|
|
1462
|
+
} else {
|
|
1463
|
+
left = left ?? Math.floor((length - textLength) / 2);
|
|
1464
|
+
right = length - textLength - left;
|
|
1465
|
+
}
|
|
1466
|
+
left = Math.max(0, left);
|
|
1467
|
+
right = Math.max(0, right);
|
|
1468
|
+
return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
|
|
1469
|
+
}
|
|
1470
|
+
return F_LONG_DASH.repeat(length);
|
|
1471
|
+
}
|
|
1454
1472
|
function formatTestPath(root, path) {
|
|
1455
1473
|
var _a;
|
|
1456
1474
|
if (isAbsolute(path))
|
|
@@ -1573,8 +1591,10 @@ function renderTree(tasks, level = 0) {
|
|
|
1573
1591
|
const createRenderer = (_tasks) => {
|
|
1574
1592
|
let tasks = _tasks;
|
|
1575
1593
|
let timer;
|
|
1594
|
+
const stdout = process.stdout;
|
|
1595
|
+
const log = createLogUpdate(stdout);
|
|
1576
1596
|
function update() {
|
|
1577
|
-
|
|
1597
|
+
log(renderTree(tasks));
|
|
1578
1598
|
}
|
|
1579
1599
|
return {
|
|
1580
1600
|
start() {
|
|
@@ -1593,17 +1613,18 @@ const createRenderer = (_tasks) => {
|
|
|
1593
1613
|
clearInterval(timer);
|
|
1594
1614
|
timer = void 0;
|
|
1595
1615
|
}
|
|
1596
|
-
|
|
1597
|
-
|
|
1616
|
+
log.clear();
|
|
1617
|
+
stdout.write(`${renderTree(tasks)}
|
|
1618
|
+
`);
|
|
1598
1619
|
return this;
|
|
1599
1620
|
},
|
|
1600
1621
|
clear() {
|
|
1601
|
-
|
|
1622
|
+
log.clear();
|
|
1602
1623
|
}
|
|
1603
1624
|
};
|
|
1604
1625
|
};
|
|
1605
1626
|
function getFullName(task) {
|
|
1606
|
-
return getNames(task).join(c.
|
|
1627
|
+
return getNames(task).join(c.dim(" > "));
|
|
1607
1628
|
}
|
|
1608
1629
|
const spinnerFrames = process.platform === "win32" ? ["-", "\\", "|", "/"] : ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1609
1630
|
function elegantSpinner() {
|
|
@@ -1620,11 +1641,23 @@ class DefaultReporter {
|
|
|
1620
1641
|
this.ctx = ctx;
|
|
1621
1642
|
this.start = 0;
|
|
1622
1643
|
this.end = 0;
|
|
1644
|
+
this.console = globalThis.console;
|
|
1645
|
+
this.isFirstWatchRun = true;
|
|
1623
1646
|
const mode = ctx.config.watch ? c.yellow(" DEV ") : c.cyan(" RUN ");
|
|
1624
|
-
|
|
1647
|
+
this.log(`${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
1625
1648
|
`);
|
|
1626
1649
|
this.start = performance.now();
|
|
1627
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
|
+
}
|
|
1628
1661
|
relative(path) {
|
|
1629
1662
|
return relative(this.ctx.config.root, path);
|
|
1630
1663
|
}
|
|
@@ -1643,16 +1676,16 @@ class DefaultReporter {
|
|
|
1643
1676
|
return;
|
|
1644
1677
|
const task = this.ctx.state.idMap[pack[0]];
|
|
1645
1678
|
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
1646
|
-
|
|
1679
|
+
this.log(` ${getStateSymbol(task)} ${getFullName(task)}`);
|
|
1647
1680
|
if (task.result.state === "fail")
|
|
1648
|
-
|
|
1681
|
+
this.log(c.red(` ${F_RIGHT} ${(_c = task.result.error) == null ? void 0 : _c.message}`));
|
|
1649
1682
|
}
|
|
1650
1683
|
}
|
|
1651
1684
|
async onFinished(files = this.ctx.state.getFiles()) {
|
|
1652
1685
|
var _a, _b;
|
|
1653
1686
|
this.end = performance.now();
|
|
1654
1687
|
await this.stopListRender();
|
|
1655
|
-
|
|
1688
|
+
this.log();
|
|
1656
1689
|
const suites = getSuites(files);
|
|
1657
1690
|
const tests = getTests(files);
|
|
1658
1691
|
const failedSuites = suites.filter((i) => {
|
|
@@ -1663,24 +1696,27 @@ class DefaultReporter {
|
|
|
1663
1696
|
var _a2;
|
|
1664
1697
|
return ((_a2 = i.result) == null ? void 0 : _a2.state) === "fail";
|
|
1665
1698
|
});
|
|
1699
|
+
const failedTotal = failedSuites.length + failedTests.length;
|
|
1700
|
+
let current = 1;
|
|
1701
|
+
const errorDivider = () => this.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
1702
|
+
`);
|
|
1666
1703
|
if (failedSuites.length) {
|
|
1667
|
-
|
|
1668
|
-
|
|
1704
|
+
this.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
1705
|
+
this.error();
|
|
1669
1706
|
for (const suite of failedSuites) {
|
|
1670
|
-
|
|
1707
|
+
this.error(c.red(`
|
|
1671
1708
|
- ${getFullName(suite)}`));
|
|
1672
1709
|
await printError((_a = suite.result) == null ? void 0 : _a.error);
|
|
1673
|
-
|
|
1710
|
+
errorDivider();
|
|
1674
1711
|
}
|
|
1675
1712
|
}
|
|
1676
1713
|
if (failedTests.length) {
|
|
1677
|
-
|
|
1678
|
-
|
|
1714
|
+
this.error(c.red(divider(c.bold(c.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
1715
|
+
this.error();
|
|
1679
1716
|
for (const test of failedTests) {
|
|
1680
|
-
|
|
1681
|
-
${c.inverse(" FAIL ")}`)} ${getFullName(test)}`);
|
|
1717
|
+
this.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
|
|
1682
1718
|
await printError((_b = test.result) == null ? void 0 : _b.error);
|
|
1683
|
-
|
|
1719
|
+
errorDivider();
|
|
1684
1720
|
}
|
|
1685
1721
|
}
|
|
1686
1722
|
const executionTime = this.end - this.start;
|
|
@@ -1696,17 +1732,17 @@ ${c.inverse(" FAIL ")}`)} ${getFullName(test)}`);
|
|
|
1696
1732
|
};
|
|
1697
1733
|
const snapshotOutput = renderSnapshotSummary(this.ctx.config.root, this.ctx.snapshot.summary);
|
|
1698
1734
|
if (snapshotOutput.length) {
|
|
1699
|
-
|
|
1735
|
+
this.log(snapshotOutput.map((t, i) => i === 0 ? `${padTitle("Snapshots")} ${t}` : `${padTitle("")} ${t}`).join("\n"));
|
|
1700
1736
|
if (snapshotOutput.length > 1)
|
|
1701
|
-
|
|
1737
|
+
this.log();
|
|
1702
1738
|
}
|
|
1703
|
-
|
|
1704
|
-
|
|
1739
|
+
this.log(padTitle("Test Files"), getStateString(files));
|
|
1740
|
+
this.log(padTitle("Tests"), getStateString(tests));
|
|
1705
1741
|
if (this.watchFilters)
|
|
1706
|
-
|
|
1742
|
+
this.log(padTitle("Time"), time(threadTime));
|
|
1707
1743
|
else
|
|
1708
|
-
|
|
1709
|
-
|
|
1744
|
+
this.log(padTitle("Time"), time(executionTime) + c.gray(` (in thread ${time(threadTime)}, ${(executionTime / threadTime * 100).toFixed(2)}%)`));
|
|
1745
|
+
this.log();
|
|
1710
1746
|
}
|
|
1711
1747
|
async onWatcherStart() {
|
|
1712
1748
|
await this.stopListRender();
|
|
@@ -1715,30 +1751,34 @@ ${c.inverse(" FAIL ")}`)} ${getFullName(test)}`);
|
|
|
1715
1751
|
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
1716
1752
|
});
|
|
1717
1753
|
if (failed.length)
|
|
1718
|
-
|
|
1754
|
+
this.log(`
|
|
1719
1755
|
${c.bold(c.inverse(c.red(" FAIL ")))}${c.red(` ${failed.length} tests failed. Watching for file changes...`)}`);
|
|
1720
1756
|
else
|
|
1721
|
-
|
|
1757
|
+
this.log(`
|
|
1722
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
|
+
}
|
|
1723
1763
|
}
|
|
1724
1764
|
async onWatcherRerun(files, trigger) {
|
|
1725
1765
|
await this.stopListRender();
|
|
1726
1766
|
this.watchFilters = files;
|
|
1727
|
-
console.clear();
|
|
1728
|
-
|
|
1767
|
+
this.console.clear();
|
|
1768
|
+
this.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
|
|
1729
1769
|
`));
|
|
1730
1770
|
}
|
|
1731
1771
|
async stopListRender() {
|
|
1732
1772
|
var _a;
|
|
1733
1773
|
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
1734
1774
|
this.renderer = void 0;
|
|
1735
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
1775
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1736
1776
|
}
|
|
1737
1777
|
onUserConsoleLog(log) {
|
|
1738
1778
|
var _a;
|
|
1739
1779
|
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
1740
1780
|
const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
|
|
1741
|
-
|
|
1781
|
+
this.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
|
|
1742
1782
|
process[log.type].write(`${log.content}
|
|
1743
1783
|
`);
|
|
1744
1784
|
}
|
|
@@ -2087,16 +2127,7 @@ var __spreadValues$1 = (a, b) => {
|
|
|
2087
2127
|
}
|
|
2088
2128
|
return a;
|
|
2089
2129
|
};
|
|
2090
|
-
const configFiles = [
|
|
2091
|
-
"vitest.config.ts",
|
|
2092
|
-
"vitest.config.js",
|
|
2093
|
-
"vitest.config.mjs",
|
|
2094
|
-
"vite.config.ts",
|
|
2095
|
-
"vite.config.js",
|
|
2096
|
-
"vite.config.mjs"
|
|
2097
|
-
];
|
|
2098
2130
|
async function initViteServer(options = {}) {
|
|
2099
|
-
var _a, _b;
|
|
2100
2131
|
const root = resolve(options.root || process.cwd());
|
|
2101
2132
|
process.chdir(root);
|
|
2102
2133
|
if (options.dom)
|
|
@@ -2105,13 +2136,27 @@ async function initViteServer(options = {}) {
|
|
|
2105
2136
|
const resolved = __spreadValues$1({}, options);
|
|
2106
2137
|
resolved.config = configPath;
|
|
2107
2138
|
resolved.root = root;
|
|
2108
|
-
if (options.cliFilters)
|
|
2109
|
-
resolved.cliFilters = toArray(options.cliFilters);
|
|
2110
2139
|
const server = await createServer({
|
|
2111
2140
|
root,
|
|
2112
2141
|
logLevel: "error",
|
|
2113
2142
|
clearScreen: false,
|
|
2114
2143
|
configFile: resolved.config,
|
|
2144
|
+
plugins: [
|
|
2145
|
+
{
|
|
2146
|
+
name: "vitest",
|
|
2147
|
+
configResolved(viteConfig) {
|
|
2148
|
+
resolveConfig(resolved, viteConfig);
|
|
2149
|
+
},
|
|
2150
|
+
async configureServer(server2) {
|
|
2151
|
+
if (resolved.api)
|
|
2152
|
+
server2.middlewares.use((await import('./middleware-37267df8.js')).default());
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
],
|
|
2156
|
+
server: {
|
|
2157
|
+
open: options.open,
|
|
2158
|
+
strictPort: true
|
|
2159
|
+
},
|
|
2115
2160
|
optimizeDeps: {
|
|
2116
2161
|
exclude: [
|
|
2117
2162
|
"vitest"
|
|
@@ -2119,7 +2164,16 @@ async function initViteServer(options = {}) {
|
|
|
2119
2164
|
}
|
|
2120
2165
|
});
|
|
2121
2166
|
await server.pluginContainer.buildStart({});
|
|
2122
|
-
|
|
2167
|
+
if (typeof resolved.api === "number")
|
|
2168
|
+
await server.listen(resolved.api);
|
|
2169
|
+
return {
|
|
2170
|
+
server,
|
|
2171
|
+
config: resolved
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
function resolveConfig(resolved, viteConfig) {
|
|
2175
|
+
var _a, _b;
|
|
2176
|
+
Object.assign(resolved, viteConfig.test);
|
|
2123
2177
|
resolved.depsInline = ((_a = resolved.deps) == null ? void 0 : _a.inline) || [];
|
|
2124
2178
|
resolved.depsExternal = ((_b = resolved.deps) == null ? void 0 : _b.external) || [];
|
|
2125
2179
|
resolved.environment = resolved.environment || "node";
|
|
@@ -2136,14 +2190,13 @@ async function initViteServer(options = {}) {
|
|
|
2136
2190
|
resolved.maxThreads = parseInt(process.env.VITEST_MAX_THREADS);
|
|
2137
2191
|
if (process.env.VITEST_MIN_THREADS)
|
|
2138
2192
|
resolved.minThreads = parseInt(process.env.VITEST_MIN_THREADS);
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
};
|
|
2193
|
+
resolved.setupFiles = Array.from(resolved.setupFiles || []).map((i) => resolve(resolved.root, i));
|
|
2194
|
+
if (resolved.api === true)
|
|
2195
|
+
resolved.api = defaultPort;
|
|
2143
2196
|
}
|
|
2144
2197
|
|
|
2145
2198
|
async function transformRequest(server, id) {
|
|
2146
|
-
if (id.match(/\.(?:[cm]?[jt]
|
|
2199
|
+
if (id.match(/\.(?:[cm]?[jt]s|json)$/)) {
|
|
2147
2200
|
return await server.transformRequest(id, { ssr: true });
|
|
2148
2201
|
} else {
|
|
2149
2202
|
const result = await server.transformRequest(id);
|
|
@@ -2269,6 +2322,7 @@ async function startWatcher(ctx, pool) {
|
|
|
2269
2322
|
let timer;
|
|
2270
2323
|
const changedTests = new Set();
|
|
2271
2324
|
const seen = new Set();
|
|
2325
|
+
let isFirstRun = true;
|
|
2272
2326
|
let promise;
|
|
2273
2327
|
server.watcher.on("change", (id) => {
|
|
2274
2328
|
id = slash(id);
|
|
@@ -2300,6 +2354,7 @@ async function startWatcher(ctx, pool) {
|
|
|
2300
2354
|
seen.clear();
|
|
2301
2355
|
return;
|
|
2302
2356
|
}
|
|
2357
|
+
isFirstRun = false;
|
|
2303
2358
|
ctx.state.getFiles().forEach((file) => {
|
|
2304
2359
|
var _a2;
|
|
2305
2360
|
if (((_a2 = file.result) == null ? void 0 : _a2.state) === "fail")
|
|
@@ -2309,7 +2364,9 @@ async function startWatcher(ctx, pool) {
|
|
|
2309
2364
|
const tests = Array.from(changedTests);
|
|
2310
2365
|
changedTests.clear();
|
|
2311
2366
|
seen.clear();
|
|
2312
|
-
promise = start(tests, id, invalidates)
|
|
2367
|
+
promise = start(tests, id, invalidates).then(() => {
|
|
2368
|
+
promise = void 0;
|
|
2369
|
+
});
|
|
2313
2370
|
await promise;
|
|
2314
2371
|
}, WATCHER_DEBOUNCE);
|
|
2315
2372
|
}
|
|
@@ -2320,8 +2377,18 @@ async function startWatcher(ctx, pool) {
|
|
|
2320
2377
|
await ((_b = reporter.onFinished) == null ? void 0 : _b.call(reporter, ctx.state.getFiles(tests)));
|
|
2321
2378
|
await ((_c = reporter.onWatcherStart) == null ? void 0 : _c.call(reporter));
|
|
2322
2379
|
}
|
|
2323
|
-
if (process.stdin.isTTY)
|
|
2324
|
-
|
|
2380
|
+
if (process.stdin.isTTY) {
|
|
2381
|
+
readline.emitKeypressEvents(process.stdin);
|
|
2382
|
+
process.stdin.setRawMode(true);
|
|
2383
|
+
process.stdin.on("keypress", (str) => {
|
|
2384
|
+
if (str === "" || str === "")
|
|
2385
|
+
process.exit();
|
|
2386
|
+
if (promise)
|
|
2387
|
+
return;
|
|
2388
|
+
if (isFirstRun)
|
|
2389
|
+
process.exit();
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2325
2392
|
await new Promise(() => {
|
|
2326
2393
|
});
|
|
2327
2394
|
}
|
|
@@ -2342,16 +2409,6 @@ function getAffectedTests(ctx, id, set = new Set(), seen = new Set()) {
|
|
|
2342
2409
|
}
|
|
2343
2410
|
return set;
|
|
2344
2411
|
}
|
|
2345
|
-
function listenToKeybard() {
|
|
2346
|
-
readline.emitKeypressEvents(process.stdin);
|
|
2347
|
-
process.stdin.setRawMode(true);
|
|
2348
|
-
process.stdin.on("keypress", (str, key) => {
|
|
2349
|
-
if (str === "" || str === "")
|
|
2350
|
-
process.exit();
|
|
2351
|
-
if (str === "\r")
|
|
2352
|
-
process.exit();
|
|
2353
|
-
});
|
|
2354
|
-
}
|
|
2355
2412
|
|
|
2356
2413
|
async function start(ctx) {
|
|
2357
2414
|
var _a, _b;
|
|
@@ -2428,7 +2485,7 @@ var __spreadValues = (a, b) => {
|
|
|
2428
2485
|
};
|
|
2429
2486
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
2430
2487
|
const cli = cac("vitest");
|
|
2431
|
-
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", {
|
|
2488
|
+
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", {
|
|
2432
2489
|
default: "node"
|
|
2433
2490
|
}).help();
|
|
2434
2491
|
cli.command("run [...filters]").action(run);
|
|
@@ -2437,20 +2494,25 @@ cli.command("dev [...filters]").action(dev);
|
|
|
2437
2494
|
cli.command("[...filters]").action(dev);
|
|
2438
2495
|
cli.parse();
|
|
2439
2496
|
async function dev(cliFilters, argv) {
|
|
2440
|
-
argv.watch
|
|
2497
|
+
if (argv.watch == null)
|
|
2498
|
+
argv.watch = !process.env.CI && !process.env.NODE_V8_COVERAGE;
|
|
2441
2499
|
await run(cliFilters, argv);
|
|
2442
2500
|
}
|
|
2443
2501
|
async function run(cliFilters, argv) {
|
|
2444
2502
|
process.env.VITEST = "true";
|
|
2445
|
-
|
|
2446
|
-
|
|
2503
|
+
process.env.NODE_ENV = "test";
|
|
2504
|
+
if (!argv.silent) {
|
|
2505
|
+
console.log(c.magenta(c.bold("\nVitest is in closed beta exclusively for Sponsors")));
|
|
2506
|
+
console.log(c.yellow("Learn more at https://vitest.dev\n"));
|
|
2507
|
+
}
|
|
2447
2508
|
const { config, server } = await initViteServer(__spreadProps(__spreadValues({}, argv), { cliFilters }));
|
|
2448
2509
|
const ctx = process.__vitest__ = {
|
|
2449
2510
|
server,
|
|
2450
2511
|
config,
|
|
2451
2512
|
state: new StateManager(),
|
|
2452
2513
|
snapshot: new SnapshotManager(config),
|
|
2453
|
-
reporter: config.reporter
|
|
2514
|
+
reporter: config.reporter,
|
|
2515
|
+
console: globalThis.console
|
|
2454
2516
|
};
|
|
2455
2517
|
ctx.reporter = ctx.reporter || new DefaultReporter(ctx);
|
|
2456
2518
|
try {
|
|
@@ -4,6 +4,16 @@ import { fileURLToPath } from 'url';
|
|
|
4
4
|
const distDir = resolve(fileURLToPath(import.meta.url), "../../dist");
|
|
5
5
|
const defaultIncludes = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
6
6
|
const defaultExcludes = ["**/node_modules/**", "**/dist/**"];
|
|
7
|
+
const defaultPort = 51204;
|
|
8
|
+
const API_PATH = "/__vitest_api__";
|
|
9
|
+
const configFiles = [
|
|
10
|
+
"vitest.config.ts",
|
|
11
|
+
"vitest.config.js",
|
|
12
|
+
"vitest.config.mjs",
|
|
13
|
+
"vite.config.ts",
|
|
14
|
+
"vite.config.js",
|
|
15
|
+
"vite.config.mjs"
|
|
16
|
+
];
|
|
7
17
|
const globalApis = [
|
|
8
18
|
"suite",
|
|
9
19
|
"test",
|
|
@@ -22,4 +32,4 @@ const globalApis = [
|
|
|
22
32
|
"afterEach"
|
|
23
33
|
];
|
|
24
34
|
|
|
25
|
-
export { defaultExcludes as a,
|
|
35
|
+
export { API_PATH as A, defaultExcludes as a, defaultPort as b, configFiles as c, defaultIncludes as d, distDir as e, globalApis as g };
|
package/dist/entry.js
CHANGED
|
@@ -5,12 +5,12 @@ import chai, { expect, util } from 'chai';
|
|
|
5
5
|
import SinonChai from 'sinon-chai';
|
|
6
6
|
import Subset from 'chai-subset';
|
|
7
7
|
import path, { basename } from 'path';
|
|
8
|
-
import { g as getNames, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
|
|
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 { d as c$1,
|
|
10
|
+
import { d as c$1, m as generateDiff } from './error-c9295525.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
|
-
import {
|
|
13
|
-
import { n as nanoid } from './index-
|
|
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-95be5909.js';
|
|
13
|
+
import { n as nanoid } from './index-9e71c815.js';
|
|
14
14
|
import 'tty';
|
|
15
15
|
import 'source-map';
|
|
16
16
|
|
|
@@ -203,6 +203,7 @@ const OTHER_KEYS = [
|
|
|
203
203
|
"innerWidth",
|
|
204
204
|
"length",
|
|
205
205
|
"location",
|
|
206
|
+
"matchMedia",
|
|
206
207
|
"moveBy",
|
|
207
208
|
"moveTo",
|
|
208
209
|
"name",
|
|
@@ -248,8 +249,15 @@ var jsdom = {
|
|
|
248
249
|
url: "http://localhost:3000"
|
|
249
250
|
});
|
|
250
251
|
const keys = KEYS.concat(Object.getOwnPropertyNames(dom.window)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
|
|
251
|
-
for (const key of keys)
|
|
252
|
-
global
|
|
252
|
+
for (const key of keys) {
|
|
253
|
+
Object.defineProperty(global, key, {
|
|
254
|
+
get() {
|
|
255
|
+
return dom.window[key];
|
|
256
|
+
},
|
|
257
|
+
configurable: true
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
global.window = global;
|
|
253
261
|
return {
|
|
254
262
|
teardown(global2) {
|
|
255
263
|
keys.forEach((key) => delete global2[key]);
|
|
@@ -264,8 +272,15 @@ var happy = {
|
|
|
264
272
|
const { Window } = await importModule("happy-dom");
|
|
265
273
|
const win = new Window();
|
|
266
274
|
const keys = KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
|
|
267
|
-
for (const key of keys)
|
|
268
|
-
global
|
|
275
|
+
for (const key of keys) {
|
|
276
|
+
Object.defineProperty(global, key, {
|
|
277
|
+
get() {
|
|
278
|
+
return win[key];
|
|
279
|
+
},
|
|
280
|
+
configurable: true
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
global.window = global;
|
|
269
284
|
return {
|
|
270
285
|
teardown(global2) {
|
|
271
286
|
win.happyDOM.cancelAsync();
|
|
@@ -2831,7 +2846,7 @@ class SnapshotState {
|
|
|
2831
2846
|
this._uncheckedKeys.delete(key);
|
|
2832
2847
|
const receivedSerialized = addExtraLineBreaks(serialize(received, void 0, this._snapshotFormat));
|
|
2833
2848
|
const expected = isInline ? inlineSnapshot : this._snapshotData[key];
|
|
2834
|
-
const pass = expected === receivedSerialized;
|
|
2849
|
+
const pass = (expected == null ? void 0 : expected.trim()) === (receivedSerialized == null ? void 0 : receivedSerialized.trim());
|
|
2835
2850
|
const hasSnapshot = expected !== void 0;
|
|
2836
2851
|
const snapshotIsPersisted = isInline || fs.existsSync(this._snapshotPath);
|
|
2837
2852
|
if (pass && !isInline) {
|
|
@@ -2909,16 +2924,23 @@ class SnapshotClient {
|
|
|
2909
2924
|
clearTest() {
|
|
2910
2925
|
this.test = void 0;
|
|
2911
2926
|
}
|
|
2912
|
-
assert(received, message) {
|
|
2927
|
+
assert(received, message, inlineSnapshot) {
|
|
2913
2928
|
if (!this.test)
|
|
2914
|
-
throw new Error("Snapshot
|
|
2929
|
+
throw new Error("Snapshot cannot be used outside of test");
|
|
2930
|
+
const testName = getNames(this.test).slice(1).join(" > ");
|
|
2915
2931
|
const { actual, expected, key, pass } = this.snapshotState.match({
|
|
2916
|
-
testName
|
|
2932
|
+
testName,
|
|
2917
2933
|
received,
|
|
2918
|
-
isInline:
|
|
2934
|
+
isInline: !!inlineSnapshot,
|
|
2935
|
+
inlineSnapshot: inlineSnapshot == null ? void 0 : inlineSnapshot.trim()
|
|
2919
2936
|
});
|
|
2920
2937
|
if (!pass) {
|
|
2921
|
-
|
|
2938
|
+
try {
|
|
2939
|
+
expect(actual.trim()).equals(expected ? expected.trim() : "");
|
|
2940
|
+
} catch (error) {
|
|
2941
|
+
error.message = `Snapshot \`${key || "unknown"}\` mismatched`;
|
|
2942
|
+
throw error;
|
|
2943
|
+
}
|
|
2922
2944
|
}
|
|
2923
2945
|
}
|
|
2924
2946
|
async saveSnap() {
|
|
@@ -2970,6 +2992,10 @@ function SnapshotPlugin() {
|
|
|
2970
2992
|
getSnapshotClient().assert(expected, message);
|
|
2971
2993
|
});
|
|
2972
2994
|
}
|
|
2995
|
+
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function(inlineSnapshot, message) {
|
|
2996
|
+
const expected = utils.flag(this, "object");
|
|
2997
|
+
getSnapshotClient().assert(expected, message, inlineSnapshot);
|
|
2998
|
+
});
|
|
2973
2999
|
};
|
|
2974
3000
|
}
|
|
2975
3001
|
|
|
@@ -3594,7 +3620,7 @@ async function setupGlobalEnv(config) {
|
|
|
3594
3620
|
setupConsoleLogSpy();
|
|
3595
3621
|
await setupChai();
|
|
3596
3622
|
if (config.global)
|
|
3597
|
-
(await import('./global-
|
|
3623
|
+
(await import('./global-38c2f902.js')).registerApiGlobally();
|
|
3598
3624
|
}
|
|
3599
3625
|
function setupConsoleLogSpy() {
|
|
3600
3626
|
const stdout = new Writable({
|
|
@@ -3635,6 +3661,13 @@ async function withEnv(name, fn) {
|
|
|
3635
3661
|
await env.teardown(globalThis);
|
|
3636
3662
|
}
|
|
3637
3663
|
}
|
|
3664
|
+
async function runSetupFiles(config) {
|
|
3665
|
+
const files = toArray(config.setupFiles);
|
|
3666
|
+
await Promise.all(files.map(async (file) => {
|
|
3667
|
+
process.__vitest_worker__.moduleCache.delete(file);
|
|
3668
|
+
await import(file);
|
|
3669
|
+
}));
|
|
3670
|
+
}
|
|
3638
3671
|
|
|
3639
3672
|
function processError(err) {
|
|
3640
3673
|
if (!err)
|
|
@@ -3646,7 +3679,7 @@ function processError(err) {
|
|
|
3646
3679
|
return err;
|
|
3647
3680
|
}
|
|
3648
3681
|
|
|
3649
|
-
async function collectTests(paths) {
|
|
3682
|
+
async function collectTests(paths, config) {
|
|
3650
3683
|
const files = [];
|
|
3651
3684
|
for (const filepath of paths) {
|
|
3652
3685
|
const file = {
|
|
@@ -3661,6 +3694,7 @@ async function collectTests(paths) {
|
|
|
3661
3694
|
setHooks(file, createSuiteHooks());
|
|
3662
3695
|
clearContext();
|
|
3663
3696
|
try {
|
|
3697
|
+
await runSetupFiles(config);
|
|
3664
3698
|
await import(filepath);
|
|
3665
3699
|
for (const c of [defaultSuite, ...context.tasks]) {
|
|
3666
3700
|
if (c.type === "test") {
|
|
@@ -3694,7 +3728,7 @@ async function collectTests(paths) {
|
|
|
3694
3728
|
return files;
|
|
3695
3729
|
}
|
|
3696
3730
|
|
|
3697
|
-
async function
|
|
3731
|
+
async function callSuiteHook(suite, name, args) {
|
|
3698
3732
|
await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)));
|
|
3699
3733
|
}
|
|
3700
3734
|
function updateTask(task) {
|
|
@@ -3711,7 +3745,7 @@ async function runTest(test) {
|
|
|
3711
3745
|
getSnapshotClient().setTest(test);
|
|
3712
3746
|
process.__vitest_worker__.current = test;
|
|
3713
3747
|
try {
|
|
3714
|
-
await
|
|
3748
|
+
await callSuiteHook(test.suite, "beforeEach", [test, test.suite]);
|
|
3715
3749
|
await getFn(test)();
|
|
3716
3750
|
test.result.state = "pass";
|
|
3717
3751
|
} catch (e) {
|
|
@@ -3719,7 +3753,7 @@ async function runTest(test) {
|
|
|
3719
3753
|
test.result.error = processError(e);
|
|
3720
3754
|
}
|
|
3721
3755
|
try {
|
|
3722
|
-
await
|
|
3756
|
+
await callSuiteHook(test.suite, "afterEach", [test, test.suite]);
|
|
3723
3757
|
} catch (e) {
|
|
3724
3758
|
test.result.state = "fail";
|
|
3725
3759
|
test.result.error = processError(e);
|
|
@@ -3744,7 +3778,7 @@ async function runSuite(suite) {
|
|
|
3744
3778
|
suite.result.state = "todo";
|
|
3745
3779
|
} else {
|
|
3746
3780
|
try {
|
|
3747
|
-
await
|
|
3781
|
+
await callSuiteHook(suite, "beforeAll", [suite]);
|
|
3748
3782
|
for (const tasksGroup of partitionSuiteChildren(suite)) {
|
|
3749
3783
|
const computeMode = tasksGroup[0].computeMode;
|
|
3750
3784
|
if (computeMode === "serial") {
|
|
@@ -3754,7 +3788,7 @@ async function runSuite(suite) {
|
|
|
3754
3788
|
await Promise.all(tasksGroup.map((c) => runSuiteChild(c)));
|
|
3755
3789
|
}
|
|
3756
3790
|
}
|
|
3757
|
-
await
|
|
3791
|
+
await callSuiteHook(suite, "afterAll", [suite]);
|
|
3758
3792
|
} catch (e) {
|
|
3759
3793
|
suite.result.state = "fail";
|
|
3760
3794
|
suite.result.error = processError(e);
|
|
@@ -3781,8 +3815,8 @@ async function runSuites(suites) {
|
|
|
3781
3815
|
for (const suite of suites)
|
|
3782
3816
|
await runSuite(suite);
|
|
3783
3817
|
}
|
|
3784
|
-
async function startTests(paths) {
|
|
3785
|
-
const files = await collectTests(paths);
|
|
3818
|
+
async function startTests(paths, config) {
|
|
3819
|
+
const files = await collectTests(paths, config);
|
|
3786
3820
|
send("onCollected", files);
|
|
3787
3821
|
await runSuites(files);
|
|
3788
3822
|
await getSnapshotClient().saveSnap();
|
|
@@ -3791,7 +3825,7 @@ async function startTests(paths) {
|
|
|
3791
3825
|
async function run(files, config) {
|
|
3792
3826
|
await setupGlobalEnv(config);
|
|
3793
3827
|
await withEnv(config.environment, async () => {
|
|
3794
|
-
await startTests(files);
|
|
3828
|
+
await startTests(files, config);
|
|
3795
3829
|
});
|
|
3796
3830
|
}
|
|
3797
3831
|
|