vitest 0.0.84 → 0.0.89
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/bin/vitest.mjs +2 -0
- package/dist/cli.js +25 -9
- package/dist/entry.js +61 -77
- package/dist/{error-c651f5ae.js → error-309196c9.js} +5 -68
- package/dist/{global-e172af93.js → global-f3eab75a.js} +2 -2
- package/dist/index-722fb5a5.js +122 -0
- package/dist/{index-ad1b10e4.js → index-733e7378.js} +178 -162
- package/dist/index.d.ts +49 -5
- package/dist/index.js +2 -2
- package/dist/node.js +5 -5
- package/dist/{suite-0e21bf9b.js → suite-b8c6cb53.js} +2 -2
- package/dist/utils-385e2d09.js +143 -0
- package/dist/utils.js +3 -0
- package/dist/worker.js +8273 -52
- package/package.json +6 -3
- package/dist/index-906ac3f9.js +0 -34
- package/dist/utils-9dcc4050.js +0 -64
|
@@ -3,17 +3,16 @@ import { createServer, mergeConfig } from 'vite';
|
|
|
3
3
|
import process$2 from 'process';
|
|
4
4
|
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
|
-
import { g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-
|
|
6
|
+
import { c, g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-385e2d09.js';
|
|
7
7
|
import { performance } from 'perf_hooks';
|
|
8
|
-
import { s as stringWidth, a as ansiStyles, b as stripAnsi,
|
|
9
|
-
import
|
|
8
|
+
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 './error-309196c9.js';
|
|
9
|
+
import assert$1 from 'assert';
|
|
10
10
|
import require$$2 from 'events';
|
|
11
11
|
import { MessageChannel } from 'worker_threads';
|
|
12
12
|
import { pathToFileURL } from 'url';
|
|
13
13
|
import Piscina from 'piscina';
|
|
14
14
|
import fg from 'fast-glob';
|
|
15
15
|
import mm from 'micromatch';
|
|
16
|
-
import readline from 'readline';
|
|
17
16
|
|
|
18
17
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
19
18
|
|
|
@@ -644,7 +643,7 @@ const processOk = function (process) {
|
|
|
644
643
|
if (!processOk(process$1)) {
|
|
645
644
|
signalExit$1.exports = function () {};
|
|
646
645
|
} else {
|
|
647
|
-
var assert =
|
|
646
|
+
var assert = assert$1;
|
|
648
647
|
var signals = signals$1.exports;
|
|
649
648
|
var isWin = /^win/i.test(process$1.platform);
|
|
650
649
|
|
|
@@ -1157,8 +1156,8 @@ createLogUpdate(process$2.stderr);
|
|
|
1157
1156
|
|
|
1158
1157
|
const DURATION_LONG = 300;
|
|
1159
1158
|
const MAX_HEIGHT = 20;
|
|
1160
|
-
const spinnerMap = new WeakMap();
|
|
1161
|
-
const outputMap = new WeakMap();
|
|
1159
|
+
const spinnerMap = /* @__PURE__ */ new WeakMap();
|
|
1160
|
+
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
1162
1161
|
const pointer = c.yellow(F_POINTER);
|
|
1163
1162
|
const skipped = c.yellow(F_DOWN);
|
|
1164
1163
|
function divider(text, left, right) {
|
|
@@ -1414,7 +1413,7 @@ class ConsoleReporter {
|
|
|
1414
1413
|
for (const suite of failedSuites) {
|
|
1415
1414
|
this.error(c.red(`
|
|
1416
1415
|
- ${getFullName(suite)}`));
|
|
1417
|
-
await printError((_a = suite.result) == null ? void 0 : _a.error);
|
|
1416
|
+
await printError((_a = suite.result) == null ? void 0 : _a.error, this.ctx);
|
|
1418
1417
|
errorDivider();
|
|
1419
1418
|
}
|
|
1420
1419
|
}
|
|
@@ -1423,7 +1422,7 @@ class ConsoleReporter {
|
|
|
1423
1422
|
this.error();
|
|
1424
1423
|
for (const test of failedTests) {
|
|
1425
1424
|
this.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
|
|
1426
|
-
await printError((_b = test.result) == null ? void 0 : _b.error);
|
|
1425
|
+
await printError((_b = test.result) == null ? void 0 : _b.error, this.ctx);
|
|
1427
1426
|
errorDivider();
|
|
1428
1427
|
}
|
|
1429
1428
|
}
|
|
@@ -1490,13 +1489,17 @@ ${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")
|
|
|
1490
1489
|
process[log.type].write(`${log.content}
|
|
1491
1490
|
`);
|
|
1492
1491
|
}
|
|
1492
|
+
onServerRestart() {
|
|
1493
|
+
this.console.clear();
|
|
1494
|
+
this.log(c.cyan("Restarted due to config changes..."));
|
|
1495
|
+
}
|
|
1493
1496
|
}
|
|
1494
1497
|
|
|
1495
1498
|
class StateManager {
|
|
1496
1499
|
constructor() {
|
|
1497
1500
|
this.filesMap = {};
|
|
1498
1501
|
this.idMap = {};
|
|
1499
|
-
this.taskFileMap = new WeakMap();
|
|
1502
|
+
this.taskFileMap = /* @__PURE__ */ new WeakMap();
|
|
1500
1503
|
}
|
|
1501
1504
|
getFiles(keys) {
|
|
1502
1505
|
if (keys)
|
|
@@ -1553,8 +1556,8 @@ function resolveConfig(options, viteConfig) {
|
|
|
1553
1556
|
const resolved = __spreadProps(__spreadValues(__spreadValues({}, options), viteConfig.test), {
|
|
1554
1557
|
root: viteConfig.root
|
|
1555
1558
|
});
|
|
1556
|
-
resolved.depsInline = ((_a = resolved.deps) == null ? void 0 : _a.inline) || [];
|
|
1557
|
-
resolved.depsExternal = ((_b = resolved.deps) == null ? void 0 : _b.external) || [];
|
|
1559
|
+
resolved.depsInline = [...((_a = resolved.deps) == null ? void 0 : _a.inline) || []];
|
|
1560
|
+
resolved.depsExternal = [...((_b = resolved.deps) == null ? void 0 : _b.external) || []];
|
|
1558
1561
|
resolved.environment = resolved.environment || "node";
|
|
1559
1562
|
resolved.threads = resolved.threads ?? true;
|
|
1560
1563
|
resolved.interpretDefault = resolved.interpretDefault ?? true;
|
|
@@ -1576,14 +1579,29 @@ function resolveConfig(options, viteConfig) {
|
|
|
1576
1579
|
}
|
|
1577
1580
|
|
|
1578
1581
|
async function transformRequest(server, id) {
|
|
1582
|
+
let result = null;
|
|
1579
1583
|
if (id.match(/\.(?:[cm]?[jt]sx?|json)$/)) {
|
|
1580
|
-
|
|
1584
|
+
result = await server.transformRequest(id, { ssr: true });
|
|
1581
1585
|
} else {
|
|
1582
|
-
|
|
1583
|
-
if (
|
|
1584
|
-
|
|
1585
|
-
return await server.ssrTransform(result.code, result.map, id);
|
|
1586
|
+
result = await server.transformRequest(id);
|
|
1587
|
+
if (result)
|
|
1588
|
+
result = await server.ssrTransform(result.code, result.map, id);
|
|
1586
1589
|
}
|
|
1590
|
+
if (result && process.env.NODE_V8_COVERAGE)
|
|
1591
|
+
withInlineSourcemap(result);
|
|
1592
|
+
return result;
|
|
1593
|
+
}
|
|
1594
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
1595
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
1596
|
+
async function withInlineSourcemap(result) {
|
|
1597
|
+
const { code, map } = result;
|
|
1598
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
1599
|
+
return result;
|
|
1600
|
+
if (map)
|
|
1601
|
+
result.code = `${code}
|
|
1602
|
+
|
|
1603
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}`;
|
|
1604
|
+
return result;
|
|
1587
1605
|
}
|
|
1588
1606
|
|
|
1589
1607
|
function createPool(ctx) {
|
|
@@ -1594,21 +1612,24 @@ function createPool(ctx) {
|
|
|
1594
1612
|
}
|
|
1595
1613
|
const workerPath = new URL("./dist/worker.js", pathToFileURL(distDir)).href;
|
|
1596
1614
|
function createFakePool(ctx) {
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1615
|
+
const runWithFiles = (name) => {
|
|
1616
|
+
return async (files, invalidates) => {
|
|
1617
|
+
const worker = await import(workerPath);
|
|
1618
|
+
const { workerPort, port } = createChannel(ctx);
|
|
1619
|
+
const data = {
|
|
1620
|
+
port: workerPort,
|
|
1621
|
+
config: ctx.config,
|
|
1622
|
+
files,
|
|
1623
|
+
invalidates
|
|
1624
|
+
};
|
|
1625
|
+
await worker[name](data, { transferList: [workerPort] });
|
|
1626
|
+
port.close();
|
|
1627
|
+
workerPort.close();
|
|
1605
1628
|
};
|
|
1606
|
-
await run(data, { transferList: [workerPort] });
|
|
1607
|
-
port.close();
|
|
1608
|
-
workerPort.close();
|
|
1609
1629
|
};
|
|
1610
1630
|
return {
|
|
1611
|
-
|
|
1631
|
+
runTests: runWithFiles("run"),
|
|
1632
|
+
collectTests: runWithFiles("collect"),
|
|
1612
1633
|
close: async () => {
|
|
1613
1634
|
}
|
|
1614
1635
|
};
|
|
@@ -1623,22 +1644,25 @@ function createWorkerPool(ctx) {
|
|
|
1623
1644
|
if (ctx.config.minThreads != null)
|
|
1624
1645
|
options.minThreads = ctx.config.minThreads;
|
|
1625
1646
|
const piscina = new Piscina(options);
|
|
1626
|
-
const
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1647
|
+
const runWithFiles = (name) => {
|
|
1648
|
+
return async (files, invalidates) => {
|
|
1649
|
+
await Promise.all(files.map(async (file) => {
|
|
1650
|
+
const { workerPort, port } = createChannel(ctx);
|
|
1651
|
+
const data = {
|
|
1652
|
+
port: workerPort,
|
|
1653
|
+
config: ctx.config,
|
|
1654
|
+
files: [file],
|
|
1655
|
+
invalidates
|
|
1656
|
+
};
|
|
1657
|
+
await piscina.run(data, { transferList: [workerPort], name });
|
|
1658
|
+
port.close();
|
|
1659
|
+
workerPort.close();
|
|
1660
|
+
}));
|
|
1661
|
+
};
|
|
1639
1662
|
};
|
|
1640
1663
|
return {
|
|
1641
|
-
|
|
1664
|
+
runTests: runWithFiles("run"),
|
|
1665
|
+
collectTests: runWithFiles("collect"),
|
|
1642
1666
|
close: () => piscina.destroy()
|
|
1643
1667
|
};
|
|
1644
1668
|
}
|
|
@@ -1661,7 +1685,7 @@ function createChannel(ctx) {
|
|
|
1661
1685
|
case "snapshotSaved":
|
|
1662
1686
|
return send(() => ctx.snapshot.add(args[0]));
|
|
1663
1687
|
case "fetch":
|
|
1664
|
-
return send(() => transformRequest(ctx.server, ...args));
|
|
1688
|
+
return send(() => transformRequest(ctx.server, ...args).then((r) => r == null ? void 0 : r.code));
|
|
1665
1689
|
case "onCollected":
|
|
1666
1690
|
ctx.state.collectFiles(args[0]);
|
|
1667
1691
|
ctx.reporters.forEach((r) => {
|
|
@@ -1693,138 +1717,129 @@ function isTargetFile(id, config) {
|
|
|
1693
1717
|
return false;
|
|
1694
1718
|
return mm.isMatch(id, config.include);
|
|
1695
1719
|
}
|
|
1696
|
-
async function globTestFiles(config) {
|
|
1697
|
-
|
|
1720
|
+
async function globTestFiles(config, filters) {
|
|
1721
|
+
let files = await fg(config.include, {
|
|
1698
1722
|
absolute: true,
|
|
1699
1723
|
cwd: config.root,
|
|
1700
1724
|
ignore: config.exclude
|
|
1701
1725
|
});
|
|
1726
|
+
if (filters == null ? void 0 : filters.length)
|
|
1727
|
+
files = files.filter((i) => filters.some((f) => i.includes(f)));
|
|
1728
|
+
return files;
|
|
1702
1729
|
}
|
|
1703
1730
|
|
|
1704
|
-
const WATCHER_DEBOUNCE =
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
server.watcher.on("change", (id) => {
|
|
1717
|
-
id = slash(id);
|
|
1718
|
-
getAffectedTests(ctx, id, changedTests, seen);
|
|
1719
|
-
if (changedTests.size === 0)
|
|
1720
|
-
return;
|
|
1721
|
-
rerunFile(id);
|
|
1722
|
-
});
|
|
1723
|
-
server.watcher.on("unlink", (id) => {
|
|
1724
|
-
id = slash(id);
|
|
1725
|
-
seen.add(id);
|
|
1726
|
-
if (id in ctx.state.filesMap) {
|
|
1727
|
-
delete ctx.state.filesMap[id];
|
|
1728
|
-
changedTests.delete(id);
|
|
1729
|
-
}
|
|
1730
|
-
});
|
|
1731
|
-
server.watcher.on("add", async (id) => {
|
|
1732
|
-
id = slash(id);
|
|
1733
|
-
if (isTargetFile(id, ctx.config)) {
|
|
1734
|
-
changedTests.add(id);
|
|
1735
|
-
rerunFile(id);
|
|
1736
|
-
}
|
|
1737
|
-
});
|
|
1738
|
-
async function rerunFile(id) {
|
|
1739
|
-
await promise;
|
|
1740
|
-
clearTimeout(timer);
|
|
1741
|
-
timer = setTimeout(async () => {
|
|
1742
|
-
if (changedTests.size === 0) {
|
|
1743
|
-
seen.clear();
|
|
1744
|
-
return;
|
|
1745
|
-
}
|
|
1746
|
-
isFirstRun = false;
|
|
1747
|
-
const invalidates = Array.from(seen);
|
|
1748
|
-
const tests = Array.from(changedTests);
|
|
1749
|
-
changedTests.clear();
|
|
1750
|
-
seen.clear();
|
|
1751
|
-
promise = start(tests, id, invalidates).then(() => {
|
|
1752
|
-
promise = void 0;
|
|
1753
|
-
});
|
|
1754
|
-
await promise;
|
|
1755
|
-
}, WATCHER_DEBOUNCE);
|
|
1731
|
+
const WATCHER_DEBOUNCE = 100;
|
|
1732
|
+
class Vitest {
|
|
1733
|
+
constructor() {
|
|
1734
|
+
this.config = void 0;
|
|
1735
|
+
this.server = void 0;
|
|
1736
|
+
this.state = void 0;
|
|
1737
|
+
this.snapshot = void 0;
|
|
1738
|
+
this.reporters = void 0;
|
|
1739
|
+
this.invalidates = /* @__PURE__ */ new Set();
|
|
1740
|
+
this.changedTests = /* @__PURE__ */ new Set();
|
|
1741
|
+
this.isFirstRun = true;
|
|
1742
|
+
this.console = globalThis.console;
|
|
1756
1743
|
}
|
|
1757
|
-
|
|
1744
|
+
setServer(options, server) {
|
|
1758
1745
|
var _a;
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
await ctx.report("onFinished", ctx.state.getFiles(tests));
|
|
1762
|
-
await ctx.report("onWatcherStart");
|
|
1763
|
-
}
|
|
1764
|
-
if (process.stdin.isTTY) {
|
|
1765
|
-
readline.emitKeypressEvents(process.stdin);
|
|
1766
|
-
process.stdin.setRawMode(true);
|
|
1767
|
-
process.stdin.on("keypress", (str) => {
|
|
1768
|
-
if (str === "" || str === "")
|
|
1769
|
-
process.exit();
|
|
1770
|
-
if (promise)
|
|
1771
|
-
return;
|
|
1772
|
-
if (isFirstRun)
|
|
1773
|
-
process.exit();
|
|
1774
|
-
});
|
|
1775
|
-
}
|
|
1776
|
-
await new Promise(() => {
|
|
1777
|
-
});
|
|
1778
|
-
}
|
|
1779
|
-
function getAffectedTests(ctx, id, set = new Set(), seen = new Set()) {
|
|
1780
|
-
if (seen.has(id) || set.has(id) || id.includes("/node_modules/") || id.includes("/vitest/dist/"))
|
|
1781
|
-
return set;
|
|
1782
|
-
seen.add(id);
|
|
1783
|
-
if (id in ctx.state.filesMap) {
|
|
1784
|
-
set.add(id);
|
|
1785
|
-
return set;
|
|
1786
|
-
}
|
|
1787
|
-
const mod = ctx.server.moduleGraph.getModuleById(id);
|
|
1788
|
-
if (mod) {
|
|
1789
|
-
mod.importers.forEach((i) => {
|
|
1790
|
-
if (i.id)
|
|
1791
|
-
getAffectedTests(ctx, i.id, set, seen);
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
return set;
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
class Vitest {
|
|
1798
|
-
constructor(options, server) {
|
|
1746
|
+
(_a = this.pool) == null ? void 0 : _a.close();
|
|
1747
|
+
this.pool = void 0;
|
|
1799
1748
|
const resolved = resolveConfig(options, server.config);
|
|
1800
1749
|
this.server = server;
|
|
1801
1750
|
this.config = resolved;
|
|
1802
1751
|
this.state = new StateManager();
|
|
1803
1752
|
this.snapshot = new SnapshotManager(resolved);
|
|
1804
1753
|
this.reporters = toArray(resolved.reporters);
|
|
1805
|
-
this.console = globalThis.console;
|
|
1806
1754
|
if (!this.reporters.length)
|
|
1807
1755
|
this.reporters.push(new ConsoleReporter(this));
|
|
1756
|
+
if (this.config.watch)
|
|
1757
|
+
this.registerWatcher();
|
|
1758
|
+
this.runningPromise = void 0;
|
|
1808
1759
|
}
|
|
1809
|
-
async
|
|
1810
|
-
|
|
1811
|
-
if (
|
|
1812
|
-
testFilepaths = testFilepaths.filter((i) => filters.some((f) => i.includes(f)));
|
|
1813
|
-
if (!testFilepaths.length) {
|
|
1760
|
+
async start(filters) {
|
|
1761
|
+
const files = await globTestFiles(this.config, filters);
|
|
1762
|
+
if (!files.length) {
|
|
1814
1763
|
console.error("No test files found");
|
|
1815
1764
|
process.exitCode = 1;
|
|
1765
|
+
}
|
|
1766
|
+
await this.runFiles(files);
|
|
1767
|
+
if (this.config.watch) {
|
|
1768
|
+
await this.report("onWatcherStart");
|
|
1769
|
+
await new Promise(() => {
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
async runFiles(files) {
|
|
1774
|
+
await this.runningPromise;
|
|
1775
|
+
this.runningPromise = (async () => {
|
|
1776
|
+
if (!this.pool)
|
|
1777
|
+
this.pool = createPool(this);
|
|
1778
|
+
const invalidates = Array.from(this.invalidates);
|
|
1779
|
+
this.invalidates.clear();
|
|
1780
|
+
await this.pool.runTests(files, invalidates);
|
|
1781
|
+
if (hasFailed(this.state.getFiles()))
|
|
1782
|
+
process.exitCode = 1;
|
|
1783
|
+
await this.report("onFinished", this.state.getFiles());
|
|
1784
|
+
})().finally(() => {
|
|
1785
|
+
this.runningPromise = void 0;
|
|
1786
|
+
});
|
|
1787
|
+
return await this.runningPromise;
|
|
1788
|
+
}
|
|
1789
|
+
registerWatcher() {
|
|
1790
|
+
let timer;
|
|
1791
|
+
const scheduleRerun = async (id) => {
|
|
1792
|
+
await this.runningPromise;
|
|
1793
|
+
clearTimeout(timer);
|
|
1794
|
+
timer = setTimeout(async () => {
|
|
1795
|
+
if (this.changedTests.size === 0) {
|
|
1796
|
+
this.invalidates.clear();
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
this.isFirstRun = false;
|
|
1800
|
+
const files = Array.from(this.changedTests);
|
|
1801
|
+
await this.report("onWatcherRerun", files, id);
|
|
1802
|
+
await this.runFiles(files);
|
|
1803
|
+
await this.report("onWatcherStart");
|
|
1804
|
+
}, WATCHER_DEBOUNCE);
|
|
1805
|
+
};
|
|
1806
|
+
this.server.watcher.on("change", (id) => {
|
|
1807
|
+
id = slash(id);
|
|
1808
|
+
this.handleFileChanged(id);
|
|
1809
|
+
if (this.changedTests.size)
|
|
1810
|
+
scheduleRerun(id);
|
|
1811
|
+
});
|
|
1812
|
+
this.server.watcher.on("unlink", (id) => {
|
|
1813
|
+
id = slash(id);
|
|
1814
|
+
this.invalidates.add(id);
|
|
1815
|
+
if (id in this.state.filesMap) {
|
|
1816
|
+
delete this.state.filesMap[id];
|
|
1817
|
+
this.changedTests.delete(id);
|
|
1818
|
+
}
|
|
1819
|
+
});
|
|
1820
|
+
this.server.watcher.on("add", async (id) => {
|
|
1821
|
+
id = slash(id);
|
|
1822
|
+
if (isTargetFile(id, this.config)) {
|
|
1823
|
+
this.changedTests.add(id);
|
|
1824
|
+
scheduleRerun(id);
|
|
1825
|
+
}
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
handleFileChanged(id) {
|
|
1829
|
+
if (this.changedTests.has(id) || this.invalidates.has(id) || id.includes("/node_modules/") || id.includes("/vitest/dist/"))
|
|
1830
|
+
return;
|
|
1831
|
+
this.invalidates.add(id);
|
|
1832
|
+
if (id in this.state.filesMap) {
|
|
1833
|
+
this.changedTests.add(id);
|
|
1816
1834
|
return;
|
|
1817
1835
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
await startWatcher(this);
|
|
1826
|
-
else
|
|
1827
|
-
await this.pool.close();
|
|
1836
|
+
const mod = this.server.moduleGraph.getModuleById(id);
|
|
1837
|
+
if (mod) {
|
|
1838
|
+
mod.importers.forEach((i) => {
|
|
1839
|
+
if (i.id)
|
|
1840
|
+
this.handleFileChanged(i.id);
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1828
1843
|
}
|
|
1829
1844
|
async close() {
|
|
1830
1845
|
var _a;
|
|
@@ -1838,14 +1853,11 @@ class Vitest {
|
|
|
1838
1853
|
}));
|
|
1839
1854
|
}
|
|
1840
1855
|
}
|
|
1841
|
-
async function createVitest(options, viteOverrides) {
|
|
1842
|
-
const
|
|
1843
|
-
const instance = new Vitest(options, server);
|
|
1844
|
-
return instance;
|
|
1845
|
-
}
|
|
1846
|
-
async function startServer(options, viteOverrides = {}) {
|
|
1856
|
+
async function createVitest(options, viteOverrides = {}) {
|
|
1857
|
+
const ctx = new Vitest();
|
|
1847
1858
|
const root = resolve(options.root || process.cwd());
|
|
1848
1859
|
const configPath = options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
|
|
1860
|
+
let haveStarted = false;
|
|
1849
1861
|
const config = {
|
|
1850
1862
|
root,
|
|
1851
1863
|
logLevel: "error",
|
|
@@ -1855,6 +1867,10 @@ async function startServer(options, viteOverrides = {}) {
|
|
|
1855
1867
|
{
|
|
1856
1868
|
name: "vitest",
|
|
1857
1869
|
async configureServer(server2) {
|
|
1870
|
+
if (haveStarted)
|
|
1871
|
+
await ctx.report("onServerRestart");
|
|
1872
|
+
ctx.setServer(options, server2);
|
|
1873
|
+
haveStarted = true;
|
|
1858
1874
|
if (options.api)
|
|
1859
1875
|
server2.middlewares.use((await import('./middleware-650c5fa0.js')).default());
|
|
1860
1876
|
}
|
|
@@ -1874,7 +1890,7 @@ async function startServer(options, viteOverrides = {}) {
|
|
|
1874
1890
|
await server.pluginContainer.buildStart({});
|
|
1875
1891
|
if (typeof options.api === "number")
|
|
1876
1892
|
await server.listen(options.api);
|
|
1877
|
-
return
|
|
1893
|
+
return ctx;
|
|
1878
1894
|
}
|
|
1879
1895
|
|
|
1880
1896
|
export { createVitest as c };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Formatter } from 'picocolors/types';
|
|
2
|
-
import { TransformResult } from 'vite';
|
|
3
2
|
import { OptionsReceived } from 'pretty-format';
|
|
4
3
|
import { MessagePort } from 'worker_threads';
|
|
5
4
|
export { assert, default as chai, expect, should } from 'chai';
|
|
6
|
-
import { spyOn, spy } from 'tinyspy';
|
|
7
5
|
export { spy, spyOn } from 'tinyspy';
|
|
8
6
|
|
|
9
7
|
declare const EXPECTED_COLOR: Formatter;
|
|
@@ -117,7 +115,7 @@ declare type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
|
|
|
117
115
|
interface ModuleCache {
|
|
118
116
|
promise?: Promise<any>;
|
|
119
117
|
exports?: any;
|
|
120
|
-
|
|
118
|
+
code?: string;
|
|
121
119
|
}
|
|
122
120
|
interface EnvironmentReturn {
|
|
123
121
|
teardown: (global: any) => Awaitable<void>;
|
|
@@ -221,6 +219,7 @@ interface Reporter {
|
|
|
221
219
|
onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
|
|
222
220
|
onWatcherStart?: () => Awaitable<void>;
|
|
223
221
|
onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
|
|
222
|
+
onServerRestart?: () => Awaitable<void>;
|
|
224
223
|
onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
|
|
225
224
|
}
|
|
226
225
|
|
|
@@ -420,7 +419,7 @@ interface WorkerContext {
|
|
|
420
419
|
invalidates?: string[];
|
|
421
420
|
}
|
|
422
421
|
interface RpcMap {
|
|
423
|
-
fetch: [[id: string],
|
|
422
|
+
fetch: [[id: string], string | undefined];
|
|
424
423
|
log: [[UserConsoleLog], void];
|
|
425
424
|
processExit: [[code?: number], void];
|
|
426
425
|
onCollected: [[files: File[]], void];
|
|
@@ -541,9 +540,54 @@ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undef
|
|
|
541
540
|
declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
|
|
542
541
|
declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
|
|
543
542
|
|
|
543
|
+
interface MockResultReturn<T> {
|
|
544
|
+
type: 'return';
|
|
545
|
+
value: T;
|
|
546
|
+
}
|
|
547
|
+
interface MockResultIncomplete {
|
|
548
|
+
type: 'incomplete';
|
|
549
|
+
value: undefined;
|
|
550
|
+
}
|
|
551
|
+
interface MockResultThrow {
|
|
552
|
+
type: 'throw';
|
|
553
|
+
value: any;
|
|
554
|
+
}
|
|
555
|
+
declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
556
|
+
interface JestMockCompatContext<T, Y> {
|
|
557
|
+
calls: Y[];
|
|
558
|
+
instances: T[];
|
|
559
|
+
invocationCallOrder: number[];
|
|
560
|
+
results: MockResult<T>[];
|
|
561
|
+
}
|
|
562
|
+
interface JestMockCompat<TArgs extends any[] = any[], TReturns = any> {
|
|
563
|
+
getMockName(): string;
|
|
564
|
+
mockName(n: string): this;
|
|
565
|
+
mock: JestMockCompatContext<TArgs, TReturns>;
|
|
566
|
+
mockClear(): this;
|
|
567
|
+
mockReset(): this;
|
|
568
|
+
mockRestore(): void;
|
|
569
|
+
getMockImplementation(): ((...args: TArgs) => TReturns) | undefined;
|
|
570
|
+
mockImplementation(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
|
|
571
|
+
mockImplementationOnce(fn: ((...args: TArgs) => TReturns) | (() => Promise<TReturns>)): this;
|
|
572
|
+
mockReturnThis(): this;
|
|
573
|
+
mockReturnValue(obj: TReturns): this;
|
|
574
|
+
mockReturnValueOnce(obj: TReturns): this;
|
|
575
|
+
mockResolvedValue(obj: Unpromisify<TReturns>): this;
|
|
576
|
+
mockResolvedValueOnce(obj: Unpromisify<TReturns>): this;
|
|
577
|
+
mockRejectedValue(obj: any): this;
|
|
578
|
+
mockRejectedValueOnce(obj: any): this;
|
|
579
|
+
}
|
|
580
|
+
interface JestMockCompatFn<TArgs extends any[] = any, TReturns = any> extends JestMockCompat<TArgs, TReturns> {
|
|
581
|
+
(...args: TArgs): TReturns;
|
|
582
|
+
}
|
|
583
|
+
declare function spyOn<T, K extends keyof T>(obj: T, method: K, accessType?: 'get' | 'set'): T[K] extends (...args: infer TArgs) => infer TReturnValue ? JestMockCompat<TArgs, TReturnValue> : JestMockCompat;
|
|
584
|
+
declare type Unpromisify<T> = T extends Promise<infer R> ? R : never;
|
|
585
|
+
declare function fn<TArgs extends any[] = any[], R = any>(): JestMockCompatFn<TArgs, R>;
|
|
586
|
+
declare function fn<TArgs extends any[] = any[], R = any>(implementation: (...args: TArgs) => R): JestMockCompatFn<TArgs, R>;
|
|
587
|
+
|
|
544
588
|
declare const vitest: {
|
|
545
589
|
spyOn: typeof spyOn;
|
|
546
|
-
fn: typeof
|
|
590
|
+
fn: typeof fn;
|
|
547
591
|
};
|
|
548
592
|
|
|
549
593
|
declare module 'vite' {
|
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-b8c6cb53.js';
|
|
2
|
+
export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, v as vitest } from './index-722fb5a5.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,14 +1,15 @@
|
|
|
1
|
-
export { c as createVitest } from './index-
|
|
1
|
+
export { c as createVitest } from './index-733e7378.js';
|
|
2
2
|
import 'path';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'process';
|
|
5
5
|
import 'fs';
|
|
6
6
|
import './constants-adef7ffb.js';
|
|
7
7
|
import 'url';
|
|
8
|
-
import './utils-
|
|
9
|
-
import '
|
|
10
|
-
import './error-c651f5ae.js';
|
|
8
|
+
import './utils-385e2d09.js';
|
|
9
|
+
import 'module';
|
|
11
10
|
import 'tty';
|
|
11
|
+
import 'perf_hooks';
|
|
12
|
+
import './error-309196c9.js';
|
|
12
13
|
import 'source-map';
|
|
13
14
|
import 'assert';
|
|
14
15
|
import 'events';
|
|
@@ -16,4 +17,3 @@ import 'worker_threads';
|
|
|
16
17
|
import 'piscina';
|
|
17
18
|
import 'fast-glob';
|
|
18
19
|
import 'micromatch';
|
|
19
|
-
import 'readline';
|
|
@@ -48,8 +48,8 @@ function normalizeTest(fn, timeout) {
|
|
|
48
48
|
return withTimeout(ensureAsyncTest(fn), timeout);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const fnMap = new WeakMap();
|
|
52
|
-
const hooksMap = new WeakMap();
|
|
51
|
+
const fnMap = /* @__PURE__ */ new WeakMap();
|
|
52
|
+
const hooksMap = /* @__PURE__ */ new WeakMap();
|
|
53
53
|
function setFn(key, fn) {
|
|
54
54
|
fnMap.set(key, fn);
|
|
55
55
|
}
|