@rstest/core 0.7.3 → 0.7.5

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/dist/131.js CHANGED
@@ -2,8 +2,10 @@ import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
3
  import { __webpack_require__ } from "./rslib-runtime.js";
4
4
  import { EventEmitter } from "events";
5
- import { createRsbuild, loadConfig, logger as core_logger, mergeRsbuildConfig } from "@rsbuild/core";
6
- import { DEFAULT_CONFIG_NAME, posix, globalApis, resolve as pathe_M_eThtNZ_resolve, pathe_M_eThtNZ_relative, filterProjects, join, glob, prettyTestPath, prettyTime, isAbsolute, TEMP_RSTEST_OUTPUT_DIR_GLOB, formatTestPath, TS_CONFIG_FILE, basename, logger_logger, dirname, isTTY, getAbsolutePath, bgColor, formatRootStr, isDynamicPattern, writeFile, castArray, isDebug, getTaskNameWithPrefix, DEFAULT_CONFIG_EXTENSIONS, formatError, normalize } from "./946.js";
5
+ import { createRsbuild, loadConfig, logger as core_logger, mergeRsbuildConfig, rspack } from "@rsbuild/core";
6
+ import "./693.js";
7
+ import { basename, logger_logger, dirname, posix, resolve as pathe_M_eThtNZ_resolve, isDebug, isAbsolute, relative, join, normalize } from "./278.js";
8
+ import { isTTY, DEFAULT_CONFIG_NAME, globalApis, filterProjects, getAbsolutePath, bgColor, formatRootStr, isDynamicPattern, glob, writeFile, castArray, prettyTestPath, prettyTime, TEMP_RSTEST_OUTPUT_DIR_GLOB, getTaskNameWithPrefix, formatTestPath, formatError, DEFAULT_CONFIG_EXTENSIONS, TS_CONFIG_FILE } from "./157.js";
7
9
  import { parse as stack_trace_parser_esm_parse } from "./672.js";
8
10
  import { decode } from "./397.js";
9
11
  function toArr(any) {
@@ -501,7 +503,7 @@ function prepareCli() {
501
503
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) logger_logger.log();
502
504
  }
503
505
  function showRstest() {
504
- logger_logger.greet(" Rstest v0.7.3");
506
+ logger_logger.greet(" Rstest v0.7.5");
505
507
  logger_logger.log('');
506
508
  }
507
509
  const applyCommonOptions = (cli)=>{
@@ -545,7 +547,7 @@ const runRest = async ({ options, filters, command })=>{
545
547
  function setupCommands() {
546
548
  const cli = dist('rstest');
547
549
  cli.help();
548
- cli.version("0.7.3");
550
+ cli.version("0.7.5");
549
551
  applyCommonOptions(cli);
550
552
  cli.command('[...filters]', 'run tests').option('-w, --watch', 'Run tests in watch mode').action(async (filters, options)=>{
551
553
  showRstest();
@@ -639,6 +641,7 @@ async function config_loadConfig({ cwd = process.cwd(), path, envMode, configLoa
639
641
  filePath: configFilePath
640
642
  };
641
643
  }
644
+ const mergeProjectConfig = (...configs)=>mergeRstestConfig(...configs);
642
645
  const mergeRstestConfig = (...configs)=>configs.reduce((result, config)=>{
643
646
  const merged = mergeRsbuildConfig(result, {
644
647
  ...config,
@@ -670,6 +673,7 @@ const createDefaultConfig = ()=>({
670
673
  override: false
671
674
  },
672
675
  setupFiles: [],
676
+ globalSetup: [],
673
677
  includeSource: [],
674
678
  pool: {
675
679
  type: 'forks'
@@ -733,6 +737,7 @@ const createDefaultConfig = ()=>({
733
737
  const withDefaultConfig = (config)=>{
734
738
  const merged = mergeRstestConfig(createDefaultConfig(), config);
735
739
  merged.setupFiles = castArray(merged.setupFiles);
740
+ merged.globalSetup = castArray(merged.globalSetup);
736
741
  merged.exclude.patterns.push(TEMP_RSTEST_OUTPUT_DIR_GLOB);
737
742
  const reportsDirectory = formatRootStr(merged.coverage.reportsDirectory, merged.root);
738
743
  merged.coverage.reportsDirectory = isAbsolute(reportsDirectory) ? reportsDirectory : pathe_M_eThtNZ_resolve(merged.root, reportsDirectory);
@@ -747,6 +752,7 @@ const withDefaultConfig = (config)=>{
747
752
  patterns: merged.exclude.patterns.map((p)=>formatRootStr(p, merged.root))
748
753
  },
749
754
  setupFiles: merged.setupFiles.map((p)=>formatRootStr(p, merged.root)),
755
+ globalSetup: merged.globalSetup.map((p)=>formatRootStr(p, merged.root)),
750
756
  includeSource: merged.includeSource.map((p)=>formatRootStr(p, merged.root))
751
757
  };
752
758
  };
@@ -787,12 +793,14 @@ function mergeWithCLIOptions(config, options) {
787
793
  }
788
794
  async function resolveConfig(options) {
789
795
  const { content: config, filePath: configFilePath } = await config_loadConfig({
790
- cwd: options.root,
796
+ cwd: options.cwd,
791
797
  path: options.config,
792
798
  configLoader: options.configLoader
793
799
  });
800
+ const mergedConfig = mergeWithCLIOptions(config, options);
801
+ if (!mergedConfig.root) mergedConfig.root = options.cwd;
794
802
  return {
795
- config: mergeWithCLIOptions(config, options),
803
+ config: mergedConfig,
796
804
  configFilePath: configFilePath ?? void 0
797
805
  };
798
806
  }
@@ -854,7 +862,7 @@ async function resolveProjects({ config, root, options }) {
854
862
  const { config, configFilePath } = await resolveConfig({
855
863
  ...options,
856
864
  config: isDirectory ? void 0 : project,
857
- root: projectRoot
865
+ cwd: projectRoot
858
866
  });
859
867
  if (configFilePath) {
860
868
  if (resolvedProjectPaths.has(configFilePath)) return;
@@ -896,7 +904,7 @@ async function init_initCli(options) {
896
904
  const root = options.root ? getAbsolutePath(cwd, options.root) : cwd;
897
905
  const { config, configFilePath } = await resolveConfig({
898
906
  ...options,
899
- root
907
+ cwd: options.root ? getAbsolutePath(cwd, options.root) : cwd
900
908
  });
901
909
  const projects = await resolveProjects({
902
910
  config,
@@ -1348,15 +1356,22 @@ const printSummaryLog = ({ results, testResults, snapshotSummary, duration, root
1348
1356
  logger_logger.log(`${DurationLabel} ${prettyTime(duration.totalTime)} ${picocolors_default().gray(`(build ${prettyTime(duration.buildTime)}, tests ${prettyTime(duration.testTime)})`)}`);
1349
1357
  logger_logger.log('');
1350
1358
  };
1351
- const printSummaryErrorLogs = async ({ testResults, results, rootPath, getSourcemap, filterRerunTestPaths })=>{
1359
+ const printSummaryErrorLogs = async ({ testResults, results, rootPath, unhandledErrors, getSourcemap, filterRerunTestPaths })=>{
1352
1360
  const failedTests = [
1353
1361
  ...results.filter((i)=>'fail' === i.status && i.errors?.length && (filterRerunTestPaths ? filterRerunTestPaths.includes(i.testPath) : true)),
1354
1362
  ...testResults.filter((i)=>'fail' === i.status && (filterRerunTestPaths ? filterRerunTestPaths.includes(i.testPath) : true))
1355
1363
  ];
1356
- if (0 === failedTests.length) return;
1364
+ if (0 === failedTests.length && !unhandledErrors?.length) return;
1357
1365
  logger_logger.stderr('');
1358
1366
  logger_logger.stderr(picocolors_default().bold('Summary of all failing tests:'));
1359
1367
  logger_logger.stderr('');
1368
+ const { printError } = await Promise.resolve().then(()=>({
1369
+ printError: error_printError
1370
+ }));
1371
+ for (const error of unhandledErrors || []){
1372
+ logger_logger.stderr(bgColor('bgRed', ' Unhandled Error '));
1373
+ await printError(error, getSourcemap, rootPath);
1374
+ }
1360
1375
  for (const test of failedTests){
1361
1376
  const relativePath = posix.relative(rootPath, test.testPath);
1362
1377
  const nameStr = getTaskNameWithPrefix(test);
@@ -1512,7 +1527,7 @@ class StatusRenderer {
1512
1527
  const testModules = this.testState.getTestModules();
1513
1528
  const shouldDisplayRunningTests = (runningTests)=>runningTests[0]?.startTime && now - runningTests[0].startTime > 2000;
1514
1529
  for (const [module, { runningTests }] of runningModules.entries()){
1515
- const relativePath = pathe_M_eThtNZ_relative(this.rootPath, module);
1530
+ const relativePath = relative(this.rootPath, module);
1516
1531
  summary.push(`${bgColor('bgYellow', ' RUNS ')} ${prettyTestPath(relativePath)}`);
1517
1532
  if (runningTests.length && shouldDisplayRunningTests(runningTests)) {
1518
1533
  let caseLog = ` ${picocolors_default().gray("➜")} ${getTaskNameWithPrefix(runningTests[0])} ${picocolors_default().magenta(prettyTime(now - runningTests[0].startTime))}`;
@@ -1591,7 +1606,7 @@ class DefaultReporter {
1591
1606
  }
1592
1607
  onTestFileResult(test) {
1593
1608
  this.statusRenderer?.onTestFileResult();
1594
- const relativePath = pathe_M_eThtNZ_relative(this.rootPath, test.testPath);
1609
+ const relativePath = relative(this.rootPath, test.testPath);
1595
1610
  const { slowTestThreshold } = this.config;
1596
1611
  logFileTitle(test, relativePath);
1597
1612
  for (const result of test.results){
@@ -1609,10 +1624,10 @@ class DefaultReporter {
1609
1624
  const shouldLog = this.config.onConsoleLog?.(log.content) ?? true;
1610
1625
  if (!shouldLog) return;
1611
1626
  const titles = [];
1612
- const testPath = pathe_M_eThtNZ_relative(this.rootPath, log.testPath);
1627
+ const testPath = relative(this.rootPath, log.testPath);
1613
1628
  if (log.trace) {
1614
1629
  const [frame] = stack_trace_parser_esm_parse(log.trace);
1615
- const filePath = pathe_M_eThtNZ_relative(this.rootPath, frame.file || '');
1630
+ const filePath = relative(this.rootPath, frame.file || '');
1616
1631
  if (filePath !== testPath) titles.push(testPath);
1617
1632
  titles.push(`${filePath}:${frame.lineNumber}:${frame.column}`);
1618
1633
  } else titles.push(testPath);
@@ -1625,12 +1640,13 @@ class DefaultReporter {
1625
1640
  async onExit() {
1626
1641
  this.statusRenderer?.clear();
1627
1642
  }
1628
- async onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths }) {
1643
+ async onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths, unhandledErrors }) {
1629
1644
  this.statusRenderer?.clear();
1630
1645
  if (false === this.options.summary) return;
1631
1646
  await printSummaryErrorLogs({
1632
1647
  testResults,
1633
1648
  results,
1649
+ unhandledErrors,
1634
1650
  rootPath: this.rootPath,
1635
1651
  getSourcemap,
1636
1652
  filterRerunTestPaths
@@ -1667,7 +1683,7 @@ class GithubActionsReporter {
1667
1683
  for (const test of failedTests){
1668
1684
  const { testPath } = test;
1669
1685
  const nameStr = getTaskNameWithPrefix(test);
1670
- const shortPath = pathe_M_eThtNZ_relative(this.rootPath, testPath);
1686
+ const shortPath = relative(this.rootPath, testPath);
1671
1687
  const title = `${shortPath} > ${nameStr}`;
1672
1688
  for (const error of test.errors || []){
1673
1689
  let file = testPath;
@@ -2012,6 +2028,8 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
2012
2028
  if (-1 === index || index === segments.length) return -1;
2013
2029
  return index;
2014
2030
  }
2031
+ const external_node_path_ = __webpack_require__("node:path");
2032
+ const isRelativePath = (p)=>/^\.\.?\//.test(p);
2015
2033
  const hintNotDefinedError = (message)=>{
2016
2034
  const [, varName] = message.match(/(\w+) is not defined/) || [];
2017
2035
  if (varName) {
@@ -2103,7 +2121,7 @@ async function error_parseErrorStacktrace({ stack, getSourcemap, fullStack = isD
2103
2121
  if (!source) return null;
2104
2122
  return {
2105
2123
  ...frame,
2106
- file: source,
2124
+ file: isRelativePath(source) ? (0, external_node_path_.resolve)(frame.file, '../', source) : new URL(source).pathname,
2107
2125
  lineNumber: line,
2108
2126
  name,
2109
2127
  column
@@ -2136,7 +2154,7 @@ class JUnitReporter {
2136
2154
  async createJUnitTestCase(test, getSourcemap) {
2137
2155
  const testCase = {
2138
2156
  name: getTaskNameWithPrefix(test),
2139
- classname: pathe_M_eThtNZ_relative(this.rootPath, test.testPath),
2157
+ classname: relative(this.rootPath, test.testPath),
2140
2158
  time: (test.duration || 0) / 1000,
2141
2159
  status: test.status
2142
2160
  };
@@ -2163,7 +2181,7 @@ class JUnitReporter {
2163
2181
  const skipped = testCases.filter((test)=>'skip' === test.status || 'todo' === test.status).length;
2164
2182
  const totalTime = testCases.reduce((sum, test)=>sum + test.time, 0);
2165
2183
  return {
2166
- name: pathe_M_eThtNZ_relative(this.rootPath, fileResult.testPath),
2184
+ name: relative(this.rootPath, fileResult.testPath),
2167
2185
  tests: testCases.length,
2168
2186
  failures,
2169
2187
  errors,
@@ -2235,7 +2253,7 @@ class JUnitReporter {
2235
2253
  class VerboseReporter extends DefaultReporter {
2236
2254
  onTestFileResult(test) {
2237
2255
  this.statusRenderer?.onTestFileResult();
2238
- const relativePath = pathe_M_eThtNZ_relative(this.rootPath, test.testPath);
2256
+ const relativePath = relative(this.rootPath, test.testPath);
2239
2257
  const { slowTestThreshold } = this.config;
2240
2258
  logFileTitle(test, relativePath, true);
2241
2259
  for (const result of test.results)logCase(result, {
@@ -2346,7 +2364,7 @@ class Rstest {
2346
2364
  });
2347
2365
  this.reporters = reporters;
2348
2366
  this.snapshotManager = snapshotManager;
2349
- this.version = "0.7.3";
2367
+ this.version = "0.7.5";
2350
2368
  this.rootPath = rootPath;
2351
2369
  this.originalConfig = userConfig;
2352
2370
  this.normalizedConfig = rstestConfig;
@@ -2366,6 +2384,7 @@ class Rstest {
2366
2384
  configFilePath: project.configFilePath,
2367
2385
  rootPath: config.root,
2368
2386
  name: config.name,
2387
+ _globalSetups: false,
2369
2388
  outputModule: config.output?.module ?? 'true' === process.env.RSTEST_OUTPUT_MODULE,
2370
2389
  environmentName: formatEnvironmentName(config.name),
2371
2390
  normalizedConfig: config
@@ -2374,6 +2393,7 @@ class Rstest {
2374
2393
  {
2375
2394
  configFilePath,
2376
2395
  rootPath,
2396
+ _globalSetups: false,
2377
2397
  name: rstestConfig.name,
2378
2398
  outputModule: rstestConfig.output?.module ?? 'true' === process.env.RSTEST_OUTPUT_MODULE,
2379
2399
  environmentName: formatEnvironmentName(rstestConfig.name),
@@ -2489,4 +2509,4 @@ function defineConfig(config) {
2489
2509
  function defineProject(config) {
2490
2510
  return config;
2491
2511
  }
2492
- export { EventEmitter, afterAll, afterEach, assert, beforeAll, beforeEach, config_loadConfig as loadConfig, core_createRstest as createRstest, core_logger, createRsbuild, defineConfig, defineProject, describe, error_printError, expect, init_initCli as initCli, it, mergeRstestConfig, onTestFailed, onTestFinished, public_rstest as rstest, public_test as test, rs, runCLI, runRest };
2512
+ export { EventEmitter, afterAll, afterEach, assert, beforeAll, beforeEach, config_loadConfig as loadConfig, core_createRstest as createRstest, core_logger, createRsbuild, defineConfig, defineProject, describe, error_printError, expect, init_initCli as initCli, it, mergeProjectConfig, mergeRstestConfig, onTestFailed, onTestFinished, public_rstest as rstest, public_test as test, rs, rspack, runCLI, runRest };