@rstest/core 0.0.10 → 0.1.1

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/worker.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*! For license information please see worker.js.LICENSE.txt */
2
+ import __rslib_shim_module__ from 'module';
3
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
2
4
  import node_process from "node:process";
3
- import * as __WEBPACK_EXTERNAL_MODULE__vitest_expect_97b57ccd__ from "@vitest/expect";
4
- import * as __WEBPACK_EXTERNAL_MODULE__vitest_snapshot_692a7094__ from "@vitest/snapshot";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_chai__ from "chai";
6
6
  import * as __WEBPACK_EXTERNAL_MODULE_node_assert_3e74d44e__ from "node:assert";
7
7
  import * as __WEBPACK_EXTERNAL_MODULE_node_console_8631dfae__ from "node:console";
@@ -10,7 +10,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/
10
10
  import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
11
11
  import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
12
12
  import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
13
- import * as __WEBPACK_EXTERNAL_MODULE_node_timers_7045d530__ from "node:timers";
14
13
  import * as __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__ from "node:tty";
15
14
  import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
16
15
  import * as __WEBPACK_EXTERNAL_MODULE_pathe__ from "pathe";
@@ -18,7 +17,6 @@ import { pathToFileURL } from "node:url";
18
17
  import node_vm from "node:vm";
19
18
  import node_v8 from "node:v8";
20
19
  import { createBirpc } from "birpc";
21
- import { NodeSnapshotEnvironment } from "@vitest/snapshot/environment";
22
20
  var __webpack_modules__ = {
23
21
  "../../node_modules/.pnpm/@jest+diff-sequences@30.0.1/node_modules/@jest/diff-sequences/build/index.js": function(module) {
24
22
  /*!
@@ -4969,8 +4967,11 @@ var __webpack_modules__ = {
4969
4967
  },
4970
4968
  "./src/runtime/util.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
4971
4969
  __webpack_require__.d(__webpack_exports__, {
4972
- K: ()=>formatName,
4973
- o: ()=>formatTestError
4970
+ KY: ()=>formatName,
4971
+ BH: ()=>getRealTimers,
4972
+ CD: ()=>setRealTimers,
4973
+ Ni: ()=>TestRegisterError,
4974
+ ov: ()=>formatTestError
4974
4975
  });
4975
4976
  var external_node_util_ = __webpack_require__("node:util");
4976
4977
  var build = __webpack_require__("../../node_modules/.pnpm/jest-diff@30.0.5/node_modules/jest-diff/build/index.js");
@@ -4984,7 +4985,12 @@ var __webpack_modules__ = {
4984
4985
  build.diffLinesUnified2;
4985
4986
  build.diffStringsRaw;
4986
4987
  build.diffStringsUnified;
4987
- const formatTestError = (err)=>{
4988
+ const REAL_TIMERS = {};
4989
+ const setRealTimers = ()=>{
4990
+ REAL_TIMERS.setTimeout ??= globalThis.setTimeout;
4991
+ };
4992
+ const getRealTimers = ()=>REAL_TIMERS;
4993
+ const formatTestError = (err, test)=>{
4988
4994
  const errors = Array.isArray(err) ? err : [
4989
4995
  err
4990
4996
  ];
@@ -4995,6 +5001,7 @@ var __webpack_modules__ = {
4995
5001
  name: error.name,
4996
5002
  stack: error.stack
4997
5003
  };
5004
+ if (error instanceof TestRegisterError && test?.type === 'case') errObj.message = `Can't nest describe or test inside a test. ${error.message} because it is nested within test '${test.name}'`;
4998
5005
  if (error.showDiff || void 0 === error.showDiff && void 0 !== error.expected && void 0 !== error.actual) errObj.diff = diff(err.expected, err.actual);
4999
5006
  for (const key of [
5000
5007
  'actual',
@@ -5027,6 +5034,8 @@ var __webpack_modules__ = {
5027
5034
  }
5028
5035
  return result;
5029
5036
  }
5037
+ class TestRegisterError extends Error {
5038
+ }
5030
5039
  },
5031
5040
  "./src/runtime/worker/setup.ts": function() {
5032
5041
  const gracefulExit = process.execArgv.some((execArg)=>execArg.startsWith('--perf') || execArg.startsWith('--prof') || execArg.startsWith('--cpu-prof') || execArg.startsWith('--heap-prof') || execArg.startsWith('--diagnostic-dir'));
@@ -5399,12 +5408,6 @@ var __webpack_modules__ = {
5399
5408
  "timers/promises": function(module) {
5400
5409
  module.exports = require("timers/promises");
5401
5410
  },
5402
- "@vitest/expect": function(module) {
5403
- module.exports = __WEBPACK_EXTERNAL_MODULE__vitest_expect_97b57ccd__;
5404
- },
5405
- "@vitest/snapshot": function(module) {
5406
- module.exports = __WEBPACK_EXTERNAL_MODULE__vitest_snapshot_692a7094__;
5407
- },
5408
5411
  chai: function(module) {
5409
5412
  module.exports = __WEBPACK_EXTERNAL_MODULE_chai__;
5410
5413
  },
@@ -5429,9 +5432,6 @@ var __webpack_modules__ = {
5429
5432
  "node:path": function(module) {
5430
5433
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__;
5431
5434
  },
5432
- "node:timers": function(module) {
5433
- module.exports = __WEBPACK_EXTERNAL_MODULE_node_timers_7045d530__;
5434
- },
5435
5435
  "node:tty": function(module) {
5436
5436
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_tty_c64aab7e__;
5437
5437
  },
@@ -5626,7 +5626,7 @@ const createRequire = (filename, distPath, rstestContext, assetFiles, interopDef
5626
5626
  return (0, external_node_module_.createRequire)(distPath);
5627
5627
  }
5628
5628
  })();
5629
- const require1 = (id)=>{
5629
+ const require = (id)=>{
5630
5630
  const currentDirectory = external_pathe_["default"].dirname(distPath);
5631
5631
  const joinedPath = isRelativePath(id) ? external_pathe_["default"].join(currentDirectory, id) : id;
5632
5632
  const content = assetFiles[joinedPath];
@@ -5645,9 +5645,9 @@ const createRequire = (filename, distPath, rstestContext, assetFiles, interopDef
5645
5645
  const resolved = _require.resolve(id);
5646
5646
  return _require(resolved);
5647
5647
  };
5648
- require1.resolve = _require.resolve;
5649
- require1.main = _require.main;
5650
- return require1;
5648
+ require.resolve = _require.resolve;
5649
+ require.main = _require.main;
5650
+ return require;
5651
5651
  };
5652
5652
  const defineRstestDynamicImport = ({ testPath, interopDefault, returnModule = false })=>async (specifier, importAttributes)=>{
5653
5653
  const resolvedPath = (0, external_node_path_.isAbsolute)(specifier) ? pathToFileURL(specifier) : await import.meta.resolve(specifier, pathToFileURL(testPath));
@@ -5762,6 +5762,42 @@ function createRuntimeRpc(options) {
5762
5762
  rpc
5763
5763
  };
5764
5764
  }
5765
+ var external_node_fs_ = __webpack_require__("fs");
5766
+ class NodeSnapshotEnvironment {
5767
+ constructor(options = {}){
5768
+ this.options = options;
5769
+ }
5770
+ getVersion() {
5771
+ return "1";
5772
+ }
5773
+ getHeader() {
5774
+ return `// Snapshot v${this.getVersion()}`;
5775
+ }
5776
+ async resolveRawPath(testPath, rawPath) {
5777
+ return (0, external_pathe_.isAbsolute)(rawPath) ? rawPath : (0, external_pathe_.resolve)((0, external_pathe_.dirname)(testPath), rawPath);
5778
+ }
5779
+ async resolvePath(filepath) {
5780
+ return (0, external_pathe_.join)((0, external_pathe_.join)((0, external_pathe_.dirname)(filepath), this.options.snapshotsDirName ?? "__snapshots__"), `${(0, external_pathe_.basename)(filepath)}.snap`);
5781
+ }
5782
+ async prepareDirectory(dirPath) {
5783
+ await external_node_fs_.promises.mkdir(dirPath, {
5784
+ recursive: true
5785
+ });
5786
+ }
5787
+ async saveSnapshotFile(filepath, snapshot) {
5788
+ await external_node_fs_.promises.mkdir((0, external_pathe_.dirname)(filepath), {
5789
+ recursive: true
5790
+ });
5791
+ await external_node_fs_.promises.writeFile(filepath, snapshot, "utf-8");
5792
+ }
5793
+ async readSnapshotFile(filepath) {
5794
+ if (!(0, external_node_fs_.existsSync)(filepath)) return null;
5795
+ return external_node_fs_.promises.readFile(filepath, "utf-8");
5796
+ }
5797
+ async removeSnapshotFile(filepath) {
5798
+ if ((0, external_node_fs_.existsSync)(filepath)) await external_node_fs_.promises.unlink(filepath);
5799
+ }
5800
+ }
5765
5801
  class RstestSnapshotEnvironment extends NodeSnapshotEnvironment {
5766
5802
  getHeader() {
5767
5803
  return `// Rstest Snapshot v${this.getVersion()}`;
@@ -5774,6 +5810,7 @@ const getGlobalApi = (api)=>constants.io.reduce((apis, key)=>{
5774
5810
  const listeners = [];
5775
5811
  let isTeardown = false;
5776
5812
  const preparePool = async ({ entryInfo: { distPath, testPath }, sourceMaps, updateSnapshot, context })=>{
5813
+ (0, util.CD)();
5777
5814
  context.runtimeConfig = (0, helper.PQ)(context.runtimeConfig);
5778
5815
  const cleanupFns = [];
5779
5816
  const { rpc } = createRuntimeRpc(createForksRpcOptions());
@@ -5798,7 +5835,7 @@ const preparePool = async ({ entryInfo: { distPath, testPath }, sourceMaps, upda
5798
5835
  environment: 'node'
5799
5836
  };
5800
5837
  const { createRstestRuntime } = await Promise.all([
5801
- __webpack_require__.e("81"),
5838
+ __webpack_require__.e("208"),
5802
5839
  __webpack_require__.e("867")
5803
5840
  ]).then(__webpack_require__.bind(__webpack_require__, "./src/runtime/api/index.ts"));
5804
5841
  const { install } = await __webpack_require__.e("64").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js", 23));
@@ -5815,13 +5852,14 @@ const preparePool = async ({ entryInfo: { distPath, testPath }, sourceMaps, upda
5815
5852
  listeners.length = 0;
5816
5853
  const unhandledErrors = [];
5817
5854
  const handleError = (e, type)=>{
5818
- e.name = type;
5855
+ const error = 'string' == typeof e ? new Error(e) : e;
5856
+ error.name = type;
5819
5857
  if (isTeardown) {
5820
- e.stack = `${helper.$_.yellow('Caught error after test environment was torn down:')}\n\n${e.stack}`;
5821
- console.error(e);
5858
+ error.stack = `${helper.$_.yellow('Caught error after test environment was torn down:')}\n\n${error.stack}`;
5859
+ console.error(error);
5822
5860
  } else {
5823
- console.error(e);
5824
- unhandledErrors.push(e);
5861
+ console.error(error);
5862
+ unhandledErrors.push(error);
5825
5863
  }
5826
5864
  };
5827
5865
  const uncaughtException = (e)=>handleError(e, 'uncaughtException');
@@ -5833,14 +5871,25 @@ const preparePool = async ({ entryInfo: { distPath, testPath }, sourceMaps, upda
5833
5871
  process.off('unhandledRejection', unhandledRejection);
5834
5872
  });
5835
5873
  const { api, runner } = createRstestRuntime(workerState);
5836
- if ('jsdom' === testEnvironment) {
5837
- const { environment } = await __webpack_require__.e("965").then(__webpack_require__.bind(__webpack_require__, "./src/runtime/worker/env/jsdom.ts"));
5838
- const { teardown } = await environment.setup(global, {});
5839
- cleanupFns.push(()=>teardown(global));
5840
- } else if ('happy-dom' === testEnvironment) {
5841
- const { environment } = await __webpack_require__.e("44").then(__webpack_require__.bind(__webpack_require__, "./src/runtime/worker/env/happyDom.ts"));
5842
- const { teardown } = await environment.setup(global, {});
5843
- cleanupFns.push(async ()=>await teardown(global));
5874
+ switch(testEnvironment){
5875
+ case 'node':
5876
+ break;
5877
+ case 'jsdom':
5878
+ {
5879
+ const { environment } = await __webpack_require__.e("965").then(__webpack_require__.bind(__webpack_require__, "./src/runtime/worker/env/jsdom.ts"));
5880
+ const { teardown } = await environment.setup(global, {});
5881
+ cleanupFns.push(()=>teardown(global));
5882
+ break;
5883
+ }
5884
+ case 'happy-dom':
5885
+ {
5886
+ const { environment } = await __webpack_require__.e("44").then(__webpack_require__.bind(__webpack_require__, "./src/runtime/worker/env/happyDom.ts"));
5887
+ const { teardown } = await environment.setup(global, {});
5888
+ cleanupFns.push(async ()=>await teardown(global));
5889
+ break;
5890
+ }
5891
+ default:
5892
+ throw new Error(`Unknown test environment: ${testEnvironment}`);
5844
5893
  }
5845
5894
  const rstestContext = {
5846
5895
  global,
@@ -5908,6 +5957,7 @@ const runInPool = async (options)=>{
5908
5957
  });
5909
5958
  process.off('SIGTERM', onExit);
5910
5959
  const teardown = async ()=>{
5960
+ await new Promise((resolve)=>(0, util.BH)().setTimeout(resolve));
5911
5961
  await Promise.all(cleanups.map((fn)=>fn()));
5912
5962
  isTeardown = true;
5913
5963
  process.once('SIGTERM', onExit);
@@ -5928,13 +5978,13 @@ const runInPool = async (options)=>{
5928
5978
  return {
5929
5979
  testPath,
5930
5980
  tests,
5931
- errors: (0, util.o)(unhandledErrors)
5981
+ errors: (0, util.ov)(unhandledErrors)
5932
5982
  };
5933
5983
  } catch (err) {
5934
5984
  return {
5935
5985
  testPath,
5936
5986
  tests: [],
5937
- errors: (0, util.o)(err)
5987
+ errors: (0, util.ov)(err)
5938
5988
  };
5939
5989
  } finally{
5940
5990
  await teardown();
@@ -5964,7 +6014,7 @@ const runInPool = async (options)=>{
5964
6014
  }, api);
5965
6015
  if (unhandledErrors.length > 0) {
5966
6016
  results.status = 'fail';
5967
- results.errors = (results.errors || []).concat(...(0, util.o)(unhandledErrors));
6017
+ results.errors = (results.errors || []).concat(...(0, util.ov)(unhandledErrors));
5968
6018
  }
5969
6019
  return results;
5970
6020
  } catch (err) {
@@ -5973,7 +6023,7 @@ const runInPool = async (options)=>{
5973
6023
  status: 'fail',
5974
6024
  name: '',
5975
6025
  results: [],
5976
- errors: (0, util.o)(err)
6026
+ errors: (0, util.ov)(err)
5977
6027
  };
5978
6028
  } finally{
5979
6029
  await teardown();
@@ -1,6 +1,4 @@
1
1
  import type { RsbuildConfig } from '@rsbuild/core';
2
- import type { SnapshotResult } from '@vitest/snapshot';
3
- import type { SnapshotSummary } from '@vitest/snapshot';
4
2
 
5
3
  declare type BuiltInReporterNames = keyof typeof reportersMap;
6
4
 
@@ -15,10 +13,10 @@ declare interface DecodedSourceMap extends SourceMapV3 {
15
13
  declare type DecodedSourceMapXInput = DecodedSourceMap & XInput;
16
14
 
17
15
  declare class DefaultReporter implements Reporter {
18
- private rootPath;
19
- private config;
16
+ protected rootPath: string;
17
+ protected config: NormalizedConfig;
20
18
  private options;
21
- private statusRenderer;
19
+ protected statusRenderer: StatusRenderer | undefined;
22
20
  constructor({ rootPath, options, config, }: {
23
21
  rootPath: string;
24
22
  config: NormalizedConfig;
@@ -70,6 +68,24 @@ declare type GeneratedColumn = number;
70
68
 
71
69
  declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
72
70
 
71
+ declare class GithubActionsReporter {
72
+ private onWritePath;
73
+ private rootPath;
74
+ constructor({ options, rootPath, }: {
75
+ rootPath: string;
76
+ options: {
77
+ onWritePath: (path: string) => string;
78
+ };
79
+ });
80
+ onTestRunEnd({ results, testResults, getSourcemap, }: {
81
+ results: TestFileResult[];
82
+ testResults: TestResult[];
83
+ duration: Duration;
84
+ snapshotSummary: SnapshotSummary;
85
+ getSourcemap: GetSourcemap;
86
+ }): Promise<void>;
87
+ }
88
+
73
89
  declare type MaybePromise<T> = T | Promise<T>;
74
90
 
75
91
  declare type NamesIndex = number;
@@ -117,6 +133,8 @@ export declare interface Reporter {
117
133
 
118
134
  declare const reportersMap: {
119
135
  default: typeof DefaultReporter;
136
+ verbose: typeof VerboseReporter;
137
+ 'github-actions': typeof GithubActionsReporter;
120
138
  };
121
139
 
122
140
  declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
@@ -297,6 +315,34 @@ declare type RstestPoolOptions = {
297
315
 
298
316
  declare type RstestPoolType = 'forks';
299
317
 
318
+ declare interface SnapshotResult {
319
+ filepath: string;
320
+ added: number;
321
+ fileDeleted: boolean;
322
+ matched: number;
323
+ unchecked: number;
324
+ uncheckedKeys: Array<string>;
325
+ unmatched: number;
326
+ updated: number;
327
+ }
328
+
329
+ declare interface SnapshotSummary {
330
+ added: number;
331
+ didUpdate: boolean;
332
+ failure: boolean;
333
+ filesAdded: number;
334
+ filesRemoved: number;
335
+ filesRemovedList: Array<string>;
336
+ filesUnmatched: number;
337
+ filesUpdated: number;
338
+ matched: number;
339
+ total: number;
340
+ unchecked: number;
341
+ uncheckedKeysByFile: Array<UncheckedSnapshot>;
342
+ unmatched: number;
343
+ updated: number;
344
+ }
345
+
300
346
  declare type SourceColumn = number;
301
347
 
302
348
  declare type SourceLine = number;
@@ -328,6 +374,17 @@ declare interface SourceMapV3 {
328
374
 
329
375
  declare type SourcesIndex = number;
330
376
 
377
+ declare class StatusRenderer {
378
+ private rootPath;
379
+ private renderer;
380
+ private runningModules;
381
+ constructor(rootPath: string);
382
+ getContent(): string[];
383
+ addRunningModule(testPath: string): void;
384
+ removeRunningModule(testPath: string): void;
385
+ clear(): void;
386
+ }
387
+
331
388
  export declare type TestFileInfo = {
332
389
  testPath: TestPath;
333
390
  };
@@ -369,6 +426,11 @@ declare class TraceMap implements SourceMap {
369
426
  constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
370
427
  }
371
428
 
429
+ declare interface UncheckedSnapshot {
430
+ filePath: string;
431
+ keys: Array<string>;
432
+ }
433
+
372
434
  declare interface UserConsoleLog {
373
435
  content: string;
374
436
  name: string;
@@ -377,6 +439,10 @@ declare interface UserConsoleLog {
377
439
  type: 'stdout' | 'stderr';
378
440
  }
379
441
 
442
+ declare class VerboseReporter extends DefaultReporter {
443
+ onTestFileResult(test: TestFileResult): void;
444
+ }
445
+
380
446
  declare type XInput = {
381
447
  x_google_ignoreList?: SourceMapV3['ignoreList'];
382
448
  };