@rstest/core 0.9.0 → 0.9.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/LICENSE.md +2 -2
- package/dist/{0~89.js → 0~8843.js} +49 -33
- package/dist/{0~1472.js → 0~browserLoader.js} +5 -5
- package/dist/{0~7882.js → 0~browser~1.js} +46 -47
- package/dist/{0~8426.js → 0~checkThresholds.js} +2 -2
- package/dist/{0~130.js → 0~console.js} +15 -17
- package/dist/0~dist.js +1014 -0
- package/dist/{0~7583.js → 0~esm.js} +68 -70
- package/dist/{0~4403.js → 0~generate.js} +5 -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} +14 -23
- package/dist/{0~6923.js → 0~loadEsModule.js} +16 -8
- package/dist/{0~5835.js → 0~loadModule.js} +27 -14
- package/dist/{0~6907.js → 0~magic-string.es.js} +2 -1
- package/dist/{0~2255.js → 0~plugin.js} +2 -4
- package/dist/{0~6588.js → 0~restart.js} +7 -11
- package/dist/{0~2173.js → 0~runTests.js} +27 -19
- package/dist/{487.js → 1255.js} +22 -15
- package/dist/{6151.js → 1949.js} +3027 -36
- package/dist/{6973.js → 255.js} +7 -8
- package/dist/{9131.js → 3145.js} +220 -486
- package/dist/{1157.js → 4411.js} +35 -35
- package/dist/{4484.js → 5040.js} +1 -2
- package/dist/{3160.js → 6830.js} +396 -93
- package/dist/7011.js +1 -1
- package/dist/{1294.js → 7552.js} +28 -22
- package/dist/{5734.js → 7704.js} +6 -5
- package/dist/browser-runtime/{2~907.js → 2~magic-string.es.js} +18 -11
- package/dist/browser-runtime/{389.js → 723.js} +3059 -80
- package/dist/browser-runtime/{389.js.LICENSE.txt → 723.js.LICENSE.txt} +0 -22
- package/dist/browser-runtime/index.js +1 -1
- package/dist/browser-runtime/rslib-runtime.js +11 -3
- package/dist/browser.js +9 -7
- package/dist/globalSetupWorker.js +4 -13
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -2
- package/dist/mockRuntimeCode.js +15 -9
- package/dist/rslib-runtime.js +5 -8
- package/dist/worker.js +23 -46
- package/package.json +12 -10
- package/dist/0~1240.js +0 -951
- package/dist/0~1981.js +0 -2
- package/dist/3160.js.LICENSE.txt +0 -21
- package/dist/4881.js +0 -2
- package/dist/6198.js +0 -2
- package/dist/721.js +0 -8
- /package/dist/{0~7583.js.LICENSE.txt → 0~esm.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
|
@@ -748,7 +748,7 @@ Licensed under MIT license in the repository at LinusU/buffer-from.
|
|
|
748
748
|
|
|
749
749
|
### cac
|
|
750
750
|
|
|
751
|
-
Licensed under MIT license in the repository at
|
|
751
|
+
Licensed under MIT license in the repository at git+https://github.com/cacjs/cac.git.
|
|
752
752
|
|
|
753
753
|
> The MIT License (MIT)
|
|
754
754
|
>
|
|
@@ -1209,7 +1209,7 @@ Licensed under MIT license in the repository at git://github.com/paulmillr/readd
|
|
|
1209
1209
|
|
|
1210
1210
|
### rslog
|
|
1211
1211
|
|
|
1212
|
-
Licensed under MIT license in the repository at https://github.com/
|
|
1212
|
+
Licensed under MIT license in the repository at https://github.com/rstackjs/rslog.git.
|
|
1213
1213
|
|
|
1214
1214
|
> MIT License
|
|
1215
1215
|
>
|
|
@@ -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, 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('%')) {
|
|
@@ -601,7 +603,6 @@ async function runGlobalTeardown() {
|
|
|
601
603
|
process.exitCode = 1;
|
|
602
604
|
}
|
|
603
605
|
}
|
|
604
|
-
const external_node_path_ = __webpack_require__("node:path");
|
|
605
606
|
const RUNTIME_CHUNK_NAME = 'runtime';
|
|
606
607
|
const requireShim = `// Rstest ESM shims
|
|
607
608
|
import __rstest_shim_module__ from 'node:module';
|
|
@@ -618,6 +619,7 @@ const pluginBasic = (context)=>({
|
|
|
618
619
|
});
|
|
619
620
|
api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig, name })=>{
|
|
620
621
|
const { normalizedConfig: { resolve, source, output, tools, dev, testEnvironment }, outputModule, rootPath } = context.projects.find((p)=>p.environmentName === name);
|
|
622
|
+
const distRootDir = context.projects.length > 1 ? `${TEMP_RSTEST_OUTPUT_DIR}/${name}` : TEMP_RSTEST_OUTPUT_DIR;
|
|
621
623
|
return mergeEnvironmentConfig(config, {
|
|
622
624
|
tools,
|
|
623
625
|
resolve,
|
|
@@ -632,6 +634,7 @@ const pluginBasic = (context)=>({
|
|
|
632
634
|
}
|
|
633
635
|
},
|
|
634
636
|
output: {
|
|
637
|
+
assetPrefix: '',
|
|
635
638
|
manifest: `${name}-manifest.json`,
|
|
636
639
|
sourceMap: {
|
|
637
640
|
js: 'source-map'
|
|
@@ -641,12 +644,12 @@ const pluginBasic = (context)=>({
|
|
|
641
644
|
js: '[name].mjs'
|
|
642
645
|
} : void 0,
|
|
643
646
|
distPath: {
|
|
644
|
-
root:
|
|
647
|
+
root: distRootDir
|
|
645
648
|
}
|
|
646
649
|
},
|
|
647
650
|
tools: {
|
|
648
651
|
rspack: (config, { isProd, rspack })=>{
|
|
649
|
-
config.context =
|
|
652
|
+
config.context = node_path.resolve(rootPath);
|
|
650
653
|
config.mode = isProd ? 'production' : 'development';
|
|
651
654
|
config.output ??= {};
|
|
652
655
|
config.output.iife = false;
|
|
@@ -717,7 +720,7 @@ const pluginBasic = (context)=>({
|
|
|
717
720
|
}
|
|
718
721
|
});
|
|
719
722
|
const PLUGIN_CSS_FILTER = 'rstest:css-filter';
|
|
720
|
-
const css_filter_dirname =
|
|
723
|
+
const css_filter_dirname = node_path.dirname(fileURLToPath(import.meta.url));
|
|
721
724
|
const pluginCSSFilter = ()=>({
|
|
722
725
|
name: PLUGIN_CSS_FILTER,
|
|
723
726
|
setup (api) {
|
|
@@ -727,19 +730,37 @@ const pluginCSSFilter = ()=>({
|
|
|
727
730
|
const emitCss = environment.config.output.emitCss ?? 'web' === target;
|
|
728
731
|
if (!emitCss) {
|
|
729
732
|
const ruleIds = [
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
733
|
+
[
|
|
734
|
+
CHAIN_ID.RULE.CSS,
|
|
735
|
+
CHAIN_ID.ONE_OF.CSS_MAIN
|
|
736
|
+
],
|
|
737
|
+
[
|
|
738
|
+
CHAIN_ID.RULE.SASS,
|
|
739
|
+
'sass'
|
|
740
|
+
],
|
|
741
|
+
[
|
|
742
|
+
CHAIN_ID.RULE.LESS,
|
|
743
|
+
'less'
|
|
744
|
+
],
|
|
745
|
+
[
|
|
746
|
+
CHAIN_ID.RULE.STYLUS,
|
|
747
|
+
'stylus'
|
|
748
|
+
]
|
|
734
749
|
];
|
|
735
|
-
for (const ruleId of ruleIds){
|
|
750
|
+
for (const [ruleId, mainId] of ruleIds){
|
|
736
751
|
if (!chain.module.rules.has(ruleId)) continue;
|
|
737
|
-
const rule = chain.module.rule(ruleId).oneOf(
|
|
752
|
+
const rule = chain.module.rule(ruleId).oneOf(mainId);
|
|
738
753
|
if (!rule.uses.has(CHAIN_ID.USE.CSS)) continue;
|
|
739
754
|
const cssLoaderOptions = rule.use(CHAIN_ID.USE.CSS).get('options');
|
|
740
|
-
if (cssLoaderOptions.modules
|
|
755
|
+
if (!cssLoaderOptions.modules || 'object' == typeof cssLoaderOptions.modules && false === cssLoaderOptions.modules.auto) continue;
|
|
756
|
+
const clonedOptions = {
|
|
757
|
+
...cssLoaderOptions,
|
|
758
|
+
importLoaders: (cssLoaderOptions.importLoaders || 0) + 1
|
|
759
|
+
};
|
|
760
|
+
rule.use(CHAIN_ID.USE.CSS).options(clonedOptions);
|
|
761
|
+
rule.use('rstest-css-pre-filter').loader(node_path.join(css_filter_dirname, 'cssFilterLoader.mjs')).options({
|
|
741
762
|
modules: cssLoaderOptions.modules
|
|
742
|
-
}).after(
|
|
763
|
+
}).after(mainId);
|
|
743
764
|
}
|
|
744
765
|
}
|
|
745
766
|
}
|
|
@@ -880,8 +901,7 @@ const pluginInspect = (options)=>{
|
|
|
880
901
|
}
|
|
881
902
|
} : null;
|
|
882
903
|
};
|
|
883
|
-
const
|
|
884
|
-
const mockRuntime_dirname = external_node_path_["default"].dirname(fileURLToPath(import.meta.url));
|
|
904
|
+
const mockRuntime_dirname = node_path.dirname(fileURLToPath(import.meta.url));
|
|
885
905
|
class MockRuntimeRspackPlugin {
|
|
886
906
|
outputModule;
|
|
887
907
|
constructor(outputModule){
|
|
@@ -894,7 +914,7 @@ class MockRuntimeRspackPlugin {
|
|
|
894
914
|
super('rstest runtime');
|
|
895
915
|
}
|
|
896
916
|
generate() {
|
|
897
|
-
const code =
|
|
917
|
+
const code = node_fs.readFileSync(node_path.join(mockRuntime_dirname, './mockRuntimeCode.js'), 'utf8');
|
|
898
918
|
return code;
|
|
899
919
|
}
|
|
900
920
|
}
|
|
@@ -1001,9 +1021,9 @@ const prepareRsbuild = async (context, globTestSourceEntries, setupFiles, global
|
|
|
1001
1021
|
const { command, normalizedConfig: { isolate, dev = {}, coverage, pool } } = context;
|
|
1002
1022
|
const projects = context.projects.filter((project)=>!project.normalizedConfig.browser.enabled);
|
|
1003
1023
|
const debugMode = isDebug();
|
|
1004
|
-
|
|
1024
|
+
logger.level = debugMode ? 'verbose' : 'error';
|
|
1005
1025
|
const writeToDisk = dev.writeToDisk || debugMode;
|
|
1006
|
-
const rsbuildInstance = await
|
|
1026
|
+
const rsbuildInstance = await createRsbuild({
|
|
1007
1027
|
callerName: 'rstest',
|
|
1008
1028
|
config: {
|
|
1009
1029
|
root: context.rootPath,
|
|
@@ -1053,12 +1073,8 @@ const prepareRsbuild = async (context, globTestSourceEntries, setupFiles, global
|
|
|
1053
1073
|
}
|
|
1054
1074
|
});
|
|
1055
1075
|
if (coverage?.enabled && 'list' !== command) {
|
|
1056
|
-
const { loadCoverageProvider } = await import("./
|
|
1057
|
-
|
|
1058
|
-
}));
|
|
1059
|
-
const { pluginCoverageCore } = await import("./0~2255.js").then((mod)=>({
|
|
1060
|
-
pluginCoverageCore: mod.pluginCoverageCore
|
|
1061
|
-
}));
|
|
1076
|
+
const { loadCoverageProvider } = await import("./7704.js");
|
|
1077
|
+
const { pluginCoverageCore } = await import("./0~plugin.js");
|
|
1062
1078
|
const { pluginCoverage } = await loadCoverageProvider(coverage, context.rootPath);
|
|
1063
1079
|
coverage.exclude.push(...Object.values(setupFiles).flatMap((files)=>Object.values(files)), ...Object.values(globalSetupFiles || {}).flatMap((files)=>Object.values(files)));
|
|
1064
1080
|
rsbuildInstance.addPlugins([
|
|
@@ -1200,7 +1216,7 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, globalSe
|
|
|
1200
1216
|
const entries = Object.keys(manifest.entries);
|
|
1201
1217
|
for (const entry of entries){
|
|
1202
1218
|
const data = manifest.entries[entry];
|
|
1203
|
-
entryFiles[entry] = ((data?.initial?.js || []).concat(data?.async?.js || []) || []).map((file)=>posix.join(outputPath, file));
|
|
1219
|
+
entryFiles[entry] = ((data?.initial?.js || []).concat(data?.async?.js || []).concat(data?.assets?.filter((asset)=>!asset.endsWith('.map')) || []) || []).map((file)=>file.startsWith(outputPath) ? file : posix.join(outputPath, file));
|
|
1204
1220
|
}
|
|
1205
1221
|
return entryFiles;
|
|
1206
1222
|
};
|
|
@@ -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 } from "./6830.js";
|
|
6
6
|
async function loadBrowserModule(options = {}) {
|
|
7
|
-
const coreVersion = "0.9.
|
|
7
|
+
const coreVersion = "0.9.2";
|
|
8
8
|
const { projectRoots = [] } = options;
|
|
9
9
|
let browserModule;
|
|
10
10
|
let browserVersion;
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { detect, resolveCommand } from "./
|
|
5
|
-
import {
|
|
6
|
-
import "./
|
|
7
|
-
|
|
8
|
-
const external_node_path_ = __webpack_require__("node: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 } 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,
|
|
@@ -348,16 +347,16 @@ async function createNonInteractive(cwd, projectInfo) {
|
|
|
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
|
-
|
|
350
|
+
dist_Wt(color.bgCyan(color.black(' rstest init browser ')));
|
|
352
351
|
const detectionLines = [];
|
|
353
352
|
if ('react' === framework && reactVersion) detectionLines.push(`${color.green('✓')} Found React ${reactVersion}`);
|
|
354
353
|
else if ('react' === framework) detectionLines.push(`${color.green('✓')} Found React`);
|
|
355
354
|
else detectionLines.push(`${color.yellow('⚠')} Framework not detected, will generate vanilla DOM example`);
|
|
356
355
|
detectionLines.push(`${color.green('✓')} Found ${'ts' === language ? 'TypeScript' : 'JavaScript'}`);
|
|
357
356
|
detectionLines.push(`${color.green('✓')} Test directory: ${testDir}/`);
|
|
358
|
-
|
|
359
|
-
if (isAgent)
|
|
360
|
-
const providerSelection = await
|
|
357
|
+
dist_Vt(detectionLines.join('\n'), 'Detecting project...');
|
|
358
|
+
if (isAgent) R.info(`AI Agent detected. For non-interactive mode, run:\n ${color.cyan('npx rstest init browser --yes')}`);
|
|
359
|
+
const providerSelection = await Jt({
|
|
361
360
|
message: 'Choose a browser provider (so far, only Playwright)',
|
|
362
361
|
options: [
|
|
363
362
|
{
|
|
@@ -367,13 +366,13 @@ async function createInteractive(cwd, projectInfo, isAgent) {
|
|
|
367
366
|
}
|
|
368
367
|
]
|
|
369
368
|
});
|
|
370
|
-
if (
|
|
371
|
-
|
|
369
|
+
if (Ct(providerSelection)) {
|
|
370
|
+
Nt('Operation cancelled.');
|
|
372
371
|
process.exit(0);
|
|
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.2");
|
|
377
376
|
const depsList = Object.entries(deps).map(([name, version])=>`${name}@${version}`).join(', ');
|
|
378
377
|
const previewLines = [
|
|
379
378
|
`${color.cyan('+')} Create ${preview.configFile}`,
|
|
@@ -383,22 +382,22 @@ async function createInteractive(cwd, projectInfo, isAgent) {
|
|
|
383
382
|
' - Add "test:browser" script',
|
|
384
383
|
` - Add devDependencies: ${color.dim(depsList)}`
|
|
385
384
|
];
|
|
386
|
-
|
|
387
|
-
const confirmed = await
|
|
385
|
+
dist_Vt(previewLines.join('\n'), 'Changes to be made');
|
|
386
|
+
const confirmed = await Rt({
|
|
388
387
|
message: 'Proceed with these changes?',
|
|
389
388
|
initialValue: true
|
|
390
389
|
});
|
|
391
|
-
if (
|
|
392
|
-
|
|
390
|
+
if (Ct(confirmed) || !confirmed) {
|
|
391
|
+
Nt('Operation cancelled.');
|
|
393
392
|
process.exit(0);
|
|
394
393
|
}
|
|
395
|
-
const s =
|
|
394
|
+
const s = be();
|
|
396
395
|
s.start('Creating files...');
|
|
397
396
|
const createdFiles = await generateFiles(cwd, projectInfo, provider);
|
|
398
397
|
s.stop('Created files');
|
|
399
398
|
const fileLines = createdFiles.map((f)=>`${color.green('✓')} Created ${f}`);
|
|
400
399
|
fileLines.push(`${color.green('✓')} Updated package.json`);
|
|
401
|
-
|
|
400
|
+
dist_Vt(fileLines.join('\n'), 'Files');
|
|
402
401
|
const nextStepsLines = [
|
|
403
402
|
`${color.bold('1.')} Install dependencies:`,
|
|
404
403
|
` ${color.cyan(getInstallCommand(agent))}`,
|
|
@@ -409,18 +408,18 @@ async function createInteractive(cwd, projectInfo, isAgent) {
|
|
|
409
408
|
`${color.bold('3.')} Run your tests:`,
|
|
410
409
|
` ${color.cyan(getRunCommand(agent))}`
|
|
411
410
|
];
|
|
412
|
-
|
|
413
|
-
|
|
411
|
+
dist_Vt(nextStepsLines.join('\n'), 'Next steps');
|
|
412
|
+
Gt(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.2");
|
|
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 } 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 = [
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
3
2
|
import { AssertionError, strict } from "node:assert";
|
|
4
3
|
import { Console } from "node:console";
|
|
5
|
-
import "
|
|
6
|
-
import { prettyTime, color } from "./
|
|
7
|
-
const external_node_util_ = __webpack_require__("node:util");
|
|
4
|
+
import { format, formatWithOptions, inspect } from "node:util";
|
|
5
|
+
import { prettyTime, color } from "./6830.js";
|
|
8
6
|
const RealDate = Date;
|
|
9
7
|
function createCustomConsole({ rpc, testPath, printConsoleTrace }) {
|
|
10
8
|
const getConsoleTrace = ()=>{
|
|
@@ -51,40 +49,40 @@ function createCustomConsole({ rpc, testPath, printConsoleTrace }) {
|
|
|
51
49
|
}
|
|
52
50
|
count(label = 'default') {
|
|
53
51
|
if (!this._counters[label]) this._counters[label] = 0;
|
|
54
|
-
this._log('count',
|
|
52
|
+
this._log('count', format(`${label}: ${++this._counters[label]}`));
|
|
55
53
|
}
|
|
56
54
|
countReset(label = 'default') {
|
|
57
55
|
this._counters[label] = 0;
|
|
58
56
|
}
|
|
59
57
|
debug(firstArg, ...args) {
|
|
60
|
-
this._log('debug',
|
|
58
|
+
this._log('debug', format(firstArg, ...args));
|
|
61
59
|
}
|
|
62
60
|
dir(firstArg, options = {}) {
|
|
63
|
-
const representation =
|
|
64
|
-
this._log('dir',
|
|
61
|
+
const representation = inspect(firstArg, options);
|
|
62
|
+
this._log('dir', formatWithOptions(options, representation));
|
|
65
63
|
}
|
|
66
64
|
dirxml(firstArg, ...args) {
|
|
67
|
-
this._log('dirxml',
|
|
65
|
+
this._log('dirxml', format(firstArg, ...args));
|
|
68
66
|
}
|
|
69
67
|
error(firstArg, ...args) {
|
|
70
|
-
this._log('error',
|
|
68
|
+
this._log('error', format(firstArg, ...args), 'stderr');
|
|
71
69
|
}
|
|
72
70
|
group(title, ...args) {
|
|
73
71
|
this._groupDepth++;
|
|
74
|
-
if (null != title || args.length > 0) this._log('group', color.bold(
|
|
72
|
+
if (null != title || args.length > 0) this._log('group', color.bold(format(title, ...args)));
|
|
75
73
|
}
|
|
76
74
|
groupCollapsed(title, ...args) {
|
|
77
75
|
this._groupDepth++;
|
|
78
|
-
if (null != title || args.length > 0) this._log('groupCollapsed', color.bold(
|
|
76
|
+
if (null != title || args.length > 0) this._log('groupCollapsed', color.bold(format(title, ...args)));
|
|
79
77
|
}
|
|
80
78
|
groupEnd() {
|
|
81
79
|
if (this._groupDepth > 0) this._groupDepth--;
|
|
82
80
|
}
|
|
83
81
|
info(firstArg, ...args) {
|
|
84
|
-
this._log('info',
|
|
82
|
+
this._log('info', format(firstArg, ...args));
|
|
85
83
|
}
|
|
86
84
|
log(firstArg, ...args) {
|
|
87
|
-
this._log('log',
|
|
85
|
+
this._log('log', format(firstArg, ...args));
|
|
88
86
|
}
|
|
89
87
|
time(label = 'default') {
|
|
90
88
|
if (null != this._timers[label]) return;
|
|
@@ -95,7 +93,7 @@ function createCustomConsole({ rpc, testPath, printConsoleTrace }) {
|
|
|
95
93
|
if (null != startTime) {
|
|
96
94
|
const endTime = RealDate.now();
|
|
97
95
|
const time = endTime - startTime.getTime();
|
|
98
|
-
this._log('time',
|
|
96
|
+
this._log('time', format(`${label}: ${prettyTime(time)}`));
|
|
99
97
|
delete this._timers[label];
|
|
100
98
|
}
|
|
101
99
|
}
|
|
@@ -104,11 +102,11 @@ function createCustomConsole({ rpc, testPath, printConsoleTrace }) {
|
|
|
104
102
|
if (null != startTime) {
|
|
105
103
|
const endTime = new RealDate();
|
|
106
104
|
const time = endTime.getTime() - startTime.getTime();
|
|
107
|
-
this._log('time',
|
|
105
|
+
this._log('time', format(`${label}: ${prettyTime(time)}`, ...data));
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
warn(firstArg, ...args) {
|
|
111
|
-
this._log('warn',
|
|
109
|
+
this._log('warn', format(firstArg, ...args), 'stderr');
|
|
112
110
|
}
|
|
113
111
|
getBuffer() {}
|
|
114
112
|
}
|