@rspack/test-tools 2.0.2 → 2.0.3

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 (118) hide show
  1. package/dist/case/builtin.js +106 -66
  2. package/dist/case/cache.js +136 -122
  3. package/dist/case/common.d.ts +4 -4
  4. package/dist/case/common.js +162 -157
  5. package/dist/case/compiler.d.ts +4 -4
  6. package/dist/case/compiler.js +75 -64
  7. package/dist/case/config.js +112 -74
  8. package/dist/case/defaults.js +136 -83
  9. package/dist/case/diagnostic.js +112 -84
  10. package/dist/case/error.d.ts +4 -4
  11. package/dist/case/error.js +105 -89
  12. package/dist/case/esm-output.js +118 -87
  13. package/dist/case/example.js +73 -35
  14. package/dist/case/hash.js +74 -59
  15. package/dist/case/hook.js +151 -138
  16. package/dist/case/hot-step.js +130 -161
  17. package/dist/case/hot.js +148 -134
  18. package/dist/case/incremental.js +91 -58
  19. package/dist/case/index.js +134 -51
  20. package/dist/case/multi-compiler.d.ts +4 -4
  21. package/dist/case/multi-compiler.js +81 -56
  22. package/dist/case/native-watcher.js +62 -30
  23. package/dist/case/normal.js +253 -185
  24. package/dist/case/runner.js +80 -51
  25. package/dist/case/serial.js +47 -16
  26. package/dist/case/stats-api.d.ts +4 -4
  27. package/dist/case/stats-api.js +63 -43
  28. package/dist/case/stats-output.d.ts +3 -3
  29. package/dist/case/stats-output.js +147 -152
  30. package/dist/case/treeshaking.js +66 -35
  31. package/dist/case/watch.d.ts +3 -19
  32. package/dist/case/watch.js +204 -224
  33. package/dist/compiler.js +222 -195
  34. package/dist/helper/directory.js +83 -71
  35. package/dist/helper/disable-iconv-lite-warning.js +35 -9
  36. package/dist/helper/expect/diff.js +39 -10
  37. package/dist/helper/expect/error.js +62 -30
  38. package/dist/helper/expect/placeholder.js +47 -21
  39. package/dist/helper/expect/rspack.js +35 -13
  40. package/dist/helper/expect/to-be-typeof.js +39 -7
  41. package/dist/helper/expect/to-end-with.js +40 -8
  42. package/dist/helper/expect/to-match-file-snapshot.js +103 -80
  43. package/dist/helper/hot-update/index.js +35 -4
  44. package/dist/helper/hot-update/loader.d.ts +1 -0
  45. package/dist/helper/hot-update/loader.js +39 -4
  46. package/dist/helper/hot-update/plugin.d.ts +1 -1
  47. package/dist/helper/hot-update/plugin.js +87 -74
  48. package/dist/helper/index.js +138 -24
  49. package/dist/helper/is.js +51 -10
  50. package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
  51. package/dist/helper/legacy/EventSourceForNode.js +83 -37
  52. package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
  53. package/dist/helper/legacy/LogTestPlugin.js +39 -6
  54. package/dist/helper/legacy/asModule.d.ts +3 -3
  55. package/dist/helper/legacy/asModule.js +68 -19
  56. package/dist/helper/legacy/captureStdio.d.ts +1 -2
  57. package/dist/helper/legacy/captureStdio.js +69 -29
  58. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
  59. package/dist/helper/legacy/checkArrayExpectation.js +132 -121
  60. package/dist/helper/legacy/copyDiff.d.ts +1 -2
  61. package/dist/helper/legacy/copyDiff.js +86 -42
  62. package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
  63. package/dist/helper/legacy/createFakeWorker.js +90 -47
  64. package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
  65. package/dist/helper/legacy/createLazyTestEnv.js +70 -59
  66. package/dist/helper/legacy/currentScript.d.ts +2 -2
  67. package/dist/helper/legacy/currentScript.js +35 -2
  68. package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
  69. package/dist/helper/legacy/deprecationTracking.js +53 -28
  70. package/dist/helper/legacy/expectSource.d.ts +3 -2
  71. package/dist/helper/legacy/expectSource.js +42 -18
  72. package/dist/helper/legacy/fakeSystem.d.ts +12 -9
  73. package/dist/helper/legacy/fakeSystem.js +68 -58
  74. package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
  75. package/dist/helper/legacy/findOutputFiles.js +60 -13
  76. package/dist/helper/legacy/parseResource.d.ts +1 -1
  77. package/dist/helper/legacy/parseResource.js +36 -6
  78. package/dist/helper/legacy/regexEscape.d.ts +1 -2
  79. package/dist/helper/legacy/regexEscape.js +39 -5
  80. package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
  81. package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
  82. package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
  83. package/dist/helper/legacy/supportsTextDecoder.js +40 -6
  84. package/dist/helper/legacy/supportsUsing.d.ts +1 -2
  85. package/dist/helper/legacy/supportsUsing.js +40 -7
  86. package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
  87. package/dist/helper/legacy/urlToRelativePath.js +56 -7
  88. package/dist/helper/parse-modules.js +52 -42
  89. package/dist/helper/read-config-file.js +60 -18
  90. package/dist/helper/serializers.js +62 -33
  91. package/dist/helper/setup-env.js +81 -91
  92. package/dist/helper/setup-expect.js +13 -13
  93. package/dist/helper/setup-wasm.js +18 -9
  94. package/dist/helper/stringify-config.js +44 -26
  95. package/dist/helper/update-snapshot.js +35 -3
  96. package/dist/helper/util/checkSourceMap.js +119 -80
  97. package/dist/helper/util/checkStats.d.ts +1 -1
  98. package/dist/helper/util/checkStats.js +42 -17
  99. package/dist/helper/util/expectWarningFactory.d.ts +1 -2
  100. package/dist/helper/util/expectWarningFactory.js +41 -8
  101. package/dist/helper/util/filterUtil.d.ts +9 -8
  102. package/dist/helper/util/filterUtil.js +63 -23
  103. package/dist/helper/win.js +46 -7
  104. package/dist/index.js +115 -23
  105. package/dist/plugin/index.js +55 -14
  106. package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
  107. package/dist/reporter/index.js +55 -14
  108. package/dist/reporter/streamed-events-reporter.js +51 -77
  109. package/dist/runner/index.js +62 -15
  110. package/dist/runner/node/index.js +365 -431
  111. package/dist/runner/web/index.js +278 -263
  112. package/dist/test/context.js +67 -41
  113. package/dist/test/creator.js +135 -167
  114. package/dist/test/debug.js +89 -58
  115. package/dist/test/tester.js +94 -74
  116. package/dist/type.d.ts +10 -9
  117. package/dist/type.js +43 -9
  118. package/package.json +21 -20
package/dist/case/hook.js CHANGED
@@ -1,199 +1,205 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HookCasesContext = void 0;
7
- exports.createHookCase = createHookCase;
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const core_1 = require("@rspack/core");
10
- const jest_snapshot_1 = require("jest-snapshot");
11
- const path_serializer_1 = require("path-serializer");
12
- const pretty_format_1 = require("pretty-format");
13
- const rspack_merge_1 = __importDefault(require("rspack-merge"));
14
- const context_1 = require("../test/context");
15
- const creator_1 = require("../test/creator");
16
- const common_1 = require("./common");
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ HookCasesContext: ()=>HookCasesContext,
37
+ createHookCase: ()=>createHookCase
38
+ });
39
+ const external_node_path_namespaceObject = require("node:path");
40
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
41
+ const core_namespaceObject = require("@rspack/core");
42
+ const external_jest_snapshot_namespaceObject = require("jest-snapshot");
43
+ const external_path_serializer_namespaceObject = require("path-serializer");
44
+ const external_pretty_format_namespaceObject = require("pretty-format");
45
+ const external_rspack_merge_namespaceObject = require("rspack-merge");
46
+ var external_rspack_merge_default = /*#__PURE__*/ __webpack_require__.n(external_rspack_merge_namespaceObject);
47
+ const context_js_namespaceObject = require("../test/context.js");
48
+ const creator_js_namespaceObject = require("../test/creator.js");
49
+ const external_common_js_namespaceObject = require("./common.js");
17
50
  const srcDir = __TEST_FIXTURES_PATH__;
18
- const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__, 'hook');
19
- const creator = new creator_1.BasicCaseCreator({
51
+ const distDir = external_node_path_default().resolve(__TEST_DIST_PATH__, 'hook');
52
+ const creator = new creator_js_namespaceObject.BasicCaseCreator({
20
53
  clean: true,
21
54
  describe: true,
22
- createContext: (config) => new HookCasesContext(config.src, config.name, config),
23
- steps: ({ name, caseConfig: _caseConfig, src }) => {
55
+ createContext: (config)=>new HookCasesContext(config.src, config.name, config),
56
+ steps: ({ name, caseConfig: _caseConfig, src })=>{
24
57
  const caseConfig = _caseConfig;
25
58
  return [
26
59
  {
27
- config: async (context) => {
60
+ config: async (context)=>{
28
61
  const compiler = context.getCompiler();
29
- const options = await (0, common_1.config)(context, name, ['rspack.config.js', 'webpack.config.js'], defaultOptions(context, caseConfig.options));
30
- if (!global.printLogger) {
31
- options.infrastructureLogging = {
32
- level: 'error',
33
- };
34
- }
62
+ const options = await (0, external_common_js_namespaceObject.config)(context, name, [
63
+ 'rspack.config.js',
64
+ 'webpack.config.js'
65
+ ], hook_defaultOptions(context, caseConfig.options));
66
+ if (!global.printLogger) options.infrastructureLogging = {
67
+ level: 'error'
68
+ };
35
69
  compiler.setOptions(options);
36
70
  },
37
- compiler: async (context) => {
38
- const c = await (0, common_1.compiler)(context, name);
39
- if (caseConfig.compiler) {
40
- await caseConfig.compiler(context, c);
41
- }
42
- },
43
- build: async (context) => {
44
- await (0, common_1.build)(context, name);
71
+ compiler: async (context)=>{
72
+ const c = await (0, external_common_js_namespaceObject.compiler)(context, name);
73
+ if (caseConfig.compiler) await caseConfig.compiler(context, c);
45
74
  },
46
- run: async (env, context) => {
47
- // no need to run, just check snapshot
75
+ build: async (context)=>{
76
+ await (0, external_common_js_namespaceObject.build)(context, name);
48
77
  },
49
- check: async (env, context) => {
50
- await (0, common_1.checkSnapshot)(env, context, name, node_path_1.default.join(src, 'output.snap.txt'), caseConfig.snapshotFileFilter);
51
- },
52
- },
78
+ run: async (env, context)=>{},
79
+ check: async (env, context)=>{
80
+ await (0, external_common_js_namespaceObject.checkSnapshot)(env, context, name, external_node_path_default().join(src, 'output.snap.txt'), caseConfig.snapshotFileFilter);
81
+ }
82
+ }
53
83
  ];
54
- },
84
+ }
55
85
  });
56
86
  function createHookCase(name, src, dist, source) {
57
- const caseConfig = require(node_path_1.default.join(src, 'test.js'));
58
- const testName = node_path_1.default.basename(name.slice(0, name.indexOf(node_path_1.default.extname(name))));
59
- creator.create(name, src, dist, undefined, {
87
+ const caseConfig = require(external_node_path_default().join(src, 'test.js'));
88
+ const testName = external_node_path_default().basename(name.slice(0, name.indexOf(external_node_path_default().extname(name))));
89
+ creator.create(name, src, dist, void 0, {
60
90
  caseConfig,
61
- description: () => caseConfig.description,
62
- createContext: (config) => new HookCasesContext(src, testName, {
63
- src: source,
64
- dist: dist,
65
- name: name,
66
- }),
91
+ description: ()=>caseConfig.description,
92
+ createContext: (config)=>new HookCasesContext(src, testName, {
93
+ src: source,
94
+ dist: dist,
95
+ name: name
96
+ })
67
97
  });
68
98
  }
69
99
  const sourceSerializer = {
70
- test(val) {
71
- return val instanceof core_1.sources.Source;
100
+ test (val) {
101
+ return val instanceof core_namespaceObject.sources.Source;
72
102
  },
73
- print(val) {
103
+ print (val) {
74
104
  return val.source();
75
- },
105
+ }
76
106
  };
77
107
  const internalSerializer = {
78
- test(val) {
79
- return val instanceof core_1.Compiler || val instanceof core_1.Compilation;
108
+ test (val) {
109
+ return val instanceof core_namespaceObject.Compiler || val instanceof core_namespaceObject.Compilation;
80
110
  },
81
- print(val) {
111
+ print (val) {
82
112
  return JSON.stringify(`${val.constructor.name}(internal ignored)`);
83
- },
113
+ }
84
114
  };
85
- const testPathSerializer = (0, path_serializer_1.createSnapshotSerializer)({
115
+ const testPathSerializer = (0, external_path_serializer_namespaceObject.createSnapshotSerializer)({
86
116
  replace: [
87
117
  {
88
118
  match: srcDir,
89
- mark: '<HOOK_SRC_DIR>',
119
+ mark: '<HOOK_SRC_DIR>'
90
120
  },
91
121
  {
92
122
  match: distDir,
93
- mark: '<HOOK_DIST_DIR>',
94
- },
95
- ],
123
+ mark: '<HOOK_DIST_DIR>'
124
+ }
125
+ ]
96
126
  });
97
127
  const escapeRegex = true;
98
128
  const printFunctionName = false;
99
- const normalizeNewlines = (str) => str.replace(/\r\n|\r/g, '\n');
100
- const serialize = (val, indent = 2, formatOverrides = {}) => normalizeNewlines((0, pretty_format_1.format)(val, {
101
- escapeRegex,
102
- indent,
103
- plugins: [
104
- ...(0, jest_snapshot_1.getSerializers)(),
105
- sourceSerializer,
106
- internalSerializer,
107
- testPathSerializer,
108
- ],
109
- printFunctionName,
110
- ...formatOverrides,
111
- }));
112
- class HookCasesContext extends context_1.TestContext {
113
- constructor(src, testName, options) {
114
- super(options);
115
- this.src = src;
116
- this.testName = testName;
117
- this.options = options;
118
- this.promises = [];
119
- this.count = 0;
120
- this.snapshots = {};
121
- this.snapshotsList = [];
129
+ const normalizeNewlines = (str)=>str.replace(/\r\n|\r/g, '\n');
130
+ const serialize = (val, indent = 2, formatOverrides = {})=>normalizeNewlines((0, external_pretty_format_namespaceObject.format)(val, {
131
+ escapeRegex,
132
+ indent,
133
+ plugins: [
134
+ ...(0, external_jest_snapshot_namespaceObject.getSerializers)(),
135
+ sourceSerializer,
136
+ internalSerializer,
137
+ testPathSerializer
138
+ ],
139
+ printFunctionName,
140
+ ...formatOverrides
141
+ }));
142
+ class HookCasesContext extends context_js_namespaceObject.TestContext {
143
+ src;
144
+ testName;
145
+ options;
146
+ promises = [];
147
+ count = 0;
148
+ snapshots = {};
149
+ snapshotsList = [];
150
+ constructor(src, testName, options){
151
+ super(options), this.src = src, this.testName = testName, this.options = options;
122
152
  this.snapped = this.snapped.bind(this);
123
153
  }
124
- /**
125
- * Snapshot function arguments and return value.
126
- * Generated snapshot is located in the same directory with the test source.
127
- * @example
128
- * compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
129
- */
130
154
  snapped(cb, prefix = '') {
131
- // eslint-disable-next-line
132
155
  const context = this;
133
- return function SNAPPED_HOOK(...args) {
156
+ return function(...args) {
134
157
  const group = prefix ? prefix : context.count++;
135
158
  context._addSnapshot(args, 'input', group);
136
159
  const output = cb.apply(this, args);
137
- if (output && typeof output.then === 'function') {
160
+ if (output && 'function' == typeof output.then) {
138
161
  let resolve;
139
- context.promises.push(new Promise((r) => (resolve = r)));
140
- return output
141
- .then((o) => {
162
+ context.promises.push(new Promise((r)=>resolve = r));
163
+ return output.then((o)=>{
142
164
  context._addSnapshot(o, 'output (Promise resolved)', group);
143
165
  return o;
144
- })
145
- .catch((o) => {
166
+ }).catch((o)=>{
146
167
  context._addSnapshot(o, 'output (Promise rejected)', group);
147
168
  return o;
148
- })
149
- .finally(resolve);
169
+ }).finally(resolve);
150
170
  }
151
171
  context._addSnapshot(output, 'output', group);
152
172
  return output;
153
173
  };
154
174
  }
155
- /**
156
- * @internal
157
- */
158
175
  _addSnapshot(content, name, group) {
159
- const normalizedContent = Buffer.isBuffer(content)
160
- ? content
161
- : serialize(content, undefined, {
162
- escapeString: true,
163
- printBasicPrototype: true,
164
- }).replace(/\r\n/g, '\n');
176
+ const normalizedContent = Buffer.isBuffer(content) ? content : serialize(content, void 0, {
177
+ escapeString: true,
178
+ printBasicPrototype: true
179
+ }).replace(/\r\n/g, '\n');
165
180
  (this.snapshots[group] = this.snapshots[group] || []).push([
166
181
  normalizedContent,
167
- name,
182
+ name
168
183
  ]);
169
- if (!this.snapshotsList.includes(group)) {
170
- this.snapshotsList.push(group);
171
- }
184
+ if (!this.snapshotsList.includes(group)) this.snapshotsList.push(group);
172
185
  }
173
- /**
174
- * @internal
175
- */
176
186
  async collectSnapshots(env, options = {
177
- diff: {},
187
+ diff: {}
178
188
  }) {
179
189
  await Promise.allSettled(this.promises);
180
- if (!this.snapshotsList.length)
181
- return;
182
- const snapshots = this.snapshotsList.reduce((acc, group, index) => {
183
- const block = this.snapshots[group || index].reduce((acc, [content, name]) => {
190
+ if (!this.snapshotsList.length) return;
191
+ const snapshots = this.snapshotsList.reduce((acc, group, index)=>{
192
+ const block = this.snapshots[group || index].reduce((acc, [content, name])=>{
184
193
  name = `## ${name || `test: ${index}`}\n\n`;
185
194
  const block = `\`\`\`javascript\n${content}\n\`\`\`\n`;
186
195
  return `${acc}${name + block}\n`;
187
196
  }, '');
188
197
  return `${acc}# ${Number.isInteger(group) ? `Group: ${index}` : group}\n\n${block}`;
189
198
  }, '');
190
- env
191
- .expect(snapshots)
192
- .toMatchFileSnapshotSync(node_path_1.default.join(this.src, 'hooks.snap.txt'), options);
199
+ env.expect(snapshots).toMatchFileSnapshotSync(external_node_path_default().join(this.src, 'hooks.snap.txt'), options);
193
200
  }
194
201
  }
195
- exports.HookCasesContext = HookCasesContext;
196
- function defaultOptions(context, custom) {
202
+ function hook_defaultOptions(context, custom) {
197
203
  let defaultOptions = {
198
204
  context: context.getSource(),
199
205
  mode: 'production',
@@ -204,24 +210,31 @@ function defaultOptions(context, custom) {
204
210
  output: {
205
211
  path: context.getDist(),
206
212
  bundlerInfo: {
207
- force: false,
208
- },
213
+ force: false
214
+ }
209
215
  },
210
216
  module: {
211
217
  defaultRules: [
212
218
  '...',
213
219
  {
214
220
  test: /\.css$/i,
215
- type: 'css/auto',
216
- },
217
- ],
221
+ type: 'css/auto'
222
+ }
223
+ ]
218
224
  },
219
225
  optimization: {
220
- minimize: false,
221
- },
226
+ minimize: false
227
+ }
222
228
  };
223
- if (custom) {
224
- defaultOptions = (0, rspack_merge_1.default)(defaultOptions, custom(context));
225
- }
229
+ if (custom) defaultOptions = external_rspack_merge_default()(defaultOptions, custom(context));
226
230
  return defaultOptions;
227
231
  }
232
+ exports.HookCasesContext = __webpack_exports__.HookCasesContext;
233
+ exports.createHookCase = __webpack_exports__.createHookCase;
234
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
235
+ "HookCasesContext",
236
+ "createHookCase"
237
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
238
+ Object.defineProperty(exports, '__esModule', {
239
+ value: true
240
+ });