@rspack/test-tools 1.0.0-alpha.5 → 1.0.0-beta.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.
package/dist/case/diff.js CHANGED
@@ -96,6 +96,7 @@ function createDiffProcessor(config) {
96
96
  files: config.files,
97
97
  modules: config.modules,
98
98
  runtimeModules: config.runtimeModules,
99
+ renameModule: config.renameModule,
99
100
  ignoreModuleId: config.ignoreModuleId ?? true,
100
101
  ignoreModuleArguments: config.ignoreModuleArguments ?? true,
101
102
  ignorePropertyQuotationMark: config.ignorePropertyQuotationMark ?? true,
@@ -33,10 +33,10 @@ class DiffComparator {
33
33
  bootstrap: this.options.bootstrap
34
34
  });
35
35
  for (const reporter of this.options.reporters) {
36
- reporter.increment(file, result.modules["modules"] || []);
36
+ reporter.increment(file, result.modules.modules || []);
37
37
  }
38
38
  for (const reporter of this.options.reporters) {
39
- reporter.increment(file, result.modules["runtimeModules"] || []);
39
+ reporter.increment(file, result.modules.runtimeModules || []);
40
40
  }
41
41
  }
42
42
  catch (e) {
@@ -25,11 +25,11 @@ function compareFile(sourceFile, distFile, compareOptions) {
25
25
  result.type = type_1.ECompareResultType.Missing;
26
26
  return result;
27
27
  }
28
- else if (!sourceExists && distExists) {
28
+ if (!sourceExists && distExists) {
29
29
  result.type = type_1.ECompareResultType.OnlyDist;
30
30
  return result;
31
31
  }
32
- else if (sourceExists && !distExists) {
32
+ if (sourceExists && !distExists) {
33
33
  result.type = type_1.ECompareResultType.OnlySource;
34
34
  return result;
35
35
  }
@@ -40,10 +40,12 @@ function compareFile(sourceFile, distFile, compareOptions) {
40
40
  // result.lines = compareContentResult.lines;
41
41
  result.type = type_1.ECompareResultType.Different;
42
42
  const sourceModules = (0, helper_1.parseModules)(sourceContent, {
43
- bootstrap: compareOptions.bootstrap
43
+ bootstrap: compareOptions.bootstrap,
44
+ renameModule: compareOptions.renameModule
44
45
  });
45
46
  const distModules = (0, helper_1.parseModules)(distContent, {
46
- bootstrap: compareOptions.bootstrap
47
+ bootstrap: compareOptions.bootstrap,
48
+ renameModule: compareOptions.renameModule
47
49
  });
48
50
  for (const type of ["modules", "runtimeModules"]) {
49
51
  const t = type;
@@ -60,9 +62,6 @@ function compareFile(sourceFile, distFile, compareOptions) {
60
62
  else {
61
63
  continue;
62
64
  }
63
- if (typeof compareOptions.renameModule === "function") {
64
- moduleList = moduleList.map(compareOptions.renameModule);
65
- }
66
65
  result.modules[t] = compareModules(moduleList, sourceModules[t], distModules[t], compareOptions);
67
66
  }
68
67
  return result;
@@ -100,58 +99,50 @@ function compareContent(sourceContent, distContent, compareOptions) {
100
99
  }
101
100
  };
102
101
  }
103
- else {
104
- const difference = compareOptions.detail
105
- ? (0, jest_diff_1.diffStringsUnified)(sourceContent.trim(), distContent.trim())
106
- : undefined;
107
- const diffLines = (0, jest_diff_1.diffLinesRaw)(sourceContent.trim().split("\n"), distContent.trim().split("\n"));
108
- return {
109
- type: type_1.ECompareResultType.Different,
110
- detail: difference,
111
- source: sourceContent,
112
- dist: distContent,
113
- lines: {
114
- source: diffLines.filter(l => l[0] < 0).length,
115
- common: diffLines.filter(l => l[0] === 0).length,
116
- dist: diffLines.filter(l => l[0] > 0).length
117
- }
118
- };
119
- }
120
- }
121
- else {
102
+ const difference = compareOptions.detail
103
+ ? (0, jest_diff_1.diffStringsUnified)(sourceContent.trim(), distContent.trim())
104
+ : undefined;
105
+ const diffLines = (0, jest_diff_1.diffLinesRaw)(sourceContent.trim().split("\n"), distContent.trim().split("\n"));
122
106
  return {
123
- type: type_1.ECompareResultType.OnlySource,
107
+ type: type_1.ECompareResultType.Different,
108
+ detail: difference,
124
109
  source: sourceContent,
125
- lines: {
126
- source: sourceContent.trim().split("\n").length,
127
- common: 0,
128
- dist: 0
129
- }
130
- };
131
- }
132
- }
133
- else {
134
- if (distContent) {
135
- return {
136
- type: type_1.ECompareResultType.OnlyDist,
137
110
  dist: distContent,
138
111
  lines: {
139
- source: 0,
140
- common: 0,
141
- dist: distContent.trim().split("\n").length
142
- }
143
- };
144
- }
145
- else {
146
- return {
147
- type: type_1.ECompareResultType.Missing,
148
- lines: {
149
- source: 0,
150
- common: 0,
151
- dist: 0
112
+ source: diffLines.filter(l => l[0] < 0).length,
113
+ common: diffLines.filter(l => l[0] === 0).length,
114
+ dist: diffLines.filter(l => l[0] > 0).length
152
115
  }
153
116
  };
154
117
  }
118
+ return {
119
+ type: type_1.ECompareResultType.OnlySource,
120
+ source: sourceContent,
121
+ lines: {
122
+ source: sourceContent.trim().split("\n").length,
123
+ common: 0,
124
+ dist: 0
125
+ }
126
+ };
155
127
  }
128
+ if (distContent) {
129
+ return {
130
+ type: type_1.ECompareResultType.OnlyDist,
131
+ dist: distContent,
132
+ lines: {
133
+ source: 0,
134
+ common: 0,
135
+ dist: distContent.trim().split("\n").length
136
+ }
137
+ };
138
+ }
139
+ return {
140
+ type: type_1.ECompareResultType.Missing,
141
+ lines: {
142
+ source: 0,
143
+ common: 0,
144
+ dist: 0
145
+ }
146
+ };
156
147
  }
157
148
  exports.compareContent = compareContent;
@@ -32,12 +32,10 @@ function describeByWalk(testFile, createCase, options = {}) {
32
32
  if (type === "file" && currentLevel === 1) {
33
33
  return (0, exports.isFile)(p);
34
34
  }
35
- else if (type === "directory" || currentLevel > 1) {
35
+ if (type === "directory" || currentLevel > 1) {
36
36
  return (0, exports.isDirectory)(p);
37
37
  }
38
- else {
39
- return false;
40
- }
38
+ return false;
41
39
  })
42
40
  .map(folder => {
43
41
  const caseName = node_path_1.default.join(dirname, folder);
@@ -65,54 +65,42 @@ function toMatchFileSnapshot(content, filepath, options = {}) {
65
65
  // The value of `pass` is reversed when used with `.not`
66
66
  return { pass: false, message: () => "" };
67
67
  }
68
- else {
69
- snapshotState.unmatched++;
70
- return {
71
- pass: true,
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
- };
74
- }
68
+ snapshotState.unmatched++;
69
+ return {
70
+ pass: true,
71
+ message: () => `Expected received content ${chalk_1.default.red("to not match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.`
72
+ };
75
73
  }
76
- else {
77
- if (isEqual(content, output)) {
78
- return { pass: true, message: () => "" };
79
- }
80
- else {
81
- if (snapshotState._updateSnapshot === "all") {
82
- mkdirp_1.default.sync(node_path_1.default.dirname(filename));
83
- node_fs_1.default.writeFileSync(filename, content);
84
- snapshotState.updated++;
85
- return { pass: true, message: () => "" };
86
- }
87
- else {
88
- snapshotState.unmatched++;
89
- const difference = Buffer.isBuffer(content) || Buffer.isBuffer(output)
90
- ? ""
91
- : `\n\n${(0, jest_diff_1.diff)(output, content, options.diff)}`;
92
- return {
93
- pass: false,
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
- };
96
- }
97
- }
74
+ if (isEqual(content, output)) {
75
+ return { pass: true, message: () => "" };
98
76
  }
99
- }
100
- else {
101
- if (!isNot &&
102
- (snapshotState._updateSnapshot === "new" ||
103
- snapshotState._updateSnapshot === "all")) {
77
+ if (snapshotState._updateSnapshot === "all") {
104
78
  mkdirp_1.default.sync(node_path_1.default.dirname(filename));
105
79
  node_fs_1.default.writeFileSync(filename, content);
106
- snapshotState.added++;
80
+ snapshotState.updated++;
107
81
  return { pass: true, message: () => "" };
108
82
  }
109
- else {
110
- snapshotState.unmatched++;
111
- return {
112
- pass: true,
113
- message: () => `The output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}.`
114
- };
115
- }
83
+ snapshotState.unmatched++;
84
+ const difference = Buffer.isBuffer(content) || Buffer.isBuffer(output)
85
+ ? ""
86
+ : `\n\n${(0, jest_diff_1.diff)(output, content, options.diff)}`;
87
+ return {
88
+ pass: false,
89
+ message: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.${difference}`
90
+ };
116
91
  }
92
+ if (!isNot &&
93
+ (snapshotState._updateSnapshot === "new" ||
94
+ snapshotState._updateSnapshot === "all")) {
95
+ mkdirp_1.default.sync(node_path_1.default.dirname(filename));
96
+ node_fs_1.default.writeFileSync(filename, content);
97
+ snapshotState.added++;
98
+ return { pass: true, message: () => "" };
99
+ }
100
+ snapshotState.unmatched++;
101
+ return {
102
+ pass: true,
103
+ message: () => `The output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}.`
104
+ };
117
105
  }
118
106
  exports.toMatchFileSnapshot = toMatchFileSnapshot;
@@ -129,29 +129,25 @@ class FakeElement {
129
129
  if (this._type === "link" && name === "href") {
130
130
  return this.href;
131
131
  }
132
- else {
133
- return this._attributes[name];
134
- }
132
+ return this._attributes[name];
135
133
  }
136
134
  _toRealUrl(value) {
137
135
  if (/^\//.test(value)) {
138
136
  return `https://test.cases${value}`;
139
137
  }
140
- else if (/^\.\.\//.test(value)) {
138
+ if (/^\.\.\//.test(value)) {
141
139
  return `https://test.cases${value.slice(2)}`;
142
140
  }
143
- else if (/^\.\//.test(value)) {
141
+ if (/^\.\//.test(value)) {
144
142
  return `https://test.cases/path${value.slice(1)}`;
145
143
  }
146
- else if (/^\w+:\/\//.test(value)) {
144
+ if (/^\w+:\/\//.test(value)) {
147
145
  return value;
148
146
  }
149
- else if (/^\/\//.test(value)) {
147
+ if (/^\/\//.test(value)) {
150
148
  return `https:${value}`;
151
149
  }
152
- else {
153
- return `https://test.cases/path/${value}`;
154
- }
150
+ return `https://test.cases/path/${value}`;
155
151
  }
156
152
  set src(value) {
157
153
  if (this._type === "script") {
@@ -84,7 +84,7 @@ module.exports = function checkArrayExpectation(testDirectory, object, kind, fil
84
84
  return (done(new Error(`More ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}`)),
85
85
  true);
86
86
  }
87
- else if (expected.length > array.length) {
87
+ if (expected.length > array.length) {
88
88
  return (done(new Error(`Less ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}`)),
89
89
  true);
90
90
  }
@@ -6,7 +6,7 @@ const rimraf = require("rimraf");
6
6
  module.exports = function copyDiff(src, dest, initial) {
7
7
  fs.mkdirSync(dest, { recursive: true });
8
8
  const files = fs.readdirSync(src);
9
- files.forEach(filename => {
9
+ for (const filename of files) {
10
10
  const srcFile = path.join(src, filename);
11
11
  const destFile = path.join(dest, filename);
12
12
  const directory = fs.statSync(srcFile).isDirectory();
@@ -29,5 +29,5 @@ module.exports = function copyDiff(src, dest, initial) {
29
29
  }
30
30
  }
31
31
  }
32
- });
32
+ }
33
33
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // @ts-nocheck
3
3
  module.exports = (globalTimeout = 2000, nameSuffix = "") => {
4
- const state = global["JEST_STATE_SYMBOL"];
4
+ const state = global.JEST_STATE_SYMBOL;
5
5
  let currentDescribeBlock;
6
6
  let currentlyRunningTest;
7
7
  let runTests = -1;
@@ -7,10 +7,10 @@ module.exports = function supportsWorker() {
7
7
  if (nodeVersion[0] >= 14) {
8
8
  return true;
9
9
  }
10
- else if (nodeVersion[0] === 13 && nodeVersion[1] >= 12) {
10
+ if (nodeVersion[0] === 13 && nodeVersion[1] >= 12) {
11
11
  return true;
12
12
  }
13
- else if (nodeVersion[0] === 12 && nodeVersion[1] >= 17) {
13
+ if (nodeVersion[0] === 12 && nodeVersion[1] >= 17) {
14
14
  return true;
15
15
  }
16
16
  return false;
@@ -1,5 +1,6 @@
1
1
  export declare function parseModules(content: string, options?: {
2
2
  bootstrap?: boolean;
3
+ renameModule?: (name: string) => string;
3
4
  }): {
4
5
  modules: Map<string, string>;
5
6
  runtimeModules: Map<string, string>;
@@ -52,12 +52,15 @@ function parseModules(content, options = {}) {
52
52
  if (!moduleContent.result) {
53
53
  throw new Error(`Module code parsed error: ${moduleName}`);
54
54
  }
55
+ const renamedModuleName = typeof options.renameModule === "function"
56
+ ? options.renameModule(moduleName)
57
+ : moduleName;
55
58
  if (moduleName.startsWith("webpack/runtime")) {
56
- runtimeModules.set(moduleName, moduleContent.result);
59
+ runtimeModules.set(renamedModuleName, moduleContent.result);
57
60
  }
58
61
  else {
59
62
  if (isValidModule(moduleName)) {
60
- modules.set(moduleName, moduleContent.result);
63
+ modules.set(renamedModuleName, moduleContent.result);
61
64
  }
62
65
  }
63
66
  currentPosition = moduleContent.remain;
@@ -43,9 +43,7 @@ if (process.env.DEBUG_INFO) {
43
43
  throw e;
44
44
  });
45
45
  }
46
- else {
47
- process.stdout.write(`DONE OK ${name}\n`);
48
- }
46
+ process.stdout.write(`DONE OK ${name}\n`);
49
47
  }
50
48
  catch (e) {
51
49
  process.stdout.write(`DONE FAIL ${name}\n`);
@@ -137,11 +137,9 @@ const makeCacheableWithContext = fn => {
137
137
  if (cachedResult !== undefined) {
138
138
  return cachedResult;
139
139
  }
140
- else {
141
- const result = fn(context, identifier);
142
- innerSubCache.set(identifier, result);
143
- return result;
144
- }
140
+ const result = fn(context, identifier);
141
+ innerSubCache.set(identifier, result);
142
+ return result;
145
143
  };
146
144
  /**
147
145
  * @param {Object=} associatedObjectForCache an object to which the cache will be attached
@@ -176,11 +174,9 @@ const makeCacheableWithContext = fn => {
176
174
  if (cachedResult !== undefined) {
177
175
  return cachedResult;
178
176
  }
179
- else {
180
- const result = fn(context, identifier);
181
- innerSubCache.set(identifier, result);
182
- return result;
183
- }
177
+ const result = fn(context, identifier);
178
+ innerSubCache.set(identifier, result);
179
+ return result;
184
180
  };
185
181
  return boundFn;
186
182
  };
@@ -214,11 +210,9 @@ const makeCacheableWithContext = fn => {
214
210
  if (cachedResult !== undefined) {
215
211
  return cachedResult;
216
212
  }
217
- else {
218
- const result = fn(context, identifier);
219
- innerSubCache.set(identifier, result);
220
- return result;
221
- }
213
+ const result = fn(context, identifier);
214
+ innerSubCache.set(identifier, result);
215
+ return result;
222
216
  };
223
217
  return boundFn;
224
218
  };
@@ -6,7 +6,7 @@ class RspackDiffConfigPlugin {
6
6
  constructor(modifier) {
7
7
  this.modifier = modifier;
8
8
  this.name = PLUGIN_NAME;
9
- process.env["RSPACK_DIFF"] = "true"; // enable rspack diff
9
+ process.env.RSPACK_DIFF = "true"; // enable rspack diff
10
10
  }
11
11
  apply(compiler) {
12
12
  const { options } = compiler;
@@ -16,8 +16,10 @@ class RspackDiffConfigPlugin {
16
16
  options.optimization.minimize = false;
17
17
  options.optimization.chunkIds = "named";
18
18
  options.optimization.moduleIds = "named";
19
- options.optimization.mangleExports = false;
19
+ options.optimization.mangleExports ??= false;
20
+ options.optimization.concatenateModules ??= false;
20
21
  options.output ??= {};
22
+ options.output.pathinfo ??= false;
21
23
  options.output.environment ??= {};
22
24
  options.output.environment.arrowFunction ??= false;
23
25
  options.output.environment.bigIntLiteral ??= false;
@@ -16,10 +16,10 @@ class WebpackDiffConfigPlugin {
16
16
  options.optimization.minimize = false;
17
17
  options.optimization.chunkIds = "named";
18
18
  options.optimization.moduleIds = "named";
19
- options.optimization.mangleExports = false;
20
- options.optimization.concatenateModules = false;
19
+ options.optimization.mangleExports ??= false;
20
+ options.optimization.concatenateModules ??= false;
21
21
  options.output ??= {};
22
- options.output.pathinfo = false;
22
+ options.output.pathinfo ??= false;
23
23
  options.output.environment ??= {};
24
24
  options.output.environment.arrowFunction ??= false;
25
25
  options.output.environment.bigIntLiteral ??= false;
@@ -10,6 +10,7 @@ export interface IDiffProcessorOptions extends IFormatCodeOptions {
10
10
  detail?: boolean;
11
11
  errors?: boolean;
12
12
  replacements?: IFormatCodeReplacement[];
13
+ renameModule?: (file: string) => string;
13
14
  onCompareFile?: (file: string, result: TFileCompareResult) => void;
14
15
  onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
15
16
  onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
@@ -63,7 +63,7 @@ class DiffProcessor {
63
63
  modules: this.options.modules,
64
64
  runtimeModules: this.options.runtimeModules,
65
65
  format: this.createFormatOptions(),
66
- renameModule: compare_1.replaceRuntimeModuleName,
66
+ renameModule: this.options.renameModule,
67
67
  bootstrap: this.options.bootstrap,
68
68
  detail: this.options.detail
69
69
  });
@@ -71,12 +71,12 @@ class DiffProcessor {
71
71
  this.options.onCompareFile(file, result);
72
72
  }
73
73
  if (typeof this.options.onCompareModules === "function" &&
74
- result.modules["modules"]) {
75
- this.options.onCompareModules(file, result.modules["modules"]);
74
+ result.modules.modules) {
75
+ this.options.onCompareModules(file, result.modules.modules);
76
76
  }
77
77
  if (typeof this.options.onCompareRuntimeModules === "function" &&
78
- result.modules["runtimeModules"]) {
79
- this.options.onCompareRuntimeModules(file, result.modules["runtimeModules"]);
78
+ result.modules.runtimeModules) {
79
+ this.options.onCompareRuntimeModules(file, result.modules.runtimeModules);
80
80
  }
81
81
  }
82
82
  }
@@ -16,12 +16,12 @@ const SELF_HANDLER = (file, options) => {
16
16
  res = Object.keys(modules);
17
17
  };
18
18
  const hotUpdateGlobalKey = escapeLocalName(`${options.output?.hotUpdateGlobal || "webpackHotUpdate"}${options.output?.uniqueName || ""}`);
19
- global["self"] ??= {};
20
- global["self"][hotUpdateGlobalKey] = hotUpdateGlobal;
19
+ global.self ??= {};
20
+ global.self[hotUpdateGlobalKey] = hotUpdateGlobal;
21
21
  require(file);
22
- delete global["self"][hotUpdateGlobalKey];
23
- if (!Object.keys(global["self"]).length) {
24
- delete global["self"];
22
+ delete global.self[hotUpdateGlobalKey];
23
+ if (!Object.keys(global.self).length) {
24
+ delete global.self;
25
25
  }
26
26
  return res;
27
27
  };
@@ -171,7 +171,7 @@ class HotSnapshotProcessor extends hot_1.HotProcessor {
171
171
  });
172
172
  return `- Update: ${renderName}, size: ${content.length}`;
173
173
  }
174
- else if (fileName.endsWith("hot-update.json")) {
174
+ if (fileName.endsWith("hot-update.json")) {
175
175
  const manifest = JSON.parse(content);
176
176
  manifest.c?.sort();
177
177
  manifest.r?.sort();
@@ -182,7 +182,7 @@ class HotSnapshotProcessor extends hot_1.HotProcessor {
182
182
  });
183
183
  return `- Manifest: ${renderName}, size: ${i.size}`;
184
184
  }
185
- else if (fileName.endsWith(".js")) {
185
+ if (fileName.endsWith(".js")) {
186
186
  return `- Bundle: ${renderName}`;
187
187
  }
188
188
  })
@@ -119,16 +119,17 @@ class NormalProcessor extends basic_1.BasicProcessor {
119
119
  .concat(testConfig.plugins || [])
120
120
  .concat(function () {
121
121
  this.hooks.compilation.tap("TestCasesTest", compilation => {
122
- [
122
+ const hooks = [
123
123
  // CHANGE: the follwing hooks are not supported yet, so comment it out
124
124
  // "optimize",
125
125
  // "optimizeModules",
126
126
  // "optimizeChunks",
127
127
  // "afterOptimizeTree",
128
128
  // "afterOptimizeAssets"
129
- ].forEach(hook => {
129
+ ];
130
+ for (const hook of hooks) {
130
131
  compilation.hooks[hook].tap("TestCasesTest", () => compilation.checkConstraints());
131
- });
132
+ }
132
133
  });
133
134
  }),
134
135
  experiments: {
@@ -32,11 +32,13 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
32
32
  async compiler(context) {
33
33
  await super.compiler(context);
34
34
  const instance = this.getCompiler(context).getCompiler();
35
- const compilers = instance.compilers ? instance.compilers : [instance];
36
- compilers.forEach((c) => {
37
- const ifs = c.inputFileSystem;
38
- c.inputFileSystem = Object.create(ifs);
39
- c.inputFileSystem.readFile = () => {
35
+ const compilers = instance.compilers
36
+ ? instance.compilers
37
+ : [instance];
38
+ for (const compiler of compilers) {
39
+ const ifs = compiler.inputFileSystem;
40
+ compiler.inputFileSystem = Object.create(ifs);
41
+ compiler.inputFileSystem.readFile = () => {
40
42
  const args = Array.prototype.slice.call(arguments);
41
43
  const callback = args.pop();
42
44
  ifs.readFile.apply(ifs, args.concat([
@@ -50,7 +52,7 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
50
52
  ]));
51
53
  };
52
54
  // CHANGE: The checkConstraints() function is currently not implemented in rspack
53
- // c.hooks.compilation.tap("StatsTestCasesTest", compilation => {
55
+ // compiler.hooks.compilation.tap("StatsTestCasesTest", compilation => {
54
56
  // [
55
57
  // "optimize",
56
58
  // "optimizeModules",
@@ -64,7 +66,7 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
64
66
  // );
65
67
  // });
66
68
  // });
67
- });
69
+ }
68
70
  }
69
71
  async check(env, context) {
70
72
  const compiler = this.getCompiler(context);
@@ -45,9 +45,7 @@ class BasicRunnerFactory {
45
45
  type_1.EDocumentType.JSDOM
46
46
  });
47
47
  }
48
- else {
49
- return new esm_1.EsmRunner(runnerOptions);
50
- }
48
+ return new esm_1.EsmRunner(runnerOptions);
51
49
  }
52
50
  }
53
51
  exports.BasicRunnerFactory = BasicRunnerFactory;
@@ -19,7 +19,7 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
19
19
  hotUpdateContext.updateIndex++;
20
20
  // TODO: find a better way to collect changed files from fake-update-loader
21
21
  const changedFiles = new Map();
22
- global["__CHANGED_FILES__"] = changedFiles;
22
+ global.__CHANGED_FILES__ = changedFiles;
23
23
  compiler
24
24
  .build()
25
25
  .then(stats => {
@@ -61,7 +61,7 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
61
61
  if (typeof testConfig.moduleScope === "function") {
62
62
  ms = testConfig.moduleScope(ms);
63
63
  }
64
- ms["NEXT"] = next;
64
+ ms.NEXT = next;
65
65
  return ms;
66
66
  }
67
67
  },
@@ -19,7 +19,7 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
19
19
  hotUpdateContext.updateIndex++;
20
20
  // TODO: find a better way to collect changed files from fake-update-loader
21
21
  const changedFiles = new Map();
22
- global["__CHANGED_FILES__"] = changedFiles;
22
+ global.__CHANGED_FILES__ = changedFiles;
23
23
  compiler
24
24
  .build()
25
25
  .then(stats => {
@@ -52,7 +52,7 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
52
52
  if (typeof testConfig.moduleScope === "function") {
53
53
  ms = testConfig.moduleScope(ms);
54
54
  }
55
- ms["NEXT"] = next;
55
+ ms.NEXT = next;
56
56
  return ms;
57
57
  }
58
58
  },
@@ -44,9 +44,7 @@ class BasicRunner {
44
44
  if (typeof res === "object" && "then" in res) {
45
45
  return res;
46
46
  }
47
- else {
48
- return Promise.resolve(res);
49
- }
47
+ return Promise.resolve(res);
50
48
  }
51
49
  getRequire() {
52
50
  const entryRequire = this.requirers.get("entry");
@@ -72,7 +70,7 @@ class BasicRunner {
72
70
  subPath: ""
73
71
  };
74
72
  }
75
- else if (isRelativePath(modulePath)) {
73
+ if (isRelativePath(modulePath)) {
76
74
  const p = node_path_1.default.join(currentDirectory, modulePath);
77
75
  return {
78
76
  path: p,
@@ -80,16 +78,14 @@ class BasicRunner {
80
78
  subPath: getSubPath(modulePath)
81
79
  };
82
80
  }
83
- else if (node_path_1.default.isAbsolute(modulePath)) {
81
+ if (node_path_1.default.isAbsolute(modulePath)) {
84
82
  return {
85
83
  path: modulePath,
86
84
  content: node_fs_1.default.readFileSync(modulePath, "utf-8"),
87
85
  subPath: "absolute_path"
88
86
  };
89
87
  }
90
- else {
91
- return null;
92
- }
88
+ return null;
93
89
  }
94
90
  preExecute(code, file) { }
95
91
  postExecute(m, file) { }
@@ -37,7 +37,7 @@ class CommonJsRunner extends basic_1.BasicRunner {
37
37
  ...this._options.env
38
38
  };
39
39
  if (this._options.stats) {
40
- baseModuleScope["__STATS__"] = this._options.stats;
40
+ baseModuleScope.__STATS__ = this._options.stats;
41
41
  }
42
42
  return baseModuleScope;
43
43
  }
@@ -66,17 +66,15 @@ class CommonJsRunner extends basic_1.BasicRunner {
66
66
  if (modules && modulePathStr in modules) {
67
67
  return modules[modulePathStr];
68
68
  }
69
- else {
70
- return require(modulePathStr.startsWith("node:")
71
- ? modulePathStr.slice(5)
72
- : modulePathStr);
73
- }
69
+ return require(modulePathStr.startsWith("node:")
70
+ ? modulePathStr.slice(5)
71
+ : modulePathStr);
74
72
  };
75
73
  }
76
74
  createCjsRequirer() {
77
75
  const requireCache = Object.create(null);
78
76
  return (currentDirectory, modulePath, context = {}) => {
79
- const file = context["file"] || this.getFile(modulePath, currentDirectory);
77
+ const file = context.file || this.getFile(modulePath, currentDirectory);
80
78
  if (!file) {
81
79
  return this.requirers.get("miss")(currentDirectory, modulePath);
82
80
  }
@@ -50,12 +50,10 @@ class EsmRunner extends cjs_1.CommonJsRunner {
50
50
  file
51
51
  });
52
52
  }
53
- else {
54
- return this.requirers.get("cjs")(currentDirectory, modulePath, {
55
- ...context,
56
- file
57
- });
58
- }
53
+ return this.requirers.get("cjs")(currentDirectory, modulePath, {
54
+ ...context,
55
+ file
56
+ });
59
57
  });
60
58
  }
61
59
  createEsmRequirer() {
@@ -69,7 +67,7 @@ class EsmRunner extends cjs_1.CommonJsRunner {
69
67
  throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/jest-cli/bin/jest'.");
70
68
  }
71
69
  const _require = this.getRequire();
72
- const file = context["file"] || this.getFile(modulePath, currentDirectory);
70
+ const file = context.file || this.getFile(modulePath, currentDirectory);
73
71
  if (!file) {
74
72
  return this.requirers.get("miss")(currentDirectory, modulePath);
75
73
  }
@@ -92,7 +90,7 @@ class EsmRunner extends cjs_1.CommonJsRunner {
92
90
  });
93
91
  esmCache.set(file.path, esm);
94
92
  }
95
- if (context["esmMode"] === type_1.EEsmMode.Unlinked)
93
+ if (context.esmMode === type_1.EEsmMode.Unlinked)
96
94
  return esm;
97
95
  return (async () => {
98
96
  await esm.link(async (specifier, referencingModule) => {
@@ -105,13 +103,11 @@ class EsmRunner extends cjs_1.CommonJsRunner {
105
103
  if (esm.instantiate)
106
104
  esm.instantiate();
107
105
  await esm.evaluate();
108
- if (context["esmMode"] === type_1.EEsmMode.Evaluated) {
106
+ if (context.esmMode === type_1.EEsmMode.Evaluated) {
109
107
  return esm;
110
108
  }
111
- else {
112
- const ns = esm.namespace;
113
- return ns.default && ns.default instanceof Promise ? ns.default : ns;
114
- }
109
+ const ns = esm.namespace;
110
+ return ns.default && ns.default instanceof Promise ? ns.default : ns;
115
111
  })();
116
112
  };
117
113
  }
@@ -16,15 +16,15 @@ class WatchRunner extends cjs_1.CommonJsRunner {
16
16
  }
17
17
  createGlobalContext() {
18
18
  const globalContext = super.createGlobalContext();
19
- globalContext["document"] = this.document;
19
+ globalContext.document = this.document;
20
20
  return globalContext;
21
21
  }
22
22
  createModuleScope(requireFn, m, file) {
23
23
  const moduleScope = super.createModuleScope(requireFn, m, file);
24
- moduleScope["__dirname"] = node_path_1.default.dirname(file.path);
25
- moduleScope["document"] = this.globalContext["document"];
26
- moduleScope["STATE"] = this.state;
27
- moduleScope["WATCH_STEP"] = this._watchOptions.stepName;
24
+ moduleScope.__dirname = node_path_1.default.dirname(file.path);
25
+ moduleScope.document = this.globalContext.document;
26
+ moduleScope.STATE = this.state;
27
+ moduleScope.WATCH_STEP = this._watchOptions.stepName;
28
28
  return moduleScope;
29
29
  }
30
30
  }
@@ -35,14 +35,14 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
35
35
  }
36
36
  createGlobalContext() {
37
37
  const globalContext = super.createGlobalContext();
38
- globalContext["document"] = this.document;
39
- globalContext["getComputedStyle"] = this.document.getComputedStyle.bind(this.document);
38
+ globalContext.document = this.document;
39
+ globalContext.getComputedStyle = this.document.getComputedStyle.bind(this.document);
40
40
  const urlToPath = (url) => {
41
41
  if (url.startsWith("https://test.cases/path/"))
42
42
  url = url.slice(24);
43
43
  return node_path_1.default.resolve(this._options.dist, `./${url}`);
44
44
  };
45
- globalContext["fetch"] = async (url) => {
45
+ globalContext.fetch = async (url) => {
46
46
  try {
47
47
  const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(urlToPath(url), (err, b) => err ? reject(err) : resolve(b)));
48
48
  return {
@@ -61,16 +61,16 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
61
61
  throw err;
62
62
  }
63
63
  };
64
- globalContext["importScripts"] = (url) => {
64
+ globalContext.importScripts = (url) => {
65
65
  this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
66
66
  this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
67
67
  };
68
- globalContext["document"] = this.document;
69
- globalContext["Worker"] = (0, createFakeWorker_1.default)(this._options.env, {
68
+ globalContext.document = this.document;
69
+ globalContext.Worker = (0, createFakeWorker_1.default)(this._options.env, {
70
70
  outputDirectory: this._options.dist
71
71
  });
72
- globalContext["EventSource"] = EventSourceForNode_1.default;
73
- globalContext["location"] = {
72
+ globalContext.EventSource = EventSourceForNode_1.default;
73
+ globalContext.location = {
74
74
  href: "https://test.cases/path/index.html",
75
75
  origin: "https://test.cases",
76
76
  toString() {
@@ -81,7 +81,7 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
81
81
  }
82
82
  createModuleScope(requireFn, m, file) {
83
83
  const subModuleScope = super.createModuleScope(requireFn, m, file);
84
- subModuleScope["importScripts"] = (url) => {
84
+ subModuleScope.importScripts = (url) => {
85
85
  this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
86
86
  this.getRequire()(this._options.dist, `.${url.slice("https://test.cases/path".length)}`);
87
87
  };
@@ -89,19 +89,19 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
89
89
  }
90
90
  createBaseModuleScope() {
91
91
  const moduleScope = super.createBaseModuleScope();
92
- moduleScope["window"] = this.globalContext;
93
- moduleScope["self"] = this.globalContext;
94
- moduleScope["globalThis"] = this.globalContext;
95
- moduleScope["document"] = this.globalContext["document"];
96
- moduleScope["fetch"] = this.globalContext["fetch"];
97
- moduleScope["importScripts"] = this.globalContext["importScripts"];
98
- moduleScope["Worker"] = this.globalContext["Worker"];
99
- moduleScope["EventSource"] = this.globalContext["EventSource"];
100
- moduleScope["URL"] = URL;
101
- moduleScope["Worker"] = (0, createFakeWorker_1.default)(this._options.env, {
92
+ moduleScope.window = this.globalContext;
93
+ moduleScope.self = this.globalContext;
94
+ moduleScope.globalThis = this.globalContext;
95
+ moduleScope.document = this.globalContext.document;
96
+ moduleScope.fetch = this.globalContext.fetch;
97
+ moduleScope.importScripts = this.globalContext.importScripts;
98
+ moduleScope.Worker = this.globalContext.Worker;
99
+ moduleScope.EventSource = this.globalContext.EventSource;
100
+ moduleScope.URL = URL;
101
+ moduleScope.Worker = (0, createFakeWorker_1.default)(this._options.env, {
102
102
  outputDirectory: this._options.dist
103
103
  });
104
- moduleScope["__dirname"] = this._options.dist;
104
+ moduleScope.__dirname = this._options.dist;
105
105
  return moduleScope;
106
106
  }
107
107
  createJsonRequirer() {
@@ -109,7 +109,7 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
109
109
  if (Array.isArray(modulePath)) {
110
110
  throw new Error("Array module path is not supported in hot cases");
111
111
  }
112
- const file = context["file"] || this.getFile(modulePath, currentDirectory);
112
+ const file = context.file || this.getFile(modulePath, currentDirectory);
113
113
  if (!file) {
114
114
  return this.requirers.get("miss")(currentDirectory, modulePath);
115
115
  }
@@ -127,9 +127,7 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
127
127
  if (modulePath.endsWith(".json")) {
128
128
  return this.requirers.get("json")(this._options.dist, modulePath, context);
129
129
  }
130
- else {
131
- return this.requirers.get("cjs")(this._options.dist, modulePath, context);
132
- }
130
+ return this.requirers.get("cjs")(this._options.dist, modulePath, context);
133
131
  });
134
132
  }
135
133
  preExecute(_, file) {
@@ -53,7 +53,7 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
53
53
  });
54
54
  `);
55
55
  const vmContext = this.dom.getInternalVMContext();
56
- vmContext["global"] = {};
56
+ vmContext.global = {};
57
57
  }
58
58
  run(file) {
59
59
  if (!file.endsWith(".js")) {
@@ -92,8 +92,8 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
92
92
  }
93
93
  createBaseModuleScope() {
94
94
  const moduleScope = super.createBaseModuleScope();
95
- moduleScope["EventSource"] = EventSourceForNode_1.default;
96
- moduleScope["Worker"] = (0, createFakeWorker_1.default)(this._options.env, {
95
+ moduleScope.EventSource = EventSourceForNode_1.default;
96
+ moduleScope.Worker = (0, createFakeWorker_1.default)(this._options.env, {
97
97
  outputDirectory: this._options.dist
98
98
  });
99
99
  const urlToPath = (url) => {
@@ -101,7 +101,7 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
101
101
  url = url.slice(24);
102
102
  return node_path_1.default.resolve(this._webOptions.dist, `./${url}`);
103
103
  };
104
- moduleScope["fetch"] = async (url) => {
104
+ moduleScope.fetch = async (url) => {
105
105
  try {
106
106
  const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(urlToPath(url), (err, b) => err ? reject(err) : resolve(b)));
107
107
  return {
@@ -120,18 +120,18 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
120
120
  throw err;
121
121
  }
122
122
  };
123
- moduleScope["URL"] = URL;
124
- moduleScope["importScripts"] = (url) => {
123
+ moduleScope.URL = URL;
124
+ moduleScope.importScripts = (url) => {
125
125
  this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
126
126
  this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
127
127
  };
128
- moduleScope["STATS"] = moduleScope.__STATS__;
128
+ moduleScope.STATS = moduleScope.__STATS__;
129
129
  return moduleScope;
130
130
  }
131
131
  createJSDOMRequirer() {
132
132
  const requireCache = Object.create(null);
133
133
  return (currentDirectory, modulePath, context = {}) => {
134
- const file = context["file"] || this.getFile(modulePath, currentDirectory);
134
+ const file = context.file || this.getFile(modulePath, currentDirectory);
135
135
  if (!file) {
136
136
  return this.requirers.get("miss")(currentDirectory, modulePath);
137
137
  }
@@ -67,15 +67,13 @@ class BasicCaseCreator {
67
67
  if (typeof this._options.runner === "function" && !testConfig.noTest) {
68
68
  return (0, createLazyTestEnv_1.default)(10000);
69
69
  }
70
- else {
71
- return {
72
- expect,
73
- it,
74
- beforeEach,
75
- afterEach,
76
- jest
77
- };
78
- }
70
+ return {
71
+ expect,
72
+ it,
73
+ beforeEach,
74
+ afterEach,
75
+ jest
76
+ };
79
77
  }
80
78
  clean(folders) {
81
79
  for (const f of folders) {
@@ -54,9 +54,7 @@ class Tester {
54
54
  this.step++;
55
55
  return true;
56
56
  }
57
- else {
58
- return false;
59
- }
57
+ return false;
60
58
  }
61
59
  async resume() {
62
60
  for (const i of this.steps) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-beta.0",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -40,13 +40,13 @@
40
40
  "csv-to-markdown-table": "^1.3.0",
41
41
  "deepmerge": "^4.3.1",
42
42
  "filenamify": "4.3.0",
43
- "fs-extra": "11.2.0",
43
+ "fs-extra": "^11.2.0",
44
44
  "glob": "^10.3.10",
45
45
  "jest-diff": "^29.7.0",
46
46
  "jest-serializer-path": "^0.1.15",
47
47
  "jest-snapshot": "29.7.0",
48
- "jsdom": "24.0.0",
49
- "memfs": "4.7.7",
48
+ "jsdom": "^24.0.0",
49
+ "memfs": "4.8.1",
50
50
  "mkdirp": "0.5.6",
51
51
  "pretty-format": "29.7.0",
52
52
  "rimraf": "3.0.2",
@@ -58,7 +58,7 @@
58
58
  "devDependencies": {
59
59
  "@arco-design/web-react": "^2.56.1",
60
60
  "@monaco-editor/react": "^4.6.0",
61
- "@swc/plugin-remove-console": "^2.0.7",
61
+ "@swc/plugin-remove-console": "^2.0.8",
62
62
  "@swc/helpers": "0.5.8",
63
63
  "@types/jsdom": "^21.1.7",
64
64
  "@types/react": "^18.2.48",
@@ -72,7 +72,7 @@
72
72
  "core-js": "3.36.1",
73
73
  "coffee-loader": "^1.0.0",
74
74
  "coffeescript": "^2.5.1",
75
- "copy-webpack-plugin": "5",
75
+ "copy-webpack-plugin": "5.1.2",
76
76
  "chalk": "^4.1.0",
77
77
  "babel-loader": "^9.1.3",
78
78
  "babel-plugin-import": "^1.13.5",
@@ -83,24 +83,24 @@
83
83
  "less-loader": "^12.2.0",
84
84
  "lodash": "^4.17.21",
85
85
  "pug-loader": "^2.4.0",
86
- "postcss-loader": "^7.3.4",
86
+ "postcss-loader": "^8.0.0",
87
87
  "postcss-pxtorem": "^6.0.0",
88
88
  "raw-loader": "^4.0.2",
89
89
  "monaco-editor": "0.47.0",
90
90
  "monaco-editor-webpack-plugin": "7.1.0",
91
91
  "normalize.css": "^8.0.0",
92
92
  "npm-run-all2": "^6.2.0",
93
- "react": "18.0.0",
94
- "react-dom": "18.0.0",
95
- "react-refresh": "0.14.0",
93
+ "react": "^18.2.0",
94
+ "react-dom": "^18.2.0",
95
+ "react-refresh": "^0.14.0",
96
96
  "sass-loader": "14.2.1",
97
97
  "style-loader": "^3.3.3",
98
98
  "source-map-loader": "^5.0.0",
99
- "terser": "5.16.1",
99
+ "terser": "5.27.2",
100
+ "typescript": "5.0.2",
100
101
  "wast-loader": "^1.12.1",
101
- "@rspack/cli": "1.0.0-alpha.5",
102
- "@rspack/core": "1.0.0-alpha.5",
103
- "@rspack/plugin-minify": "1.0.0-alpha.5"
102
+ "@rspack/core": "1.0.0-beta.0",
103
+ "@rspack/cli": "1.0.0-beta.0"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "@rspack/core": ">=0.7.0"