@rstest/core 0.8.0 → 0.8.1
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/LICENSE.md +0 -200
- package/dist/0~130.js +7 -9
- package/dist/0~1472.js +8 -12
- package/dist/0~2173.js +39 -43
- package/dist/0~2255.js +1 -1
- package/dist/0~3919.js +1 -1
- package/dist/0~4403.js +1 -2
- package/dist/0~5835.js +2 -2
- package/dist/0~6588.js +3 -6
- package/dist/0~6923.js +2 -2
- package/dist/0~7583.js +6 -7
- package/dist/0~7882.js +35 -151
- package/dist/0~8426.js +5 -7
- package/dist/0~89.js +10 -12
- package/dist/0~9348.js +1 -2
- package/dist/0~9634.js +2 -5
- package/dist/1157.js +126 -40
- package/dist/1157.js.LICENSE.txt +21 -0
- package/dist/1294.js +1 -1
- package/dist/{2672.js → 3160.js} +309 -5
- package/dist/487.js +1 -1
- package/dist/5734.js +2 -5
- package/dist/6151.js +198 -3
- package/dist/6973.js +4 -6
- package/dist/7011.js +19 -0
- package/dist/9131.js +80 -59
- package/dist/browser-runtime/389.js +615 -13
- package/dist/browser-runtime/389.js.map +1 -1
- package/dist/browser-runtime/index.d.ts +163 -7
- package/dist/browser.d.ts +168 -9
- package/dist/browser.js +1 -7
- package/dist/globalSetupWorker.js +2 -4
- package/dist/index.d.ts +174 -7
- package/dist/mockRuntimeCode.js +92 -0
- package/dist/rslib-runtime.js +0 -27
- package/dist/worker.js +2 -4
- package/package.json +2 -3
- package/dist/3278.js +0 -318
package/dist/7011.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { _path } from "./3160.js";
|
|
4
|
+
const delimiter = /* @__PURE__ */ (()=>globalThis.process?.platform === "win32" ? ";" : ":")();
|
|
5
|
+
const _platforms = {
|
|
6
|
+
posix: void 0,
|
|
7
|
+
win32: void 0
|
|
8
|
+
};
|
|
9
|
+
const mix = (del = delimiter)=>new Proxy(_path, {
|
|
10
|
+
get (_, prop) {
|
|
11
|
+
if ("delimiter" === prop) return del;
|
|
12
|
+
if ("posix" === prop) return posix;
|
|
13
|
+
if ("win32" === prop) return win32;
|
|
14
|
+
return _platforms[prop] || _path[prop];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const posix = /* @__PURE__ */ mix(":");
|
|
18
|
+
const win32 = /* @__PURE__ */ mix(";");
|
|
19
|
+
export { posix };
|
package/dist/9131.js
CHANGED
|
@@ -2,11 +2,11 @@ import 'module';
|
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
3
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
4
|
import { EventEmitter } from "events";
|
|
5
|
-
import { basename, isTTY, dirname, resolve as pathe_M_eThtNZ_resolve, relative, getAbsolutePath, join, bgColor, formatRootStr, castArray, prettyTime, getTaskNameWithPrefix,
|
|
5
|
+
import { basename, isTTY, dirname, resolve as pathe_M_eThtNZ_resolve, relative, getAbsolutePath, join, bgColor, formatRootStr, logger as logger_logger, castArray, prettyTime, getTaskNameWithPrefix, isDebug, color, isAbsolute, normalize, formatError } from "./3160.js";
|
|
6
6
|
import "./721.js";
|
|
7
|
-
import { isDynamicPattern, glob, DEFAULT_CONFIG_NAME, prettyTestPath, globalApis, TEMP_RSTEST_OUTPUT_DIR_GLOB, formatTestPath, filterProjects, DEFAULT_CONFIG_EXTENSIONS, TS_CONFIG_FILE } from "./1157.js";
|
|
8
|
-
import { posix, logger as logger_logger, isDebug } from "./3278.js";
|
|
7
|
+
import { isDynamicPattern, glob, DEFAULT_CONFIG_NAME, prettyTestPath, globalApis, writeFile, TEMP_RSTEST_OUTPUT_DIR_GLOB, formatTestPath, filterProjects, DEFAULT_CONFIG_EXTENSIONS, TS_CONFIG_FILE } from "./1157.js";
|
|
9
8
|
import { rsbuild as __rspack_external__rsbuild_core_1b356efc } from "./4484.js";
|
|
9
|
+
import { posix } from "./7011.js";
|
|
10
10
|
import { parse as stack_trace_parser_esm_parse } from "./1672.js";
|
|
11
11
|
import { decode } from "./4397.js";
|
|
12
12
|
function toArr(any) {
|
|
@@ -504,13 +504,14 @@ function prepareCli() {
|
|
|
504
504
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) logger_logger.log();
|
|
505
505
|
}
|
|
506
506
|
function showRstest() {
|
|
507
|
-
logger_logger.greet(" Rstest v0.8.
|
|
507
|
+
logger_logger.greet(" Rstest v0.8.1");
|
|
508
508
|
logger_logger.log('');
|
|
509
509
|
}
|
|
510
510
|
const applyCommonOptions = (cli)=>{
|
|
511
511
|
cli.option('-c, --config <config>', 'Specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'Specify the loader to load the config file, can be `jiti` or `native`', {
|
|
512
512
|
default: 'jiti'
|
|
513
513
|
}).option('-r, --root <root>', 'Specify the project root directory, can be an absolute path or a path relative to cwd').option('--globals', 'Provide global APIs').option('--isolate', 'Run tests in an isolated environment').option('--include <include>', 'Match test files').option('--exclude <exclude>', 'Exclude files from test').option('-u, --update', 'Update snapshot files').option('--coverage', 'Enable code coverage collection').option('--project <name>', 'Run only projects that match the name, can be a full name or wildcards pattern').option('--passWithNoTests', 'Allows the test suite to pass when no files are found').option('--printConsoleTrace', 'Print console traces when calling any console method').option('--disableConsoleIntercept', 'Disable console intercept').option('--logHeapUsage', 'Log heap usage after each test').option('--slowTestThreshold <value>', 'The number of milliseconds after which a test or suite is considered slow').option('--reporter <reporter>', 'Specify the reporter to use').option('-t, --testNamePattern <value>', 'Run only tests with a name that matches the regex').option('--testEnvironment <name>', 'The environment that will be used for testing').option('--testTimeout <value>', 'Timeout of a test in milliseconds').option('--hookTimeout <value>', 'Timeout of hook in milliseconds').option('--hideSkippedTests', 'Hide skipped tests from the output').option('--hideSkippedTestFiles', 'Hide skipped test files from the output').option('--retry <retry>', 'Number of times to retry a test if it fails').option('--bail [number]', 'Stop running tests after n failures. Set to 0 to run all tests regardless of failures').option('--maxConcurrency <value>', 'Maximum number of concurrent tests').option('--clearMocks', 'Automatically clear mock calls, instances, contexts and results before every test').option('--resetMocks', 'Automatically reset mock state before every test').option('--restoreMocks', 'Automatically restore mock state and implementation before every test').option('--browser', 'Run tests in browser mode').option('--browser.enabled', 'Run tests in browser mode').option('--browser.name <name>', 'Browser to use: chromium, firefox, webkit (default: chromium)').option('--browser.headless', 'Run browser in headless mode (default: true in CI)').option('--browser.port <port>', 'Port for the browser mode dev server').option('--browser.strictPort', 'Exit if the specified port is already in use').option('--unstubGlobals', 'Restores all global variables that were changed with `rstest.stubGlobal` before every test').option('--unstubEnvs', 'Restores all `process.env` values that were changed with `rstest.stubEnv` before every test').option('--includeTaskLocation', 'Collect test and suite locations. This might increase the running time.');
|
|
514
|
+
cli.option('--pool <type>', 'Shorthand for --pool.type').option('--pool.type <type>', 'Specify the test pool type (e.g. forks)').option('--pool.maxWorkers <value>', 'Maximum number or percentage of workers (e.g. 4 or 50%)').option('--pool.minWorkers <value>', 'Minimum number or percentage of workers (e.g. 1 or 25%)').option('--pool.execArgv <arg>', 'Additional Node.js execArgv passed to worker processes (can be specified multiple times)');
|
|
514
515
|
};
|
|
515
516
|
const handleUnexpectedExit = (rstest, err)=>{
|
|
516
517
|
for (const reporter of rstest?.context.reporters || [])reporter.onExit?.();
|
|
@@ -561,7 +562,7 @@ const runRest = async ({ options, filters, command })=>{
|
|
|
561
562
|
function setupCommands() {
|
|
562
563
|
const cli = dist('rstest');
|
|
563
564
|
cli.help();
|
|
564
|
-
cli.version("0.8.
|
|
565
|
+
cli.version("0.8.1");
|
|
565
566
|
applyCommonOptions(cli);
|
|
566
567
|
cli.command('[...filters]', 'run tests').option('-w, --watch', 'Run tests in watch mode').action(async (filters, options)=>{
|
|
567
568
|
showRstest();
|
|
@@ -627,7 +628,6 @@ function setupCommands() {
|
|
|
627
628
|
select: mod.ve,
|
|
628
629
|
isCancel: mod.pD
|
|
629
630
|
}));
|
|
630
|
-
const color = (await import("./2672.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js", 23))).default;
|
|
631
631
|
console.log();
|
|
632
632
|
const selected = await select({
|
|
633
633
|
message: 'What would you like to initialize?',
|
|
@@ -988,14 +988,12 @@ function G() {
|
|
|
988
988
|
const P = G();
|
|
989
989
|
P?.name;
|
|
990
990
|
const external_node_fs_ = __webpack_require__("node:fs");
|
|
991
|
-
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
992
|
-
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
993
991
|
const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_["default"].existsSync);
|
|
994
992
|
const resolveConfigPath = (root, customConfig)=>{
|
|
995
993
|
if (customConfig) {
|
|
996
994
|
const customConfigPath = isAbsolute(customConfig) ? customConfig : join(root, customConfig);
|
|
997
995
|
if (external_node_fs_["default"].existsSync(customConfigPath)) return customConfigPath;
|
|
998
|
-
throw `Cannot find config file: ${
|
|
996
|
+
throw `Cannot find config file: ${color.dim(customConfigPath)}`;
|
|
999
997
|
}
|
|
1000
998
|
const configFilePath = findConfig(join(root, DEFAULT_CONFIG_NAME));
|
|
1001
999
|
if (configFilePath) return configFilePath;
|
|
@@ -1222,6 +1220,29 @@ function mergeWithCLIOptions(config, options) {
|
|
|
1222
1220
|
if (void 0 !== options.browser.strictPort) config.browser.strictPort = options.browser.strictPort;
|
|
1223
1221
|
}
|
|
1224
1222
|
}
|
|
1223
|
+
if (void 0 !== options.pool) {
|
|
1224
|
+
const poolFromCli = options.pool;
|
|
1225
|
+
if ('string' == typeof poolFromCli) {
|
|
1226
|
+
if ('string' == typeof config.pool) config.pool = {
|
|
1227
|
+
type: config.pool
|
|
1228
|
+
};
|
|
1229
|
+
config.pool ??= {};
|
|
1230
|
+
if ('object' != typeof config.pool) config.pool = {};
|
|
1231
|
+
const pool = config.pool;
|
|
1232
|
+
pool.type = poolFromCli;
|
|
1233
|
+
} else {
|
|
1234
|
+
if ('string' == typeof config.pool) config.pool = {
|
|
1235
|
+
type: config.pool
|
|
1236
|
+
};
|
|
1237
|
+
config.pool ??= {};
|
|
1238
|
+
if ('object' != typeof config.pool) config.pool = {};
|
|
1239
|
+
const pool = config.pool;
|
|
1240
|
+
if (void 0 !== poolFromCli.type) pool.type = poolFromCli.type;
|
|
1241
|
+
if (void 0 !== poolFromCli.maxWorkers) pool.maxWorkers = poolFromCli.maxWorkers;
|
|
1242
|
+
if (void 0 !== poolFromCli.minWorkers) pool.minWorkers = poolFromCli.minWorkers;
|
|
1243
|
+
if (void 0 !== poolFromCli.execArgv) pool.execArgv = castArray(poolFromCli.execArgv);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1225
1246
|
return config;
|
|
1226
1247
|
}
|
|
1227
1248
|
async function resolveConfig(options) {
|
|
@@ -1323,8 +1344,8 @@ async function resolveProjects({ config, root, options }) {
|
|
|
1323
1344
|
const projects = await getProjects(config, root).then((p)=>filterProjects(p, options));
|
|
1324
1345
|
if (!projects.length) {
|
|
1325
1346
|
let errorMsg = `No projects found, please make sure you have at least one valid project.
|
|
1326
|
-
${
|
|
1327
|
-
if (options.project) errorMsg += `\n${
|
|
1347
|
+
${color.gray('projects:')} ${JSON.stringify(config.projects, null, 2)}`;
|
|
1348
|
+
if (options.project) errorMsg += `\n${color.gray('projectName filter:')} ${JSON.stringify(options.project, null, 2)}`;
|
|
1328
1349
|
throw errorMsg;
|
|
1329
1350
|
}
|
|
1330
1351
|
const names = new Set();
|
|
@@ -1366,6 +1387,7 @@ async function runCLI() {
|
|
|
1366
1387
|
} catch (err) {
|
|
1367
1388
|
logger_logger.error('Failed to start Rstest CLI.');
|
|
1368
1389
|
logger_logger.error(err);
|
|
1390
|
+
process.exit(1);
|
|
1369
1391
|
}
|
|
1370
1392
|
}
|
|
1371
1393
|
class SnapshotManager {
|
|
@@ -1426,53 +1448,53 @@ function addSnapshotResult(summary, result) {
|
|
|
1426
1448
|
summary.total += result.added + result.matched + result.unmatched + result.updated;
|
|
1427
1449
|
}
|
|
1428
1450
|
const getSummaryStatusString = (tasks, name = 'tests', showTotal = true)=>{
|
|
1429
|
-
if (0 === tasks.length) return
|
|
1451
|
+
if (0 === tasks.length) return color.dim(`no ${name}`);
|
|
1430
1452
|
const passed = tasks.filter((result)=>'pass' === result.status);
|
|
1431
1453
|
const failed = tasks.filter((result)=>'fail' === result.status);
|
|
1432
1454
|
const skipped = tasks.filter((result)=>'skip' === result.status);
|
|
1433
1455
|
const todo = tasks.filter((result)=>'todo' === result.status);
|
|
1434
1456
|
const status = [
|
|
1435
|
-
failed.length ?
|
|
1436
|
-
passed.length ?
|
|
1437
|
-
skipped.length ?
|
|
1438
|
-
todo.length ?
|
|
1457
|
+
failed.length ? color.bold(color.red(`${failed.length} failed`)) : null,
|
|
1458
|
+
passed.length ? color.bold(color.green(`${passed.length} passed`)) : null,
|
|
1459
|
+
skipped.length ? color.yellow(`${skipped.length} skipped`) : null,
|
|
1460
|
+
todo.length ? color.gray(`${todo.length} todo`) : null
|
|
1439
1461
|
].filter(Boolean);
|
|
1440
|
-
return status.join(
|
|
1462
|
+
return status.join(color.dim(' | ')) + (showTotal && status.length > 1 ? color.gray(` (${tasks.length})`) : '');
|
|
1441
1463
|
};
|
|
1442
1464
|
const printSnapshotSummaryLog = (snapshots, rootDir)=>{
|
|
1443
1465
|
const summary = [];
|
|
1444
|
-
if (snapshots.added) summary.push(
|
|
1445
|
-
if (snapshots.unmatched) summary.push(
|
|
1446
|
-
if (snapshots.updated) summary.push(
|
|
1447
|
-
if (snapshots.filesRemoved) if (snapshots.didUpdate) summary.push(
|
|
1448
|
-
else summary.push(
|
|
1466
|
+
if (snapshots.added) summary.push(color.bold(color.green(`${snapshots.added} written`)));
|
|
1467
|
+
if (snapshots.unmatched) summary.push(color.bold(color.red(`${snapshots.unmatched} failed`)));
|
|
1468
|
+
if (snapshots.updated) summary.push(color.bold(color.green(`${snapshots.updated} updated `)));
|
|
1469
|
+
if (snapshots.filesRemoved) if (snapshots.didUpdate) summary.push(color.bold(color.green(`${snapshots.filesRemoved} files removed `)));
|
|
1470
|
+
else summary.push(color.bold(color.yellow(`${snapshots.filesRemoved} files obsolete `)));
|
|
1449
1471
|
if (snapshots.filesRemovedList?.length) {
|
|
1450
1472
|
const [head, ...tail] = snapshots.filesRemovedList;
|
|
1451
|
-
summary.push(`${
|
|
1473
|
+
summary.push(`${color.gray("➜")} ${formatTestPath(rootDir, head)}`);
|
|
1452
1474
|
for (const key of tail)summary.push(` ${formatTestPath(rootDir, key)}`);
|
|
1453
1475
|
}
|
|
1454
1476
|
if (snapshots.unchecked) {
|
|
1455
|
-
if (snapshots.didUpdate) summary.push(
|
|
1456
|
-
else summary.push(
|
|
1477
|
+
if (snapshots.didUpdate) summary.push(color.bold(color.green(`${snapshots.unchecked} removed`)));
|
|
1478
|
+
else summary.push(color.bold(color.yellow(`${snapshots.unchecked} obsolete`)));
|
|
1457
1479
|
for (const uncheckedFile of snapshots.uncheckedKeysByFile){
|
|
1458
|
-
summary.push(`${
|
|
1480
|
+
summary.push(`${color.gray("➜")} ${formatTestPath(rootDir, uncheckedFile.filePath)}`);
|
|
1459
1481
|
for (const key of uncheckedFile.keys)summary.push(` ${key}`);
|
|
1460
1482
|
}
|
|
1461
1483
|
}
|
|
1462
1484
|
for (const [index, snapshot] of summary.entries()){
|
|
1463
1485
|
const title = 0 === index ? 'Snapshots' : '';
|
|
1464
|
-
logger_logger.log(`${
|
|
1486
|
+
logger_logger.log(`${color.gray(title.padStart(12))} ${snapshot}`);
|
|
1465
1487
|
}
|
|
1466
1488
|
};
|
|
1467
|
-
const TestFileSummaryLabel =
|
|
1468
|
-
const TestSummaryLabel =
|
|
1469
|
-
const DurationLabel =
|
|
1489
|
+
const TestFileSummaryLabel = color.gray('Test Files'.padStart(11));
|
|
1490
|
+
const TestSummaryLabel = color.gray('Tests'.padStart(11));
|
|
1491
|
+
const DurationLabel = color.gray('Duration'.padStart(11));
|
|
1470
1492
|
const printSummaryLog = ({ results, testResults, snapshotSummary, duration, rootPath })=>{
|
|
1471
1493
|
logger_logger.log('');
|
|
1472
1494
|
printSnapshotSummaryLog(snapshotSummary, rootPath);
|
|
1473
1495
|
logger_logger.log(`${TestFileSummaryLabel} ${getSummaryStatusString(results)}`);
|
|
1474
1496
|
logger_logger.log(`${TestSummaryLabel} ${getSummaryStatusString(testResults)}`);
|
|
1475
|
-
logger_logger.log(`${DurationLabel} ${prettyTime(duration.totalTime)} ${
|
|
1497
|
+
logger_logger.log(`${DurationLabel} ${prettyTime(duration.totalTime)} ${color.gray(`(build ${prettyTime(duration.buildTime)}, tests ${prettyTime(duration.testTime)})`)}`);
|
|
1476
1498
|
logger_logger.log('');
|
|
1477
1499
|
};
|
|
1478
1500
|
const printSummaryErrorLogs = async ({ testResults, results, rootPath, unhandledErrors, getSourcemap, filterRerunTestPaths })=>{
|
|
@@ -1482,7 +1504,7 @@ const printSummaryErrorLogs = async ({ testResults, results, rootPath, unhandled
|
|
|
1482
1504
|
];
|
|
1483
1505
|
if (0 === failedTests.length && !unhandledErrors?.length) return;
|
|
1484
1506
|
logger_logger.stderr('');
|
|
1485
|
-
logger_logger.stderr(
|
|
1507
|
+
logger_logger.stderr(color.bold('Summary of all failing tests:'));
|
|
1486
1508
|
logger_logger.stderr('');
|
|
1487
1509
|
const { printError } = await Promise.resolve().then(()=>({
|
|
1488
1510
|
printError: error_printError
|
|
@@ -1494,7 +1516,7 @@ const printSummaryErrorLogs = async ({ testResults, results, rootPath, unhandled
|
|
|
1494
1516
|
for (const test of failedTests){
|
|
1495
1517
|
const relativePath = posix.relative(rootPath, test.testPath);
|
|
1496
1518
|
const nameStr = getTaskNameWithPrefix(test);
|
|
1497
|
-
logger_logger.stderr(`${bgColor('bgRed', ' FAIL ')} ${prettyTestPath(relativePath)} ${nameStr.length ? `${
|
|
1519
|
+
logger_logger.stderr(`${bgColor('bgRed', ' FAIL ')} ${prettyTestPath(relativePath)} ${nameStr.length ? `${color.dim(">")} ${nameStr}` : ''}`);
|
|
1498
1520
|
if (test.errors) {
|
|
1499
1521
|
const { printError } = await Promise.resolve().then(()=>({
|
|
1500
1522
|
printError: error_printError
|
|
@@ -1649,14 +1671,14 @@ class StatusRenderer {
|
|
|
1649
1671
|
const relativePath = relative(this.rootPath, module);
|
|
1650
1672
|
summary.push(`${bgColor('bgYellow', ' RUNS ')} ${prettyTestPath(relativePath)}`);
|
|
1651
1673
|
if (runningTests.length && shouldDisplayRunningTests(runningTests)) {
|
|
1652
|
-
let caseLog = ` ${
|
|
1653
|
-
if (runningTests.length > 1) caseLog +=
|
|
1674
|
+
let caseLog = ` ${color.gray("➜")} ${getTaskNameWithPrefix(runningTests[0])} ${color.magenta(prettyTime(now - runningTests[0].startTime))}`;
|
|
1675
|
+
if (runningTests.length > 1) caseLog += color.gray(` and ${runningTests.length - 1} more cases`);
|
|
1654
1676
|
summary.push(caseLog);
|
|
1655
1677
|
}
|
|
1656
1678
|
}
|
|
1657
1679
|
summary.push('');
|
|
1658
1680
|
if (0 === testModules.length) summary.push(`${TestFileSummaryLabel} ${runningModules.size} total`);
|
|
1659
|
-
else summary.push(`${TestFileSummaryLabel} ${getSummaryStatusString(testModules, '', false)} ${
|
|
1681
|
+
else summary.push(`${TestFileSummaryLabel} ${getSummaryStatusString(testModules, '', false)} ${color.dim('|')} ${runningModules.size + testModules.length} total`);
|
|
1660
1682
|
const testResults = Array.from(runningModules.values()).flatMap(({ results })=>results).concat(testModules.flatMap((mod)=>mod.results));
|
|
1661
1683
|
if (testResults.length) summary.push(`${TestSummaryLabel} ${getSummaryStatusString(testResults, '', false)}`);
|
|
1662
1684
|
summary.push(`${DurationLabel} ${prettyTime(Date.now() - this.startTime)}`);
|
|
@@ -1684,10 +1706,10 @@ const statusStr = {
|
|
|
1684
1706
|
skip: '-'
|
|
1685
1707
|
};
|
|
1686
1708
|
const statusColor = {
|
|
1687
|
-
fail:
|
|
1688
|
-
pass:
|
|
1689
|
-
todo:
|
|
1690
|
-
skip:
|
|
1709
|
+
fail: color.red,
|
|
1710
|
+
pass: color.green,
|
|
1711
|
+
todo: color.gray,
|
|
1712
|
+
skip: color.gray
|
|
1691
1713
|
};
|
|
1692
1714
|
const statusColorfulStr = {
|
|
1693
1715
|
fail: statusColor.fail(statusStr.fail),
|
|
@@ -1698,23 +1720,23 @@ const statusColorfulStr = {
|
|
|
1698
1720
|
const logCase = (result, options)=>{
|
|
1699
1721
|
const isSlowCase = (result.duration || 0) > options.slowTestThreshold;
|
|
1700
1722
|
if (options.hideSkippedTests && 'skip' === result.status) return;
|
|
1701
|
-
const icon = isSlowCase && 'pass' === result.status ?
|
|
1723
|
+
const icon = isSlowCase && 'pass' === result.status ? color.yellow(statusStr[result.status]) : statusColorfulStr[result.status];
|
|
1702
1724
|
const nameStr = getTaskNameWithPrefix(result);
|
|
1703
1725
|
const duration = void 0 !== result.duration ? ` (${prettyTime(result.duration)})` : '';
|
|
1704
|
-
const retry = result.retryCount ?
|
|
1705
|
-
const heap = result.heap ? ` ${
|
|
1706
|
-
logger_logger.log(` ${icon} ${nameStr}${
|
|
1707
|
-
if (result.errors) for (const error of result.errors)logger_logger.log(
|
|
1726
|
+
const retry = result.retryCount ? color.yellow(` (retry x${result.retryCount})`) : '';
|
|
1727
|
+
const heap = result.heap ? ` ${color.magenta(formatHeapUsed(result.heap))}` : '';
|
|
1728
|
+
logger_logger.log(` ${icon} ${nameStr}${color.gray(duration)}${retry}${heap}`);
|
|
1729
|
+
if (result.errors) for (const error of result.errors)logger_logger.log(color.red(` ${error.message}`));
|
|
1708
1730
|
};
|
|
1709
1731
|
const formatHeapUsed = (heap)=>`${Math.floor(heap / 1024 / 1024)} MB heap used`;
|
|
1710
1732
|
const logFileTitle = (test, relativePath, alwaysShowTime = false, showProjectName = false)=>{
|
|
1711
|
-
let title = ` ${
|
|
1733
|
+
let title = ` ${color.bold(statusColorfulStr[test.status])}`;
|
|
1712
1734
|
if (showProjectName && test.project) title += ` ${statusColor[test.status](`[${test.project}]`)}`;
|
|
1713
1735
|
title += ` ${prettyTestPath(relativePath)}`;
|
|
1714
|
-
const formatDuration = (duration)=>
|
|
1715
|
-
title += ` ${
|
|
1736
|
+
const formatDuration = (duration)=>color.green(prettyTime(duration));
|
|
1737
|
+
title += ` ${color.gray(`(${test.results.length})`)}`;
|
|
1716
1738
|
if (alwaysShowTime) title += ` ${formatDuration(test.duration)}`;
|
|
1717
|
-
if (test.heap) title += ` ${
|
|
1739
|
+
if (test.heap) title += ` ${color.magenta(formatHeapUsed(test.heap))}`;
|
|
1718
1740
|
logger_logger.log(title);
|
|
1719
1741
|
};
|
|
1720
1742
|
class DefaultReporter {
|
|
@@ -1768,7 +1790,7 @@ class DefaultReporter {
|
|
|
1768
1790
|
} else titles.push(testPath);
|
|
1769
1791
|
const logOutput = 'stdout' === log.type ? logger_logger.log : logger_logger.stderr;
|
|
1770
1792
|
logOutput('');
|
|
1771
|
-
logOutput(`${log.name}${
|
|
1793
|
+
logOutput(`${log.name}${color.gray(color.dim(` | ${titles.join(color.gray(color.dim(' | ')))}`))}`);
|
|
1772
1794
|
logOutput(log.content);
|
|
1773
1795
|
logOutput('');
|
|
1774
1796
|
}
|
|
@@ -2173,7 +2195,7 @@ const hintNotDefinedError = (message)=>{
|
|
|
2173
2195
|
'jest',
|
|
2174
2196
|
'vitest'
|
|
2175
2197
|
].includes(varName)) return message.replace(`${varName} is not defined`, `${varName} is not defined. Did you mean rstest?`);
|
|
2176
|
-
if ('React' === varName) return message.replace(`${varName} is not defined`, `${varName} is not defined. Did you forget to install "${
|
|
2198
|
+
if ('React' === varName) return message.replace(`${varName} is not defined`, `${varName} is not defined. Did you forget to install "${color.yellow('@rsbuild/plugin-react')}" plugin?`);
|
|
2177
2199
|
}
|
|
2178
2200
|
return message;
|
|
2179
2201
|
};
|
|
@@ -2183,14 +2205,14 @@ async function error_printError(error, getSourcemap, rootPath) {
|
|
|
2183
2205
|
const tips = [
|
|
2184
2206
|
'Error: not support import `vitest` in Rstest test environment.\n',
|
|
2185
2207
|
'Solution:',
|
|
2186
|
-
` - Update your code to use imports from "${
|
|
2208
|
+
` - Update your code to use imports from "${color.yellow('@rstest/core')}" instead of "${color.yellow('vitest')}".`,
|
|
2187
2209
|
' - Enable `globals` configuration and use global API.'
|
|
2188
2210
|
];
|
|
2189
|
-
logger_logger.stderr(`${
|
|
2211
|
+
logger_logger.stderr(`${color.red(tips.join('\n'))}\n`);
|
|
2190
2212
|
return;
|
|
2191
2213
|
}
|
|
2192
2214
|
if (error.message.includes('is not defined')) error.message = hintNotDefinedError(error.message);
|
|
2193
|
-
logger_logger.stderr(`${
|
|
2215
|
+
logger_logger.stderr(`${color.red(color.bold(errorName))}${color.red(`: ${error.message}`)}\n`);
|
|
2194
2216
|
if (error.diff) {
|
|
2195
2217
|
logger_logger.stderr(error.diff);
|
|
2196
2218
|
logger_logger.stderr('');
|
|
@@ -2201,7 +2223,7 @@ async function error_printError(error, getSourcemap, rootPath) {
|
|
|
2201
2223
|
fullStack: error.fullStack,
|
|
2202
2224
|
getSourcemap
|
|
2203
2225
|
});
|
|
2204
|
-
if (!stackFrames.length && !(error.fullStack || isDebug()) && !error.stack.endsWith(error.message)) logger_logger.stderr(
|
|
2226
|
+
if (!stackFrames.length && !(error.fullStack || isDebug()) && !error.stack.endsWith(error.message)) logger_logger.stderr(color.gray("No error stack found, set 'DEBUG=rstest' to show fullStack."));
|
|
2205
2227
|
if (stackFrames[0]) await printCodeFrame(stackFrames[0]);
|
|
2206
2228
|
printStack(stackFrames, rootPath);
|
|
2207
2229
|
}
|
|
@@ -2228,7 +2250,7 @@ function formatStack(frame, rootPath) {
|
|
|
2228
2250
|
return '<unknown>' !== frame.methodName ? `at ${frame.methodName} (${formatTestPath(rootPath, frame.file)}:${frame.lineNumber}:${frame.column})` : `at ${formatTestPath(rootPath, frame.file)}:${frame.lineNumber}:${frame.column}`;
|
|
2229
2251
|
}
|
|
2230
2252
|
function printStack(stackFrames, rootPath) {
|
|
2231
|
-
for (const frame of stackFrames)logger_logger.stderr(
|
|
2253
|
+
for (const frame of stackFrames)logger_logger.stderr(color.gray(` ${formatStack(frame, rootPath)}`));
|
|
2232
2254
|
stackFrames.length && logger_logger.stderr('');
|
|
2233
2255
|
}
|
|
2234
2256
|
const stackIgnores = [
|
|
@@ -2272,7 +2294,6 @@ async function error_parseErrorStacktrace({ stack, getSourcemap, fullStack = isD
|
|
|
2272
2294
|
})).then((frames)=>frames.filter((frame)=>null !== frame));
|
|
2273
2295
|
return stackFrames;
|
|
2274
2296
|
}
|
|
2275
|
-
const promises_ = __webpack_require__("node:fs/promises");
|
|
2276
2297
|
class JUnitReporter {
|
|
2277
2298
|
rootPath;
|
|
2278
2299
|
outputPath;
|
|
@@ -2382,7 +2403,7 @@ class JUnitReporter {
|
|
|
2382
2403
|
};
|
|
2383
2404
|
const xmlContent = this.generateJUnitXml(report);
|
|
2384
2405
|
if (this.outputPath) try {
|
|
2385
|
-
await
|
|
2406
|
+
await writeFile(this.outputPath, xmlContent, 'utf-8');
|
|
2386
2407
|
logger_logger.log(`JUnit XML report written to: ${this.outputPath}`);
|
|
2387
2408
|
} catch (error) {
|
|
2388
2409
|
logger_logger.stderr(`Failed to write JUnit XML report to ${this.outputPath}:`, error);
|
|
@@ -2520,7 +2541,7 @@ class Rstest {
|
|
|
2520
2541
|
updateSnapshot: rstestConfig.update ? 'all' : T ? 'none' : 'new'
|
|
2521
2542
|
});
|
|
2522
2543
|
this.snapshotManager = snapshotManager;
|
|
2523
|
-
this.version = "0.8.
|
|
2544
|
+
this.version = "0.8.1";
|
|
2524
2545
|
this.rootPath = rootPath;
|
|
2525
2546
|
this.originalConfig = userConfig;
|
|
2526
2547
|
this.normalizedConfig = rstestConfig;
|