@midscene/cli 1.9.4 → 1.9.5-beta-20260611031026.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.
@@ -8,7 +8,6 @@ import { getMidsceneRunSubDir } from "@midscene/shared/common";
8
8
  import { getDebug } from "@midscene/shared/logger";
9
9
  import { createRequire } from "node:module";
10
10
  import { pathToFileURL } from "node:url";
11
- import { test } from "@rstest/core";
12
11
  import { ScriptPlayer, parseYamlScript } from "@midscene/core/yaml";
13
12
  import { buildChromeArgs, defaultViewportHeight, defaultViewportWidth, puppeteerAgentForTarget } from "@midscene/web/puppeteer-agent-launcher";
14
13
  import lodash_merge from "lodash.merge";
@@ -2612,6 +2611,21 @@ function printExecutionSummary(results, summaryPath) {
2612
2611
  else console.log('\n⚠️ Some files failed or were not executed.');
2613
2612
  return success;
2614
2613
  }
2614
+ const requireFromCliPackage = ()=>{
2615
+ if ('undefined' != typeof __dirname) return createRequire(join(__dirname, 'index.js'));
2616
+ const entry = process.argv[1] ? external_node_path_resolve(process.argv[1]) : join(process.cwd(), 'midscene-cli.js');
2617
+ return createRequire(entry);
2618
+ };
2619
+ const resolvePackageFromRstestCore = (packageName)=>{
2620
+ const require = requireFromCliPackage();
2621
+ const rstestPackageJsonPath = require.resolve('@rstest/core/package.json');
2622
+ return createRequire(rstestPackageJsonPath).resolve(packageName);
2623
+ };
2624
+ function resolveRstestCoreImportPath() {
2625
+ const require = requireFromCliPackage();
2626
+ const packageJsonPath = require.resolve('@rstest/core/package.json');
2627
+ return join(dirname(packageJsonPath), 'dist', 'index.js');
2628
+ }
2615
2629
  const DEFAULT_YAML_TEST_TIMEOUT = 0;
2616
2630
  const RSTEST_YAML_BATCH_TEST_MODULE = 'virtual:midscene-yaml/batch.test.ts';
2617
2631
  const RSTEST_YAML_BATCH_TEST_NAME = 'midscene yaml batch';
@@ -2638,9 +2652,16 @@ const createGeneratedTestContent = (options)=>{
2638
2652
  webRuntimeOptions: options.webRuntimeOptions
2639
2653
  } : {}
2640
2654
  };
2641
- return `import { defineYamlCaseTest } from ${toImportLiteral(options.frameworkImport)};
2655
+ return `import { test } from ${toImportLiteral(options.rstestCoreImport)};
2656
+ import { defineYamlCaseTest } from ${toImportLiteral(options.frameworkImport)};
2642
2657
 
2643
- defineYamlCaseTest(${JSON.stringify(testOptions, null, 2)});
2658
+ const testOptions = ${JSON.stringify(testOptions, null, 2)};
2659
+
2660
+ if (defineYamlCaseTest.length >= 2) {
2661
+ defineYamlCaseTest(test, testOptions);
2662
+ } else {
2663
+ defineYamlCaseTest(testOptions);
2664
+ }
2644
2665
  `;
2645
2666
  };
2646
2667
  const createGeneratedBatchTestContent = (options)=>{
@@ -2649,9 +2670,16 @@ const createGeneratedBatchTestContent = (options)=>{
2649
2670
  config: options.config,
2650
2671
  resultFiles: options.resultFiles
2651
2672
  };
2652
- return `import { defineYamlBatchTest } from ${toImportLiteral(options.frameworkImport)};
2673
+ return `import { test } from ${toImportLiteral(options.rstestCoreImport)};
2674
+ import { defineYamlBatchTest } from ${toImportLiteral(options.frameworkImport)};
2675
+
2676
+ const testOptions = ${JSON.stringify(testOptions, null, 2)};
2653
2677
 
2654
- defineYamlBatchTest(${JSON.stringify(testOptions, null, 2)});
2678
+ if (defineYamlBatchTest.length >= 2) {
2679
+ defineYamlBatchTest(test, testOptions);
2680
+ } else {
2681
+ defineYamlBatchTest(testOptions);
2682
+ }
2655
2683
  `;
2656
2684
  };
2657
2685
  const resolveDefaultFrameworkImport = (moduleDir)=>{
@@ -2672,6 +2700,7 @@ function createRstestYamlProject(options) {
2672
2700
  const outputDir = options.outputDir || join(getMidsceneRunSubDir('tmp'), `rstest-yaml-${Date.now()}`);
2673
2701
  const resultDir = options.resultDir || join(outputDir, 'results');
2674
2702
  const frameworkImport = options.frameworkImport || resolveDefaultFrameworkImport();
2703
+ const rstestCoreImport = options.rstestCoreImport || resolveRstestCoreImportPath();
2675
2704
  const testTimeout = options.testTimeout ?? DEFAULT_YAML_TEST_TIMEOUT;
2676
2705
  rmSync(outputDir, {
2677
2706
  recursive: true,
@@ -2688,6 +2717,7 @@ function createRstestYamlProject(options) {
2688
2717
  const resultFile = join(resultDir, `${fileStem}.json`);
2689
2718
  const testModule = toVirtualModuleId(fileStem);
2690
2719
  virtualModules[testModule] = createGeneratedTestContent({
2720
+ rstestCoreImport,
2691
2721
  frameworkImport,
2692
2722
  yamlFile,
2693
2723
  resultFile,
@@ -2720,6 +2750,7 @@ function createRstestYamlProject(options) {
2720
2750
  ],
2721
2751
  virtualModules: {
2722
2752
  [batchTest.testModule]: createGeneratedBatchTestContent({
2753
+ rstestCoreImport,
2723
2754
  frameworkImport,
2724
2755
  testName: batchTest.testName,
2725
2756
  config: options.batchConfig,
@@ -2746,21 +2777,6 @@ function createRstestYamlProject(options) {
2746
2777
  retry: options.retry
2747
2778
  };
2748
2779
  }
2749
- const requireFromCliPackage = ()=>{
2750
- if ('undefined' != typeof __dirname) return createRequire(join(__dirname, 'index.js'));
2751
- const entry = process.argv[1] ? external_node_path_resolve(process.argv[1]) : join(process.cwd(), 'midscene-cli.js');
2752
- return createRequire(entry);
2753
- };
2754
- const resolvePackageFromRstestCore = (packageName)=>{
2755
- const require = requireFromCliPackage();
2756
- const rstestPackageJsonPath = require.resolve('@rstest/core/package.json');
2757
- return createRequire(rstestPackageJsonPath).resolve(packageName);
2758
- };
2759
- function resolveRstestCoreImportPath() {
2760
- const require = requireFromCliPackage();
2761
- const packageJsonPath = require.resolve('@rstest/core/package.json');
2762
- return join(dirname(packageJsonPath), 'dist', 'index.js');
2763
- }
2764
2780
  const formatRunError = (error)=>error.stack || `${error.name}: ${error.message}`;
2765
2781
  const collectRunErrors = (result)=>{
2766
2782
  const messages = [];
@@ -4093,7 +4109,12 @@ const createRuntimeFailureResult = (file, startTime, error)=>({
4093
4109
  resultType: 'failed',
4094
4110
  error: rstest_entry_errorMessageOf(error)
4095
4111
  });
4096
- function defineYamlCaseTest(options) {
4112
+ let rstestCorePromise;
4113
+ const loadRstestTest = async ()=>{
4114
+ if (!rstestCorePromise) rstestCorePromise = import("@rstest/core");
4115
+ return (await rstestCorePromise).test;
4116
+ };
4117
+ const registerYamlCaseTest = (test, options)=>{
4097
4118
  test(options.testName, async ()=>{
4098
4119
  const file = external_node_path_resolve(options.yamlFile);
4099
4120
  const startTime = Date.now();
@@ -4115,14 +4136,26 @@ function defineYamlCaseTest(options) {
4115
4136
  throw error;
4116
4137
  }
4117
4138
  });
4139
+ };
4140
+ function defineYamlCaseTest(testOrOptions, maybeOptions) {
4141
+ if (maybeOptions) return void registerYamlCaseTest(testOrOptions, maybeOptions);
4142
+ return loadRstestTest().then((test)=>{
4143
+ registerYamlCaseTest(test, testOrOptions);
4144
+ });
4118
4145
  }
4119
- function defineYamlBatchTest(options) {
4146
+ const registerYamlBatchTest = (test, options)=>{
4120
4147
  test(options.testName, async ()=>{
4121
4148
  await runYamlBatchInRstest({
4122
4149
  config: options.config,
4123
4150
  resultFiles: options.resultFiles
4124
4151
  });
4125
4152
  });
4153
+ };
4154
+ function defineYamlBatchTest(testOrOptions, maybeOptions) {
4155
+ if (maybeOptions) return void registerYamlBatchTest(testOrOptions, maybeOptions);
4156
+ return loadRstestTest().then((test)=>{
4157
+ registerYamlBatchTest(test, testOrOptions);
4158
+ });
4126
4159
  }
4127
4160
  export { createRstestYamlProject, createYamlCaseFailure, createYamlCaseResult, defineYamlBatchTest, defineYamlCaseTest, getYamlPlayerFailure, resolveRstestCoreImportPath, resolveTestName, runFrameworkTestConfig, runRstestYamlProject, runYamlBatchInRstest, runYamlCase, runYamlCaseResult };
4128
4161