@rstest/core 0.1.2 → 0.2.0

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.
@@ -3,6 +3,8 @@ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.ur
3
3
  import node_process from "node:process";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_birpc__ from "birpc";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_events__ from "events";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__ from "fs/promises";
6
8
  import * as __WEBPACK_EXTERNAL_MODULE_node_events_0a6aefe7__ from "node:events";
7
9
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
8
10
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
@@ -10,6 +12,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_inspector_dd9822d6__ from "node:inspe
10
12
  import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
11
13
  import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
12
14
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
15
+ import * as __WEBPACK_EXTERNAL_MODULE_node_stream_444d1c2b__ from "node:stream";
13
16
  import * as __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__ from "node:tty";
14
17
  import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
15
18
  import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
@@ -17,7 +20,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_v8_d0df5498__ from "node:v8";
17
20
  import * as __WEBPACK_EXTERNAL_MODULE_pathe__ from "pathe";
18
21
  import * as __WEBPACK_EXTERNAL_MODULE_std_env_1c7b8267__ from "std-env";
19
22
  import * as __WEBPACK_EXTERNAL_MODULE_tinypool__ from "tinypool";
20
- import { EventEmitter } from "events";
21
23
  var __webpack_modules__ = {
22
24
  "../../node_modules/.pnpm/fdir@6.4.4_picomatch@4.0.2/node_modules/fdir/dist/api/async.js": function(__unused_webpack_module, exports, __webpack_require__) {
23
25
  Object.defineProperty(exports, "__esModule", {
@@ -235,7 +237,7 @@ var __webpack_modules__ = {
235
237
  value: true
236
238
  });
237
239
  exports.build = void 0;
238
- const fs_1 = __importDefault(__webpack_require__("fs"));
240
+ const fs_1 = __importDefault(__webpack_require__("node:fs"));
239
241
  const path_1 = __webpack_require__("node:path");
240
242
  const resolveSymlinksAsync = function(path, state, callback) {
241
243
  const { queue, options: { suppressErrors } } = state;
@@ -294,7 +296,7 @@ var __webpack_modules__ = {
294
296
  value: true
295
297
  });
296
298
  exports.build = void 0;
297
- const fs_1 = __importDefault(__webpack_require__("fs"));
299
+ const fs_1 = __importDefault(__webpack_require__("node:fs"));
298
300
  const readdirOpts = {
299
301
  withFileTypes: true
300
302
  };
@@ -2177,12 +2179,652 @@ var __webpack_modules__ = {
2177
2179
  return last;
2178
2180
  };
2179
2181
  },
2182
+ "./src/cli/commands.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2183
+ __webpack_require__.d(__webpack_exports__, {
2184
+ mR: ()=>runRest,
2185
+ X_: ()=>setupCommands
2186
+ });
2187
+ var external_events_ = __webpack_require__("events");
2188
+ function toArr(any) {
2189
+ return null == any ? [] : Array.isArray(any) ? any : [
2190
+ any
2191
+ ];
2192
+ }
2193
+ function toVal(out, key, val, opts) {
2194
+ var x, old = out[key], nxt = ~opts.string.indexOf(key) ? null == val || true === val ? '' : String(val) : 'boolean' == typeof val ? val : ~opts.boolean.indexOf(key) ? 'false' === val ? false : 'true' === val || (out._.push((x = +val, 0 * x === 0) ? x : val), !!val) : (x = +val, 0 * x === 0) ? x : val;
2195
+ out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
2196
+ old,
2197
+ nxt
2198
+ ];
2199
+ }
2200
+ function mri2(args, opts) {
2201
+ args = args || [];
2202
+ opts = opts || {};
2203
+ var k, arr, arg, name, val, out = {
2204
+ _: []
2205
+ };
2206
+ var i = 0, j = 0, idx = 0, len = args.length;
2207
+ const alibi = void 0 !== opts.alias;
2208
+ const strict = void 0 !== opts.unknown;
2209
+ const defaults = void 0 !== opts.default;
2210
+ opts.alias = opts.alias || {};
2211
+ opts.string = toArr(opts.string);
2212
+ opts.boolean = toArr(opts.boolean);
2213
+ if (alibi) for(k in opts.alias){
2214
+ arr = opts.alias[k] = toArr(opts.alias[k]);
2215
+ for(i = 0; i < arr.length; i++)(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
2216
+ }
2217
+ for(i = opts.boolean.length; i-- > 0;){
2218
+ arr = opts.alias[opts.boolean[i]] || [];
2219
+ for(j = arr.length; j-- > 0;)opts.boolean.push(arr[j]);
2220
+ }
2221
+ for(i = opts.string.length; i-- > 0;){
2222
+ arr = opts.alias[opts.string[i]] || [];
2223
+ for(j = arr.length; j-- > 0;)opts.string.push(arr[j]);
2224
+ }
2225
+ if (defaults) for(k in opts.default){
2226
+ name = typeof opts.default[k];
2227
+ arr = opts.alias[k] = opts.alias[k] || [];
2228
+ if (void 0 !== opts[name]) {
2229
+ opts[name].push(k);
2230
+ for(i = 0; i < arr.length; i++)opts[name].push(arr[i]);
2231
+ }
2232
+ }
2233
+ const keys = strict ? Object.keys(opts.alias) : [];
2234
+ for(i = 0; i < len; i++){
2235
+ arg = args[i];
2236
+ if ('--' === arg) {
2237
+ out._ = out._.concat(args.slice(++i));
2238
+ break;
2239
+ }
2240
+ for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
2241
+ if (0 === j) out._.push(arg);
2242
+ else if ('no-' === arg.substring(j, j + 3)) {
2243
+ name = arg.substring(j + 3);
2244
+ if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
2245
+ out[name] = false;
2246
+ } else {
2247
+ for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
2248
+ name = arg.substring(j, idx);
2249
+ val = arg.substring(++idx) || i + 1 === len || 45 === ('' + args[i + 1]).charCodeAt(0) || args[++i];
2250
+ arr = 2 === j ? [
2251
+ name
2252
+ ] : name;
2253
+ for(idx = 0; idx < arr.length; idx++){
2254
+ name = arr[idx];
2255
+ if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
2256
+ toVal(out, name, idx + 1 < arr.length || val, opts);
2257
+ }
2258
+ }
2259
+ }
2260
+ if (defaults) {
2261
+ for(k in opts.default)if (void 0 === out[k]) out[k] = opts.default[k];
2262
+ }
2263
+ if (alibi) for(k in out){
2264
+ arr = opts.alias[k] || [];
2265
+ while(arr.length > 0)out[arr.shift()] = out[k];
2266
+ }
2267
+ return out;
2268
+ }
2269
+ const removeBrackets = (v)=>v.replace(/[<[].+/, "").trim();
2270
+ const findAllBrackets = (v)=>{
2271
+ const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
2272
+ const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
2273
+ const res = [];
2274
+ const parse = (match)=>{
2275
+ let variadic = false;
2276
+ let value = match[1];
2277
+ if (value.startsWith("...")) {
2278
+ value = value.slice(3);
2279
+ variadic = true;
2280
+ }
2281
+ return {
2282
+ required: match[0].startsWith("<"),
2283
+ value,
2284
+ variadic
2285
+ };
2286
+ };
2287
+ let angledMatch;
2288
+ while(angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v))res.push(parse(angledMatch));
2289
+ let squareMatch;
2290
+ while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
2291
+ return res;
2292
+ };
2293
+ const getMriOptions = (options)=>{
2294
+ const result = {
2295
+ alias: {},
2296
+ boolean: []
2297
+ };
2298
+ for (const [index, option] of options.entries()){
2299
+ if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
2300
+ if (option.isBoolean) if (option.negated) {
2301
+ const hasStringTypeOption = options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required);
2302
+ if (!hasStringTypeOption) result.boolean.push(option.names[0]);
2303
+ } else result.boolean.push(option.names[0]);
2304
+ }
2305
+ return result;
2306
+ };
2307
+ const findLongest = (arr)=>arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
2308
+ const padRight = (str, length)=>str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
2309
+ const camelcase = (input)=>input.replace(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
2310
+ const setDotProp = (obj, keys, val)=>{
2311
+ let i = 0;
2312
+ let length = keys.length;
2313
+ let t = obj;
2314
+ let x;
2315
+ for(; i < length; ++i){
2316
+ x = t[keys[i]];
2317
+ t = t[keys[i]] = i === length - 1 ? val : null != x ? x : !~keys[i + 1].indexOf(".") && +keys[i + 1] > -1 ? [] : {};
2318
+ }
2319
+ };
2320
+ const setByType = (obj, transforms)=>{
2321
+ for (const key of Object.keys(transforms)){
2322
+ const transform = transforms[key];
2323
+ if (transform.shouldTransform) {
2324
+ obj[key] = Array.prototype.concat.call([], obj[key]);
2325
+ if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
2326
+ }
2327
+ }
2328
+ };
2329
+ const getFileName = (input)=>{
2330
+ const m = /([^\\\/]+)$/.exec(input);
2331
+ return m ? m[1] : "";
2332
+ };
2333
+ const camelcaseOptionName = (name)=>name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
2334
+ class CACError extends Error {
2335
+ constructor(message){
2336
+ super(message);
2337
+ this.name = this.constructor.name;
2338
+ if ("function" == typeof Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
2339
+ else this.stack = new Error(message).stack;
2340
+ }
2341
+ }
2342
+ class Option {
2343
+ constructor(rawName, description, config){
2344
+ this.rawName = rawName;
2345
+ this.description = description;
2346
+ this.config = Object.assign({}, config);
2347
+ rawName = rawName.replace(/\.\*/g, "");
2348
+ this.negated = false;
2349
+ this.names = removeBrackets(rawName).split(",").map((v)=>{
2350
+ let name = v.trim().replace(/^-{1,2}/, "");
2351
+ if (name.startsWith("no-")) {
2352
+ this.negated = true;
2353
+ name = name.replace(/^no-/, "");
2354
+ }
2355
+ return camelcaseOptionName(name);
2356
+ }).sort((a, b)=>a.length > b.length ? 1 : -1);
2357
+ this.name = this.names[this.names.length - 1];
2358
+ if (this.negated && null == this.config.default) this.config.default = true;
2359
+ if (rawName.includes("<")) this.required = true;
2360
+ else if (rawName.includes("[")) this.required = false;
2361
+ else this.isBoolean = true;
2362
+ }
2363
+ }
2364
+ const processArgs = process.argv;
2365
+ const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
2366
+ class Command {
2367
+ constructor(rawName, description, config = {}, cli){
2368
+ this.rawName = rawName;
2369
+ this.description = description;
2370
+ this.config = config;
2371
+ this.cli = cli;
2372
+ this.options = [];
2373
+ this.aliasNames = [];
2374
+ this.name = removeBrackets(rawName);
2375
+ this.args = findAllBrackets(rawName);
2376
+ this.examples = [];
2377
+ }
2378
+ usage(text) {
2379
+ this.usageText = text;
2380
+ return this;
2381
+ }
2382
+ allowUnknownOptions() {
2383
+ this.config.allowUnknownOptions = true;
2384
+ return this;
2385
+ }
2386
+ ignoreOptionDefaultValue() {
2387
+ this.config.ignoreOptionDefaultValue = true;
2388
+ return this;
2389
+ }
2390
+ version(version, customFlags = "-v, --version") {
2391
+ this.versionNumber = version;
2392
+ this.option(customFlags, "Display version number");
2393
+ return this;
2394
+ }
2395
+ example(example) {
2396
+ this.examples.push(example);
2397
+ return this;
2398
+ }
2399
+ option(rawName, description, config) {
2400
+ const option = new Option(rawName, description, config);
2401
+ this.options.push(option);
2402
+ return this;
2403
+ }
2404
+ alias(name) {
2405
+ this.aliasNames.push(name);
2406
+ return this;
2407
+ }
2408
+ action(callback) {
2409
+ this.commandAction = callback;
2410
+ return this;
2411
+ }
2412
+ isMatched(name) {
2413
+ return this.name === name || this.aliasNames.includes(name);
2414
+ }
2415
+ get isDefaultCommand() {
2416
+ return "" === this.name || this.aliasNames.includes("!");
2417
+ }
2418
+ get isGlobalCommand() {
2419
+ return this instanceof GlobalCommand;
2420
+ }
2421
+ hasOption(name) {
2422
+ name = name.split(".")[0];
2423
+ return this.options.find((option)=>option.names.includes(name));
2424
+ }
2425
+ outputHelp() {
2426
+ const { name, commands } = this.cli;
2427
+ const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
2428
+ let sections = [
2429
+ {
2430
+ body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
2431
+ }
2432
+ ];
2433
+ sections.push({
2434
+ title: "Usage",
2435
+ body: ` $ ${name} ${this.usageText || this.rawName}`
2436
+ });
2437
+ const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
2438
+ if (showCommands) {
2439
+ const longestCommandName = findLongest(commands.map((command)=>command.rawName));
2440
+ sections.push({
2441
+ title: "Commands",
2442
+ body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
2443
+ });
2444
+ sections.push({
2445
+ title: "For more info, run any command with the `--help` flag",
2446
+ body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
2447
+ });
2448
+ }
2449
+ let options = this.isGlobalCommand ? globalOptions : [
2450
+ ...this.options,
2451
+ ...globalOptions || []
2452
+ ];
2453
+ if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option)=>"version" !== option.name);
2454
+ if (options.length > 0) {
2455
+ const longestOptionName = findLongest(options.map((option)=>option.rawName));
2456
+ sections.push({
2457
+ title: "Options",
2458
+ body: options.map((option)=>` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${void 0 === option.config.default ? "" : `(default: ${option.config.default})`}`).join("\n")
2459
+ });
2460
+ }
2461
+ if (this.examples.length > 0) sections.push({
2462
+ title: "Examples",
2463
+ body: this.examples.map((example)=>{
2464
+ if ("function" == typeof example) return example(name);
2465
+ return example;
2466
+ }).join("\n")
2467
+ });
2468
+ if (helpCallback) sections = helpCallback(sections) || sections;
2469
+ console.log(sections.map((section)=>section.title ? `${section.title}:
2470
+ ${section.body}` : section.body).join("\n\n"));
2471
+ }
2472
+ outputVersion() {
2473
+ const { name } = this.cli;
2474
+ const { versionNumber } = this.cli.globalCommand;
2475
+ if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
2476
+ }
2477
+ checkRequiredArgs() {
2478
+ const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
2479
+ if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
2480
+ }
2481
+ checkUnknownOptions() {
2482
+ const { options, globalCommand } = this.cli;
2483
+ if (!this.config.allowUnknownOptions) {
2484
+ for (const name of Object.keys(options))if ("--" !== name && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
2485
+ }
2486
+ }
2487
+ checkOptionValue() {
2488
+ const { options: parsedOptions, globalCommand } = this.cli;
2489
+ const options = [
2490
+ ...globalCommand.options,
2491
+ ...this.options
2492
+ ];
2493
+ for (const option of options){
2494
+ const value = parsedOptions[option.name.split(".")[0]];
2495
+ if (option.required) {
2496
+ const hasNegated = options.some((o)=>o.negated && o.names.includes(option.name));
2497
+ if (true === value || false === value && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
2498
+ }
2499
+ }
2500
+ }
2501
+ }
2502
+ class GlobalCommand extends Command {
2503
+ constructor(cli){
2504
+ super("@@global@@", "", {}, cli);
2505
+ }
2506
+ }
2507
+ var __assign = Object.assign;
2508
+ class CAC extends external_events_.EventEmitter {
2509
+ constructor(name = ""){
2510
+ super();
2511
+ this.name = name;
2512
+ this.commands = [];
2513
+ this.rawArgs = [];
2514
+ this.args = [];
2515
+ this.options = {};
2516
+ this.globalCommand = new GlobalCommand(this);
2517
+ this.globalCommand.usage("<command> [options]");
2518
+ }
2519
+ usage(text) {
2520
+ this.globalCommand.usage(text);
2521
+ return this;
2522
+ }
2523
+ command(rawName, description, config) {
2524
+ const command = new Command(rawName, description || "", config, this);
2525
+ command.globalCommand = this.globalCommand;
2526
+ this.commands.push(command);
2527
+ return command;
2528
+ }
2529
+ option(rawName, description, config) {
2530
+ this.globalCommand.option(rawName, description, config);
2531
+ return this;
2532
+ }
2533
+ help(callback) {
2534
+ this.globalCommand.option("-h, --help", "Display this message");
2535
+ this.globalCommand.helpCallback = callback;
2536
+ this.showHelpOnExit = true;
2537
+ return this;
2538
+ }
2539
+ version(version, customFlags = "-v, --version") {
2540
+ this.globalCommand.version(version, customFlags);
2541
+ this.showVersionOnExit = true;
2542
+ return this;
2543
+ }
2544
+ example(example) {
2545
+ this.globalCommand.example(example);
2546
+ return this;
2547
+ }
2548
+ outputHelp() {
2549
+ if (this.matchedCommand) this.matchedCommand.outputHelp();
2550
+ else this.globalCommand.outputHelp();
2551
+ }
2552
+ outputVersion() {
2553
+ this.globalCommand.outputVersion();
2554
+ }
2555
+ setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
2556
+ this.args = args;
2557
+ this.options = options;
2558
+ if (matchedCommand) this.matchedCommand = matchedCommand;
2559
+ if (matchedCommandName) this.matchedCommandName = matchedCommandName;
2560
+ return this;
2561
+ }
2562
+ unsetMatchedCommand() {
2563
+ this.matchedCommand = void 0;
2564
+ this.matchedCommandName = void 0;
2565
+ }
2566
+ parse(argv = processArgs, { run = true } = {}) {
2567
+ this.rawArgs = argv;
2568
+ if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
2569
+ let shouldParse = true;
2570
+ for (const command of this.commands){
2571
+ const parsed = this.mri(argv.slice(2), command);
2572
+ const commandName = parsed.args[0];
2573
+ if (command.isMatched(commandName)) {
2574
+ shouldParse = false;
2575
+ const parsedInfo = __assign(__assign({}, parsed), {
2576
+ args: parsed.args.slice(1)
2577
+ });
2578
+ this.setParsedInfo(parsedInfo, command, commandName);
2579
+ this.emit(`command:${commandName}`, command);
2580
+ }
2581
+ }
2582
+ if (shouldParse) {
2583
+ for (const command of this.commands)if ("" === command.name) {
2584
+ shouldParse = false;
2585
+ const parsed = this.mri(argv.slice(2), command);
2586
+ this.setParsedInfo(parsed, command);
2587
+ this.emit("command:!", command);
2588
+ }
2589
+ }
2590
+ if (shouldParse) {
2591
+ const parsed = this.mri(argv.slice(2));
2592
+ this.setParsedInfo(parsed);
2593
+ }
2594
+ if (this.options.help && this.showHelpOnExit) {
2595
+ this.outputHelp();
2596
+ run = false;
2597
+ this.unsetMatchedCommand();
2598
+ }
2599
+ if (this.options.version && this.showVersionOnExit && null == this.matchedCommandName) {
2600
+ this.outputVersion();
2601
+ run = false;
2602
+ this.unsetMatchedCommand();
2603
+ }
2604
+ const parsedArgv = {
2605
+ args: this.args,
2606
+ options: this.options
2607
+ };
2608
+ if (run) this.runMatchedCommand();
2609
+ if (!this.matchedCommand && this.args[0]) this.emit("command:*");
2610
+ return parsedArgv;
2611
+ }
2612
+ mri(argv, command) {
2613
+ const cliOptions = [
2614
+ ...this.globalCommand.options,
2615
+ ...command ? command.options : []
2616
+ ];
2617
+ const mriOptions = getMriOptions(cliOptions);
2618
+ let argsAfterDoubleDashes = [];
2619
+ const doubleDashesIndex = argv.indexOf("--");
2620
+ if (doubleDashesIndex > -1) {
2621
+ argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
2622
+ argv = argv.slice(0, doubleDashesIndex);
2623
+ }
2624
+ let parsed = mri2(argv, mriOptions);
2625
+ parsed = Object.keys(parsed).reduce((res, name)=>__assign(__assign({}, res), {
2626
+ [camelcaseOptionName(name)]: parsed[name]
2627
+ }), {
2628
+ _: []
2629
+ });
2630
+ const args = parsed._;
2631
+ const options = {
2632
+ "--": argsAfterDoubleDashes
2633
+ };
2634
+ const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
2635
+ let transforms = Object.create(null);
2636
+ for (const cliOption of cliOptions){
2637
+ if (!ignoreDefault && void 0 !== cliOption.config.default) for (const name of cliOption.names)options[name] = cliOption.config.default;
2638
+ if (Array.isArray(cliOption.config.type)) {
2639
+ if (void 0 === transforms[cliOption.name]) {
2640
+ transforms[cliOption.name] = Object.create(null);
2641
+ transforms[cliOption.name]["shouldTransform"] = true;
2642
+ transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
2643
+ }
2644
+ }
2645
+ }
2646
+ for (const key of Object.keys(parsed))if ("_" !== key) {
2647
+ const keys = key.split(".");
2648
+ setDotProp(options, keys, parsed[key]);
2649
+ setByType(options, transforms);
2650
+ }
2651
+ return {
2652
+ args,
2653
+ options
2654
+ };
2655
+ }
2656
+ runMatchedCommand() {
2657
+ const { args, options, matchedCommand: command } = this;
2658
+ if (!command || !command.commandAction) return;
2659
+ command.checkUnknownOptions();
2660
+ command.checkOptionValue();
2661
+ command.checkRequiredArgs();
2662
+ const actionArgs = [];
2663
+ command.args.forEach((arg, index)=>{
2664
+ if (arg.variadic) actionArgs.push(args.slice(index));
2665
+ else actionArgs.push(args[index]);
2666
+ });
2667
+ actionArgs.push(options);
2668
+ return command.commandAction.apply(this, actionArgs);
2669
+ }
2670
+ }
2671
+ const cac = (name = "")=>new CAC(name);
2672
+ const dist = cac;
2673
+ var external_pathe_ = __webpack_require__("pathe");
2674
+ var src_config = __webpack_require__("./src/config.ts");
2675
+ var helper = __webpack_require__("./src/utils/helper.ts");
2676
+ var logger = __webpack_require__("./src/utils/logger.ts");
2677
+ var prepare = __webpack_require__("./src/cli/prepare.ts");
2678
+ const applyCommonOptions = (cli)=>{
2679
+ cli.option('-c, --config <config>', 'Specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'Specify the loader to load the config file, can be `jiti` or `native`', {
2680
+ default: 'jiti'
2681
+ }).option('-r, --root <root>', 'Specify the project root directory, can be an absolute path or a path relative to cwd').option('--globals', 'Provide global APIs').option('--isolate', 'Run tests in an isolated environment').option('--include <include>', 'Match test files').option('--exclude <exclude>', 'Exclude files from test').option('-u, --update', 'Update snapshot files').option('--passWithNoTests', 'Allows the test suite to pass when no files are found').option('--printConsoleTrace', 'Print console traces when calling any console method').option('--disableConsoleIntercept', 'Disable console intercept').option('--slowTestThreshold <value>', 'The number of milliseconds after which a test or suite is considered slow').option('--reporter <reporter>', 'Specify the reporter to use').option('-t, --testNamePattern <value>', 'Run only tests with a name that matches the regex').option('--testEnvironment <name>', 'The environment that will be used for testing').option('--testTimeout <value>', 'Timeout of a test in milliseconds').option('--hookTimeout <value>', 'Timeout of hook in milliseconds').option('--retry <retry>', 'Number of times to retry a test if it fails').option('--maxConcurrency <value>', 'Maximum number of concurrent tests').option('--clearMocks', 'Automatically clear mock calls, instances, contexts and results before every test').option('--resetMocks', 'Automatically reset mock state before every test').option('--restoreMocks', 'Automatically restore mock state and implementation before every test').option('--unstubGlobals', 'Restores all global variables that were changed with `rstest.stubGlobal` before every test').option('--unstubEnvs', 'Restores all `process.env` values that were changed with `rstest.stubEnv` before every test');
2682
+ };
2683
+ async function initCli(options) {
2684
+ const cwd = process.cwd();
2685
+ const root = options.root ? (0, helper.ZY)(cwd, options.root) : cwd;
2686
+ const { content: config, filePath: configFilePath } = await (0, src_config.ME)({
2687
+ cwd: root,
2688
+ path: options.config,
2689
+ configLoader: options.configLoader
2690
+ });
2691
+ const keys = [
2692
+ 'root',
2693
+ 'globals',
2694
+ 'isolate',
2695
+ 'passWithNoTests',
2696
+ 'update',
2697
+ 'testNamePattern',
2698
+ 'testTimeout',
2699
+ 'hookTimeout',
2700
+ 'clearMocks',
2701
+ 'resetMocks',
2702
+ 'restoreMocks',
2703
+ 'unstubEnvs',
2704
+ 'unstubGlobals',
2705
+ 'retry',
2706
+ 'slowTestThreshold',
2707
+ 'maxConcurrency',
2708
+ 'printConsoleTrace',
2709
+ 'disableConsoleIntercept',
2710
+ 'testEnvironment'
2711
+ ];
2712
+ for (const key of keys)if (void 0 !== options[key]) config[key] = options[key];
2713
+ if (options.exclude) config.exclude = (0, helper.XQ)(options.exclude);
2714
+ if (options.reporter) config.reporters = (0, helper.XQ)(options.reporter);
2715
+ if (options.include) config.include = (0, helper.XQ)(options.include);
2716
+ return {
2717
+ config,
2718
+ configFilePath: configFilePath ?? void 0
2719
+ };
2720
+ }
2721
+ const runRest = async ({ options, filters, command })=>{
2722
+ let rstest;
2723
+ try {
2724
+ const { config, configFilePath } = await initCli(options);
2725
+ const { createRstest } = await __webpack_require__.e("359").then(__webpack_require__.bind(__webpack_require__, "./src/core/index.ts"));
2726
+ rstest = createRstest({
2727
+ config,
2728
+ configFilePath
2729
+ }, command, filters.map(external_pathe_.normalize));
2730
+ if ('watch' === command && configFilePath) {
2731
+ const { watchFilesForRestart } = await __webpack_require__.e("25").then(__webpack_require__.bind(__webpack_require__, "./src/core/restart.ts"));
2732
+ watchFilesForRestart({
2733
+ rstest,
2734
+ options,
2735
+ filters
2736
+ });
2737
+ }
2738
+ await rstest.runTests();
2739
+ } catch (err) {
2740
+ for (const reporter of rstest?.context.reporters || [])reporter.onExit?.();
2741
+ logger.k.error('Failed to run Rstest.');
2742
+ logger.k.error((0, helper.Z)(err));
2743
+ process.exit(1);
2744
+ }
2745
+ };
2746
+ function setupCommands() {
2747
+ const cli = dist('rstest');
2748
+ cli.help();
2749
+ cli.version("0.2.0");
2750
+ applyCommonOptions(cli);
2751
+ cli.command('[...filters]', 'run tests').option('--watch', 'Run tests in watch mode').action(async (filters, options)=>{
2752
+ (0, prepare.U)();
2753
+ if (options.watch) await runRest({
2754
+ options,
2755
+ filters,
2756
+ command: 'watch'
2757
+ });
2758
+ else await runRest({
2759
+ options,
2760
+ filters,
2761
+ command: 'run'
2762
+ });
2763
+ });
2764
+ cli.command('run [...filters]', 'run tests without watch mode').action(async (filters, options)=>{
2765
+ (0, prepare.U)();
2766
+ await runRest({
2767
+ options,
2768
+ filters,
2769
+ command: 'run'
2770
+ });
2771
+ });
2772
+ cli.command('watch [...filters]', 'run tests in watch mode').action(async (filters, options)=>{
2773
+ (0, prepare.U)();
2774
+ await runRest({
2775
+ options,
2776
+ filters,
2777
+ command: 'watch'
2778
+ });
2779
+ });
2780
+ cli.command('list [...filters]', 'lists all test files that Rstest will run').option('--filesOnly', 'only list the test files').option('--json [boolean/path]', 'print tests as JSON or write to a file').action(async (filters, options)=>{
2781
+ try {
2782
+ const { config, configFilePath } = await initCli(options);
2783
+ const { createRstest } = await __webpack_require__.e("359").then(__webpack_require__.bind(__webpack_require__, "./src/core/index.ts"));
2784
+ const rstest = createRstest({
2785
+ config,
2786
+ configFilePath
2787
+ }, 'list', filters.map(external_pathe_.normalize));
2788
+ await rstest.listTests({
2789
+ filesOnly: options.filesOnly,
2790
+ json: options.json
2791
+ });
2792
+ } catch (err) {
2793
+ logger.k.error('Failed to run Rstest list.');
2794
+ logger.k.error((0, helper.Z)(err));
2795
+ process.exit(1);
2796
+ }
2797
+ });
2798
+ cli.parse();
2799
+ }
2800
+ },
2801
+ "./src/cli/prepare.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2802
+ __webpack_require__.d(__webpack_exports__, {
2803
+ U: ()=>showRstest,
2804
+ n: ()=>prepareCli
2805
+ });
2806
+ var _utils_logger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/utils/logger.ts");
2807
+ function initNodeEnv() {
2808
+ if (!process.env.NODE_ENV) process.env.NODE_ENV = 'test';
2809
+ }
2810
+ function prepareCli() {
2811
+ initNodeEnv();
2812
+ process.env.RSTEST = 'true';
2813
+ const { npm_execpath } = process.env;
2814
+ if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
2815
+ }
2816
+ function showRstest() {
2817
+ _utils_logger__WEBPACK_IMPORTED_MODULE_0__.k.greet(" Rstest v0.2.0");
2818
+ _utils_logger__WEBPACK_IMPORTED_MODULE_0__.k.log('');
2819
+ }
2820
+ },
2180
2821
  "./src/config.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2181
2822
  __webpack_require__.d(__webpack_exports__, {
2182
2823
  ME: ()=>loadConfig,
2824
+ en: ()=>mergeRstestConfig,
2183
2825
  hY: ()=>withDefaultConfig
2184
2826
  });
2185
- var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("fs");
2827
+ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
2186
2828
  var _rsbuild_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("@rsbuild/core");
2187
2829
  var pathe__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("pathe");
2188
2830
  var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/utils/index.ts");
@@ -2302,6 +2944,7 @@ var __webpack_modules__ = {
2302
2944
  Yz: ()=>getTaskNameWithPrefix,
2303
2945
  Z: ()=>formatError,
2304
2946
  ZY: ()=>getAbsolutePath,
2947
+ _l: ()=>isTTY,
2305
2948
  v8: ()=>serializableConfig
2306
2949
  });
2307
2950
  var pathe__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("pathe");
@@ -2443,12 +3086,14 @@ var __webpack_modules__ = {
2443
3086
  /^node:/,
2444
3087
  'pnpapi'
2445
3088
  ];
3089
+ const isTTY = (type = 'stdout')=>('stdin' === type ? process.stdin.isTTY : process.stdout.isTTY) && !process.env.CI;
2446
3090
  },
2447
3091
  "./src/utils/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2448
3092
  __webpack_require__.d(__webpack_exports__, {
2449
3093
  F7: ()=>constants.F7,
2450
3094
  GL: ()=>getTestEntries,
2451
3095
  aj: ()=>prettyTestPath,
3096
+ _l: ()=>helper._l,
2452
3097
  aA: ()=>getSetupFiles,
2453
3098
  kg: ()=>logger.k,
2454
3099
  Io: ()=>constants.Io,
@@ -2468,7 +3113,7 @@ var __webpack_modules__ = {
2468
3113
  var constants = __webpack_require__("./src/utils/constants.ts");
2469
3114
  var helper = __webpack_require__("./src/utils/helper.ts");
2470
3115
  var logger = __webpack_require__("./src/utils/logger.ts");
2471
- var external_node_fs_ = __webpack_require__("fs");
3116
+ var external_node_fs_ = __webpack_require__("node:fs");
2472
3117
  var promises_ = __webpack_require__("node:fs/promises");
2473
3118
  var external_node_module_ = __webpack_require__("node:module");
2474
3119
  var external_pathe_ = __webpack_require__("pathe");
@@ -2488,7 +3133,7 @@ var __webpack_modules__ = {
2488
3133
  const hasInSourceTestCode = (code)=>code.includes('import.meta.rstest');
2489
3134
  const formatTestEntryName = (name)=>name.replace(/\.*[/\\]/g, '_').replace(/\./g, '~');
2490
3135
  const getTestEntries = async ({ include, exclude, root, fileFilters, includeSource })=>{
2491
- const testFiles = await (0, dist.zA)(include, {
3136
+ const testFiles = await (0, dist.glob)(include, {
2492
3137
  cwd: root,
2493
3138
  absolute: true,
2494
3139
  ignore: exclude,
@@ -2496,7 +3141,7 @@ var __webpack_modules__ = {
2496
3141
  expandDirectories: false
2497
3142
  });
2498
3143
  if (includeSource?.length) {
2499
- const sourceFiles = await (0, dist.zA)(includeSource, {
3144
+ const sourceFiles = await (0, dist.glob)(includeSource, {
2500
3145
  cwd: root,
2501
3146
  absolute: true,
2502
3147
  ignore: exclude,
@@ -2569,7 +3214,7 @@ var __webpack_modules__ = {
2569
3214
  k: ()=>src_logger
2570
3215
  });
2571
3216
  var external_node_os_ = __webpack_require__("node:os");
2572
- var external_node_tty_ = __webpack_require__("node:tty");
3217
+ var external_node_tty_ = __webpack_require__("tty");
2573
3218
  function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
2574
3219
  const prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--';
2575
3220
  const position = argv.indexOf(prefix + flag);
@@ -2639,6 +3284,7 @@ var __webpack_modules__ = {
2639
3284
  if ('TEAMCITY_VERSION' in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
2640
3285
  if ('truecolor' === env.COLORTERM) return 3;
2641
3286
  if ('xterm-kitty' === env.TERM) return 3;
3287
+ if ('xterm-ghostty' === env.TERM) return 3;
2642
3288
  if ('TERM_PROGRAM' in env) {
2643
3289
  const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
2644
3290
  switch(env.TERM_PROGRAM){
@@ -2836,7 +3482,7 @@ var __webpack_modules__ = {
2836
3482
  src_logger.override({
2837
3483
  debug: (message, ...args)=>{
2838
3484
  if ('verbose' !== src_logger.level) return;
2839
- const time = helper.$_.gray(`${getTime()}`);
3485
+ const time = helper.$_.gray(getTime());
2840
3486
  console.log(` ${helper.$_.magenta('rstest')} ${time} ${message}`, ...args);
2841
3487
  }
2842
3488
  });
@@ -2847,10 +3493,16 @@ var __webpack_modules__ = {
2847
3493
  birpc: function(module) {
2848
3494
  module.exports = __WEBPACK_EXTERNAL_MODULE_birpc__;
2849
3495
  },
3496
+ events: function(module) {
3497
+ module.exports = __WEBPACK_EXTERNAL_MODULE_events__;
3498
+ },
3499
+ "fs/promises": function(module) {
3500
+ module.exports = __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__;
3501
+ },
2850
3502
  "node:events": function(module) {
2851
3503
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_events_0a6aefe7__;
2852
3504
  },
2853
- fs: function(module) {
3505
+ "node:fs": function(module) {
2854
3506
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__;
2855
3507
  },
2856
3508
  "node:fs/promises": function(module) {
@@ -2868,7 +3520,10 @@ var __webpack_modules__ = {
2868
3520
  "node:path": function(module) {
2869
3521
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__;
2870
3522
  },
2871
- "node:tty": function(module) {
3523
+ "node:stream": function(module) {
3524
+ module.exports = __WEBPACK_EXTERNAL_MODULE_node_stream_444d1c2b__;
3525
+ },
3526
+ tty: function(module) {
2872
3527
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__;
2873
3528
  },
2874
3529
  "node:url": function(module) {
@@ -2891,7 +3546,7 @@ var __webpack_modules__ = {
2891
3546
  },
2892
3547
  "../../node_modules/.pnpm/tinyglobby@0.2.14/node_modules/tinyglobby/dist/index.mjs": function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
2893
3548
  __webpack_require__.d(__webpack_exports__, {
2894
- zA: ()=>glob
3549
+ glob: ()=>glob
2895
3550
  });
2896
3551
  var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:path");
2897
3552
  var fdir__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../../node_modules/.pnpm/fdir@6.4.4_picomatch@4.0.2/node_modules/fdir/dist/index.js");
@@ -3158,9 +3813,19 @@ __webpack_require__.m = __webpack_modules__;
3158
3813
  (()=>{
3159
3814
  __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
3160
3815
  })();
3816
+ (()=>{
3817
+ __webpack_require__.r = (exports)=>{
3818
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
3819
+ value: 'Module'
3820
+ });
3821
+ Object.defineProperty(exports, '__esModule', {
3822
+ value: true
3823
+ });
3824
+ };
3825
+ })();
3161
3826
  (()=>{
3162
3827
  var installedChunks = {
3163
- 614: 0
3828
+ 980: 0
3164
3829
  };
3165
3830
  var installChunk = (data)=>{
3166
3831
  var __webpack_ids__ = data.__webpack_ids__;
@@ -3196,606 +3861,20 @@ __webpack_require__.m = __webpack_modules__;
3196
3861
  };
3197
3862
  })();
3198
3863
  var logger = __webpack_require__("./src/utils/logger.ts");
3199
- function toArr(any) {
3200
- return null == any ? [] : Array.isArray(any) ? any : [
3201
- any
3202
- ];
3203
- }
3204
- function toVal(out, key, val, opts) {
3205
- var x, old = out[key], nxt = ~opts.string.indexOf(key) ? null == val || true === val ? '' : String(val) : 'boolean' == typeof val ? val : ~opts.boolean.indexOf(key) ? 'false' === val ? false : 'true' === val || (out._.push((x = +val, 0 * x === 0) ? x : val), !!val) : (x = +val, 0 * x === 0) ? x : val;
3206
- out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
3207
- old,
3208
- nxt
3209
- ];
3210
- }
3211
- function mri2(args, opts) {
3212
- args = args || [];
3213
- opts = opts || {};
3214
- var k, arr, arg, name, val, out = {
3215
- _: []
3216
- };
3217
- var i = 0, j = 0, idx = 0, len = args.length;
3218
- const alibi = void 0 !== opts.alias;
3219
- const strict = void 0 !== opts.unknown;
3220
- const defaults = void 0 !== opts.default;
3221
- opts.alias = opts.alias || {};
3222
- opts.string = toArr(opts.string);
3223
- opts.boolean = toArr(opts.boolean);
3224
- if (alibi) for(k in opts.alias){
3225
- arr = opts.alias[k] = toArr(opts.alias[k]);
3226
- for(i = 0; i < arr.length; i++)(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
3227
- }
3228
- for(i = opts.boolean.length; i-- > 0;){
3229
- arr = opts.alias[opts.boolean[i]] || [];
3230
- for(j = arr.length; j-- > 0;)opts.boolean.push(arr[j]);
3231
- }
3232
- for(i = opts.string.length; i-- > 0;){
3233
- arr = opts.alias[opts.string[i]] || [];
3234
- for(j = arr.length; j-- > 0;)opts.string.push(arr[j]);
3235
- }
3236
- if (defaults) for(k in opts.default){
3237
- name = typeof opts.default[k];
3238
- arr = opts.alias[k] = opts.alias[k] || [];
3239
- if (void 0 !== opts[name]) {
3240
- opts[name].push(k);
3241
- for(i = 0; i < arr.length; i++)opts[name].push(arr[i]);
3242
- }
3243
- }
3244
- const keys = strict ? Object.keys(opts.alias) : [];
3245
- for(i = 0; i < len; i++){
3246
- arg = args[i];
3247
- if ('--' === arg) {
3248
- out._ = out._.concat(args.slice(++i));
3249
- break;
3250
- }
3251
- for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
3252
- if (0 === j) out._.push(arg);
3253
- else if ('no-' === arg.substring(j, j + 3)) {
3254
- name = arg.substring(j + 3);
3255
- if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
3256
- out[name] = false;
3257
- } else {
3258
- for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
3259
- name = arg.substring(j, idx);
3260
- val = arg.substring(++idx) || i + 1 === len || 45 === ('' + args[i + 1]).charCodeAt(0) || args[++i];
3261
- arr = 2 === j ? [
3262
- name
3263
- ] : name;
3264
- for(idx = 0; idx < arr.length; idx++){
3265
- name = arr[idx];
3266
- if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
3267
- toVal(out, name, idx + 1 < arr.length || val, opts);
3268
- }
3269
- }
3270
- }
3271
- if (defaults) {
3272
- for(k in opts.default)if (void 0 === out[k]) out[k] = opts.default[k];
3273
- }
3274
- if (alibi) for(k in out){
3275
- arr = opts.alias[k] || [];
3276
- while(arr.length > 0)out[arr.shift()] = out[k];
3277
- }
3278
- return out;
3279
- }
3280
- const removeBrackets = (v)=>v.replace(/[<[].+/, "").trim();
3281
- const findAllBrackets = (v)=>{
3282
- const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
3283
- const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
3284
- const res = [];
3285
- const parse = (match)=>{
3286
- let variadic = false;
3287
- let value = match[1];
3288
- if (value.startsWith("...")) {
3289
- value = value.slice(3);
3290
- variadic = true;
3291
- }
3292
- return {
3293
- required: match[0].startsWith("<"),
3294
- value,
3295
- variadic
3296
- };
3297
- };
3298
- let angledMatch;
3299
- while(angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v))res.push(parse(angledMatch));
3300
- let squareMatch;
3301
- while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
3302
- return res;
3303
- };
3304
- const getMriOptions = (options)=>{
3305
- const result = {
3306
- alias: {},
3307
- boolean: []
3308
- };
3309
- for (const [index, option] of options.entries()){
3310
- if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
3311
- if (option.isBoolean) if (option.negated) {
3312
- const hasStringTypeOption = options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required);
3313
- if (!hasStringTypeOption) result.boolean.push(option.names[0]);
3314
- } else result.boolean.push(option.names[0]);
3315
- }
3316
- return result;
3317
- };
3318
- const findLongest = (arr)=>arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
3319
- const padRight = (str, length)=>str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
3320
- const camelcase = (input)=>input.replace(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
3321
- const setDotProp = (obj, keys, val)=>{
3322
- let i = 0;
3323
- let length = keys.length;
3324
- let t = obj;
3325
- let x;
3326
- for(; i < length; ++i){
3327
- x = t[keys[i]];
3328
- t = t[keys[i]] = i === length - 1 ? val : null != x ? x : !~keys[i + 1].indexOf(".") && +keys[i + 1] > -1 ? [] : {};
3329
- }
3330
- };
3331
- const setByType = (obj, transforms)=>{
3332
- for (const key of Object.keys(transforms)){
3333
- const transform = transforms[key];
3334
- if (transform.shouldTransform) {
3335
- obj[key] = Array.prototype.concat.call([], obj[key]);
3336
- if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
3337
- }
3338
- }
3339
- };
3340
- const getFileName = (input)=>{
3341
- const m = /([^\\\/]+)$/.exec(input);
3342
- return m ? m[1] : "";
3343
- };
3344
- const camelcaseOptionName = (name)=>name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
3345
- class CACError extends Error {
3346
- constructor(message){
3347
- super(message);
3348
- this.name = this.constructor.name;
3349
- if ("function" == typeof Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
3350
- else this.stack = new Error(message).stack;
3351
- }
3352
- }
3353
- class Option {
3354
- constructor(rawName, description, config){
3355
- this.rawName = rawName;
3356
- this.description = description;
3357
- this.config = Object.assign({}, config);
3358
- rawName = rawName.replace(/\.\*/g, "");
3359
- this.negated = false;
3360
- this.names = removeBrackets(rawName).split(",").map((v)=>{
3361
- let name = v.trim().replace(/^-{1,2}/, "");
3362
- if (name.startsWith("no-")) {
3363
- this.negated = true;
3364
- name = name.replace(/^no-/, "");
3365
- }
3366
- return camelcaseOptionName(name);
3367
- }).sort((a, b)=>a.length > b.length ? 1 : -1);
3368
- this.name = this.names[this.names.length - 1];
3369
- if (this.negated && null == this.config.default) this.config.default = true;
3370
- if (rawName.includes("<")) this.required = true;
3371
- else if (rawName.includes("[")) this.required = false;
3372
- else this.isBoolean = true;
3373
- }
3374
- }
3375
- const processArgs = process.argv;
3376
- const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
3377
- class Command {
3378
- constructor(rawName, description, config = {}, cli){
3379
- this.rawName = rawName;
3380
- this.description = description;
3381
- this.config = config;
3382
- this.cli = cli;
3383
- this.options = [];
3384
- this.aliasNames = [];
3385
- this.name = removeBrackets(rawName);
3386
- this.args = findAllBrackets(rawName);
3387
- this.examples = [];
3388
- }
3389
- usage(text) {
3390
- this.usageText = text;
3391
- return this;
3392
- }
3393
- allowUnknownOptions() {
3394
- this.config.allowUnknownOptions = true;
3395
- return this;
3396
- }
3397
- ignoreOptionDefaultValue() {
3398
- this.config.ignoreOptionDefaultValue = true;
3399
- return this;
3400
- }
3401
- version(version, customFlags = "-v, --version") {
3402
- this.versionNumber = version;
3403
- this.option(customFlags, "Display version number");
3404
- return this;
3405
- }
3406
- example(example) {
3407
- this.examples.push(example);
3408
- return this;
3409
- }
3410
- option(rawName, description, config) {
3411
- const option = new Option(rawName, description, config);
3412
- this.options.push(option);
3413
- return this;
3414
- }
3415
- alias(name) {
3416
- this.aliasNames.push(name);
3417
- return this;
3418
- }
3419
- action(callback) {
3420
- this.commandAction = callback;
3421
- return this;
3422
- }
3423
- isMatched(name) {
3424
- return this.name === name || this.aliasNames.includes(name);
3425
- }
3426
- get isDefaultCommand() {
3427
- return "" === this.name || this.aliasNames.includes("!");
3428
- }
3429
- get isGlobalCommand() {
3430
- return this instanceof GlobalCommand;
3431
- }
3432
- hasOption(name) {
3433
- name = name.split(".")[0];
3434
- return this.options.find((option)=>option.names.includes(name));
3435
- }
3436
- outputHelp() {
3437
- const { name, commands } = this.cli;
3438
- const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
3439
- let sections = [
3440
- {
3441
- body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
3442
- }
3443
- ];
3444
- sections.push({
3445
- title: "Usage",
3446
- body: ` $ ${name} ${this.usageText || this.rawName}`
3447
- });
3448
- const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
3449
- if (showCommands) {
3450
- const longestCommandName = findLongest(commands.map((command)=>command.rawName));
3451
- sections.push({
3452
- title: "Commands",
3453
- body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
3454
- });
3455
- sections.push({
3456
- title: "For more info, run any command with the `--help` flag",
3457
- body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
3458
- });
3459
- }
3460
- let options = this.isGlobalCommand ? globalOptions : [
3461
- ...this.options,
3462
- ...globalOptions || []
3463
- ];
3464
- if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option)=>"version" !== option.name);
3465
- if (options.length > 0) {
3466
- const longestOptionName = findLongest(options.map((option)=>option.rawName));
3467
- sections.push({
3468
- title: "Options",
3469
- body: options.map((option)=>` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${void 0 === option.config.default ? "" : `(default: ${option.config.default})`}`).join("\n")
3470
- });
3471
- }
3472
- if (this.examples.length > 0) sections.push({
3473
- title: "Examples",
3474
- body: this.examples.map((example)=>{
3475
- if ("function" == typeof example) return example(name);
3476
- return example;
3477
- }).join("\n")
3478
- });
3479
- if (helpCallback) sections = helpCallback(sections) || sections;
3480
- console.log(sections.map((section)=>section.title ? `${section.title}:
3481
- ${section.body}` : section.body).join("\n\n"));
3482
- }
3483
- outputVersion() {
3484
- const { name } = this.cli;
3485
- const { versionNumber } = this.cli.globalCommand;
3486
- if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
3487
- }
3488
- checkRequiredArgs() {
3489
- const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
3490
- if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
3491
- }
3492
- checkUnknownOptions() {
3493
- const { options, globalCommand } = this.cli;
3494
- if (!this.config.allowUnknownOptions) {
3495
- for (const name of Object.keys(options))if ("--" !== name && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
3496
- }
3497
- }
3498
- checkOptionValue() {
3499
- const { options: parsedOptions, globalCommand } = this.cli;
3500
- const options = [
3501
- ...globalCommand.options,
3502
- ...this.options
3503
- ];
3504
- for (const option of options){
3505
- const value = parsedOptions[option.name.split(".")[0]];
3506
- if (option.required) {
3507
- const hasNegated = options.some((o)=>o.negated && o.names.includes(option.name));
3508
- if (true === value || false === value && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
3509
- }
3510
- }
3511
- }
3512
- }
3513
- class GlobalCommand extends Command {
3514
- constructor(cli){
3515
- super("@@global@@", "", {}, cli);
3516
- }
3517
- }
3518
- var __assign = Object.assign;
3519
- class CAC extends EventEmitter {
3520
- constructor(name = ""){
3521
- super();
3522
- this.name = name;
3523
- this.commands = [];
3524
- this.rawArgs = [];
3525
- this.args = [];
3526
- this.options = {};
3527
- this.globalCommand = new GlobalCommand(this);
3528
- this.globalCommand.usage("<command> [options]");
3529
- }
3530
- usage(text) {
3531
- this.globalCommand.usage(text);
3532
- return this;
3533
- }
3534
- command(rawName, description, config) {
3535
- const command = new Command(rawName, description || "", config, this);
3536
- command.globalCommand = this.globalCommand;
3537
- this.commands.push(command);
3538
- return command;
3539
- }
3540
- option(rawName, description, config) {
3541
- this.globalCommand.option(rawName, description, config);
3542
- return this;
3543
- }
3544
- help(callback) {
3545
- this.globalCommand.option("-h, --help", "Display this message");
3546
- this.globalCommand.helpCallback = callback;
3547
- this.showHelpOnExit = true;
3548
- return this;
3549
- }
3550
- version(version, customFlags = "-v, --version") {
3551
- this.globalCommand.version(version, customFlags);
3552
- this.showVersionOnExit = true;
3553
- return this;
3554
- }
3555
- example(example) {
3556
- this.globalCommand.example(example);
3557
- return this;
3558
- }
3559
- outputHelp() {
3560
- if (this.matchedCommand) this.matchedCommand.outputHelp();
3561
- else this.globalCommand.outputHelp();
3562
- }
3563
- outputVersion() {
3564
- this.globalCommand.outputVersion();
3565
- }
3566
- setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
3567
- this.args = args;
3568
- this.options = options;
3569
- if (matchedCommand) this.matchedCommand = matchedCommand;
3570
- if (matchedCommandName) this.matchedCommandName = matchedCommandName;
3571
- return this;
3572
- }
3573
- unsetMatchedCommand() {
3574
- this.matchedCommand = void 0;
3575
- this.matchedCommandName = void 0;
3576
- }
3577
- parse(argv = processArgs, { run = true } = {}) {
3578
- this.rawArgs = argv;
3579
- if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
3580
- let shouldParse = true;
3581
- for (const command of this.commands){
3582
- const parsed = this.mri(argv.slice(2), command);
3583
- const commandName = parsed.args[0];
3584
- if (command.isMatched(commandName)) {
3585
- shouldParse = false;
3586
- const parsedInfo = __assign(__assign({}, parsed), {
3587
- args: parsed.args.slice(1)
3588
- });
3589
- this.setParsedInfo(parsedInfo, command, commandName);
3590
- this.emit(`command:${commandName}`, command);
3591
- }
3592
- }
3593
- if (shouldParse) {
3594
- for (const command of this.commands)if ("" === command.name) {
3595
- shouldParse = false;
3596
- const parsed = this.mri(argv.slice(2), command);
3597
- this.setParsedInfo(parsed, command);
3598
- this.emit("command:!", command);
3599
- }
3600
- }
3601
- if (shouldParse) {
3602
- const parsed = this.mri(argv.slice(2));
3603
- this.setParsedInfo(parsed);
3604
- }
3605
- if (this.options.help && this.showHelpOnExit) {
3606
- this.outputHelp();
3607
- run = false;
3608
- this.unsetMatchedCommand();
3609
- }
3610
- if (this.options.version && this.showVersionOnExit && null == this.matchedCommandName) {
3611
- this.outputVersion();
3612
- run = false;
3613
- this.unsetMatchedCommand();
3614
- }
3615
- const parsedArgv = {
3616
- args: this.args,
3617
- options: this.options
3618
- };
3619
- if (run) this.runMatchedCommand();
3620
- if (!this.matchedCommand && this.args[0]) this.emit("command:*");
3621
- return parsedArgv;
3622
- }
3623
- mri(argv, command) {
3624
- const cliOptions = [
3625
- ...this.globalCommand.options,
3626
- ...command ? command.options : []
3627
- ];
3628
- const mriOptions = getMriOptions(cliOptions);
3629
- let argsAfterDoubleDashes = [];
3630
- const doubleDashesIndex = argv.indexOf("--");
3631
- if (doubleDashesIndex > -1) {
3632
- argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
3633
- argv = argv.slice(0, doubleDashesIndex);
3634
- }
3635
- let parsed = mri2(argv, mriOptions);
3636
- parsed = Object.keys(parsed).reduce((res, name)=>__assign(__assign({}, res), {
3637
- [camelcaseOptionName(name)]: parsed[name]
3638
- }), {
3639
- _: []
3640
- });
3641
- const args = parsed._;
3642
- const options = {
3643
- "--": argsAfterDoubleDashes
3644
- };
3645
- const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
3646
- let transforms = Object.create(null);
3647
- for (const cliOption of cliOptions){
3648
- if (!ignoreDefault && void 0 !== cliOption.config.default) for (const name of cliOption.names)options[name] = cliOption.config.default;
3649
- if (Array.isArray(cliOption.config.type)) {
3650
- if (void 0 === transforms[cliOption.name]) {
3651
- transforms[cliOption.name] = Object.create(null);
3652
- transforms[cliOption.name]["shouldTransform"] = true;
3653
- transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
3654
- }
3655
- }
3656
- }
3657
- for (const key of Object.keys(parsed))if ("_" !== key) {
3658
- const keys = key.split(".");
3659
- setDotProp(options, keys, parsed[key]);
3660
- setByType(options, transforms);
3661
- }
3662
- return {
3663
- args,
3664
- options
3665
- };
3666
- }
3667
- runMatchedCommand() {
3668
- const { args, options, matchedCommand: command } = this;
3669
- if (!command || !command.commandAction) return;
3670
- command.checkUnknownOptions();
3671
- command.checkOptionValue();
3672
- command.checkRequiredArgs();
3673
- const actionArgs = [];
3674
- command.args.forEach((arg, index)=>{
3675
- if (arg.variadic) actionArgs.push(args.slice(index));
3676
- else actionArgs.push(args[index]);
3677
- });
3678
- actionArgs.push(options);
3679
- return command.commandAction.apply(this, actionArgs);
3680
- }
3681
- }
3682
- const cac = (name = "")=>new CAC(name);
3683
- const dist = cac;
3684
- var external_pathe_ = __webpack_require__("pathe");
3685
- var src_config = __webpack_require__("./src/config.ts");
3686
- var helper = __webpack_require__("./src/utils/helper.ts");
3687
- function initNodeEnv() {
3688
- if (!process.env.NODE_ENV) process.env.NODE_ENV = 'test';
3689
- }
3690
- function prepareCli() {
3691
- initNodeEnv();
3692
- process.env.RSTEST = 'true';
3693
- const { npm_execpath } = process.env;
3694
- if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
3695
- }
3696
- function showRstest() {
3697
- logger.k.greet(" Rstest v0.1.2");
3698
- logger.k.log('');
3699
- }
3700
- const applyCommonOptions = (cli)=>{
3701
- cli.option('-c, --config <config>', 'Specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'Specify the loader to load the config file, can be `jiti` or `native`', {
3702
- default: 'jiti'
3703
- }).option('-r, --root <root>', 'Specify the project root directory, can be an absolute path or a path relative to cwd').option('--globals', 'Provide global APIs').option('--isolate', 'Run tests in an isolated environment').option('--include <include>', 'Match test files').option('--exclude <exclude>', 'Exclude files from test').option('-u, --update', 'Update snapshot files').option('--passWithNoTests', 'Allows the test suite to pass when no files are found').option('--printConsoleTrace', 'Print console traces when calling any console method').option('--disableConsoleIntercept', 'Disable console intercept').option('--slowTestThreshold <value>', 'The number of milliseconds after which a test or suite is considered slow').option('--reporter <reporter>', 'Specify the reporter to use').option('-t, --testNamePattern <value>', 'Run only tests with a name that matches the regex').option('--testEnvironment <name>', 'The environment that will be used for testing').option('--testTimeout <value>', 'Timeout of a test in milliseconds').option('--hookTimeout <value>', 'Timeout of hook in milliseconds').option('--retry <retry>', 'Number of times to retry a test if it fails').option('--maxConcurrency <value>', 'Maximum number of concurrent tests').option('--clearMocks', 'Automatically clear mock calls, instances, contexts and results before every test').option('--resetMocks', 'Automatically reset mock state before every test').option('--restoreMocks', 'Automatically restore mock state and implementation before every test').option('--unstubGlobals', 'Restores all global variables that were changed with `rstest.stubGlobal` before every test').option('--unstubEnvs', 'Restores all `process.env` values that were changed with `rstest.stubEnv` before every test');
3704
- };
3705
- async function initCli(options) {
3706
- const cwd = process.cwd();
3707
- const root = options.root ? (0, helper.ZY)(cwd, options.root) : cwd;
3708
- const { content: config, filePath: configFilePath } = await (0, src_config.ME)({
3709
- cwd: root,
3710
- path: options.config,
3711
- configLoader: options.configLoader
3712
- });
3713
- const keys = [
3714
- 'root',
3715
- 'globals',
3716
- 'isolate',
3717
- 'passWithNoTests',
3718
- 'update',
3719
- 'testNamePattern',
3720
- 'testTimeout',
3721
- 'hookTimeout',
3722
- 'clearMocks',
3723
- 'resetMocks',
3724
- 'restoreMocks',
3725
- 'unstubEnvs',
3726
- 'unstubGlobals',
3727
- 'retry',
3728
- 'slowTestThreshold',
3729
- 'maxConcurrency',
3730
- 'printConsoleTrace',
3731
- 'disableConsoleIntercept',
3732
- 'testEnvironment'
3733
- ];
3734
- for (const key of keys)if (void 0 !== options[key]) config[key] = options[key];
3735
- if (options.exclude) config.exclude = (0, helper.XQ)(options.exclude);
3736
- if (options.reporter) config.reporters = (0, helper.XQ)(options.reporter);
3737
- if (options.include) config.include = (0, helper.XQ)(options.include);
3738
- return {
3739
- config,
3740
- configFilePath
3741
- };
3742
- }
3743
- function setupCommands() {
3744
- const cli = dist('rstest');
3745
- cli.help();
3746
- cli.version("0.1.2");
3747
- applyCommonOptions(cli);
3748
- cli.command('[...filters]', 'run tests').option('--watch', 'Run tests in watch mode').action(async (filters, options)=>{
3749
- showRstest();
3750
- if (options.watch) await runRest(options, filters, 'watch');
3751
- else await runRest(options, filters, 'run');
3752
- });
3753
- const runRest = async (options, filters, command)=>{
3754
- let rstest;
3755
- try {
3756
- const { config } = await initCli(options);
3757
- const { createRstest } = await __webpack_require__.e("359").then(__webpack_require__.bind(__webpack_require__, "./src/core/index.ts"));
3758
- rstest = createRstest(config, command, filters.map(external_pathe_.normalize));
3759
- await rstest.runTests();
3760
- } catch (err) {
3761
- for (const reporter of rstest?.context.reporters || [])reporter.onExit?.();
3762
- logger.k.error('Failed to run Rstest.');
3763
- logger.k.error((0, helper.Z)(err));
3764
- process.exit(1);
3765
- }
3766
- };
3767
- cli.command('run [...filters]', 'run tests without watch mode').action(async (filters, options)=>{
3768
- showRstest();
3769
- await runRest(options, filters, 'run');
3770
- });
3771
- cli.command('watch [...filters]', 'run tests in watch mode').action(async (filters, options)=>{
3772
- showRstest();
3773
- await runRest(options, filters, 'watch');
3774
- });
3775
- cli.command('list [...filters]', 'lists all test files that Rstest will run').option('--filesOnly', 'only list the test files').option('--json [boolean/path]', 'print tests as JSON or write to a file').action(async (filters, options)=>{
3776
- try {
3777
- const { config } = await initCli(options);
3778
- const { createRstest } = await __webpack_require__.e("359").then(__webpack_require__.bind(__webpack_require__, "./src/core/index.ts"));
3779
- const rstest = createRstest(config, 'list', filters.map(external_pathe_.normalize));
3780
- await rstest.listTests({
3781
- filesOnly: options.filesOnly,
3782
- json: options.json
3783
- });
3784
- } catch (err) {
3785
- logger.k.error('Failed to run Rstest list.');
3786
- logger.k.error((0, helper.Z)(err));
3787
- process.exit(1);
3788
- }
3789
- });
3790
- cli.parse();
3791
- }
3864
+ var commands = __webpack_require__("./src/cli/commands.ts");
3865
+ var prepare = __webpack_require__("./src/cli/prepare.ts");
3792
3866
  async function runCLI() {
3793
- prepareCli();
3867
+ (0, prepare.n)();
3794
3868
  try {
3795
- setupCommands();
3869
+ (0, commands.X_)();
3796
3870
  } catch (err) {
3797
3871
  logger.k.error('Failed to start Rstest CLI.');
3798
3872
  logger.k.error(err);
3799
3873
  }
3800
3874
  }
3801
- export { runCLI };
3875
+ var src_config = __webpack_require__("./src/config.ts");
3876
+ function defineConfig(config) {
3877
+ return config;
3878
+ }
3879
+ var __webpack_exports__mergeRstestConfig = src_config.en;
3880
+ export { defineConfig, runCLI, __webpack_exports__mergeRstestConfig as mergeRstestConfig };