@rspack/test-tools 1.0.0-alpha.3 → 1.0.0-alpha.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.
Files changed (59) hide show
  1. package/dist/case/builtin.js +2 -2
  2. package/dist/case/defaults.js +3 -3
  3. package/dist/case/diff.js +10 -10
  4. package/dist/case/hook.js +4 -4
  5. package/dist/case/normal.js +2 -2
  6. package/dist/case/stats-output.js +1 -1
  7. package/dist/case/watch.js +4 -4
  8. package/dist/compare/comparator.js +6 -6
  9. package/dist/compare/compare.js +2 -2
  10. package/dist/compare/format-code.js +3 -3
  11. package/dist/compare/replace-runtime-module-name.js +1 -1
  12. package/dist/compiler.d.ts +1 -1
  13. package/dist/compiler.js +2 -2
  14. package/dist/helper/directory.js +16 -16
  15. package/dist/helper/expect/to-match-file-snapshot.js +14 -14
  16. package/dist/helper/legacy/EventSourceForNode.js +1 -1
  17. package/dist/helper/legacy/FakeDocument.js +3 -3
  18. package/dist/helper/legacy/asModule.d.ts +1 -1
  19. package/dist/helper/legacy/asModule.js +1 -1
  20. package/dist/helper/legacy/checkArrayExpectation.js +1 -1
  21. package/dist/helper/legacy/copyDiff.js +2 -2
  22. package/dist/helper/legacy/createFakeWorker.js +3 -3
  23. package/dist/helper/legacy/warmup-webpack.js +1 -1
  24. package/dist/helper/replace-paths.js +5 -5
  25. package/dist/helper/util/checkSourceMap.js +2 -2
  26. package/dist/helper/util/expectWarningFactory.js +1 -1
  27. package/dist/helper/util/identifier.js +1 -1
  28. package/dist/helper/win.js +2 -2
  29. package/dist/plugin/webpack-module-placeholder-plugin.js +2 -2
  30. package/dist/processor/basic.js +6 -6
  31. package/dist/processor/builtin.js +5 -5
  32. package/dist/processor/config.js +4 -4
  33. package/dist/processor/diagnostic.js +4 -4
  34. package/dist/processor/diff.js +8 -8
  35. package/dist/processor/error.js +3 -3
  36. package/dist/processor/hook.js +10 -10
  37. package/dist/processor/hot-step.js +26 -22
  38. package/dist/processor/hot.js +4 -4
  39. package/dist/processor/multi.js +1 -1
  40. package/dist/processor/normal.js +5 -5
  41. package/dist/processor/snapshot.js +5 -5
  42. package/dist/processor/stats.js +5 -5
  43. package/dist/processor/watch.js +9 -9
  44. package/dist/reporter/diff-html.js +13 -13
  45. package/dist/reporter/diff-stats.js +9 -9
  46. package/dist/runner/runner/basic.js +7 -7
  47. package/dist/runner/runner/cjs.js +8 -8
  48. package/dist/runner/runner/esm.js +13 -13
  49. package/dist/runner/runner/normal.js +2 -2
  50. package/dist/runner/runner/watch.js +2 -2
  51. package/dist/runner/runner/web/fake.js +6 -6
  52. package/dist/runner/runner/web/jsdom.js +7 -7
  53. package/dist/runner/watch.js +1 -1
  54. package/dist/test/context.js +4 -4
  55. package/dist/test/creator.d.ts +1 -1
  56. package/dist/test/creator.js +7 -7
  57. package/dist/test/tester.js +5 -5
  58. package/dist/type.d.ts +1 -1
  59. package/package.json +25 -5
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createBuiltinCase = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const processor_1 = require("../processor");
9
9
  const creator_1 = require("../test/creator");
10
10
  const type_1 = require("../type");
@@ -21,7 +21,7 @@ const creator = new creator_1.BasicCaseCreator({
21
21
  return `${name} should match snapshot`;
22
22
  },
23
23
  steps: ({ name, src }) => {
24
- const cat = path_1.default.basename(path_1.default.dirname(src));
24
+ const cat = node_path_1.default.basename(node_path_1.default.dirname(src));
25
25
  const filter = FILTERS[cat];
26
26
  return [
27
27
  new processor_1.BuiltinProcessor({
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createDefaultsCase = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const processor_1 = require("../processor");
9
9
  const context_1 = require("../test/context");
10
10
  const type_1 = require("../type");
11
- const srcDir = path_1.default.resolve(__dirname, "../../tests/fixtures");
12
- const distDir = path_1.default.resolve(__dirname, "../../tests/js/defaults");
11
+ const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
12
+ const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/defaults");
13
13
  const context = new context_1.TestContext({
14
14
  src: srcDir,
15
15
  dist: distDir
package/dist/case/diff.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createDiffCase = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const rimraf_1 = __importDefault(require("rimraf"));
10
10
  const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
@@ -20,7 +20,7 @@ const DEFAULT_CASE_CONFIG = {
20
20
  errors: false
21
21
  };
22
22
  function createDiffCase(name, src, dist) {
23
- const caseConfigFile = path_1.default.join(src, "test.config.js");
23
+ const caseConfigFile = node_path_1.default.join(src, "test.config.js");
24
24
  if (!fs_extra_1.default.existsSync(caseConfigFile)) {
25
25
  return;
26
26
  }
@@ -37,20 +37,20 @@ function createDiffCase(name, src, dist) {
37
37
  await tester.prepare();
38
38
  });
39
39
  do {
40
- const prefix = path_1.default.basename(name);
40
+ const prefix = node_path_1.default.basename(name);
41
41
  describe(`${prefix}:build`, () => {
42
42
  beforeAll(async () => {
43
43
  await tester.compile();
44
44
  });
45
- checkBundleFiles("webpack", path_1.default.join(dist, "webpack"), caseConfig.files);
46
- checkBundleFiles("rspack", path_1.default.join(dist, "rspack"), caseConfig.files);
45
+ checkBundleFiles("webpack", node_path_1.default.join(dist, "webpack"), caseConfig.files);
46
+ checkBundleFiles("rspack", node_path_1.default.join(dist, "rspack"), caseConfig.files);
47
47
  });
48
48
  describe(`${prefix}:check`, () => {
49
49
  beforeAll(async () => {
50
50
  compareMap.clear();
51
51
  await tester.check(env);
52
52
  });
53
- for (let file of caseConfig.files) {
53
+ for (const file of caseConfig.files) {
54
54
  describe(`Comparing "${file}"`, () => {
55
55
  let moduleResults = [];
56
56
  let runtimeResults = [];
@@ -115,9 +115,9 @@ function createDiffProcessor(config) {
115
115
  }
116
116
  function checkBundleFiles(name, dist, files) {
117
117
  describe(`Checking ${name} dist files`, () => {
118
- for (let file of files) {
118
+ for (const file of files) {
119
119
  it(`${name}: ${file} should be generated`, () => {
120
- expect(fs_extra_1.default.existsSync(path_1.default.join(dist, file))).toBeTruthy();
120
+ expect(fs_extra_1.default.existsSync(node_path_1.default.join(dist, file))).toBeTruthy();
121
121
  });
122
122
  }
123
123
  });
@@ -139,8 +139,8 @@ function checkCompareResults(name, getResults) {
139
139
  .filter(i => i.type === type_1.ECompareResultType.OnlyDist)
140
140
  .map(i => i.name)).toEqual([]);
141
141
  });
142
- it(`all modules should be the same`, () => {
143
- for (let result of getResults().filter(i => i.type === type_1.ECompareResultType.Different)) {
142
+ it("all modules should be the same", () => {
143
+ for (const result of getResults().filter(i => i.type === type_1.ECompareResultType.Different)) {
144
144
  console.log(`${result.name}:\n${result.detail}`);
145
145
  }
146
146
  expect(getResults().every(i => i.type === type_1.ECompareResultType.Same)).toEqual(true);
package/dist/case/hook.js CHANGED
@@ -4,15 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createHookCase = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
9
9
  const processor_1 = require("../processor");
10
10
  const runner_1 = require("../runner");
11
11
  const simple_1 = require("../test/simple");
12
12
  const type_1 = require("../type");
13
13
  function createHookCase(name, src, dist, source) {
14
- const caseConfig = require(path_1.default.join(src, "test.js"));
15
- const testName = path_1.default.basename(name.slice(0, name.indexOf(path_1.default.extname(name))));
14
+ const caseConfig = require(node_path_1.default.join(src, "test.js"));
15
+ const testName = node_path_1.default.basename(name.slice(0, name.indexOf(node_path_1.default.extname(name))));
16
16
  const runner = (0, simple_1.getSimpleProcessorRunner)(source, dist, {
17
17
  env: () => env,
18
18
  context: () => new processor_1.HookCasesContext(src, testName, {
@@ -26,7 +26,7 @@ function createHookCase(name, src, dist, source) {
26
26
  name,
27
27
  compilerType: type_1.ECompilerType.Rspack,
28
28
  findBundle: () => ["main.js"],
29
- snapshot: path_1.default.join(src, "output.snap.txt"),
29
+ snapshot: node_path_1.default.join(src, "output.snap.txt"),
30
30
  runable: true,
31
31
  ...caseConfig
32
32
  }));
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createNormalCase = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const normal_1 = require("../processor/normal");
9
9
  const runner_1 = require("../runner");
10
10
  const creator_1 = require("../test/creator");
@@ -15,7 +15,7 @@ const creator = new creator_1.BasicCaseCreator({
15
15
  steps: ({ name }) => [
16
16
  new normal_1.NormalProcessor({
17
17
  name,
18
- root: path_1.default.resolve(__dirname, "../../tests/normalCases"),
18
+ root: node_path_1.default.resolve(__dirname, "../../tests/normalCases"),
19
19
  compilerOptions: {},
20
20
  runable: true,
21
21
  compilerType: type_1.ECompilerType.Rspack
@@ -14,7 +14,7 @@ const creator = new creator_1.BasicCaseCreator({
14
14
  configFiles: ["rspack.config.js", "webpack.config.js"]
15
15
  })
16
16
  ],
17
- description: () => `should print correct stats for`
17
+ description: () => "should print correct stats for"
18
18
  });
19
19
  function createStatsOutputCase(name, src, dist) {
20
20
  creator.create(name, src, dist);
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createWatchCase = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
9
  const watch_1 = require("../processor/watch");
10
10
  const runner_1 = require("../runner");
11
11
  const creator_1 = require("../test/creator");
@@ -20,11 +20,11 @@ const creator = new creator_1.BasicCaseCreator({
20
20
  },
21
21
  describe: false,
22
22
  steps: ({ name, src, temp }) => {
23
- const runs = fs_1.default
23
+ const runs = node_fs_1.default
24
24
  .readdirSync(src)
25
25
  .sort()
26
26
  .filter(name => {
27
- return fs_1.default.statSync(path_1.default.join(src, name)).isDirectory();
27
+ return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
28
28
  })
29
29
  .map(name => ({ name }));
30
30
  return runs.map((run, index) => index === 0
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DiffComparator = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const deepmerge_1 = __importDefault(require("deepmerge"));
9
9
  const compare_1 = require("./compare");
10
10
  const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
@@ -13,9 +13,9 @@ class DiffComparator {
13
13
  this.options = options;
14
14
  }
15
15
  async compare() {
16
- for (let file of this.options.files) {
16
+ for (const file of this.options.files) {
17
17
  try {
18
- const result = (0, compare_1.compareFile)(path_1.default.join(this.options.rspackDist, file), path_1.default.join(this.options.webpackDist, file), {
18
+ const result = (0, compare_1.compareFile)(node_path_1.default.join(this.options.rspackDist, file), node_path_1.default.join(this.options.webpackDist, file), {
19
19
  modules: this.options.modules,
20
20
  runtimeModules: this.options.runtimeModules,
21
21
  format: (0, deepmerge_1.default)({
@@ -32,16 +32,16 @@ class DiffComparator {
32
32
  renameModule: replace_runtime_module_name_1.replaceRuntimeModuleName,
33
33
  bootstrap: this.options.bootstrap
34
34
  });
35
- for (let reporter of this.options.reporters) {
35
+ for (const reporter of this.options.reporters) {
36
36
  reporter.increment(file, result.modules["modules"] || []);
37
37
  }
38
- for (let reporter of this.options.reporters) {
38
+ for (const reporter of this.options.reporters) {
39
39
  reporter.increment(file, result.modules["runtimeModules"] || []);
40
40
  }
41
41
  }
42
42
  catch (e) {
43
43
  console.error(e);
44
- for (let reporter of this.options.reporters) {
44
+ for (const reporter of this.options.reporters) {
45
45
  reporter.failure(file);
46
46
  }
47
47
  }
@@ -45,7 +45,7 @@ function compareFile(sourceFile, distFile, compareOptions) {
45
45
  const distModules = (0, helper_1.parseModules)(distContent, {
46
46
  bootstrap: compareOptions.bootstrap
47
47
  });
48
- for (let type of ["modules", "runtimeModules"]) {
48
+ for (const type of ["modules", "runtimeModules"]) {
49
49
  const t = type;
50
50
  let moduleList = [];
51
51
  if (compareOptions[t] === true) {
@@ -70,7 +70,7 @@ function compareFile(sourceFile, distFile, compareOptions) {
70
70
  exports.compareFile = compareFile;
71
71
  function compareModules(modules, sourceModules, distModules, compareOptions) {
72
72
  const compareResults = [];
73
- for (let name of modules) {
73
+ for (const name of modules) {
74
74
  const renamed = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(name);
75
75
  const sourceContent = sourceModules.has(renamed) &&
76
76
  (0, format_code_1.formatCode)(name, sourceModules.get(renamed), compareOptions.format);
@@ -67,7 +67,7 @@ function formatCode(name, raw, options) {
67
67
  }
68
68
  if (options.ignoreSwcHelpersPath) {
69
69
  if (SWC_HELPER_PATH_REG.test(path.node.name)) {
70
- path.node.name = `$$SWC_HELPERS$$`;
70
+ path.node.name = "$$SWC_HELPERS$$";
71
71
  }
72
72
  }
73
73
  },
@@ -162,7 +162,7 @@ function formatCode(name, raw, options) {
162
162
  },
163
163
  ObjectExpression(path) {
164
164
  if (options.ignoreObjectPropertySequence) {
165
- let result = [];
165
+ const result = [];
166
166
  let safe = [];
167
167
  while (path.node.properties.length || safe.length) {
168
168
  const cur = path.node.properties.shift();
@@ -207,7 +207,7 @@ function formatCode(name, raw, options) {
207
207
  result = (0, replace_module_argument_1.replaceModuleArgument)(result);
208
208
  }
209
209
  if (options.replacements) {
210
- for (let { from, to } of options.replacements) {
210
+ for (const { from, to } of options.replacements) {
211
211
  result = result.replaceAll(from, to);
212
212
  }
213
213
  }
@@ -54,7 +54,7 @@ const RUNTIME_MODULE_PARAM_REGEX = {
54
54
  "webpack/runtime/chunk_prefetch_function": /webpack\/runtime\/chunk_prefetch_function\/([\w.\-_\s]+)(\*\/)?/g
55
55
  };
56
56
  function replaceRuntimeModuleName(raw) {
57
- for (let [rspackName, webpackName] of Object.entries(RUNTIME_MODULE_NAME_MAPPING)) {
57
+ for (const [rspackName, webpackName] of Object.entries(RUNTIME_MODULE_NAME_MAPPING)) {
58
58
  if (RUNTIME_MODULE_PARAM_REGEX[rspackName]) {
59
59
  raw = raw.replace(RUNTIME_MODULE_PARAM_REGEX[rspackName], (full, $1, $2) => {
60
60
  return webpackName.replace("$1", $1.trim()) + ($2 ? " */" : "");
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import EventEmitter from "events";
2
+ import EventEmitter from "node:events";
3
3
  import { ECompilerType, type ITestCompilerManager, type TCompiler, type TCompilerFactories, type TCompilerOptions, type TCompilerStats } from "./type";
4
4
  export declare const enum ECompilerEvent {
5
5
  Build = "build",
package/dist/compiler.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TestCompilerManager = exports.COMPILER_FACTORIES = exports.ECompilerEvent = void 0;
7
- const events_1 = __importDefault(require("events"));
7
+ const node_events_1 = __importDefault(require("node:events"));
8
8
  const webpack_merge_1 = __importDefault(require("webpack-merge"));
9
9
  const type_1 = require("./type");
10
10
  var ECompilerEvent;
@@ -25,7 +25,7 @@ class TestCompilerManager {
25
25
  this.compilerOptions = {};
26
26
  this.compilerInstance = null;
27
27
  this.compilerStats = null;
28
- this.emitter = new events_1.default();
28
+ this.emitter = new node_events_1.default();
29
29
  }
30
30
  getOptions() {
31
31
  return this.compilerOptions;
@@ -4,31 +4,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.describeByWalk = exports.isValidCaseDirectory = exports.isFile = exports.isDirectory = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
9
  const _1 = require(".");
10
- const isDirectory = (p) => fs_1.default.lstatSync(p).isDirectory();
10
+ const isDirectory = (p) => node_fs_1.default.lstatSync(p).isDirectory();
11
11
  exports.isDirectory = isDirectory;
12
- const isFile = (p) => fs_1.default.lstatSync(p).isFile();
12
+ const isFile = (p) => node_fs_1.default.lstatSync(p).isFile();
13
13
  exports.isFile = isFile;
14
14
  const isValidCaseDirectory = (name) => !name.startsWith("_") && !name.startsWith(".") && name !== "node_modules";
15
15
  exports.isValidCaseDirectory = isValidCaseDirectory;
16
16
  function describeByWalk(testFile, createCase, options = {}) {
17
17
  const describeFn = options.describe || describe;
18
- const testBasename = path_1.default
18
+ const testBasename = node_path_1.default
19
19
  .basename(testFile)
20
20
  .replace(/\.(diff|hot)?test\.(j|t)s/, "");
21
21
  const testId = testBasename.charAt(0).toLowerCase() + testBasename.slice(1);
22
- const sourceBase = options.source || path_1.default.join(path_1.default.dirname(testFile), `${testId}Cases`);
23
- const distBase = options.dist || path_1.default.join(path_1.default.dirname(testFile), "js", testId);
22
+ const sourceBase = options.source || node_path_1.default.join(node_path_1.default.dirname(testFile), `${testId}Cases`);
23
+ const distBase = options.dist || node_path_1.default.join(node_path_1.default.dirname(testFile), "js", testId);
24
24
  const level = options.level || 2;
25
25
  const type = options.type || "directory";
26
26
  const absoluteDist = options.absoluteDist ?? true;
27
27
  function describeDirectory(dirname, currentLevel) {
28
- fs_1.default.readdirSync(path_1.default.join(sourceBase, dirname))
28
+ node_fs_1.default.readdirSync(node_path_1.default.join(sourceBase, dirname))
29
29
  .filter(exports.isValidCaseDirectory)
30
30
  .filter(folder => {
31
- const p = path_1.default.join(sourceBase, dirname, folder);
31
+ const p = node_path_1.default.join(sourceBase, dirname, folder);
32
32
  if (type === "file" && currentLevel === 1) {
33
33
  return (0, exports.isFile)(p);
34
34
  }
@@ -40,25 +40,25 @@ function describeByWalk(testFile, createCase, options = {}) {
40
40
  }
41
41
  })
42
42
  .map(folder => {
43
- const caseName = path_1.default.join(dirname, folder);
43
+ const caseName = node_path_1.default.join(dirname, folder);
44
44
  if (currentLevel > 1) {
45
45
  describeDirectory(caseName, currentLevel - 1);
46
46
  }
47
47
  else {
48
- const name = (0, _1.escapeSep)(path_1.default.join(testId, caseName).split(".").shift());
48
+ const name = (0, _1.escapeSep)(node_path_1.default.join(testId, caseName).split(".").shift());
49
49
  describeFn(name, () => {
50
- let source = path_1.default.join(sourceBase, caseName);
50
+ const source = node_path_1.default.join(sourceBase, caseName);
51
51
  let dist = "";
52
52
  if (absoluteDist) {
53
- dist = path_1.default.join(distBase, caseName);
53
+ dist = node_path_1.default.join(distBase, caseName);
54
54
  }
55
55
  else {
56
56
  const relativeDist = options.dist || "dist";
57
- if (path_1.default.isAbsolute(relativeDist)) {
58
- dist = path_1.default.join(relativeDist, caseName);
57
+ if (node_path_1.default.isAbsolute(relativeDist)) {
58
+ dist = node_path_1.default.join(relativeDist, caseName);
59
59
  }
60
60
  else {
61
- dist = path_1.default.join(sourceBase, caseName, relativeDist);
61
+ dist = node_path_1.default.join(sourceBase, caseName, relativeDist);
62
62
  }
63
63
  }
64
64
  createCase(name, source, dist);
@@ -6,8 +6,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.toMatchFileSnapshot = void 0;
8
8
  /* istanbul ignore file */
9
- const fs_1 = __importDefault(require("fs"));
10
- const path_1 = __importDefault(require("path"));
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
11
  const chalk_1 = __importDefault(require("chalk"));
12
12
  const filenamify_1 = __importDefault(require("filenamify"));
13
13
  const jest_diff_1 = require("jest-diff");
@@ -33,7 +33,7 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
33
33
  const { isNot, snapshotState } = this;
34
34
  const filename = filepath === undefined
35
35
  ? // If file name is not specified, generate one from the test title
36
- path_1.default.join(path_1.default.dirname(this.testPath), "__file_snapshots__", `${(0, filenamify_1.default)(this.currentTestName, {
36
+ node_path_1.default.join(node_path_1.default.dirname(this.testPath), "__file_snapshots__", `${(0, filenamify_1.default)(this.currentTestName, {
37
37
  replacement: "-"
38
38
  }).replace(/\s/g, "-")}-${this.assertionCalls}`)
39
39
  : filepath;
@@ -45,18 +45,18 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
45
45
  aAnnotation: "Snapshot"
46
46
  }, options.diff || {})
47
47
  };
48
- if (snapshotState._updateSnapshot === "none" && !fs_1.default.existsSync(filename)) {
48
+ if (snapshotState._updateSnapshot === "none" && !node_fs_1.default.existsSync(filename)) {
49
49
  // We're probably running in CI environment
50
50
  snapshotState.unmatched++;
51
51
  return {
52
52
  pass: isNot,
53
- message: () => `New output file ${chalk_1.default.blue(path_1.default.basename(filename))} was ${chalk_1.default.bold.red("not written")}.\n\n` +
53
+ message: () => `New output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} was ${chalk_1.default.bold.red("not written")}.\n\n` +
54
54
  "The update flag must be explicitly passed to write a new snapshot.\n\n" +
55
55
  `This is likely because this test is run in a ${chalk_1.default.blue("continuous integration (CI) environment")} in which snapshots are not written by default.\n\n`
56
56
  };
57
57
  }
58
- if (fs_1.default.existsSync(filename)) {
59
- const output = fs_1.default
58
+ if (node_fs_1.default.existsSync(filename)) {
59
+ const output = node_fs_1.default
60
60
  .readFileSync(filename, Buffer.isBuffer(content) ? null : "utf8")
61
61
  .replace(/\r\n/g, "\n");
62
62
  if (isNot) {
@@ -69,7 +69,7 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
69
69
  snapshotState.unmatched++;
70
70
  return {
71
71
  pass: true,
72
- message: () => `Expected received content ${chalk_1.default.red("to not match")} the file ${chalk_1.default.blue(path_1.default.basename(filename))}.`
72
+ message: () => `Expected received content ${chalk_1.default.red("to not match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.`
73
73
  };
74
74
  }
75
75
  }
@@ -79,8 +79,8 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
79
79
  }
80
80
  else {
81
81
  if (snapshotState._updateSnapshot === "all") {
82
- mkdirp_1.default.sync(path_1.default.dirname(filename));
83
- fs_1.default.writeFileSync(filename, content);
82
+ mkdirp_1.default.sync(node_path_1.default.dirname(filename));
83
+ node_fs_1.default.writeFileSync(filename, content);
84
84
  snapshotState.updated++;
85
85
  return { pass: true, message: () => "" };
86
86
  }
@@ -91,7 +91,7 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
91
91
  : `\n\n${(0, jest_diff_1.diff)(output, content, options.diff)}`;
92
92
  return {
93
93
  pass: false,
94
- message: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(path_1.default.basename(filename))}.${difference}`
94
+ message: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.${difference}`
95
95
  };
96
96
  }
97
97
  }
@@ -101,8 +101,8 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
101
101
  if (!isNot &&
102
102
  (snapshotState._updateSnapshot === "new" ||
103
103
  snapshotState._updateSnapshot === "all")) {
104
- mkdirp_1.default.sync(path_1.default.dirname(filename));
105
- fs_1.default.writeFileSync(filename, content);
104
+ mkdirp_1.default.sync(node_path_1.default.dirname(filename));
105
+ node_fs_1.default.writeFileSync(filename, content);
106
106
  snapshotState.added++;
107
107
  return { pass: true, message: () => "" };
108
108
  }
@@ -110,7 +110,7 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
110
110
  snapshotState.unmatched++;
111
111
  return {
112
112
  pass: true,
113
- message: () => `The output file ${chalk_1.default.blue(path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}.`
113
+ message: () => `The output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}.`
114
114
  };
115
115
  }
116
116
  }
@@ -12,7 +12,7 @@
12
12
  module.exports = class EventSource {
13
13
  constructor(url) {
14
14
  this.response = undefined;
15
- const request = (url.startsWith("https:") ? require("https") : require("http")).request(url, {
15
+ const request = (url.startsWith("https:") ? require("node:https") : require("node:http")).request(url, {
16
16
  agent: false,
17
17
  headers: { accept: "text/event-stream" }
18
18
  }, res => {
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FakeSheet = exports.FakeElement = void 0;
4
4
  // @ts-nocheck
5
- const fs = require("fs");
6
- const path = require("path");
5
+ const fs = require("node:fs");
6
+ const path = require("node:path");
7
7
  const getPropertyValue = function (property) {
8
8
  return this[property];
9
9
  };
@@ -34,7 +34,7 @@ class FakeDocument {
34
34
  }
35
35
  _onElementRemoved(element) {
36
36
  const type = element._type;
37
- let list = this._elementsByTagName.get(type);
37
+ const list = this._elementsByTagName.get(type);
38
38
  const idx = list.indexOf(element);
39
39
  list.splice(idx, 1);
40
40
  }
@@ -1,4 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  declare function _exports(something: any, context: any, unlinked: any): Promise<vm.Module>;
3
3
  export = _exports;
4
- import vm = require("vm");
4
+ import vm = require("node:vm");
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
- const vm = require("vm");
3
+ const vm = require("node:vm");
4
4
  const SYNTHETIC_MODULES_STORE = "__SYNTHETIC_MODULES_STORE";
5
5
  module.exports = async (something, context, unlinked) => {
6
6
  if (something instanceof (vm.Module || /* node.js 10 */ vm.SourceTextModule)) {
@@ -1,7 +1,7 @@
1
1
  // @ts-nocheck
2
2
  "use strict";
3
3
  const fs = require("graceful-fs");
4
- const path = require("path");
4
+ const path = require("node:path");
5
5
  const check = (expected, actual) => {
6
6
  if (expected instanceof RegExp) {
7
7
  expected = { message: expected };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
- const fs = require("fs");
4
- const path = require("path");
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
5
  const rimraf = require("rimraf");
6
6
  module.exports = function copyDiff(src, dest, initial) {
7
7
  fs.mkdirSync(dest, { recursive: true });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
- const path = require("path");
3
+ const path = require("node:path");
4
4
  module.exports = (env, { outputDirectory }) => class Worker {
5
5
  constructor(url, options = {}) {
6
6
  env.expect(url).toBeInstanceOf(URL);
@@ -23,7 +23,7 @@ const urlToPath = url => {
23
23
  self.importScripts = url => {
24
24
  ${options.type === "module"
25
25
  ? `throw new Error("importScripts is not supported in module workers")`
26
- : `require(urlToPath(url))`};
26
+ : "require(urlToPath(url))"};
27
27
  };
28
28
  self.fetch = async url => {
29
29
  try {
@@ -57,7 +57,7 @@ self.postMessage = data => {
57
57
  };
58
58
  require(${JSON.stringify(path.resolve(outputDirectory, file))});
59
59
  `;
60
- this.worker = new (require("worker_threads").Worker)(workerBootstrap, {
60
+ this.worker = new (require("node:worker_threads").Worker)(workerBootstrap, {
61
61
  eval: true
62
62
  });
63
63
  this._onmessage = undefined;
@@ -3,7 +3,7 @@
3
3
  describe("warmup", () => {
4
4
  it("should warmup webpack", done => {
5
5
  let webpack = require("@rspack/core");
6
- let END = new Error("end warmup");
6
+ const END = new Error("end warmup");
7
7
  webpack({
8
8
  entry: "data:text/javascript,import 'data:text/javascript,'",
9
9
  plugins: [
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.replacePaths = void 0;
7
- const os_1 = __importDefault(require("os"));
8
- const path_1 = __importDefault(require("path"));
7
+ const node_os_1 = __importDefault(require("node:os"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
9
  const serializer = require("jest-serializer-path");
10
10
  const normalizePaths = serializer.normalizePaths;
11
- const rspackPath = path_1.default.resolve(__dirname, "../../../rspack");
11
+ const rspackPath = node_path_1.default.resolve(__dirname, "../../../rspack");
12
12
  function replacePaths(input) {
13
13
  const rspackRoot = normalizePaths(rspackPath);
14
14
  input = input.split("\\\\").join("\\");
15
- if (os_1.default.platform() === "win32") {
16
- const winRspackRoot = rspackRoot.split("\\\\").join(path_1.default.win32.sep);
15
+ if (node_os_1.default.platform() === "win32") {
16
+ const winRspackRoot = rspackRoot.split("\\\\").join(node_path_1.default.win32.sep);
17
17
  return normalizePaths(input)
18
18
  .split(rspackRoot)
19
19
  .join("<RSPACK_ROOT>")
@@ -12,9 +12,9 @@ async function checkSourceMap(out, outCodeMap, toSearch, _checkColumn = true //
12
12
  }
13
13
  };
14
14
  const sourceMap = require("source-map");
15
- const path = require("path");
15
+ const path = require("node:path");
16
16
  const sources = JSON.parse(outCodeMap).sources;
17
- for (let source of sources) {
17
+ for (const source of sources) {
18
18
  if (sources.filter(s => s === source).length > 1) {
19
19
  throw new Error(`Duplicate source ${JSON.stringify(source)} found in source map`);
20
20
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
3
  module.exports = () => {
4
- let warnings = [];
4
+ const warnings = [];
5
5
  let oldWarn;
6
6
  beforeEach(done => {
7
7
  oldWarn = console.warn;
@@ -3,7 +3,7 @@
3
3
  MIT License http://www.opensource.org/licenses/mit-license.php
4
4
  */
5
5
  "use strict";
6
- const path = require("path");
6
+ const path = require("node:path");
7
7
  const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
8
8
  const SEGMENTS_SPLIT_REGEXP = /([|!])/;
9
9
  const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;