@rstest/core 0.5.3 → 0.5.4

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/0~816.js CHANGED
@@ -728,6 +728,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
728
728
  b: ()=>createPool
729
729
  });
730
730
  var external_node_os_ = __webpack_require__("node:os");
731
+ var pathe_M_eThtNZ = __webpack_require__("../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs");
731
732
  var utils = __webpack_require__("./src/utils/index.ts");
732
733
  var memory = __webpack_require__("./src/utils/memory.ts");
733
734
  var external_node_url_ = __webpack_require__("node:url");
@@ -893,7 +894,6 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
893
894
  while(i--)id += urlAlphabet[64 * random() | 0];
894
895
  return id;
895
896
  }
896
- var pathe_M_eThtNZ = __webpack_require__("../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs");
897
897
  const forks_filename = (0, external_node_url_.fileURLToPath)(import.meta.url);
898
898
  const forks_dirname = (0, pathe_M_eThtNZ.d)(forks_filename);
899
899
  function createChannel(rpcMethods) {
@@ -1047,6 +1047,12 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
1047
1047
  },
1048
1048
  onTestFileStart: async (test)=>{
1049
1049
  await Promise.all(reporters.map((reporter)=>reporter.onTestFileStart?.(test)));
1050
+ },
1051
+ resolveSnapshotPath: (testPath)=>{
1052
+ const snapExtension = '.snap';
1053
+ const resolver = context.normalizedConfig.resolveSnapshotPath || (()=>(0, pathe_M_eThtNZ.j)((0, pathe_M_eThtNZ.d)(testPath), '__snapshots__', `${(0, pathe_M_eThtNZ.c)(testPath)}${snapExtension}`));
1054
+ const snapshotPath = resolver(testPath, snapExtension);
1055
+ return snapshotPath;
1050
1056
  }
1051
1057
  };
1052
1058
  return {
package/dist/index.js CHANGED
@@ -2076,7 +2076,7 @@ ${section.body}` : section.body).join("\n\n"));
2076
2076
  const applyCommonOptions = (cli)=>{
2077
2077
  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`', {
2078
2078
  default: 'jiti'
2079
- }).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('--coverage', 'Enable code coverage collection').option('--project <name>', 'Run only projects that match the name, can be a full name or wildcards pattern').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');
2079
+ }).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('--coverage', 'Enable code coverage collection').option('--project <name>', 'Run only projects that match the name, can be a full name or wildcards pattern').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('--hideSkippedTests', 'Hide skipped tests from the output').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');
2080
2080
  };
2081
2081
  const runRest = async ({ options, filters, command })=>{
2082
2082
  let rstest;
@@ -2108,7 +2108,7 @@ ${section.body}` : section.body).join("\n\n"));
2108
2108
  function setupCommands() {
2109
2109
  const cli = dist('rstest');
2110
2110
  cli.help();
2111
- cli.version("0.5.3");
2111
+ cli.version("0.5.4");
2112
2112
  applyCommonOptions(cli);
2113
2113
  cli.command('[...filters]', 'run tests').option('-w, --watch', 'Run tests in watch mode').action(async (filters, options)=>{
2114
2114
  (0, prepare.N)();
@@ -2215,7 +2215,8 @@ ${section.body}` : section.body).join("\n\n"));
2215
2215
  'maxConcurrency',
2216
2216
  'printConsoleTrace',
2217
2217
  'disableConsoleIntercept',
2218
- 'testEnvironment'
2218
+ 'testEnvironment',
2219
+ 'hideSkippedTests'
2219
2220
  ];
2220
2221
  for (const key of keys)if (void 0 !== options[key]) config[key] = options[key];
2221
2222
  if (options.reporter) config.reporters = (0, utils.bg)(options.reporter);
@@ -2347,7 +2348,7 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
2347
2348
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
2348
2349
  }
2349
2350
  function showRstest() {
2350
- _utils_logger__WEBPACK_IMPORTED_MODULE_0__.vF.greet(" Rstest v0.5.3");
2351
+ _utils_logger__WEBPACK_IMPORTED_MODULE_0__.vF.greet(" Rstest v0.5.4");
2351
2352
  _utils_logger__WEBPACK_IMPORTED_MODULE_0__.vF.log('');
2352
2353
  }
2353
2354
  },
@@ -2452,6 +2453,7 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
2452
2453
  disableConsoleIntercept: false,
2453
2454
  snapshotFormat: {},
2454
2455
  env: {},
2456
+ hideSkippedTests: false,
2455
2457
  coverage: {
2456
2458
  exclude: [
2457
2459
  '**/node_modules/**',
@@ -3144,8 +3146,9 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
3144
3146
  todo: utils.yW.gray(statusStr.todo),
3145
3147
  skip: utils.yW.gray(statusStr.skip)
3146
3148
  };
3147
- const logCase = (result, slowTestThreshold)=>{
3148
- const isSlowCase = (result.duration || 0) > slowTestThreshold;
3149
+ const logCase = (result, options)=>{
3150
+ const isSlowCase = (result.duration || 0) > options.slowTestThreshold;
3151
+ if (options.hideSkippedTests && 'skip' === result.status) return;
3149
3152
  const icon = isSlowCase && 'pass' === result.status ? utils.yW.yellow(statusStr[result.status]) : statusColorfulStr[result.status];
3150
3153
  const nameStr = (0, utils.fN)(result);
3151
3154
  const duration = void 0 !== result.duration ? ` (${(0, utils.kV)(result.duration)})` : '';
@@ -3181,7 +3184,10 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
3181
3184
  logFileTitle(test, relativePath);
3182
3185
  for (const result of test.results){
3183
3186
  const isDisplayed = 'fail' === result.status || (result.duration ?? 0) > slowTestThreshold || (result.retryCount ?? 0) > 0;
3184
- isDisplayed && logCase(result, slowTestThreshold);
3187
+ isDisplayed && logCase(result, {
3188
+ slowTestThreshold,
3189
+ hideSkippedTests: this.config.hideSkippedTests
3190
+ });
3185
3191
  }
3186
3192
  }
3187
3193
  onTestCaseResult(result) {
@@ -3190,17 +3196,16 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
3190
3196
  onUserConsoleLog(log) {
3191
3197
  const shouldLog = this.config.onConsoleLog?.(log.content) ?? true;
3192
3198
  if (!shouldLog) return;
3193
- const titles = [
3194
- log.name
3195
- ];
3199
+ const titles = [];
3196
3200
  const testPath = (0, pathe_M_eThtNZ.b)(this.rootPath, log.testPath);
3197
3201
  if (log.trace) {
3198
3202
  const [frame] = (0, stack_trace_parser_esm.q)(log.trace);
3199
3203
  const filePath = (0, pathe_M_eThtNZ.b)(this.rootPath, frame.file || '');
3200
- if (filePath !== testPath) titles.push((0, utils.EQ)(testPath));
3201
- titles.push((0, utils.EQ)(filePath) + utils.yW.gray(`:${frame.lineNumber}:${frame.column}`));
3202
- } else titles.push((0, utils.EQ)(testPath));
3203
- utils.vF.log(titles.join(utils.yW.gray(' | ')));
3204
+ if (filePath !== testPath) titles.push(testPath);
3205
+ titles.push(`${filePath}:${frame.lineNumber}:${frame.column}`);
3206
+ } else titles.push(testPath);
3207
+ utils.vF.log('');
3208
+ utils.vF.log(`${log.name}${utils.yW.gray(utils.yW.dim(` | ${titles.join(utils.yW.gray(utils.yW.dim(' | ')))}`))}`);
3204
3209
  utils.vF.log(log.content);
3205
3210
  utils.vF.log('');
3206
3211
  }
@@ -3418,7 +3423,10 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
3418
3423
  const relativePath = (0, pathe_M_eThtNZ.b)(this.rootPath, test.testPath);
3419
3424
  const { slowTestThreshold } = this.config;
3420
3425
  logFileTitle(test, relativePath, true);
3421
- for (const result of test.results)logCase(result, slowTestThreshold);
3426
+ for (const result of test.results)logCase(result, {
3427
+ slowTestThreshold,
3428
+ hideSkippedTests: this.config.hideSkippedTests
3429
+ });
3422
3430
  }
3423
3431
  }
3424
3432
  function formatEnvironmentName(name) {
@@ -3460,11 +3468,12 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
3460
3468
  });
3461
3469
  this.reporters = reporters;
3462
3470
  this.snapshotManager = snapshotManager;
3463
- this.version = "0.5.3";
3471
+ this.version = "0.5.4";
3464
3472
  this.rootPath = rootPath;
3465
3473
  this.originalConfig = userConfig;
3466
3474
  this.normalizedConfig = rstestConfig;
3467
3475
  this.projects = projects.length ? projects.map((project)=>{
3476
+ project.config.root = (0, utils.FI)(rootPath, project.config.root);
3468
3477
  const config = (0, src_config.wX)(project.config);
3469
3478
  config.isolate = rstestConfig.isolate;
3470
3479
  config.source ??= {};
@@ -4014,6 +4023,18 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
4014
4023
  }
4015
4024
  var stack_trace_parser_esm = __webpack_require__("../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js");
4016
4025
  var utils = __webpack_require__("./src/utils/index.ts");
4026
+ const hintNotDefinedError = (message)=>{
4027
+ const [, varName] = message.match(/(\w+) is not defined/) || [];
4028
+ if (varName) {
4029
+ if (utils.TE.includes(varName)) return message.replace(`${varName} is not defined`, `${varName} is not defined. Did you forget to enable "globals" configuration?`);
4030
+ if ([
4031
+ 'jest',
4032
+ 'vitest'
4033
+ ].includes(varName)) return message.replace(`${varName} is not defined`, `${varName} is not defined. Did you mean rstest?`);
4034
+ if ('React' === varName) return message.replace(`${varName} is not defined`, `${varName} is not defined. Did you forget to install "${utils.yW.yellow('@rsbuild/plugin-react')}" plugin?`);
4035
+ }
4036
+ return message;
4037
+ };
4017
4038
  async function printError(error, getSourcemap, rootPath) {
4018
4039
  const errorName = error.name || 'Unknown Error';
4019
4040
  if (error.message.includes('Vitest failed to access its internal state')) {
@@ -4026,16 +4047,7 @@ ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')
4026
4047
  utils.vF.log(`${utils.yW.red(tips.join('\n'))}\n`);
4027
4048
  return;
4028
4049
  }
4029
- if (error.message.includes('is not defined')) {
4030
- const [, varName] = error.message.match(/(.*) is not defined/) || [];
4031
- if (varName) {
4032
- if (utils.TE.includes(varName)) error.message = error.message.replace(`${varName} is not defined`, `${varName} is not defined. Did you forget to enable "globals" configuration?`);
4033
- else if ([
4034
- 'jest',
4035
- 'vitest'
4036
- ].includes(varName)) error.message = error.message.replace(`${varName} is not defined`, `${varName} is not defined. Did you mean rstest?`);
4037
- }
4038
- }
4050
+ if (error.message.includes('is not defined')) error.message = hintNotDefinedError(error.message);
4039
4051
  utils.vF.log(`${utils.yW.red(utils.yW.bold(errorName))}${utils.yW.red(`: ${error.message}`)}\n`);
4040
4052
  if (error.diff) {
4041
4053
  utils.vF.log(error.diff);
package/dist/worker.js CHANGED
@@ -8199,9 +8199,17 @@ class NodeSnapshotEnvironment {
8199
8199
  }
8200
8200
  }
8201
8201
  class RstestSnapshotEnvironment extends NodeSnapshotEnvironment {
8202
+ resolveSnapshotPath;
8203
+ constructor(options){
8204
+ super();
8205
+ this.resolveSnapshotPath = options.resolveSnapshotPath;
8206
+ }
8202
8207
  getHeader() {
8203
8208
  return `// Rstest Snapshot v${this.getVersion()}`;
8204
8209
  }
8210
+ resolvePath(filepath) {
8211
+ return this.resolveSnapshotPath(filepath);
8212
+ }
8205
8213
  }
8206
8214
  let sourceMaps = {};
8207
8215
  (0, source_map_support.install)({
@@ -8242,7 +8250,9 @@ const preparePool = async ({ entryInfo: { distPath, testPath }, updateSnapshot,
8242
8250
  ...context,
8243
8251
  snapshotOptions: {
8244
8252
  updateSnapshot,
8245
- snapshotEnvironment: new RstestSnapshotEnvironment(),
8253
+ snapshotEnvironment: new RstestSnapshotEnvironment({
8254
+ resolveSnapshotPath: (filepath)=>rpc.resolveSnapshotPath(filepath)
8255
+ }),
8246
8256
  snapshotFormat
8247
8257
  },
8248
8258
  distPath,
@@ -332,6 +332,7 @@ declare type CommonOptions = {
332
332
  retry?: number;
333
333
  maxConcurrency?: number;
334
334
  slowTestThreshold?: number;
335
+ hideSkippedTests?: boolean;
335
336
  };
336
337
 
337
338
  declare type CompareKeys = ((a: string, b: string) => number) | null | undefined;
@@ -1938,7 +1939,7 @@ declare type OnTestFinishedHandler = (params: {
1938
1939
  };
1939
1940
  }) => MaybePromise<void>;
1940
1941
 
1941
- declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1942
+ declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'resolveSnapshotPath';
1942
1943
 
1943
1944
  declare type OptionsReceived = PrettyFormatOptions;
1944
1945
 
@@ -2226,6 +2227,12 @@ export declare interface RstestConfig {
2226
2227
  * @default ['default']
2227
2228
  */
2228
2229
  reporters?: Reporter | BuiltInReporterNames | (Reporter | BuiltInReporterNames | [BuiltInReporterNames] | ReporterWithOptions)[];
2230
+ /**
2231
+ * Hide skipped tests logs.
2232
+ *
2233
+ * @default false
2234
+ */
2235
+ hideSkippedTests?: boolean;
2229
2236
  /**
2230
2237
  * Run only tests with a name that matches the regex.
2231
2238
  */
@@ -2281,6 +2288,10 @@ export declare interface RstestConfig {
2281
2288
  onConsoleLog?: (content: string) => boolean | void;
2282
2289
  /** Format snapshot output */
2283
2290
  snapshotFormat?: SnapshotFormat;
2291
+ /**
2292
+ * Resolve custom snapshot path
2293
+ */
2294
+ resolveSnapshotPath?: (testPath: string, snapExtension: string) => string;
2284
2295
  /**
2285
2296
  * Custom environment variables available on `process.env` during tests.
2286
2297
  */
@@ -1614,7 +1614,7 @@ declare type OnTestFinishedHandler = (params: {
1614
1614
  };
1615
1615
  }) => MaybePromise<void>;
1616
1616
 
1617
- declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
1617
+ declare type OptionalKeys = 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog' | 'resolveSnapshotPath';
1618
1618
 
1619
1619
  declare type OptionsReceived = PrettyFormatOptions;
1620
1620
 
@@ -1882,6 +1882,12 @@ declare interface RstestConfig {
1882
1882
  * @default ['default']
1883
1883
  */
1884
1884
  reporters?: Reporter | BuiltInReporterNames | (Reporter | BuiltInReporterNames | [BuiltInReporterNames] | ReporterWithOptions)[];
1885
+ /**
1886
+ * Hide skipped tests logs.
1887
+ *
1888
+ * @default false
1889
+ */
1890
+ hideSkippedTests?: boolean;
1885
1891
  /**
1886
1892
  * Run only tests with a name that matches the regex.
1887
1893
  */
@@ -1937,6 +1943,10 @@ declare interface RstestConfig {
1937
1943
  onConsoleLog?: (content: string) => boolean | void;
1938
1944
  /** Format snapshot output */
1939
1945
  snapshotFormat?: SnapshotFormat;
1946
+ /**
1947
+ * Resolve custom snapshot path
1948
+ */
1949
+ resolveSnapshotPath?: (testPath: string, snapExtension: string) => string;
1940
1950
  /**
1941
1951
  * Custom environment variables available on `process.env` during tests.
1942
1952
  */
@@ -2027,6 +2037,7 @@ declare type RuntimeRPC = {
2027
2037
  }>;
2028
2038
  onTestCaseResult: (result: TestResult) => Promise<void>;
2029
2039
  onConsoleLog: (log: UserConsoleLog) => void;
2040
+ resolveSnapshotPath: (filepath: string) => string;
2030
2041
  };
2031
2042
 
2032
2043
  declare type RunWorkerOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"