@rstest/core 0.7.7 → 0.7.9
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 +294 -0
- package/dist/0~130.js +2 -2
- package/dist/0~1472.js +48 -0
- package/dist/0~1981.js +3 -0
- package/dist/0~2173.js +25 -10
- package/dist/0~2255.js +2 -2
- package/dist/0~3062.js +0 -5
- package/dist/0~3919.js +1 -1
- package/dist/0~4403.js +6 -5
- package/dist/0~4809.js +4 -4
- package/dist/0~5835.js +2 -2
- package/dist/0~62.js +3 -3
- package/dist/0~6588.js +3 -3
- package/dist/0~6923.js +2 -2
- package/dist/0~7583.js +9 -8
- package/dist/0~7882.js +1144 -0
- package/dist/0~8426.js +1 -2
- package/dist/0~89.js +33 -24
- package/dist/0~9348.js +953 -0
- package/dist/0~9634.js +58 -10
- package/dist/1157.js +13 -118
- package/dist/{7913.js → 1294.js} +51 -1745
- package/dist/2672.js +647 -0
- package/dist/3278.js +3 -450
- package/dist/4484.js +38 -0
- package/dist/487.js +1739 -0
- package/dist/4899.js +11 -0
- package/dist/5734.js +1 -1
- package/dist/{0~6151.js → 6151.js} +169 -21
- package/dist/{0~6973.js → 6973.js} +5 -5
- package/dist/721.js +9 -0
- package/dist/9131.js +559 -502
- package/dist/browser-runtime/2~907.js +1211 -0
- package/dist/browser-runtime/2~907.js.map +1 -0
- package/dist/browser-runtime/389.js +22071 -0
- package/dist/browser-runtime/389.js.LICENSE.txt +329 -0
- package/dist/browser-runtime/389.js.map +1 -0
- package/dist/browser-runtime/index.d.ts +2806 -0
- package/dist/browser-runtime/index.js +1 -0
- package/dist/browser-runtime/rslib-runtime.js +50 -0
- package/dist/browser-runtime/rslib-runtime.js.map +1 -0
- package/dist/browser.d.ts +3329 -0
- package/dist/browser.js +14 -0
- package/dist/cssFilterLoader.mjs +1 -1
- package/dist/globalSetupWorker.js +3 -2
- package/dist/index.d.ts +67 -2
- package/dist/index.js +2 -1
- package/dist/rslib-runtime.js +27 -0
- package/dist/rstestSuppressWarnings.cjs +9 -0
- package/dist/worker.d.ts +66 -2
- package/dist/worker.js +415 -1
- package/package.json +29 -14
- package/dist/0~8957.js +0 -149
- package/dist/554.js +0 -417
- package/dist/5693.js +0 -91
- /package/dist/{7913.js.LICENSE.txt → 1294.js.LICENSE.txt} +0 -0
- /package/dist/{0~6151.js.LICENSE.txt → 6151.js.LICENSE.txt} +0 -0
package/dist/0~7882.js
ADDED
|
@@ -0,0 +1,1144 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
|
+
import "./1157.js";
|
|
5
|
+
import "./2672.js";
|
|
6
|
+
import { node_process } from "./3278.js";
|
|
7
|
+
import { Ie, Me, ye, M, dist_Y, Se, ve, pD, xe } from "./0~9348.js";
|
|
8
|
+
__webpack_require__.add({
|
|
9
|
+
"../../node_modules/.pnpm/@vercel+detect-agent@1.0.0/node_modules/@vercel/detect-agent/dist/index.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all)=>{
|
|
15
|
+
for(var name in all)__defProp(target, name, {
|
|
16
|
+
get: all[name],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
21
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
22
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
+
get: ()=>from[key],
|
|
24
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: true
|
|
31
|
+
}), mod);
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
KNOWN_AGENTS: ()=>KNOWN_AGENTS,
|
|
35
|
+
determineAgent: ()=>determineAgent
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
var import_promises = __webpack_require__("node:fs/promises");
|
|
39
|
+
var import_node_fs = __webpack_require__("fs");
|
|
40
|
+
const DEVIN_LOCAL_PATH = "/opt/.devin";
|
|
41
|
+
const CURSOR = "cursor";
|
|
42
|
+
const CURSOR_CLI = "cursor-cli";
|
|
43
|
+
const CLAUDE = "claude";
|
|
44
|
+
const DEVIN = "devin";
|
|
45
|
+
const REPLIT = "replit";
|
|
46
|
+
const GEMINI = "gemini";
|
|
47
|
+
const CODEX = "codex";
|
|
48
|
+
const KNOWN_AGENTS = {
|
|
49
|
+
CURSOR,
|
|
50
|
+
CURSOR_CLI,
|
|
51
|
+
CLAUDE,
|
|
52
|
+
DEVIN,
|
|
53
|
+
REPLIT,
|
|
54
|
+
GEMINI,
|
|
55
|
+
CODEX
|
|
56
|
+
};
|
|
57
|
+
async function determineAgent() {
|
|
58
|
+
if (process.env.AI_AGENT) {
|
|
59
|
+
const name = process.env.AI_AGENT.trim();
|
|
60
|
+
if (name) return {
|
|
61
|
+
isAgent: true,
|
|
62
|
+
agent: {
|
|
63
|
+
name
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (process.env.CURSOR_TRACE_ID) return {
|
|
68
|
+
isAgent: true,
|
|
69
|
+
agent: {
|
|
70
|
+
name: CURSOR
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (process.env.CURSOR_AGENT) return {
|
|
74
|
+
isAgent: true,
|
|
75
|
+
agent: {
|
|
76
|
+
name: CURSOR_CLI
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
if (process.env.GEMINI_CLI) return {
|
|
80
|
+
isAgent: true,
|
|
81
|
+
agent: {
|
|
82
|
+
name: GEMINI
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
if (process.env.CODEX_SANDBOX) return {
|
|
86
|
+
isAgent: true,
|
|
87
|
+
agent: {
|
|
88
|
+
name: CODEX
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
if (process.env.CLAUDECODE || process.env.CLAUDE_CODE) return {
|
|
92
|
+
isAgent: true,
|
|
93
|
+
agent: {
|
|
94
|
+
name: CLAUDE
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
if (process.env.REPL_ID) return {
|
|
98
|
+
isAgent: true,
|
|
99
|
+
agent: {
|
|
100
|
+
name: REPLIT
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
await (0, import_promises.access)(DEVIN_LOCAL_PATH, import_node_fs.constants.F_OK);
|
|
105
|
+
return {
|
|
106
|
+
isAgent: true,
|
|
107
|
+
agent: {
|
|
108
|
+
name: DEVIN
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {}
|
|
112
|
+
return {
|
|
113
|
+
isAgent: false,
|
|
114
|
+
agent: void 0
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const constants_AGENTS = [
|
|
120
|
+
"npm",
|
|
121
|
+
"yarn",
|
|
122
|
+
"yarn@berry",
|
|
123
|
+
"pnpm",
|
|
124
|
+
"pnpm@6",
|
|
125
|
+
"bun",
|
|
126
|
+
"deno"
|
|
127
|
+
];
|
|
128
|
+
const LOCKS = {
|
|
129
|
+
"bun.lock": "bun",
|
|
130
|
+
"bun.lockb": "bun",
|
|
131
|
+
"deno.lock": "deno",
|
|
132
|
+
"pnpm-lock.yaml": "pnpm",
|
|
133
|
+
"pnpm-workspace.yaml": "pnpm",
|
|
134
|
+
"yarn.lock": "yarn",
|
|
135
|
+
"package-lock.json": "npm",
|
|
136
|
+
"npm-shrinkwrap.json": "npm"
|
|
137
|
+
};
|
|
138
|
+
const INSTALL_METADATA = {
|
|
139
|
+
"node_modules/.deno/": "deno",
|
|
140
|
+
"node_modules/.pnpm/": "pnpm",
|
|
141
|
+
"node_modules/.yarn-state.yml": "yarn",
|
|
142
|
+
"node_modules/.yarn_integrity": "yarn",
|
|
143
|
+
"node_modules/.package-lock.json": "npm",
|
|
144
|
+
".pnp.cjs": "yarn",
|
|
145
|
+
".pnp.js": "yarn",
|
|
146
|
+
"bun.lock": "bun",
|
|
147
|
+
"bun.lockb": "bun"
|
|
148
|
+
};
|
|
149
|
+
const promises_ = __webpack_require__("node:fs/promises");
|
|
150
|
+
const external_node_path_ = __webpack_require__("node:path");
|
|
151
|
+
async function pathExists(path2, type) {
|
|
152
|
+
try {
|
|
153
|
+
const stat = await promises_["default"].stat(path2);
|
|
154
|
+
return "file" === type ? stat.isFile() : stat.isDirectory();
|
|
155
|
+
} catch {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function* lookup(cwd = node_process.cwd()) {
|
|
160
|
+
let directory = external_node_path_["default"].resolve(cwd);
|
|
161
|
+
const { root } = external_node_path_["default"].parse(directory);
|
|
162
|
+
while(directory && directory !== root){
|
|
163
|
+
yield directory;
|
|
164
|
+
directory = external_node_path_["default"].dirname(directory);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function parsePackageJson(filepath, options) {
|
|
168
|
+
if (!filepath || !await pathExists(filepath, "file")) return null;
|
|
169
|
+
return await handlePackageManager(filepath, options);
|
|
170
|
+
}
|
|
171
|
+
async function detect(options = {}) {
|
|
172
|
+
const { cwd, strategies = [
|
|
173
|
+
"lockfile",
|
|
174
|
+
"packageManager-field",
|
|
175
|
+
"devEngines-field"
|
|
176
|
+
] } = options;
|
|
177
|
+
let stopDir;
|
|
178
|
+
if ("string" == typeof options.stopDir) {
|
|
179
|
+
const resolved = external_node_path_["default"].resolve(options.stopDir);
|
|
180
|
+
stopDir = (dir)=>dir === resolved;
|
|
181
|
+
} else stopDir = options.stopDir;
|
|
182
|
+
for (const directory of lookup(cwd)){
|
|
183
|
+
for (const strategy of strategies)switch(strategy){
|
|
184
|
+
case "lockfile":
|
|
185
|
+
for (const lock of Object.keys(LOCKS))if (await pathExists(external_node_path_["default"].join(directory, lock), "file")) {
|
|
186
|
+
const name = LOCKS[lock];
|
|
187
|
+
const result = await parsePackageJson(external_node_path_["default"].join(directory, "package.json"), options);
|
|
188
|
+
if (result) return result;
|
|
189
|
+
return {
|
|
190
|
+
name,
|
|
191
|
+
agent: name
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
case "packageManager-field":
|
|
196
|
+
case "devEngines-field":
|
|
197
|
+
{
|
|
198
|
+
const result = await parsePackageJson(external_node_path_["default"].join(directory, "package.json"), options);
|
|
199
|
+
if (result) return result;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case "install-metadata":
|
|
203
|
+
for (const metadata of Object.keys(INSTALL_METADATA)){
|
|
204
|
+
const fileOrDir = metadata.endsWith("/") ? "dir" : "file";
|
|
205
|
+
if (await pathExists(external_node_path_["default"].join(directory, metadata), fileOrDir)) {
|
|
206
|
+
const name = INSTALL_METADATA[metadata];
|
|
207
|
+
const agent = "yarn" === name ? isMetadataYarnClassic(metadata) ? "yarn" : "yarn@berry" : name;
|
|
208
|
+
return {
|
|
209
|
+
name,
|
|
210
|
+
agent
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
if (stopDir?.(directory)) break;
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
function getNameAndVer(pkg) {
|
|
221
|
+
const handelVer = (version)=>version?.match(/\d+(\.\d+){0,2}/)?.[0] ?? version;
|
|
222
|
+
if ("string" == typeof pkg.packageManager) {
|
|
223
|
+
const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
|
|
224
|
+
return {
|
|
225
|
+
name,
|
|
226
|
+
ver: handelVer(ver)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if ("string" == typeof pkg.devEngines?.packageManager?.name) return {
|
|
230
|
+
name: pkg.devEngines.packageManager.name,
|
|
231
|
+
ver: handelVer(pkg.devEngines.packageManager.version)
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
async function handlePackageManager(filepath, options) {
|
|
235
|
+
try {
|
|
236
|
+
const content = await promises_["default"].readFile(filepath, "utf8");
|
|
237
|
+
const pkg = options.packageJsonParser ? await options.packageJsonParser(content, filepath) : JSON.parse(content);
|
|
238
|
+
let agent;
|
|
239
|
+
const nameAndVer = getNameAndVer(pkg);
|
|
240
|
+
if (nameAndVer) {
|
|
241
|
+
const name = nameAndVer.name;
|
|
242
|
+
const ver = nameAndVer.ver;
|
|
243
|
+
let version = ver;
|
|
244
|
+
if ("yarn" === name && ver && Number.parseInt(ver) > 1) {
|
|
245
|
+
agent = "yarn@berry";
|
|
246
|
+
version = "berry";
|
|
247
|
+
return {
|
|
248
|
+
name,
|
|
249
|
+
agent,
|
|
250
|
+
version
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if ("pnpm" === name && ver && Number.parseInt(ver) < 7) {
|
|
254
|
+
agent = "pnpm@6";
|
|
255
|
+
return {
|
|
256
|
+
name,
|
|
257
|
+
agent,
|
|
258
|
+
version
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (!constants_AGENTS.includes(name)) return options.onUnknown?.(pkg.packageManager) ?? null;
|
|
262
|
+
agent = name;
|
|
263
|
+
return {
|
|
264
|
+
name,
|
|
265
|
+
agent,
|
|
266
|
+
version
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
} catch {}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
function isMetadataYarnClassic(metadataPath) {
|
|
273
|
+
return metadataPath.endsWith(".yarn_integrity");
|
|
274
|
+
}
|
|
275
|
+
const external_node_fs_ = __webpack_require__("fs");
|
|
276
|
+
function getUniqueBaseName(dir, baseName, ext) {
|
|
277
|
+
const fullPath = external_node_path_["default"].join(dir, `${baseName}${ext}`);
|
|
278
|
+
if (!external_node_fs_["default"].existsSync(fullPath)) return baseName;
|
|
279
|
+
let suffix = 1;
|
|
280
|
+
while(external_node_fs_["default"].existsSync(external_node_path_["default"].join(dir, `${baseName}_${suffix}${ext}`)))suffix++;
|
|
281
|
+
return `${baseName}_${suffix}`;
|
|
282
|
+
}
|
|
283
|
+
function ensureDir(dir) {
|
|
284
|
+
if (!external_node_fs_["default"].existsSync(dir)) external_node_fs_["default"].mkdirSync(dir, {
|
|
285
|
+
recursive: true
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function writeFile(filePath, content) {
|
|
289
|
+
external_node_fs_["default"].writeFileSync(filePath, content, 'utf-8');
|
|
290
|
+
}
|
|
291
|
+
function readPackageJson(cwd) {
|
|
292
|
+
const pkgPath = external_node_path_["default"].join(cwd, 'package.json');
|
|
293
|
+
if (!external_node_fs_["default"].existsSync(pkgPath)) return null;
|
|
294
|
+
try {
|
|
295
|
+
const content = external_node_fs_["default"].readFileSync(pkgPath, 'utf-8');
|
|
296
|
+
return JSON.parse(content);
|
|
297
|
+
} catch {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function updatePackageJsonScripts(cwd, scripts) {
|
|
302
|
+
const pkgPath = external_node_path_["default"].join(cwd, 'package.json');
|
|
303
|
+
let pkg;
|
|
304
|
+
if (external_node_fs_["default"].existsSync(pkgPath)) {
|
|
305
|
+
const content = external_node_fs_["default"].readFileSync(pkgPath, 'utf-8');
|
|
306
|
+
pkg = JSON.parse(content);
|
|
307
|
+
} else pkg = {};
|
|
308
|
+
const existingScripts = pkg.scripts ?? {};
|
|
309
|
+
pkg.scripts = {
|
|
310
|
+
...existingScripts,
|
|
311
|
+
...scripts
|
|
312
|
+
};
|
|
313
|
+
external_node_fs_["default"].writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8');
|
|
314
|
+
}
|
|
315
|
+
function updatePackageJsonDevDeps(cwd, deps) {
|
|
316
|
+
const pkgPath = external_node_path_["default"].join(cwd, 'package.json');
|
|
317
|
+
let pkg;
|
|
318
|
+
if (external_node_fs_["default"].existsSync(pkgPath)) {
|
|
319
|
+
const content = external_node_fs_["default"].readFileSync(pkgPath, 'utf-8');
|
|
320
|
+
pkg = JSON.parse(content);
|
|
321
|
+
} else pkg = {};
|
|
322
|
+
const existingDevDeps = pkg.devDependencies ?? {};
|
|
323
|
+
for (const [name, version] of Object.entries(deps))if (!existingDevDeps[name]) existingDevDeps[name] = version;
|
|
324
|
+
pkg.devDependencies = existingDevDeps;
|
|
325
|
+
external_node_fs_["default"].writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, 'utf-8');
|
|
326
|
+
}
|
|
327
|
+
async function detectPackageManagerAgent(cwd) {
|
|
328
|
+
const result = await detect({
|
|
329
|
+
cwd
|
|
330
|
+
});
|
|
331
|
+
return result?.agent ?? 'npm';
|
|
332
|
+
}
|
|
333
|
+
function detectTestDir(cwd) {
|
|
334
|
+
const candidates = [
|
|
335
|
+
'tests',
|
|
336
|
+
'test',
|
|
337
|
+
'__tests__',
|
|
338
|
+
'src/__tests__'
|
|
339
|
+
];
|
|
340
|
+
for (const dir of candidates){
|
|
341
|
+
const fullPath = external_node_path_["default"].join(cwd, dir);
|
|
342
|
+
if (external_node_fs_["default"].existsSync(fullPath) && external_node_fs_["default"].statSync(fullPath).isDirectory()) return dir;
|
|
343
|
+
}
|
|
344
|
+
return 'tests';
|
|
345
|
+
}
|
|
346
|
+
function detectReact(pkg) {
|
|
347
|
+
const deps = pkg.dependencies ?? {};
|
|
348
|
+
const devDeps = pkg.devDependencies ?? {};
|
|
349
|
+
const reactVersion = deps.react ?? devDeps.react ?? null;
|
|
350
|
+
if (reactVersion) {
|
|
351
|
+
const cleanVersion = reactVersion.replace(/^[\^~>=<]+/, '');
|
|
352
|
+
return {
|
|
353
|
+
detected: true,
|
|
354
|
+
version: cleanVersion
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
detected: false,
|
|
359
|
+
version: null
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function detectTypeScript(cwd) {
|
|
363
|
+
return external_node_fs_["default"].existsSync(external_node_path_["default"].join(cwd, 'tsconfig.json'));
|
|
364
|
+
}
|
|
365
|
+
async function detectProject(cwd) {
|
|
366
|
+
const pkg = readPackageJson(cwd);
|
|
367
|
+
const { detected: hasReact, version: reactVersion } = pkg ? detectReact(pkg) : {
|
|
368
|
+
detected: false,
|
|
369
|
+
version: null
|
|
370
|
+
};
|
|
371
|
+
const hasTypeScript = detectTypeScript(cwd);
|
|
372
|
+
const testDir = detectTestDir(cwd);
|
|
373
|
+
const agent = await detectPackageManagerAgent(cwd);
|
|
374
|
+
return {
|
|
375
|
+
framework: hasReact ? 'react' : null,
|
|
376
|
+
language: hasTypeScript ? 'ts' : 'js',
|
|
377
|
+
testDir,
|
|
378
|
+
agent,
|
|
379
|
+
reactVersion
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function dashDashArg(agent, agentCommand) {
|
|
383
|
+
return (args)=>{
|
|
384
|
+
if (args.length > 1) return [
|
|
385
|
+
agent,
|
|
386
|
+
agentCommand,
|
|
387
|
+
args[0],
|
|
388
|
+
"--",
|
|
389
|
+
...args.slice(1)
|
|
390
|
+
];
|
|
391
|
+
return [
|
|
392
|
+
agent,
|
|
393
|
+
agentCommand,
|
|
394
|
+
args[0]
|
|
395
|
+
];
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function denoExecute() {
|
|
399
|
+
return (args)=>[
|
|
400
|
+
"deno",
|
|
401
|
+
"run",
|
|
402
|
+
`npm:${args[0]}`,
|
|
403
|
+
...args.slice(1)
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
const npm = {
|
|
407
|
+
agent: [
|
|
408
|
+
"npm",
|
|
409
|
+
0
|
|
410
|
+
],
|
|
411
|
+
run: dashDashArg("npm", "run"),
|
|
412
|
+
install: [
|
|
413
|
+
"npm",
|
|
414
|
+
"i",
|
|
415
|
+
0
|
|
416
|
+
],
|
|
417
|
+
frozen: [
|
|
418
|
+
"npm",
|
|
419
|
+
"ci",
|
|
420
|
+
0
|
|
421
|
+
],
|
|
422
|
+
global: [
|
|
423
|
+
"npm",
|
|
424
|
+
"i",
|
|
425
|
+
"-g",
|
|
426
|
+
0
|
|
427
|
+
],
|
|
428
|
+
add: [
|
|
429
|
+
"npm",
|
|
430
|
+
"i",
|
|
431
|
+
0
|
|
432
|
+
],
|
|
433
|
+
upgrade: [
|
|
434
|
+
"npm",
|
|
435
|
+
"update",
|
|
436
|
+
0
|
|
437
|
+
],
|
|
438
|
+
"upgrade-interactive": null,
|
|
439
|
+
dedupe: [
|
|
440
|
+
"npm",
|
|
441
|
+
"dedupe",
|
|
442
|
+
0
|
|
443
|
+
],
|
|
444
|
+
execute: [
|
|
445
|
+
"npx",
|
|
446
|
+
0
|
|
447
|
+
],
|
|
448
|
+
"execute-local": [
|
|
449
|
+
"npx",
|
|
450
|
+
0
|
|
451
|
+
],
|
|
452
|
+
uninstall: [
|
|
453
|
+
"npm",
|
|
454
|
+
"uninstall",
|
|
455
|
+
0
|
|
456
|
+
],
|
|
457
|
+
global_uninstall: [
|
|
458
|
+
"npm",
|
|
459
|
+
"uninstall",
|
|
460
|
+
"-g",
|
|
461
|
+
0
|
|
462
|
+
]
|
|
463
|
+
};
|
|
464
|
+
const yarn = {
|
|
465
|
+
agent: [
|
|
466
|
+
"yarn",
|
|
467
|
+
0
|
|
468
|
+
],
|
|
469
|
+
run: [
|
|
470
|
+
"yarn",
|
|
471
|
+
"run",
|
|
472
|
+
0
|
|
473
|
+
],
|
|
474
|
+
install: [
|
|
475
|
+
"yarn",
|
|
476
|
+
"install",
|
|
477
|
+
0
|
|
478
|
+
],
|
|
479
|
+
frozen: [
|
|
480
|
+
"yarn",
|
|
481
|
+
"install",
|
|
482
|
+
"--frozen-lockfile",
|
|
483
|
+
0
|
|
484
|
+
],
|
|
485
|
+
global: [
|
|
486
|
+
"yarn",
|
|
487
|
+
"global",
|
|
488
|
+
"add",
|
|
489
|
+
0
|
|
490
|
+
],
|
|
491
|
+
add: [
|
|
492
|
+
"yarn",
|
|
493
|
+
"add",
|
|
494
|
+
0
|
|
495
|
+
],
|
|
496
|
+
upgrade: [
|
|
497
|
+
"yarn",
|
|
498
|
+
"upgrade",
|
|
499
|
+
0
|
|
500
|
+
],
|
|
501
|
+
"upgrade-interactive": [
|
|
502
|
+
"yarn",
|
|
503
|
+
"upgrade-interactive",
|
|
504
|
+
0
|
|
505
|
+
],
|
|
506
|
+
dedupe: null,
|
|
507
|
+
execute: [
|
|
508
|
+
"npx",
|
|
509
|
+
0
|
|
510
|
+
],
|
|
511
|
+
"execute-local": dashDashArg("yarn", "exec"),
|
|
512
|
+
uninstall: [
|
|
513
|
+
"yarn",
|
|
514
|
+
"remove",
|
|
515
|
+
0
|
|
516
|
+
],
|
|
517
|
+
global_uninstall: [
|
|
518
|
+
"yarn",
|
|
519
|
+
"global",
|
|
520
|
+
"remove",
|
|
521
|
+
0
|
|
522
|
+
]
|
|
523
|
+
};
|
|
524
|
+
const yarnBerry = {
|
|
525
|
+
...yarn,
|
|
526
|
+
frozen: [
|
|
527
|
+
"yarn",
|
|
528
|
+
"install",
|
|
529
|
+
"--immutable",
|
|
530
|
+
0
|
|
531
|
+
],
|
|
532
|
+
upgrade: [
|
|
533
|
+
"yarn",
|
|
534
|
+
"up",
|
|
535
|
+
0
|
|
536
|
+
],
|
|
537
|
+
"upgrade-interactive": [
|
|
538
|
+
"yarn",
|
|
539
|
+
"up",
|
|
540
|
+
"-i",
|
|
541
|
+
0
|
|
542
|
+
],
|
|
543
|
+
dedupe: [
|
|
544
|
+
"yarn",
|
|
545
|
+
"dedupe",
|
|
546
|
+
0
|
|
547
|
+
],
|
|
548
|
+
execute: [
|
|
549
|
+
"yarn",
|
|
550
|
+
"dlx",
|
|
551
|
+
0
|
|
552
|
+
],
|
|
553
|
+
"execute-local": [
|
|
554
|
+
"yarn",
|
|
555
|
+
"exec",
|
|
556
|
+
0
|
|
557
|
+
],
|
|
558
|
+
global: [
|
|
559
|
+
"npm",
|
|
560
|
+
"i",
|
|
561
|
+
"-g",
|
|
562
|
+
0
|
|
563
|
+
],
|
|
564
|
+
global_uninstall: [
|
|
565
|
+
"npm",
|
|
566
|
+
"uninstall",
|
|
567
|
+
"-g",
|
|
568
|
+
0
|
|
569
|
+
]
|
|
570
|
+
};
|
|
571
|
+
const pnpm = {
|
|
572
|
+
agent: [
|
|
573
|
+
"pnpm",
|
|
574
|
+
0
|
|
575
|
+
],
|
|
576
|
+
run: [
|
|
577
|
+
"pnpm",
|
|
578
|
+
"run",
|
|
579
|
+
0
|
|
580
|
+
],
|
|
581
|
+
install: [
|
|
582
|
+
"pnpm",
|
|
583
|
+
"i",
|
|
584
|
+
0
|
|
585
|
+
],
|
|
586
|
+
frozen: [
|
|
587
|
+
"pnpm",
|
|
588
|
+
"i",
|
|
589
|
+
"--frozen-lockfile",
|
|
590
|
+
0
|
|
591
|
+
],
|
|
592
|
+
global: [
|
|
593
|
+
"pnpm",
|
|
594
|
+
"add",
|
|
595
|
+
"-g",
|
|
596
|
+
0
|
|
597
|
+
],
|
|
598
|
+
add: [
|
|
599
|
+
"pnpm",
|
|
600
|
+
"add",
|
|
601
|
+
0
|
|
602
|
+
],
|
|
603
|
+
upgrade: [
|
|
604
|
+
"pnpm",
|
|
605
|
+
"update",
|
|
606
|
+
0
|
|
607
|
+
],
|
|
608
|
+
"upgrade-interactive": [
|
|
609
|
+
"pnpm",
|
|
610
|
+
"update",
|
|
611
|
+
"-i",
|
|
612
|
+
0
|
|
613
|
+
],
|
|
614
|
+
dedupe: [
|
|
615
|
+
"pnpm",
|
|
616
|
+
"dedupe",
|
|
617
|
+
0
|
|
618
|
+
],
|
|
619
|
+
execute: [
|
|
620
|
+
"pnpm",
|
|
621
|
+
"dlx",
|
|
622
|
+
0
|
|
623
|
+
],
|
|
624
|
+
"execute-local": [
|
|
625
|
+
"pnpm",
|
|
626
|
+
"exec",
|
|
627
|
+
0
|
|
628
|
+
],
|
|
629
|
+
uninstall: [
|
|
630
|
+
"pnpm",
|
|
631
|
+
"remove",
|
|
632
|
+
0
|
|
633
|
+
],
|
|
634
|
+
global_uninstall: [
|
|
635
|
+
"pnpm",
|
|
636
|
+
"remove",
|
|
637
|
+
"--global",
|
|
638
|
+
0
|
|
639
|
+
]
|
|
640
|
+
};
|
|
641
|
+
const bun = {
|
|
642
|
+
agent: [
|
|
643
|
+
"bun",
|
|
644
|
+
0
|
|
645
|
+
],
|
|
646
|
+
run: [
|
|
647
|
+
"bun",
|
|
648
|
+
"run",
|
|
649
|
+
0
|
|
650
|
+
],
|
|
651
|
+
install: [
|
|
652
|
+
"bun",
|
|
653
|
+
"install",
|
|
654
|
+
0
|
|
655
|
+
],
|
|
656
|
+
frozen: [
|
|
657
|
+
"bun",
|
|
658
|
+
"install",
|
|
659
|
+
"--frozen-lockfile",
|
|
660
|
+
0
|
|
661
|
+
],
|
|
662
|
+
global: [
|
|
663
|
+
"bun",
|
|
664
|
+
"add",
|
|
665
|
+
"-g",
|
|
666
|
+
0
|
|
667
|
+
],
|
|
668
|
+
add: [
|
|
669
|
+
"bun",
|
|
670
|
+
"add",
|
|
671
|
+
0
|
|
672
|
+
],
|
|
673
|
+
upgrade: [
|
|
674
|
+
"bun",
|
|
675
|
+
"update",
|
|
676
|
+
0
|
|
677
|
+
],
|
|
678
|
+
"upgrade-interactive": [
|
|
679
|
+
"bun",
|
|
680
|
+
"update",
|
|
681
|
+
"-i",
|
|
682
|
+
0
|
|
683
|
+
],
|
|
684
|
+
dedupe: null,
|
|
685
|
+
execute: [
|
|
686
|
+
"bun",
|
|
687
|
+
"x",
|
|
688
|
+
0
|
|
689
|
+
],
|
|
690
|
+
"execute-local": [
|
|
691
|
+
"bun",
|
|
692
|
+
"x",
|
|
693
|
+
0
|
|
694
|
+
],
|
|
695
|
+
uninstall: [
|
|
696
|
+
"bun",
|
|
697
|
+
"remove",
|
|
698
|
+
0
|
|
699
|
+
],
|
|
700
|
+
global_uninstall: [
|
|
701
|
+
"bun",
|
|
702
|
+
"remove",
|
|
703
|
+
"-g",
|
|
704
|
+
0
|
|
705
|
+
]
|
|
706
|
+
};
|
|
707
|
+
const deno = {
|
|
708
|
+
agent: [
|
|
709
|
+
"deno",
|
|
710
|
+
0
|
|
711
|
+
],
|
|
712
|
+
run: [
|
|
713
|
+
"deno",
|
|
714
|
+
"task",
|
|
715
|
+
0
|
|
716
|
+
],
|
|
717
|
+
install: [
|
|
718
|
+
"deno",
|
|
719
|
+
"install",
|
|
720
|
+
0
|
|
721
|
+
],
|
|
722
|
+
frozen: [
|
|
723
|
+
"deno",
|
|
724
|
+
"install",
|
|
725
|
+
"--frozen",
|
|
726
|
+
0
|
|
727
|
+
],
|
|
728
|
+
global: [
|
|
729
|
+
"deno",
|
|
730
|
+
"install",
|
|
731
|
+
"-g",
|
|
732
|
+
0
|
|
733
|
+
],
|
|
734
|
+
add: [
|
|
735
|
+
"deno",
|
|
736
|
+
"add",
|
|
737
|
+
0
|
|
738
|
+
],
|
|
739
|
+
upgrade: [
|
|
740
|
+
"deno",
|
|
741
|
+
"outdated",
|
|
742
|
+
"--update",
|
|
743
|
+
0
|
|
744
|
+
],
|
|
745
|
+
"upgrade-interactive": [
|
|
746
|
+
"deno",
|
|
747
|
+
"outdated",
|
|
748
|
+
"--update",
|
|
749
|
+
0
|
|
750
|
+
],
|
|
751
|
+
dedupe: null,
|
|
752
|
+
execute: denoExecute(),
|
|
753
|
+
"execute-local": [
|
|
754
|
+
"deno",
|
|
755
|
+
"task",
|
|
756
|
+
"--eval",
|
|
757
|
+
0
|
|
758
|
+
],
|
|
759
|
+
uninstall: [
|
|
760
|
+
"deno",
|
|
761
|
+
"remove",
|
|
762
|
+
0
|
|
763
|
+
],
|
|
764
|
+
global_uninstall: [
|
|
765
|
+
"deno",
|
|
766
|
+
"uninstall",
|
|
767
|
+
"-g",
|
|
768
|
+
0
|
|
769
|
+
]
|
|
770
|
+
};
|
|
771
|
+
const COMMANDS = {
|
|
772
|
+
npm: npm,
|
|
773
|
+
yarn: yarn,
|
|
774
|
+
"yarn@berry": yarnBerry,
|
|
775
|
+
pnpm: pnpm,
|
|
776
|
+
"pnpm@6": {
|
|
777
|
+
...pnpm,
|
|
778
|
+
run: dashDashArg("pnpm", "run")
|
|
779
|
+
},
|
|
780
|
+
bun: bun,
|
|
781
|
+
deno: deno
|
|
782
|
+
};
|
|
783
|
+
function resolveCommand(agent, command, args) {
|
|
784
|
+
const value = COMMANDS[agent][command];
|
|
785
|
+
return constructCommand(value, args);
|
|
786
|
+
}
|
|
787
|
+
function constructCommand(value, args) {
|
|
788
|
+
if (null == value) return null;
|
|
789
|
+
const list = "function" == typeof value ? value(args) : value.flatMap((v)=>{
|
|
790
|
+
if ("number" == typeof v) return args;
|
|
791
|
+
return [
|
|
792
|
+
v
|
|
793
|
+
];
|
|
794
|
+
});
|
|
795
|
+
return {
|
|
796
|
+
command: list[0],
|
|
797
|
+
args: list.slice(1)
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
function getConfigTemplate() {
|
|
801
|
+
return `import { defineConfig } from '@rstest/core';
|
|
802
|
+
|
|
803
|
+
export default defineConfig({
|
|
804
|
+
browser: {
|
|
805
|
+
enabled: true,
|
|
806
|
+
},
|
|
807
|
+
});
|
|
808
|
+
`;
|
|
809
|
+
}
|
|
810
|
+
function getReactComponentTemplate(lang) {
|
|
811
|
+
if ('ts' === lang) return `import { useState } from 'react';
|
|
812
|
+
|
|
813
|
+
export default function Counter({ initial = 0 }: { initial?: number }) {
|
|
814
|
+
const [count, setCount] = useState(initial);
|
|
815
|
+
|
|
816
|
+
return (
|
|
817
|
+
<div>
|
|
818
|
+
<p>Count: {count}</p>
|
|
819
|
+
<button type="button" onClick={() => setCount((c) => c + 1)}>
|
|
820
|
+
Increment
|
|
821
|
+
</button>
|
|
822
|
+
<button type="button" onClick={() => setCount((c) => c - 1)}>
|
|
823
|
+
Decrement
|
|
824
|
+
</button>
|
|
825
|
+
</div>
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
`;
|
|
829
|
+
return `import { useState } from 'react';
|
|
830
|
+
|
|
831
|
+
export default function Counter({ initial = 0 }) {
|
|
832
|
+
const [count, setCount] = useState(initial);
|
|
833
|
+
|
|
834
|
+
return (
|
|
835
|
+
<div>
|
|
836
|
+
<p>Count: {count}</p>
|
|
837
|
+
<button type="button" onClick={() => setCount((c) => c + 1)}>
|
|
838
|
+
Increment
|
|
839
|
+
</button>
|
|
840
|
+
<button type="button" onClick={() => setCount((c) => c - 1)}>
|
|
841
|
+
Decrement
|
|
842
|
+
</button>
|
|
843
|
+
</div>
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
`;
|
|
847
|
+
}
|
|
848
|
+
function getReactTestTemplate(lang) {
|
|
849
|
+
const componentExt = 'ts' === lang ? 'tsx' : 'jsx';
|
|
850
|
+
return `import { expect, test } from '@rstest/core';
|
|
851
|
+
import { render } from '@rstest/browser-react';
|
|
852
|
+
import Counter from './Counter.${componentExt}';
|
|
853
|
+
|
|
854
|
+
test('increments count on button click', async () => {
|
|
855
|
+
const screen = await render(<Counter initial={5} />);
|
|
856
|
+
|
|
857
|
+
await expect.element(screen.getByText('Count: 5')).toBeInTheDocument();
|
|
858
|
+
|
|
859
|
+
await screen.getByRole('button', { name: 'Increment' }).click();
|
|
860
|
+
await expect.element(screen.getByText('Count: 6')).toBeInTheDocument();
|
|
861
|
+
});
|
|
862
|
+
`;
|
|
863
|
+
}
|
|
864
|
+
function getVanillaComponentTemplate(lang) {
|
|
865
|
+
if ('ts' === lang) return `export function createCounter(initial = 0): HTMLElement {
|
|
866
|
+
let count = initial;
|
|
867
|
+
|
|
868
|
+
const container = document.createElement('div');
|
|
869
|
+
const display = document.createElement('p');
|
|
870
|
+
const incBtn = document.createElement('button');
|
|
871
|
+
const decBtn = document.createElement('button');
|
|
872
|
+
|
|
873
|
+
display.textContent = \`Count: \${count}\`;
|
|
874
|
+
incBtn.textContent = 'Increment';
|
|
875
|
+
decBtn.textContent = 'Decrement';
|
|
876
|
+
|
|
877
|
+
incBtn.addEventListener('click', () => {
|
|
878
|
+
count++;
|
|
879
|
+
display.textContent = \`Count: \${count}\`;
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
decBtn.addEventListener('click', () => {
|
|
883
|
+
count--;
|
|
884
|
+
display.textContent = \`Count: \${count}\`;
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
container.append(display, incBtn, decBtn);
|
|
888
|
+
return container;
|
|
889
|
+
}
|
|
890
|
+
`;
|
|
891
|
+
return `export function createCounter(initial = 0) {
|
|
892
|
+
let count = initial;
|
|
893
|
+
|
|
894
|
+
const container = document.createElement('div');
|
|
895
|
+
const display = document.createElement('p');
|
|
896
|
+
const incBtn = document.createElement('button');
|
|
897
|
+
const decBtn = document.createElement('button');
|
|
898
|
+
|
|
899
|
+
display.textContent = \`Count: \${count}\`;
|
|
900
|
+
incBtn.textContent = 'Increment';
|
|
901
|
+
decBtn.textContent = 'Decrement';
|
|
902
|
+
|
|
903
|
+
incBtn.addEventListener('click', () => {
|
|
904
|
+
count++;
|
|
905
|
+
display.textContent = \`Count: \${count}\`;
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
decBtn.addEventListener('click', () => {
|
|
909
|
+
count--;
|
|
910
|
+
display.textContent = \`Count: \${count}\`;
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
container.append(display, incBtn, decBtn);
|
|
914
|
+
return container;
|
|
915
|
+
}
|
|
916
|
+
`;
|
|
917
|
+
}
|
|
918
|
+
function getVanillaTestTemplate(lang) {
|
|
919
|
+
const ext = 'ts' === lang ? 'ts' : 'js';
|
|
920
|
+
return `import { expect, test } from '@rstest/core';
|
|
921
|
+
import { page } from '@rstest/browser';
|
|
922
|
+
import { createCounter } from './Counter.${ext}';
|
|
923
|
+
|
|
924
|
+
test('increments count on button click', async () => {
|
|
925
|
+
document.body.appendChild(createCounter(5));
|
|
926
|
+
|
|
927
|
+
await expect.element(page.getByText('Count: 5')).toBeInTheDocument();
|
|
928
|
+
|
|
929
|
+
await page.getByRole('button', { name: 'Increment' }).click();
|
|
930
|
+
await expect.element(page.getByText('Count: 6')).toBeInTheDocument();
|
|
931
|
+
});
|
|
932
|
+
`;
|
|
933
|
+
}
|
|
934
|
+
function getDependenciesWithVersions(framework, provider, rstestVersion) {
|
|
935
|
+
const deps = {
|
|
936
|
+
'@rstest/browser': `^${rstestVersion}`,
|
|
937
|
+
'@testing-library/dom': '^10.0.0'
|
|
938
|
+
};
|
|
939
|
+
if ('playwright' === provider) deps.playwright = "^1.49.1";
|
|
940
|
+
if ('react' === framework) deps['@rstest/browser-react'] = `^${rstestVersion}`;
|
|
941
|
+
return deps;
|
|
942
|
+
}
|
|
943
|
+
function getInstallCommand(agent) {
|
|
944
|
+
const resolved = resolveCommand(agent, 'install', []);
|
|
945
|
+
if (!resolved) return 'npm install';
|
|
946
|
+
return [
|
|
947
|
+
resolved.command,
|
|
948
|
+
...resolved.args
|
|
949
|
+
].join(' ');
|
|
950
|
+
}
|
|
951
|
+
function getPlaywrightInstallCommand(agent, _provider) {
|
|
952
|
+
const resolved = resolveCommand(agent, 'execute', [
|
|
953
|
+
'playwright',
|
|
954
|
+
'install',
|
|
955
|
+
'--with-deps'
|
|
956
|
+
]);
|
|
957
|
+
if (!resolved) return 'npx playwright install --with-deps';
|
|
958
|
+
return [
|
|
959
|
+
resolved.command,
|
|
960
|
+
...resolved.args
|
|
961
|
+
].join(' ');
|
|
962
|
+
}
|
|
963
|
+
function getRunCommand(agent) {
|
|
964
|
+
const resolved = resolveCommand(agent, 'run', [
|
|
965
|
+
'test:browser'
|
|
966
|
+
]);
|
|
967
|
+
if (!resolved) return 'npm run test:browser';
|
|
968
|
+
return [
|
|
969
|
+
resolved.command,
|
|
970
|
+
...resolved.args
|
|
971
|
+
].join(' ');
|
|
972
|
+
}
|
|
973
|
+
function getConfigFileName() {
|
|
974
|
+
return 'rstest.browser.config.ts';
|
|
975
|
+
}
|
|
976
|
+
const dist = __webpack_require__("../../node_modules/.pnpm/@vercel+detect-agent@1.0.0/node_modules/@vercel/detect-agent/dist/index.js");
|
|
977
|
+
const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
978
|
+
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
979
|
+
async function create(options = {}) {
|
|
980
|
+
const cwd = process.cwd();
|
|
981
|
+
const { yes: nonInteractive } = options;
|
|
982
|
+
const projectInfo = await detectProject(cwd);
|
|
983
|
+
const { isAgent } = await (0, dist.determineAgent)();
|
|
984
|
+
if (nonInteractive) await createNonInteractive(cwd, projectInfo);
|
|
985
|
+
else await createInteractive(cwd, projectInfo, isAgent);
|
|
986
|
+
}
|
|
987
|
+
function computeFilePreview(cwd, projectInfo) {
|
|
988
|
+
const { language, testDir, framework } = projectInfo;
|
|
989
|
+
const effectiveFramework = 'react' === framework ? 'react' : 'vanilla';
|
|
990
|
+
const configFile = getConfigFileName();
|
|
991
|
+
let componentExt;
|
|
992
|
+
let testExt;
|
|
993
|
+
if ('react' === effectiveFramework) {
|
|
994
|
+
componentExt = 'ts' === language ? '.tsx' : '.jsx';
|
|
995
|
+
testExt = 'ts' === language ? '.test.tsx' : '.test.jsx';
|
|
996
|
+
} else {
|
|
997
|
+
componentExt = 'ts' === language ? '.ts' : '.js';
|
|
998
|
+
testExt = 'ts' === language ? '.test.ts' : '.test.js';
|
|
999
|
+
}
|
|
1000
|
+
const testDirPath = external_node_path_["default"].join(cwd, testDir);
|
|
1001
|
+
const baseName = getUniqueBaseName(testDirPath, 'Counter', componentExt);
|
|
1002
|
+
return {
|
|
1003
|
+
configFile,
|
|
1004
|
+
componentFile: `${testDir}/${baseName}${componentExt}`,
|
|
1005
|
+
testFile: `${testDir}/${baseName}${testExt}`,
|
|
1006
|
+
framework: effectiveFramework
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
async function createNonInteractive(cwd, projectInfo) {
|
|
1010
|
+
const { agent, testDir, framework, reactVersion } = projectInfo;
|
|
1011
|
+
const provider = 'playwright';
|
|
1012
|
+
console.log();
|
|
1013
|
+
console.log(picocolors_default().cyan('◆'), picocolors_default().bold('rstest init browser --yes'));
|
|
1014
|
+
console.log();
|
|
1015
|
+
console.log(' Detecting project...');
|
|
1016
|
+
if ('react' === framework && reactVersion) console.log(picocolors_default().green(' ✓'), `Found React ${reactVersion}`);
|
|
1017
|
+
else if ('react' === framework) console.log(picocolors_default().green(' ✓'), 'Found React');
|
|
1018
|
+
else console.log(picocolors_default().yellow(' ⚠'), 'Framework not detected, generating vanilla DOM example');
|
|
1019
|
+
console.log(picocolors_default().green(' ✓'), 'Using playwright as browser provider');
|
|
1020
|
+
console.log(picocolors_default().green(' ✓'), `Test directory: ${testDir}/`);
|
|
1021
|
+
console.log();
|
|
1022
|
+
const createdFiles = await generateFiles(cwd, projectInfo, provider);
|
|
1023
|
+
console.log(' Created files:');
|
|
1024
|
+
for (const file of createdFiles)console.log(` - ${file}`);
|
|
1025
|
+
console.log(' - Updated package.json');
|
|
1026
|
+
console.log();
|
|
1027
|
+
console.log(' Next steps:');
|
|
1028
|
+
console.log(` ${getInstallCommand(agent)}`);
|
|
1029
|
+
console.log(` ${getPlaywrightInstallCommand(agent, provider)}`);
|
|
1030
|
+
console.log(` ${getRunCommand(agent)}`);
|
|
1031
|
+
console.log();
|
|
1032
|
+
console.log(picocolors_default().green('└'), 'Done!');
|
|
1033
|
+
}
|
|
1034
|
+
async function createInteractive(cwd, projectInfo, isAgent) {
|
|
1035
|
+
const { agent, language, testDir, framework, reactVersion } = projectInfo;
|
|
1036
|
+
const effectiveFramework = 'react' === framework ? 'react' : 'vanilla';
|
|
1037
|
+
Ie(picocolors_default().bgCyan(picocolors_default().black(' rstest init browser ')));
|
|
1038
|
+
const detectionLines = [];
|
|
1039
|
+
if ('react' === framework && reactVersion) detectionLines.push(`${picocolors_default().green('✓')} Found React ${reactVersion}`);
|
|
1040
|
+
else if ('react' === framework) detectionLines.push(`${picocolors_default().green('✓')} Found React`);
|
|
1041
|
+
else detectionLines.push(`${picocolors_default().yellow('⚠')} Framework not detected, will generate vanilla DOM example`);
|
|
1042
|
+
detectionLines.push(`${picocolors_default().green('✓')} Found ${'ts' === language ? 'TypeScript' : 'JavaScript'}`);
|
|
1043
|
+
detectionLines.push(`${picocolors_default().green('✓')} Test directory: ${testDir}/`);
|
|
1044
|
+
Me(detectionLines.join('\n'), 'Detecting project...');
|
|
1045
|
+
if (isAgent) M.info(`AI Agent detected. For non-interactive mode, run:\n ${picocolors_default().cyan('npx rstest init browser --yes')}`);
|
|
1046
|
+
const providerSelection = await ve({
|
|
1047
|
+
message: 'Choose a browser provider (so far, only Playwright)',
|
|
1048
|
+
options: [
|
|
1049
|
+
{
|
|
1050
|
+
value: 'playwright',
|
|
1051
|
+
label: 'Playwright',
|
|
1052
|
+
hint: 'recommended'
|
|
1053
|
+
}
|
|
1054
|
+
]
|
|
1055
|
+
});
|
|
1056
|
+
if (pD(providerSelection)) {
|
|
1057
|
+
xe('Operation cancelled.');
|
|
1058
|
+
process.exit(0);
|
|
1059
|
+
}
|
|
1060
|
+
const provider = providerSelection;
|
|
1061
|
+
const preview = computeFilePreview(cwd, projectInfo);
|
|
1062
|
+
const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.7.9");
|
|
1063
|
+
const depsList = Object.entries(deps).map(([name, version])=>`${name}@${version}`).join(', ');
|
|
1064
|
+
const previewLines = [
|
|
1065
|
+
`${picocolors_default().cyan('+')} Create ${preview.configFile}`,
|
|
1066
|
+
`${picocolors_default().cyan('+')} Create ${preview.componentFile}`,
|
|
1067
|
+
`${picocolors_default().cyan('+')} Create ${preview.testFile}`,
|
|
1068
|
+
`${picocolors_default().yellow('~')} Modify package.json`,
|
|
1069
|
+
' - Add "test:browser" script',
|
|
1070
|
+
` - Add devDependencies: ${picocolors_default().dim(depsList)}`
|
|
1071
|
+
];
|
|
1072
|
+
Me(previewLines.join('\n'), 'Changes to be made');
|
|
1073
|
+
const confirmed = await ye({
|
|
1074
|
+
message: 'Proceed with these changes?',
|
|
1075
|
+
initialValue: true
|
|
1076
|
+
});
|
|
1077
|
+
if (pD(confirmed) || !confirmed) {
|
|
1078
|
+
xe('Operation cancelled.');
|
|
1079
|
+
process.exit(0);
|
|
1080
|
+
}
|
|
1081
|
+
const s = dist_Y();
|
|
1082
|
+
s.start('Creating files...');
|
|
1083
|
+
const createdFiles = await generateFiles(cwd, projectInfo, provider);
|
|
1084
|
+
s.stop('Created files');
|
|
1085
|
+
const fileLines = createdFiles.map((f)=>`${picocolors_default().green('✓')} Created ${f}`);
|
|
1086
|
+
fileLines.push(`${picocolors_default().green('✓')} Updated package.json`);
|
|
1087
|
+
Me(fileLines.join('\n'), 'Files');
|
|
1088
|
+
const nextStepsLines = [
|
|
1089
|
+
`${picocolors_default().bold('1.')} Install dependencies:`,
|
|
1090
|
+
` ${picocolors_default().cyan(getInstallCommand(agent))}`,
|
|
1091
|
+
'',
|
|
1092
|
+
`${picocolors_default().bold('2.')} Install Playwright browsers:`,
|
|
1093
|
+
` ${picocolors_default().cyan(getPlaywrightInstallCommand(agent, provider))}`,
|
|
1094
|
+
'',
|
|
1095
|
+
`${picocolors_default().bold('3.')} Run your tests:`,
|
|
1096
|
+
` ${picocolors_default().cyan(getRunCommand(agent))}`
|
|
1097
|
+
];
|
|
1098
|
+
Me(nextStepsLines.join('\n'), 'Next steps');
|
|
1099
|
+
Se(picocolors_default().green('Done! Happy testing with Rstest!'));
|
|
1100
|
+
}
|
|
1101
|
+
async function generateFiles(cwd, projectInfo, provider) {
|
|
1102
|
+
const { language, testDir, framework } = projectInfo;
|
|
1103
|
+
const effectiveFramework = 'react' === framework ? 'react' : 'vanilla';
|
|
1104
|
+
const createdFiles = [];
|
|
1105
|
+
const configFileName = getConfigFileName();
|
|
1106
|
+
const configPath = external_node_path_["default"].join(cwd, configFileName);
|
|
1107
|
+
writeFile(configPath, getConfigTemplate());
|
|
1108
|
+
createdFiles.push(configFileName);
|
|
1109
|
+
const testDirPath = external_node_path_["default"].join(cwd, testDir);
|
|
1110
|
+
ensureDir(testDirPath);
|
|
1111
|
+
let componentExt;
|
|
1112
|
+
let testExt;
|
|
1113
|
+
if ('react' === effectiveFramework) {
|
|
1114
|
+
componentExt = 'ts' === language ? '.tsx' : '.jsx';
|
|
1115
|
+
testExt = 'ts' === language ? '.test.tsx' : '.test.jsx';
|
|
1116
|
+
} else {
|
|
1117
|
+
componentExt = 'ts' === language ? '.ts' : '.js';
|
|
1118
|
+
testExt = 'ts' === language ? '.test.ts' : '.test.js';
|
|
1119
|
+
}
|
|
1120
|
+
const baseName = getUniqueBaseName(testDirPath, 'Counter', componentExt);
|
|
1121
|
+
const componentFileName = `${baseName}${componentExt}`;
|
|
1122
|
+
const componentPath = external_node_path_["default"].join(testDirPath, componentFileName);
|
|
1123
|
+
'react' === effectiveFramework ? writeFile(componentPath, getReactComponentTemplate(language)) : writeFile(componentPath, getVanillaComponentTemplate(language));
|
|
1124
|
+
createdFiles.push(`${testDir}/${componentFileName}`);
|
|
1125
|
+
const testFileName = `${baseName}${testExt}`;
|
|
1126
|
+
const testPath = external_node_path_["default"].join(testDirPath, testFileName);
|
|
1127
|
+
let testContent;
|
|
1128
|
+
if ('react' === effectiveFramework) {
|
|
1129
|
+
testContent = getReactTestTemplate(language);
|
|
1130
|
+
if ('Counter' !== baseName) testContent = testContent.replace(/from '\.\/Counter\.(tsx|jsx)'/, `from './${baseName}.$1'`);
|
|
1131
|
+
} else {
|
|
1132
|
+
testContent = getVanillaTestTemplate(language);
|
|
1133
|
+
if ('Counter' !== baseName) testContent = testContent.replace(/from '\.\/Counter\.(ts|js)'/, `from './${baseName}.$1'`);
|
|
1134
|
+
}
|
|
1135
|
+
writeFile(testPath, testContent);
|
|
1136
|
+
createdFiles.push(`${testDir}/${testFileName}`);
|
|
1137
|
+
updatePackageJsonScripts(cwd, {
|
|
1138
|
+
'test:browser': 'rstest --config=rstest.browser.config.ts'
|
|
1139
|
+
});
|
|
1140
|
+
const deps = getDependenciesWithVersions(effectiveFramework, provider, "0.7.9");
|
|
1141
|
+
updatePackageJsonDevDeps(cwd, deps);
|
|
1142
|
+
return createdFiles;
|
|
1143
|
+
}
|
|
1144
|
+
export { create };
|