@rstest/core 0.9.1 → 0.9.3
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 +1 -1
- package/dist/{0~89.js → 0~8843.js} +24 -28
- package/dist/{0~1472.js → 0~browserLoader.js} +11 -11
- package/dist/{0~7882.js → 0~browser~1.js} +60 -61
- package/dist/{0~8426.js → 0~checkThresholds.js} +6 -6
- package/dist/{0~7583.js → 0~chokidar.js} +113 -72
- package/dist/{0~130.js → 0~console.js} +19 -20
- package/dist/{0~9744.js → 0~dist.js} +57 -57
- package/dist/{0~4403.js → 0~generate.js} +9 -6
- package/dist/{0~4809.js → 0~happyDom.js} +2 -2
- package/dist/{0~3346.js → 0~interop.js} +0 -1
- package/dist/{0~62.js → 0~jsdom.js} +2 -2
- package/dist/{0~262.js → 0~lib.js} +4 -1
- package/dist/{0~9634.js → 0~listTests.js} +15 -24
- package/dist/{0~6923.js → 0~loadEsModule.js} +7 -7
- package/dist/{0~5835.js → 0~loadModule.js} +11 -11
- package/dist/{0~6907.js → 0~magic-string.es.js} +2 -1
- package/dist/0~mergeReports.js +127 -0
- package/dist/{0~2255.js → 0~plugin.js} +2 -4
- package/dist/{0~6588.js → 0~restart.js} +8 -12
- package/dist/{0~2173.js → 0~runTests.js} +51 -60
- package/dist/{487.js → 1255.js} +22 -15
- package/dist/{6151.js → 1949.js} +41 -25
- package/dist/{6973.js → 255.js} +9 -10
- package/dist/{9131.js → 3145.js} +229 -479
- package/dist/{1157.js → 4411.js} +37 -37
- package/dist/{4484.js → 5040.js} +1 -2
- package/dist/{3160.js → 6830.js} +429 -106
- package/dist/7011.js +1 -1
- package/dist/{1294.js → 7552.js} +106 -83
- package/dist/{5734.js → 7704.js} +7 -6
- package/dist/browser-runtime/{2~907.js → 2~magic-string.es.js} +18 -11
- package/dist/browser-runtime/{389.js → 723.js} +178 -134
- package/dist/browser-runtime/{389.js.LICENSE.txt → 723.js.LICENSE.txt} +0 -22
- package/dist/browser-runtime/index.d.ts +40 -5
- package/dist/browser-runtime/index.js +1 -1
- package/dist/browser-runtime/rslib-runtime.js +11 -3
- package/dist/browser.d.ts +40 -5
- package/dist/browser.js +9 -7
- package/dist/globalSetupWorker.js +7 -14
- package/dist/index.d.ts +53 -6
- package/dist/index.js +2 -2
- package/dist/rslib-runtime.js +5 -8
- package/dist/worker.d.ts +30 -3
- package/dist/worker.js +20 -46
- package/package.json +19 -18
- package/dist/3160.js.LICENSE.txt +0 -21
- package/dist/4881.js +0 -2
- package/dist/6198.js +0 -2
- /package/dist/{0~7583.js.LICENSE.txt → 0~chokidar.js.LICENSE.txt} +0 -0
- /package/dist/{0~3062.js → 0~utils.js} +0 -0
- /package/dist/{6151.js.LICENSE.txt → 1949.js.LICENSE.txt} +0 -0
- /package/dist/{4597.js → 1983.js} +0 -0
- /package/dist/{1294.js.LICENSE.txt → 7552.js.LICENSE.txt} +0 -0
package/LICENSE.md
CHANGED
|
@@ -1183,7 +1183,7 @@ Licensed under MIT license in the repository at https://github.com/facebook/reac
|
|
|
1183
1183
|
|
|
1184
1184
|
### readdirp
|
|
1185
1185
|
|
|
1186
|
-
Licensed under MIT license in the repository at
|
|
1186
|
+
Licensed under MIT license in the repository at https://github.com/paulmillr/readdirp.git.
|
|
1187
1187
|
|
|
1188
1188
|
> MIT License
|
|
1189
1189
|
>
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import
|
|
2
|
+
import node_os from "node:os";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import node_process from "node:process";
|
|
3
5
|
import node_events from "node:events";
|
|
4
6
|
import { Tinypool } from "tinypool";
|
|
7
|
+
import { createRsbuild, logger } from "@rsbuild/core";
|
|
8
|
+
import node_path from "node:path";
|
|
9
|
+
import { isBuiltin } from "node:module";
|
|
5
10
|
import node_inspector from "node:inspector";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { parseWorkerMetaMessage, createBirpc } from "./
|
|
9
|
-
import { TEMP_RSTEST_OUTPUT_DIR, TEMP_RSTEST_OUTPUT_DIR_GLOB } from "./
|
|
11
|
+
import node_fs from "node:fs";
|
|
12
|
+
import { basename, bgColor, isDeno, dirname, castArray, resolve as pathe_M_eThtNZ_resolve, isDebug, color as logger_color, getForceColorEnv, ADDITIONAL_NODE_BUILTINS, needFlagExperimentalDetectModule, join } from "./6830.js";
|
|
13
|
+
import { parseWorkerMetaMessage, createBirpc } from "./1983.js";
|
|
14
|
+
import { TEMP_RSTEST_OUTPUT_DIR, TEMP_RSTEST_OUTPUT_DIR_GLOB } from "./4411.js";
|
|
10
15
|
import { posix } from "./7011.js";
|
|
11
|
-
import { isBuiltin } from "./4881.js";
|
|
12
|
-
import { rsbuild as __rspack_external__rsbuild_core_1b356efc } from "./4484.js";
|
|
13
16
|
const DefaultMaxHeapSize = 1073741824;
|
|
14
17
|
function memory_isMemorySufficient(options) {
|
|
15
18
|
const { memoryThreshold = 0.7, maxHeapSize = DefaultMaxHeapSize } = options || {};
|
|
@@ -292,8 +295,7 @@ const createForksPool = (poolOptions)=>{
|
|
|
292
295
|
}
|
|
293
296
|
};
|
|
294
297
|
};
|
|
295
|
-
const
|
|
296
|
-
const getNumCpus = ()=>external_node_os_["default"].availableParallelism?.() ?? external_node_os_["default"].cpus().length;
|
|
298
|
+
const getNumCpus = ()=>node_os.availableParallelism?.() ?? node_os.cpus().length;
|
|
297
299
|
const parseWorkers = (maxWorkers)=>{
|
|
298
300
|
const parsed = Number.parseInt(maxWorkers.toString(), 10);
|
|
299
301
|
if ('string' == typeof maxWorkers && maxWorkers.trim().endsWith('%')) {
|
|
@@ -452,8 +454,8 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
|
|
|
452
454
|
const runningModule = context.stateManager.runningModules.get(entryInfo.testPath);
|
|
453
455
|
if (runningModule?.runningTests.length) {
|
|
454
456
|
const getCaseName = (test)=>`"${test.name}"${test.parentNames?.length ? ` (Under suite: ${test.parentNames?.join(' > ')})` : ''}`;
|
|
455
|
-
if (runningModule?.runningTests.length === 1) err.message += `\n\n${
|
|
456
|
-
else err.message += `\n\n${
|
|
457
|
+
if (runningModule?.runningTests.length === 1) err.message += `\n\n${logger_color.white(`Maybe relevant test case: ${getCaseName(runningModule.runningTests[0])} which is running when the error occurs.`)}`;
|
|
458
|
+
else err.message += `\n\n${logger_color.white(`The below test cases may be relevant, as they were running when the error occurred:\n - ${runningModule.runningTests.map((t)=>getCaseName(t)).join('\n - ')}`)}`;
|
|
457
459
|
}
|
|
458
460
|
return {
|
|
459
461
|
testId: '0',
|
|
@@ -596,12 +598,11 @@ async function runGlobalTeardown() {
|
|
|
596
598
|
await teardown();
|
|
597
599
|
} catch (error) {
|
|
598
600
|
console.error(bgColor('bgRed', 'Error during global teardown'));
|
|
599
|
-
if (error instanceof Error) error.stack ? console.error(
|
|
600
|
-
else console.error(
|
|
601
|
+
if (error instanceof Error) error.stack ? console.error(logger_color.red(error.stack)) : console.error(logger_color.red(error.message));
|
|
602
|
+
else console.error(logger_color.red(String(error)));
|
|
601
603
|
process.exitCode = 1;
|
|
602
604
|
}
|
|
603
605
|
}
|
|
604
|
-
const external_node_path_ = __webpack_require__("path");
|
|
605
606
|
const RUNTIME_CHUNK_NAME = 'runtime';
|
|
606
607
|
const requireShim = `// Rstest ESM shims
|
|
607
608
|
import __rstest_shim_module__ from 'node:module';
|
|
@@ -648,7 +649,7 @@ const pluginBasic = (context)=>({
|
|
|
648
649
|
},
|
|
649
650
|
tools: {
|
|
650
651
|
rspack: (config, { isProd, rspack })=>{
|
|
651
|
-
config.context =
|
|
652
|
+
config.context = node_path.resolve(rootPath);
|
|
652
653
|
config.mode = isProd ? 'production' : 'development';
|
|
653
654
|
config.output ??= {};
|
|
654
655
|
config.output.iife = false;
|
|
@@ -719,7 +720,7 @@ const pluginBasic = (context)=>({
|
|
|
719
720
|
}
|
|
720
721
|
});
|
|
721
722
|
const PLUGIN_CSS_FILTER = 'rstest:css-filter';
|
|
722
|
-
const css_filter_dirname =
|
|
723
|
+
const css_filter_dirname = node_path.dirname(fileURLToPath(import.meta.url));
|
|
723
724
|
const pluginCSSFilter = ()=>({
|
|
724
725
|
name: PLUGIN_CSS_FILTER,
|
|
725
726
|
setup (api) {
|
|
@@ -757,7 +758,7 @@ const pluginCSSFilter = ()=>({
|
|
|
757
758
|
importLoaders: (cssLoaderOptions.importLoaders || 0) + 1
|
|
758
759
|
};
|
|
759
760
|
rule.use(CHAIN_ID.USE.CSS).options(clonedOptions);
|
|
760
|
-
rule.use('rstest-css-pre-filter').loader(
|
|
761
|
+
rule.use('rstest-css-pre-filter').loader(node_path.join(css_filter_dirname, 'cssFilterLoader.mjs')).options({
|
|
761
762
|
modules: cssLoaderOptions.modules
|
|
762
763
|
}).after(mainId);
|
|
763
764
|
}
|
|
@@ -900,8 +901,7 @@ const pluginInspect = (options)=>{
|
|
|
900
901
|
}
|
|
901
902
|
} : null;
|
|
902
903
|
};
|
|
903
|
-
const
|
|
904
|
-
const mockRuntime_dirname = external_node_path_["default"].dirname(fileURLToPath(import.meta.url));
|
|
904
|
+
const mockRuntime_dirname = node_path.dirname(fileURLToPath(import.meta.url));
|
|
905
905
|
class MockRuntimeRspackPlugin {
|
|
906
906
|
outputModule;
|
|
907
907
|
constructor(outputModule){
|
|
@@ -914,7 +914,7 @@ class MockRuntimeRspackPlugin {
|
|
|
914
914
|
super('rstest runtime');
|
|
915
915
|
}
|
|
916
916
|
generate() {
|
|
917
|
-
const code =
|
|
917
|
+
const code = node_fs.readFileSync(node_path.join(mockRuntime_dirname, './mockRuntimeCode.js'), 'utf8');
|
|
918
918
|
return code;
|
|
919
919
|
}
|
|
920
920
|
}
|
|
@@ -1021,9 +1021,9 @@ const prepareRsbuild = async (context, globTestSourceEntries, setupFiles, global
|
|
|
1021
1021
|
const { command, normalizedConfig: { isolate, dev = {}, coverage, pool } } = context;
|
|
1022
1022
|
const projects = context.projects.filter((project)=>!project.normalizedConfig.browser.enabled);
|
|
1023
1023
|
const debugMode = isDebug();
|
|
1024
|
-
|
|
1024
|
+
logger.level = debugMode ? 'verbose' : 'error';
|
|
1025
1025
|
const writeToDisk = dev.writeToDisk || debugMode;
|
|
1026
|
-
const rsbuildInstance = await
|
|
1026
|
+
const rsbuildInstance = await createRsbuild({
|
|
1027
1027
|
callerName: 'rstest',
|
|
1028
1028
|
config: {
|
|
1029
1029
|
root: context.rootPath,
|
|
@@ -1073,12 +1073,8 @@ const prepareRsbuild = async (context, globTestSourceEntries, setupFiles, global
|
|
|
1073
1073
|
}
|
|
1074
1074
|
});
|
|
1075
1075
|
if (coverage?.enabled && 'list' !== command) {
|
|
1076
|
-
const { loadCoverageProvider } = await import("./
|
|
1077
|
-
|
|
1078
|
-
}));
|
|
1079
|
-
const { pluginCoverageCore } = await import("./0~2255.js").then((mod)=>({
|
|
1080
|
-
pluginCoverageCore: mod.pluginCoverageCore
|
|
1081
|
-
}));
|
|
1076
|
+
const { loadCoverageProvider } = await import("./7704.js");
|
|
1077
|
+
const { pluginCoverageCore } = await import("./0~plugin.js");
|
|
1082
1078
|
const { pluginCoverage } = await loadCoverageProvider(coverage, context.rootPath);
|
|
1083
1079
|
coverage.exclude.push(...Object.values(setupFiles).flatMap((files)=>Object.values(files)), ...Object.values(globalSetupFiles || {}).flatMap((files)=>Object.values(files)));
|
|
1084
1080
|
rsbuildInstance.addPlugins([
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { createRequire } from "
|
|
3
|
-
import { pathToFileURL } from "
|
|
4
|
-
import "./
|
|
5
|
-
import { logger as logger_logger, color } from "./
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import "./4411.js";
|
|
5
|
+
import { logger as logger_logger, color as logger_color } from "./6830.js";
|
|
6
6
|
async function loadBrowserModule(options = {}) {
|
|
7
|
-
const coreVersion = "0.9.
|
|
7
|
+
const coreVersion = "0.9.3";
|
|
8
8
|
const { projectRoots = [] } = options;
|
|
9
9
|
let browserModule;
|
|
10
10
|
let browserVersion;
|
|
@@ -24,9 +24,9 @@ async function loadBrowserModule(options = {}) {
|
|
|
24
24
|
const browserPkg = userRequire(browserPkgPath);
|
|
25
25
|
browserVersion = browserPkg.version;
|
|
26
26
|
if (browserVersion !== coreVersion) {
|
|
27
|
-
logger_logger.error(`\n${
|
|
28
|
-
logger_logger.error(` @rstest/core version: ${
|
|
29
|
-
logger_logger.error(`Please ensure both packages have the same version:\n\n ${
|
|
27
|
+
logger_logger.error(`\n${logger_color.red('Error:')} Version mismatch between ${logger_color.cyan('@rstest/core')} and ${logger_color.cyan('@rstest/browser')}.\n`);
|
|
28
|
+
logger_logger.error(` @rstest/core version: ${logger_color.yellow(coreVersion)}\n @rstest/browser version: ${logger_color.yellow(browserVersion)}\n`);
|
|
29
|
+
logger_logger.error(`Please ensure both packages have the same version:\n\n ${logger_color.cyan(`npm install @rstest/browser@${coreVersion}`)}\n`);
|
|
30
30
|
process.exit(1);
|
|
31
31
|
}
|
|
32
32
|
return browserModule;
|
|
@@ -35,9 +35,9 @@ async function loadBrowserModule(options = {}) {
|
|
|
35
35
|
if ('ERR_MODULE_NOT_FOUND' === err.code || 'MODULE_NOT_FOUND' === err.code) continue;
|
|
36
36
|
throw error;
|
|
37
37
|
}
|
|
38
|
-
logger_logger.error(`\n${
|
|
39
|
-
logger_logger.error(`Please install it with:\n\n ${
|
|
40
|
-
logger_logger.error(`Or if using pnpm:\n\n ${
|
|
38
|
+
logger_logger.error(`\n${logger_color.red('Error:')} Browser mode requires ${logger_color.cyan('@rstest/browser')} to be installed.\n`);
|
|
39
|
+
logger_logger.error(`Please install it with:\n\n ${logger_color.cyan(`npm install @rstest/browser@${coreVersion}`)}\n`);
|
|
40
|
+
logger_logger.error(`Or if using pnpm:\n\n ${logger_color.cyan(`pnpm add @rstest/browser@${coreVersion}`)}\n`);
|
|
41
41
|
process.exit(1);
|
|
42
42
|
}
|
|
43
43
|
export { loadBrowserModule };
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { detect, resolveCommand } from "./
|
|
5
|
-
import { Rt, dist_Wt,
|
|
6
|
-
import "./
|
|
7
|
-
|
|
8
|
-
const external_node_path_ = __webpack_require__("path");
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import node_fs from "node:fs";
|
|
4
|
+
import { detect, resolveCommand } from "./3145.js";
|
|
5
|
+
import { confirm as Rt, intro as dist_Wt, log as R, note as dist_Vt, outro as Gt, cancel as Nt, isCancel as Ct, spinner as be, select as Jt } from "./0~dist.js";
|
|
6
|
+
import "./4411.js";
|
|
7
|
+
import { determineAgent, color as logger_color } from "./6830.js";
|
|
9
8
|
function getUniqueBaseName(dir, baseName, ext) {
|
|
10
|
-
const fullPath =
|
|
11
|
-
if (!
|
|
9
|
+
const fullPath = node_path.join(dir, `${baseName}${ext}`);
|
|
10
|
+
if (!node_fs.existsSync(fullPath)) return baseName;
|
|
12
11
|
let suffix = 1;
|
|
13
|
-
while(
|
|
12
|
+
while(node_fs.existsSync(node_path.join(dir, `${baseName}_${suffix}${ext}`)))suffix++;
|
|
14
13
|
return `${baseName}_${suffix}`;
|
|
15
14
|
}
|
|
16
15
|
function ensureDir(dir) {
|
|
17
|
-
if (!
|
|
16
|
+
if (!node_fs.existsSync(dir)) node_fs.mkdirSync(dir, {
|
|
18
17
|
recursive: true
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
20
|
function writeFile(filePath, content) {
|
|
22
|
-
|
|
21
|
+
node_fs.writeFileSync(filePath, content, 'utf-8');
|
|
23
22
|
}
|
|
24
23
|
function readPackageJson(cwd) {
|
|
25
|
-
const pkgPath =
|
|
26
|
-
if (!
|
|
24
|
+
const pkgPath = node_path.join(cwd, 'package.json');
|
|
25
|
+
if (!node_fs.existsSync(pkgPath)) return null;
|
|
27
26
|
try {
|
|
28
|
-
const content =
|
|
27
|
+
const content = node_fs.readFileSync(pkgPath, 'utf-8');
|
|
29
28
|
return JSON.parse(content);
|
|
30
29
|
} catch {
|
|
31
30
|
return null;
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
function updatePackageJsonScripts(cwd, scripts) {
|
|
35
|
-
const pkgPath =
|
|
34
|
+
const pkgPath = node_path.join(cwd, 'package.json');
|
|
36
35
|
let pkg;
|
|
37
|
-
if (
|
|
38
|
-
const content =
|
|
36
|
+
if (node_fs.existsSync(pkgPath)) {
|
|
37
|
+
const content = node_fs.readFileSync(pkgPath, 'utf-8');
|
|
39
38
|
pkg = JSON.parse(content);
|
|
40
39
|
} else pkg = {};
|
|
41
40
|
const existingScripts = pkg.scripts ?? {};
|
|
@@ -43,19 +42,19 @@ function updatePackageJsonScripts(cwd, scripts) {
|
|
|
43
42
|
...existingScripts,
|
|
44
43
|
...scripts
|
|
45
44
|
};
|
|
46
|
-
|
|
45
|
+
node_fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8');
|
|
47
46
|
}
|
|
48
47
|
function updatePackageJsonDevDeps(cwd, deps) {
|
|
49
|
-
const pkgPath =
|
|
48
|
+
const pkgPath = node_path.join(cwd, 'package.json');
|
|
50
49
|
let pkg;
|
|
51
|
-
if (
|
|
52
|
-
const content =
|
|
50
|
+
if (node_fs.existsSync(pkgPath)) {
|
|
51
|
+
const content = node_fs.readFileSync(pkgPath, 'utf-8');
|
|
53
52
|
pkg = JSON.parse(content);
|
|
54
53
|
} else pkg = {};
|
|
55
54
|
const existingDevDeps = pkg.devDependencies ?? {};
|
|
56
55
|
for (const [name, version] of Object.entries(deps))if (!existingDevDeps[name]) existingDevDeps[name] = version;
|
|
57
56
|
pkg.devDependencies = existingDevDeps;
|
|
58
|
-
|
|
57
|
+
node_fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8');
|
|
59
58
|
}
|
|
60
59
|
async function detectPackageManagerAgent(cwd) {
|
|
61
60
|
const result = await detect({
|
|
@@ -71,8 +70,8 @@ function detectTestDir(cwd) {
|
|
|
71
70
|
'src/__tests__'
|
|
72
71
|
];
|
|
73
72
|
for (const dir of candidates){
|
|
74
|
-
const fullPath =
|
|
75
|
-
if (
|
|
73
|
+
const fullPath = node_path.join(cwd, dir);
|
|
74
|
+
if (node_fs.existsSync(fullPath) && node_fs.statSync(fullPath).isDirectory()) return dir;
|
|
76
75
|
}
|
|
77
76
|
return 'tests';
|
|
78
77
|
}
|
|
@@ -93,7 +92,7 @@ function detectReact(pkg) {
|
|
|
93
92
|
};
|
|
94
93
|
}
|
|
95
94
|
function detectTypeScript(cwd) {
|
|
96
|
-
return
|
|
95
|
+
return node_fs.existsSync(node_path.join(cwd, 'tsconfig.json'));
|
|
97
96
|
}
|
|
98
97
|
async function detectProject(cwd) {
|
|
99
98
|
const pkg = readPackageJson(cwd);
|
|
@@ -311,7 +310,7 @@ function computeFilePreview(cwd, projectInfo) {
|
|
|
311
310
|
componentExt = 'ts' === language ? '.ts' : '.js';
|
|
312
311
|
testExt = 'ts' === language ? '.test.ts' : '.test.js';
|
|
313
312
|
}
|
|
314
|
-
const testDirPath =
|
|
313
|
+
const testDirPath = node_path.join(cwd, testDir);
|
|
315
314
|
const baseName = getUniqueBaseName(testDirPath, 'Counter', componentExt);
|
|
316
315
|
return {
|
|
317
316
|
configFile,
|
|
@@ -324,14 +323,14 @@ async function createNonInteractive(cwd, projectInfo) {
|
|
|
324
323
|
const { agent, testDir, framework, reactVersion } = projectInfo;
|
|
325
324
|
const provider = 'playwright';
|
|
326
325
|
console.log();
|
|
327
|
-
console.log(
|
|
326
|
+
console.log(logger_color.cyan('◆'), logger_color.bold('rstest init browser --yes'));
|
|
328
327
|
console.log();
|
|
329
328
|
console.log(' Detecting project...');
|
|
330
|
-
if ('react' === framework && reactVersion) console.log(
|
|
331
|
-
else if ('react' === framework) console.log(
|
|
332
|
-
else console.log(
|
|
333
|
-
console.log(
|
|
334
|
-
console.log(
|
|
329
|
+
if ('react' === framework && reactVersion) console.log(logger_color.green(' ✓'), `Found React ${reactVersion}`);
|
|
330
|
+
else if ('react' === framework) console.log(logger_color.green(' ✓'), 'Found React');
|
|
331
|
+
else console.log(logger_color.yellow(' ⚠'), 'Framework not detected, generating vanilla DOM example');
|
|
332
|
+
console.log(logger_color.green(' ✓'), 'Using playwright as browser provider');
|
|
333
|
+
console.log(logger_color.green(' ✓'), `Test directory: ${testDir}/`);
|
|
335
334
|
console.log();
|
|
336
335
|
const createdFiles = await generateFiles(cwd, projectInfo, provider);
|
|
337
336
|
console.log(' Created files:');
|
|
@@ -343,20 +342,20 @@ async function createNonInteractive(cwd, projectInfo) {
|
|
|
343
342
|
console.log(` ${getPlaywrightInstallCommand(agent, provider)}`);
|
|
344
343
|
console.log(` ${getRunCommand(agent)}`);
|
|
345
344
|
console.log();
|
|
346
|
-
console.log(
|
|
345
|
+
console.log(logger_color.green('└'), 'Done!');
|
|
347
346
|
}
|
|
348
347
|
async function createInteractive(cwd, projectInfo, isAgent) {
|
|
349
348
|
const { agent, language, testDir, framework, reactVersion } = projectInfo;
|
|
350
349
|
const effectiveFramework = 'react' === framework ? 'react' : 'vanilla';
|
|
351
|
-
dist_Wt(
|
|
350
|
+
dist_Wt(logger_color.bgCyan(logger_color.black(' rstest init browser ')));
|
|
352
351
|
const detectionLines = [];
|
|
353
|
-
if ('react' === framework && reactVersion) detectionLines.push(`${
|
|
354
|
-
else if ('react' === framework) detectionLines.push(`${
|
|
355
|
-
else detectionLines.push(`${
|
|
356
|
-
detectionLines.push(`${
|
|
357
|
-
detectionLines.push(`${
|
|
352
|
+
if ('react' === framework && reactVersion) detectionLines.push(`${logger_color.green('✓')} Found React ${reactVersion}`);
|
|
353
|
+
else if ('react' === framework) detectionLines.push(`${logger_color.green('✓')} Found React`);
|
|
354
|
+
else detectionLines.push(`${logger_color.yellow('⚠')} Framework not detected, will generate vanilla DOM example`);
|
|
355
|
+
detectionLines.push(`${logger_color.green('✓')} Found ${'ts' === language ? 'TypeScript' : 'JavaScript'}`);
|
|
356
|
+
detectionLines.push(`${logger_color.green('✓')} Test directory: ${testDir}/`);
|
|
358
357
|
dist_Vt(detectionLines.join('\n'), 'Detecting project...');
|
|
359
|
-
if (isAgent) R.info(`AI Agent detected. For non-interactive mode, run:\n ${
|
|
358
|
+
if (isAgent) R.info(`AI Agent detected. For non-interactive mode, run:\n ${logger_color.cyan('npx rstest init browser --yes')}`);
|
|
360
359
|
const providerSelection = await Jt({
|
|
361
360
|
message: 'Choose a browser provider (so far, only Playwright)',
|
|
362
361
|
options: [
|
|
@@ -373,15 +372,15 @@ async function createInteractive(cwd, projectInfo, isAgent) {
|
|
|
373
372
|
}
|
|
374
373
|
const provider = providerSelection;
|
|
375
374
|
const preview = computeFilePreview(cwd, projectInfo);
|
|
376
|
-
const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.9.
|
|
375
|
+
const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.9.3");
|
|
377
376
|
const depsList = Object.entries(deps).map(([name, version])=>`${name}@${version}`).join(', ');
|
|
378
377
|
const previewLines = [
|
|
379
|
-
`${
|
|
380
|
-
`${
|
|
381
|
-
`${
|
|
382
|
-
`${
|
|
378
|
+
`${logger_color.cyan('+')} Create ${preview.configFile}`,
|
|
379
|
+
`${logger_color.cyan('+')} Create ${preview.componentFile}`,
|
|
380
|
+
`${logger_color.cyan('+')} Create ${preview.testFile}`,
|
|
381
|
+
`${logger_color.yellow('~')} Modify package.json`,
|
|
383
382
|
' - Add "test:browser" script',
|
|
384
|
-
` - Add devDependencies: ${
|
|
383
|
+
` - Add devDependencies: ${logger_color.dim(depsList)}`
|
|
385
384
|
];
|
|
386
385
|
dist_Vt(previewLines.join('\n'), 'Changes to be made');
|
|
387
386
|
const confirmed = await Rt({
|
|
@@ -396,31 +395,31 @@ async function createInteractive(cwd, projectInfo, isAgent) {
|
|
|
396
395
|
s.start('Creating files...');
|
|
397
396
|
const createdFiles = await generateFiles(cwd, projectInfo, provider);
|
|
398
397
|
s.stop('Created files');
|
|
399
|
-
const fileLines = createdFiles.map((f)=>`${
|
|
400
|
-
fileLines.push(`${
|
|
398
|
+
const fileLines = createdFiles.map((f)=>`${logger_color.green('✓')} Created ${f}`);
|
|
399
|
+
fileLines.push(`${logger_color.green('✓')} Updated package.json`);
|
|
401
400
|
dist_Vt(fileLines.join('\n'), 'Files');
|
|
402
401
|
const nextStepsLines = [
|
|
403
|
-
`${
|
|
404
|
-
` ${
|
|
402
|
+
`${logger_color.bold('1.')} Install dependencies:`,
|
|
403
|
+
` ${logger_color.cyan(getInstallCommand(agent))}`,
|
|
405
404
|
'',
|
|
406
|
-
`${
|
|
407
|
-
` ${
|
|
405
|
+
`${logger_color.bold('2.')} Install Playwright browsers:`,
|
|
406
|
+
` ${logger_color.cyan(getPlaywrightInstallCommand(agent, provider))}`,
|
|
408
407
|
'',
|
|
409
|
-
`${
|
|
410
|
-
` ${
|
|
408
|
+
`${logger_color.bold('3.')} Run your tests:`,
|
|
409
|
+
` ${logger_color.cyan(getRunCommand(agent))}`
|
|
411
410
|
];
|
|
412
411
|
dist_Vt(nextStepsLines.join('\n'), 'Next steps');
|
|
413
|
-
Gt(
|
|
412
|
+
Gt(logger_color.green('Done! Happy testing with Rstest!'));
|
|
414
413
|
}
|
|
415
414
|
async function generateFiles(cwd, projectInfo, provider) {
|
|
416
415
|
const { language, testDir, framework } = projectInfo;
|
|
417
416
|
const effectiveFramework = 'react' === framework ? 'react' : 'vanilla';
|
|
418
417
|
const createdFiles = [];
|
|
419
418
|
const configFileName = getConfigFileName();
|
|
420
|
-
const configPath =
|
|
419
|
+
const configPath = node_path.join(cwd, configFileName);
|
|
421
420
|
writeFile(configPath, getConfigTemplate());
|
|
422
421
|
createdFiles.push(configFileName);
|
|
423
|
-
const testDirPath =
|
|
422
|
+
const testDirPath = node_path.join(cwd, testDir);
|
|
424
423
|
ensureDir(testDirPath);
|
|
425
424
|
let componentExt;
|
|
426
425
|
let testExt;
|
|
@@ -433,11 +432,11 @@ async function generateFiles(cwd, projectInfo, provider) {
|
|
|
433
432
|
}
|
|
434
433
|
const baseName = getUniqueBaseName(testDirPath, 'Counter', componentExt);
|
|
435
434
|
const componentFileName = `${baseName}${componentExt}`;
|
|
436
|
-
const componentPath =
|
|
435
|
+
const componentPath = node_path.join(testDirPath, componentFileName);
|
|
437
436
|
'react' === effectiveFramework ? writeFile(componentPath, getReactComponentTemplate(language)) : writeFile(componentPath, getVanillaComponentTemplate(language));
|
|
438
437
|
createdFiles.push(`${testDir}/${componentFileName}`);
|
|
439
438
|
const testFileName = `${baseName}${testExt}`;
|
|
440
|
-
const testPath =
|
|
439
|
+
const testPath = node_path.join(testDirPath, testFileName);
|
|
441
440
|
let testContent;
|
|
442
441
|
if ('react' === effectiveFramework) {
|
|
443
442
|
testContent = getReactTestTemplate(language);
|
|
@@ -451,7 +450,7 @@ async function generateFiles(cwd, projectInfo, provider) {
|
|
|
451
450
|
updatePackageJsonScripts(cwd, {
|
|
452
451
|
'test:browser': 'rstest --config=rstest.browser.config.ts'
|
|
453
452
|
});
|
|
454
|
-
const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.9.
|
|
453
|
+
const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.9.3");
|
|
455
454
|
updatePackageJsonDevDeps(cwd, deps);
|
|
456
455
|
return createdFiles;
|
|
457
456
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
3
|
-
import "./
|
|
4
|
-
import { relative, color } from "./
|
|
3
|
+
import "./4411.js";
|
|
4
|
+
import { relative, color as logger_color } from "./6830.js";
|
|
5
5
|
const picomatch = __webpack_require__("../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/index.js");
|
|
6
6
|
var picomatch_default = /*#__PURE__*/ __webpack_require__.n(picomatch);
|
|
7
7
|
const THRESHOLD_KEYS = [
|
|
@@ -34,7 +34,7 @@ function checkThresholds({ coverageMap, thresholds, coverageProvider, rootPath }
|
|
|
34
34
|
const matcher = picomatch_default()(key);
|
|
35
35
|
const matchedFiles = allFiles.filter((file)=>matcher(relative(rootPath, file)));
|
|
36
36
|
if (!matchedFiles.length) {
|
|
37
|
-
failedThresholds.push(`${
|
|
37
|
+
failedThresholds.push(`${logger_color.red('Error')}: coverage data for "${key}" was not found`);
|
|
38
38
|
continue;
|
|
39
39
|
}
|
|
40
40
|
for (const file of matchedFiles){
|
|
@@ -52,10 +52,10 @@ function checkThresholds({ coverageMap, thresholds, coverageProvider, rootPath }
|
|
|
52
52
|
if (void 0 !== expected) {
|
|
53
53
|
if (expected < 0) {
|
|
54
54
|
const uncovered = actual.total - actual.covered;
|
|
55
|
-
if (uncovered > -expected) errorMsg += `uncovered ${name} ${
|
|
56
|
-
} else if (actual.pct < expected) errorMsg += `coverage for ${name} ${
|
|
55
|
+
if (uncovered > -expected) errorMsg += `uncovered ${name} ${logger_color.red(`${uncovered}`)} exceeds maximum ${'global' === type ? 'global' : `"${type}"`} threshold allowed ${logger_color.yellow(`${-expected}`)}`;
|
|
56
|
+
} else if (actual.pct < expected) errorMsg += `coverage for ${name} ${logger_color.red(`${actual.pct}%`)} does not meet ${'global' === type ? 'global' : `"${type}"`} threshold ${logger_color.yellow(`${expected}%`)}`;
|
|
57
57
|
}
|
|
58
|
-
if (errorMsg) failedThresholds.push(`${
|
|
58
|
+
if (errorMsg) failedThresholds.push(`${logger_color.red('Error')}: ${file ? `${relative(rootPath, file)} ` : ''}${errorMsg}`);
|
|
59
59
|
};
|
|
60
60
|
thresholdGroup.forEach(({ name, coverageMap, ...thresholds })=>{
|
|
61
61
|
const summaries = thresholds.perFile ? coverageMap.files().map((file)=>({
|