@cldmv/vitest-runner 1.1.0 → 1.4.2
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/README.md +141 -78
- package/bin/vitest-runner.mjs +1549 -85
- package/dist/index.cjs +1389 -0
- package/dist/index.mjs +1335 -0
- package/package.json +41 -15
- package/types/src/bin/vitest-runner.d.mts +2 -0
- package/types/src/cli/args.d.mts +16 -0
- package/types/src/core/discover.d.mts +23 -0
- package/types/src/core/scratch.d.mts +64 -0
- package/types/src/core/spawn.d.mts +3 -1
- package/types/src/runner.d.mts +23 -0
- package/types/src/utils/ansi.d.mts +12 -0
- package/types/src/utils/duration.d.mts +12 -0
- package/types/src/utils/env.d.mts +12 -0
- package/index.cjs +0 -17
- package/index.mjs +0 -5
- package/src/cli/args.mjs +0 -134
- package/src/cli/help.mjs +0 -84
- package/src/core/discover.mjs +0 -167
- package/src/core/parse.mjs +0 -167
- package/src/core/progress.mjs +0 -164
- package/src/core/report.mjs +0 -255
- package/src/core/spawn.mjs +0 -219
- package/src/runner.mjs +0 -696
- package/src/utils/ansi.mjs +0 -32
- package/src/utils/duration.mjs +0 -25
- package/src/utils/env.mjs +0 -38
- package/src/utils/resolve.mjs +0 -86
package/src/utils/ansi.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview ANSI escape-code helpers.
|
|
3
|
-
* @module vitest-runner/src/utils/ansi
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Strip ANSI colour/style escape codes from a string.
|
|
8
|
-
* @param {string} text - Input text that may contain ANSI codes.
|
|
9
|
-
* @returns {string} Clean text without escape codes.
|
|
10
|
-
* @example
|
|
11
|
-
* stripAnsi('\x1B[32mhello\x1B[0m'); // 'hello'
|
|
12
|
-
*/
|
|
13
|
-
export function stripAnsi(text) {
|
|
14
|
-
// eslint-disable-next-line no-control-regex
|
|
15
|
-
return text.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Colour-code a coverage percentage value using chalk.
|
|
20
|
-
* ≥ 80 % → green, ≥ 50 % → yellow, < 50 % → red.
|
|
21
|
-
* @param {import('chalk').ChalkInstance} chalk - Chalk instance supplied by the caller.
|
|
22
|
-
* @param {number} pct - Coverage percentage 0–100.
|
|
23
|
-
* @returns {string} Chalk-coloured, right-aligned percentage string.
|
|
24
|
-
* @example
|
|
25
|
-
* colourPct(chalk, 75.5); // yellow ' 75.50'
|
|
26
|
-
*/
|
|
27
|
-
export function colourPct(chalk, pct) {
|
|
28
|
-
const str = pct.toFixed(2).padStart(6);
|
|
29
|
-
if (pct >= 80) return chalk.green(str);
|
|
30
|
-
if (pct >= 50) return chalk.yellow(str);
|
|
31
|
-
return chalk.red(str);
|
|
32
|
-
}
|
package/src/utils/duration.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Duration formatting utilities.
|
|
3
|
-
* @module vitest-runner/src/utils/duration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Format a millisecond duration as a human-readable `m:ss` or `h:mm:ss` string.
|
|
8
|
-
* @param {number} ms - Duration in milliseconds.
|
|
9
|
-
* @returns {string} Formatted duration string.
|
|
10
|
-
* @example
|
|
11
|
-
* formatDuration(65000); // '1:05'
|
|
12
|
-
* formatDuration(3661000); // '1:01:01'
|
|
13
|
-
*/
|
|
14
|
-
export function formatDuration(ms) {
|
|
15
|
-
const totalSeconds = Math.max(0, Math.floor(ms / 1000));
|
|
16
|
-
const hours = Math.floor(totalSeconds / 3600);
|
|
17
|
-
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
18
|
-
const seconds = totalSeconds % 60;
|
|
19
|
-
|
|
20
|
-
if (hours > 0) {
|
|
21
|
-
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return `${minutes}:${seconds.toString().padStart(2, "0")}`;
|
|
25
|
-
}
|
package/src/utils/env.mjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview NODE_OPTIONS / environment helpers.
|
|
3
|
-
* @module vitest-runner/src/utils/env
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Build a `NODE_OPTIONS` string suitable for passing to child vitest processes.
|
|
8
|
-
*
|
|
9
|
-
* Merges any existing base value with optional `--max-old-space-size` and
|
|
10
|
-
* `--conditions` flags. Each flag is only added once even if called multiple
|
|
11
|
-
* times with the same value.
|
|
12
|
-
*
|
|
13
|
-
* @param {Object} opts
|
|
14
|
-
* @param {number|undefined} opts.maxOldSpaceMb - Heap ceiling to add (omit or `undefined` to skip).
|
|
15
|
-
* @param {string[]} [opts.conditions=[]] - Additional `--conditions` values to append.
|
|
16
|
-
* @param {string} [opts.base] - Starting `NODE_OPTIONS` string; defaults to `process.env.NODE_OPTIONS`.
|
|
17
|
-
* @returns {string} Combined `NODE_OPTIONS` string (trimmed).
|
|
18
|
-
* @example
|
|
19
|
-
* buildNodeOptions({ maxOldSpaceMb: 4096, conditions: ['my-dev'] });
|
|
20
|
-
* // '--conditions=my-dev --max-old-space-size=4096'
|
|
21
|
-
*/
|
|
22
|
-
export function buildNodeOptions({ maxOldSpaceMb, conditions = [], base = process.env.NODE_OPTIONS ?? "" }) {
|
|
23
|
-
let opts = base;
|
|
24
|
-
|
|
25
|
-
for (const cond of conditions) {
|
|
26
|
-
const flag = `--conditions=${cond}`;
|
|
27
|
-
if (!opts.includes(flag)) {
|
|
28
|
-
opts = opts ? `${opts} ${flag}` : flag;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (maxOldSpaceMb && !opts.includes("--max-old-space-size")) {
|
|
33
|
-
const flag = `--max-old-space-size=${maxOldSpaceMb}`;
|
|
34
|
-
opts = opts ? `${opts} ${flag}` : flag;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return opts.trim();
|
|
38
|
-
}
|
package/src/utils/resolve.mjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Package-bin and vitest-config resolution helpers.
|
|
3
|
-
* @module vitest-runner/src/utils/resolve
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createRequire } from "node:module";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import fs from "node:fs/promises";
|
|
9
|
-
import { pathToFileURL } from "node:url";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Resolve the absolute path of a binary shipped with an npm package.
|
|
13
|
-
*
|
|
14
|
-
* The `require` instance is rooted at `cwd` so the package is found in the
|
|
15
|
-
* consumer project's `node_modules`, not the runner's own.
|
|
16
|
-
*
|
|
17
|
-
* @param {string} cwd - Consumer project root to search from.
|
|
18
|
-
* @param {string} pkgName - The npm package name (e.g. `'vitest'`).
|
|
19
|
-
* @param {string} [binName=pkgName] - The bin alias key to look up.
|
|
20
|
-
* @returns {string} Absolute path to the binary entry point.
|
|
21
|
-
* @throws {Error} When the bin entry is not found in the package manifest.
|
|
22
|
-
* @example
|
|
23
|
-
* resolveBin('/my/project', 'vitest');
|
|
24
|
-
* // '/my/project/node_modules/vitest/dist/cli.mjs'
|
|
25
|
-
*/
|
|
26
|
-
export function resolveBin(cwd, pkgName, binName = pkgName) {
|
|
27
|
-
const require = createRequire(pathToFileURL(path.join(cwd, "package.json")));
|
|
28
|
-
const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
|
|
29
|
-
const pkg = require(pkgJsonPath);
|
|
30
|
-
|
|
31
|
-
const rel = pkg.bin?.[binName] ?? pkg.bin;
|
|
32
|
-
if (!rel) throw new Error(`No bin "${binName}" found in ${pkgName}/package.json`);
|
|
33
|
-
|
|
34
|
-
return path.join(path.dirname(pkgJsonPath), rel);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Ordered list of default vitest / vite config file names.
|
|
39
|
-
* The search walks this list in declaration order, relative to `cwd`.
|
|
40
|
-
* @type {readonly string[]}
|
|
41
|
-
*/
|
|
42
|
-
const DEFAULT_CONFIG_NAMES = Object.freeze([
|
|
43
|
-
"vitest.config.ts",
|
|
44
|
-
"vitest.config.mts",
|
|
45
|
-
"vitest.config.cts",
|
|
46
|
-
"vitest.config.mjs",
|
|
47
|
-
"vitest.config.js",
|
|
48
|
-
"vitest.config.cjs",
|
|
49
|
-
"vite.config.ts",
|
|
50
|
-
"vite.config.mts",
|
|
51
|
-
"vite.config.mjs",
|
|
52
|
-
"vite.config.js"
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Resolve the vitest config path to use for a project.
|
|
57
|
-
*
|
|
58
|
-
* - If `configPath` is provided it is returned as-is (resolved absolute if relative).
|
|
59
|
-
* - Otherwise the function walks {@link DEFAULT_CONFIG_NAMES} relative to `cwd`
|
|
60
|
-
* and returns the first file that exists.
|
|
61
|
-
* - Returns `undefined` when nothing is found, letting vitest use its own defaults.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} cwd - Project root directory.
|
|
64
|
-
* @param {string|undefined} configPath - Explicit config path, or `undefined` for auto-detect.
|
|
65
|
-
* @returns {Promise<string|undefined>} Resolved absolute config path, or `undefined`.
|
|
66
|
-
* @example
|
|
67
|
-
* const cfg = await resolveVitestConfig('/my/project', undefined);
|
|
68
|
-
* // '/my/project/vitest.config.ts' (if that file exists)
|
|
69
|
-
*/
|
|
70
|
-
export async function resolveVitestConfig(cwd, configPath) {
|
|
71
|
-
if (configPath) {
|
|
72
|
-
return path.isAbsolute(configPath) ? configPath : path.resolve(cwd, configPath);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
for (const name of DEFAULT_CONFIG_NAMES) {
|
|
76
|
-
const candidate = path.join(cwd, name);
|
|
77
|
-
try {
|
|
78
|
-
await fs.access(candidate);
|
|
79
|
-
return candidate;
|
|
80
|
-
} catch {
|
|
81
|
-
// not found — try next
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|