@rspack/test-tools 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/case/builtin.js +1 -1
  2. package/dist/case/compiler.d.ts +5 -0
  3. package/dist/case/compiler.js +18 -0
  4. package/dist/case/config.js +1 -1
  5. package/dist/case/defaults.js +2 -2
  6. package/dist/case/diagnostic.js +2 -7
  7. package/dist/case/error.d.ts +6 -0
  8. package/dist/case/error.js +23 -0
  9. package/dist/case/hook.d.ts +1 -0
  10. package/dist/case/hook.js +37 -0
  11. package/dist/case/hot-step.js +1 -1
  12. package/dist/case/index.d.ts +5 -1
  13. package/dist/case/index.js +5 -1
  14. package/dist/case/normal.js +2 -2
  15. package/dist/case/stats-api.d.ts +6 -0
  16. package/dist/case/stats-api.js +23 -0
  17. package/dist/case/stats-output.d.ts +1 -0
  18. package/dist/case/{stats.js → stats-output.js} +3 -3
  19. package/dist/case/treeshaking.js +1 -1
  20. package/dist/helper/directory.d.ts +7 -3
  21. package/dist/helper/directory.js +60 -31
  22. package/dist/helper/index.d.ts +1 -0
  23. package/dist/helper/index.js +1 -0
  24. package/dist/helper/jestFileSnapshot.d.ts +18 -0
  25. package/dist/helper/jestFileSnapshot.js +112 -0
  26. package/dist/helper/legacy/fakeSystem.d.ts +9 -0
  27. package/dist/helper/legacy/fakeSystem.js +124 -0
  28. package/dist/helper/legacy/supportsWorker.d.ts +2 -0
  29. package/dist/helper/legacy/supportsWorker.js +17 -0
  30. package/dist/helper/legacy/warmup-webpack.d.ts +1 -0
  31. package/dist/helper/legacy/warmup-webpack.js +26 -0
  32. package/dist/helper/setupTestFramework.d.ts +1 -0
  33. package/dist/helper/setupTestFramework.js +121 -0
  34. package/dist/helper/util/checkSourceMap.d.ts +1 -0
  35. package/dist/helper/util/checkSourceMap.js +80 -0
  36. package/dist/helper/util/currentWatchStep.d.ts +1 -0
  37. package/dist/helper/util/currentWatchStep.js +2 -0
  38. package/dist/helper/util/expectWarningFactory.d.ts +2 -0
  39. package/dist/helper/util/expectWarningFactory.js +21 -0
  40. package/dist/helper/util/filterUtil.d.ts +8 -0
  41. package/dist/helper/util/filterUtil.js +50 -0
  42. package/dist/helper/util/identifier.d.ts +76 -0
  43. package/dist/helper/util/identifier.js +345 -0
  44. package/dist/helper/util/replaceMitteDiagnostic.d.ts +2 -0
  45. package/dist/helper/util/replaceMitteDiagnostic.js +17 -0
  46. package/dist/helper/win.d.ts +2 -0
  47. package/dist/helper/win.js +15 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.js +1 -0
  50. package/dist/plugin/webpack-module-placeholder-plugin.js +2 -3
  51. package/dist/processor/defaults.js +11 -23
  52. package/dist/processor/diagnostic.d.ts +0 -3
  53. package/dist/processor/diagnostic.js +17 -20
  54. package/dist/processor/error.d.ts +23 -0
  55. package/dist/processor/error.js +142 -0
  56. package/dist/processor/hook.d.ts +41 -0
  57. package/dist/processor/hook.js +189 -0
  58. package/dist/processor/hot-step.d.ts +2 -1
  59. package/dist/processor/hot-step.js +66 -14
  60. package/dist/processor/index.d.ts +2 -0
  61. package/dist/processor/index.js +2 -0
  62. package/dist/processor/normal.d.ts +0 -2
  63. package/dist/processor/normal.js +1 -10
  64. package/dist/processor/simple.js +2 -6
  65. package/dist/processor/snapshot.js +6 -6
  66. package/dist/processor/stats-api.d.ts +0 -2
  67. package/dist/processor/stats-api.js +1 -13
  68. package/dist/processor/stats.js +2 -1
  69. package/dist/processor/watch.js +4 -4
  70. package/dist/runner/hot-step.js +3 -2
  71. package/dist/runner/runner/basic.d.ts +1 -0
  72. package/dist/runner/runner/basic.js +3 -0
  73. package/dist/runner/runner/web/jsdom.d.ts +1 -0
  74. package/dist/runner/runner/web/jsdom.js +11 -5
  75. package/dist/runner/runner/web.d.ts +1 -0
  76. package/dist/runner/runner/web.js +3 -0
  77. package/dist/runner/type.d.ts +13 -0
  78. package/dist/test/simple.d.ts +5 -0
  79. package/dist/test/simple.js +36 -0
  80. package/dist/type.d.ts +1 -0
  81. package/package.json +11 -6
  82. package/dist/case/stats.d.ts +0 -1
@@ -0,0 +1,345 @@
1
+ // @ts-nocheck
2
+ /*
3
+ MIT License http://www.opensource.org/licenses/mit-license.php
4
+ */
5
+ "use strict";
6
+ const path = require("path");
7
+ const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
8
+ const SEGMENTS_SPLIT_REGEXP = /([|!])/;
9
+ const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
10
+ /**
11
+ * @typedef {Object} MakeRelativePathsCache
12
+ * @property {Map<string, Map<string, string>>=} relativePaths
13
+ */
14
+ const relativePathToRequest = relativePath => {
15
+ if (relativePath === "")
16
+ return "./.";
17
+ if (relativePath === "..")
18
+ return "../.";
19
+ if (relativePath.startsWith("../"))
20
+ return relativePath;
21
+ return `./${relativePath}`;
22
+ };
23
+ /**
24
+ * @param {string} context context for relative path
25
+ * @param {string} maybeAbsolutePath path to make relative
26
+ * @returns {string} relative path in request style
27
+ */
28
+ const absoluteToRequest = (context, maybeAbsolutePath) => {
29
+ if (maybeAbsolutePath[0] === "/") {
30
+ if (maybeAbsolutePath.length > 1 &&
31
+ maybeAbsolutePath[maybeAbsolutePath.length - 1] === "/") {
32
+ // this 'path' is actually a regexp generated by dynamic requires.
33
+ // Don't treat it as an absolute path.
34
+ return maybeAbsolutePath;
35
+ }
36
+ const querySplitPos = maybeAbsolutePath.indexOf("?");
37
+ let resource = querySplitPos === -1
38
+ ? maybeAbsolutePath
39
+ : maybeAbsolutePath.slice(0, querySplitPos);
40
+ resource = relativePathToRequest(path.posix.relative(context, resource));
41
+ return querySplitPos === -1
42
+ ? resource
43
+ : resource + maybeAbsolutePath.slice(querySplitPos);
44
+ }
45
+ if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) {
46
+ const querySplitPos = maybeAbsolutePath.indexOf("?");
47
+ let resource = querySplitPos === -1
48
+ ? maybeAbsolutePath
49
+ : maybeAbsolutePath.slice(0, querySplitPos);
50
+ resource = path.win32.relative(context, resource);
51
+ if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
52
+ resource = relativePathToRequest(resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, "/"));
53
+ }
54
+ return querySplitPos === -1
55
+ ? resource
56
+ : resource + maybeAbsolutePath.slice(querySplitPos);
57
+ }
58
+ // not an absolute path
59
+ return maybeAbsolutePath;
60
+ };
61
+ /**
62
+ * @param {string} context context for relative path
63
+ * @param {string} relativePath path
64
+ * @returns {string} absolute path
65
+ */
66
+ const requestToAbsolute = (context, relativePath) => {
67
+ if (relativePath.startsWith("./") || relativePath.startsWith("../"))
68
+ return path.join(context, relativePath);
69
+ return relativePath;
70
+ };
71
+ const makeCacheable = realFn => {
72
+ /** @type {WeakMap<object, Map<string, ParsedResource>>} */
73
+ const cache = new WeakMap();
74
+ const getCache = associatedObjectForCache => {
75
+ const entry = cache.get(associatedObjectForCache);
76
+ if (entry !== undefined)
77
+ return entry;
78
+ /** @type {Map<string, ParsedResource>} */
79
+ const map = new Map();
80
+ cache.set(associatedObjectForCache, map);
81
+ return map;
82
+ };
83
+ /**
84
+ * @param {string} str the path with query and fragment
85
+ * @param {Object=} associatedObjectForCache an object to which the cache will be attached
86
+ * @returns {ParsedResource} parsed parts
87
+ */
88
+ const fn = (str, associatedObjectForCache) => {
89
+ if (!associatedObjectForCache)
90
+ return realFn(str);
91
+ const cache = getCache(associatedObjectForCache);
92
+ const entry = cache.get(str);
93
+ if (entry !== undefined)
94
+ return entry;
95
+ const result = realFn(str);
96
+ cache.set(str, result);
97
+ return result;
98
+ };
99
+ fn.bindCache = associatedObjectForCache => {
100
+ const cache = getCache(associatedObjectForCache);
101
+ return str => {
102
+ const entry = cache.get(str);
103
+ if (entry !== undefined)
104
+ return entry;
105
+ const result = realFn(str);
106
+ cache.set(str, result);
107
+ return result;
108
+ };
109
+ };
110
+ return fn;
111
+ };
112
+ const makeCacheableWithContext = fn => {
113
+ /** @type {WeakMap<object, Map<string, Map<string, string>>>} */
114
+ const cache = new WeakMap();
115
+ /**
116
+ * @param {string} context context used to create relative path
117
+ * @param {string} identifier identifier used to create relative path
118
+ * @param {Object=} associatedObjectForCache an object to which the cache will be attached
119
+ * @returns {string} the returned relative path
120
+ */
121
+ const cachedFn = (context, identifier, associatedObjectForCache) => {
122
+ if (!associatedObjectForCache)
123
+ return fn(context, identifier);
124
+ let innerCache = cache.get(associatedObjectForCache);
125
+ if (innerCache === undefined) {
126
+ innerCache = new Map();
127
+ cache.set(associatedObjectForCache, innerCache);
128
+ }
129
+ let cachedResult;
130
+ let innerSubCache = innerCache.get(context);
131
+ if (innerSubCache === undefined) {
132
+ innerCache.set(context, (innerSubCache = new Map()));
133
+ }
134
+ else {
135
+ cachedResult = innerSubCache.get(identifier);
136
+ }
137
+ if (cachedResult !== undefined) {
138
+ return cachedResult;
139
+ }
140
+ else {
141
+ const result = fn(context, identifier);
142
+ innerSubCache.set(identifier, result);
143
+ return result;
144
+ }
145
+ };
146
+ /**
147
+ * @param {Object=} associatedObjectForCache an object to which the cache will be attached
148
+ * @returns {function(string, string): string} cached function
149
+ */
150
+ cachedFn.bindCache = associatedObjectForCache => {
151
+ let innerCache;
152
+ if (associatedObjectForCache) {
153
+ innerCache = cache.get(associatedObjectForCache);
154
+ if (innerCache === undefined) {
155
+ innerCache = new Map();
156
+ cache.set(associatedObjectForCache, innerCache);
157
+ }
158
+ }
159
+ else {
160
+ innerCache = new Map();
161
+ }
162
+ /**
163
+ * @param {string} context context used to create relative path
164
+ * @param {string} identifier identifier used to create relative path
165
+ * @returns {string} the returned relative path
166
+ */
167
+ const boundFn = (context, identifier) => {
168
+ let cachedResult;
169
+ let innerSubCache = innerCache.get(context);
170
+ if (innerSubCache === undefined) {
171
+ innerCache.set(context, (innerSubCache = new Map()));
172
+ }
173
+ else {
174
+ cachedResult = innerSubCache.get(identifier);
175
+ }
176
+ if (cachedResult !== undefined) {
177
+ return cachedResult;
178
+ }
179
+ else {
180
+ const result = fn(context, identifier);
181
+ innerSubCache.set(identifier, result);
182
+ return result;
183
+ }
184
+ };
185
+ return boundFn;
186
+ };
187
+ /**
188
+ * @param {string} context context used to create relative path
189
+ * @param {Object=} associatedObjectForCache an object to which the cache will be attached
190
+ * @returns {function(string): string} cached function
191
+ */
192
+ cachedFn.bindContextCache = (context, associatedObjectForCache) => {
193
+ let innerSubCache;
194
+ if (associatedObjectForCache) {
195
+ let innerCache = cache.get(associatedObjectForCache);
196
+ if (innerCache === undefined) {
197
+ innerCache = new Map();
198
+ cache.set(associatedObjectForCache, innerCache);
199
+ }
200
+ innerSubCache = innerCache.get(context);
201
+ if (innerSubCache === undefined) {
202
+ innerCache.set(context, (innerSubCache = new Map()));
203
+ }
204
+ }
205
+ else {
206
+ innerSubCache = new Map();
207
+ }
208
+ /**
209
+ * @param {string} identifier identifier used to create relative path
210
+ * @returns {string} the returned relative path
211
+ */
212
+ const boundFn = identifier => {
213
+ const cachedResult = innerSubCache.get(identifier);
214
+ if (cachedResult !== undefined) {
215
+ return cachedResult;
216
+ }
217
+ else {
218
+ const result = fn(context, identifier);
219
+ innerSubCache.set(identifier, result);
220
+ return result;
221
+ }
222
+ };
223
+ return boundFn;
224
+ };
225
+ return cachedFn;
226
+ };
227
+ /**
228
+ *
229
+ * @param {string} context context for relative path
230
+ * @param {string} identifier identifier for path
231
+ * @returns {string} a converted relative path
232
+ */
233
+ const _makePathsRelative = (context, identifier) => {
234
+ return identifier
235
+ .split(SEGMENTS_SPLIT_REGEXP)
236
+ .map(str => absoluteToRequest(context, str))
237
+ .join("");
238
+ };
239
+ exports.makePathsRelative = makeCacheableWithContext(_makePathsRelative);
240
+ /**
241
+ *
242
+ * @param {string} context context for relative path
243
+ * @param {string} identifier identifier for path
244
+ * @returns {string} a converted relative path
245
+ */
246
+ const _makePathsAbsolute = (context, identifier) => {
247
+ return identifier
248
+ .split(SEGMENTS_SPLIT_REGEXP)
249
+ .map(str => requestToAbsolute(context, str))
250
+ .join("");
251
+ };
252
+ exports.makePathsAbsolute = makeCacheableWithContext(_makePathsAbsolute);
253
+ /**
254
+ * @param {string} context absolute context path
255
+ * @param {string} request any request string may containing absolute paths, query string, etc.
256
+ * @returns {string} a new request string avoiding absolute paths when possible
257
+ */
258
+ const _contextify = (context, request) => {
259
+ return request
260
+ .split("!")
261
+ .map(r => absoluteToRequest(context, r))
262
+ .join("!");
263
+ };
264
+ const contextify = makeCacheableWithContext(_contextify);
265
+ exports.contextify = contextify;
266
+ /**
267
+ * @param {string} context absolute context path
268
+ * @param {string} request any request string
269
+ * @returns {string} a new request string using absolute paths when possible
270
+ */
271
+ const _absolutify = (context, request) => {
272
+ return request
273
+ .split("!")
274
+ .map(r => requestToAbsolute(context, r))
275
+ .join("!");
276
+ };
277
+ const absolutify = makeCacheableWithContext(_absolutify);
278
+ exports.absolutify = absolutify;
279
+ const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
280
+ const PATH_QUERY_REGEXP = /^((?:\0.|[^?\0])*)(\?.*)?$/;
281
+ /** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */
282
+ /** @typedef {{ resource: string, path: string, query: string }} ParsedResourceWithoutFragment */
283
+ /**
284
+ * @param {string} str the path with query and fragment
285
+ * @returns {ParsedResource} parsed parts
286
+ */
287
+ const _parseResource = str => {
288
+ const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
289
+ return {
290
+ resource: str,
291
+ path: match[1].replace(/\0(.)/g, "$1"),
292
+ query: match[2] ? match[2].replace(/\0(.)/g, "$1") : "",
293
+ fragment: match[3] || ""
294
+ };
295
+ };
296
+ exports.parseResource = makeCacheable(_parseResource);
297
+ /**
298
+ * Parse resource, skips fragment part
299
+ * @param {string} str the path with query and fragment
300
+ * @returns {ParsedResourceWithoutFragment} parsed parts
301
+ */
302
+ const _parseResourceWithoutFragment = str => {
303
+ const match = PATH_QUERY_REGEXP.exec(str);
304
+ return {
305
+ resource: str,
306
+ path: match[1].replace(/\0(.)/g, "$1"),
307
+ query: match[2] ? match[2].replace(/\0(.)/g, "$1") : ""
308
+ };
309
+ };
310
+ exports.parseResourceWithoutFragment = makeCacheable(_parseResourceWithoutFragment);
311
+ /**
312
+ * @param {string} filename the filename which should be undone
313
+ * @param {string} outputPath the output path that is restored (only relevant when filename contains "..")
314
+ * @param {boolean} enforceRelative true returns ./ for empty paths
315
+ * @returns {string} repeated ../ to leave the directory of the provided filename to be back on output dir
316
+ */
317
+ exports.getUndoPath = (filename, outputPath, enforceRelative) => {
318
+ let depth = -1;
319
+ let append = "";
320
+ outputPath = outputPath.replace(/[\\/]$/, "");
321
+ for (const part of filename.split(/[/\\]+/)) {
322
+ if (part === "..") {
323
+ if (depth > -1) {
324
+ depth--;
325
+ }
326
+ else {
327
+ const i = outputPath.lastIndexOf("/");
328
+ const j = outputPath.lastIndexOf("\\");
329
+ const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
330
+ if (pos < 0)
331
+ return outputPath + "/";
332
+ append = outputPath.slice(pos + 1) + "/" + append;
333
+ outputPath = outputPath.slice(0, pos);
334
+ }
335
+ }
336
+ else if (part !== ".") {
337
+ depth++;
338
+ }
339
+ }
340
+ return depth > 0
341
+ ? `${"../".repeat(depth)}${append}`
342
+ : enforceRelative
343
+ ? `./${append}`
344
+ : append;
345
+ };
@@ -0,0 +1,2 @@
1
+ export function replace(s: any): any;
2
+ export function replaceStack(s: any): any;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ // Remove the "|" padding from miette,
4
+ // used to ensure no line breaks with padding being returned,
5
+ // miette generates diagnostics lines with respect to terminal size
6
+ // and this might varies among different `process.cwd()` being used,
7
+ // which breaks local and CI checks.
8
+ const replace = s => s.replace(/\r?\n[ ]+│ /g, "");
9
+ // HOW THIS WORKS:
10
+ // 1. Remove potential line break and "|"
11
+ // 2. Save the JS stack for each line
12
+ // 3. If the current line was splitted because of terminal size, merge them together
13
+ const replaceStack = s => s.replace(/(?:\s|│)*(at.*)(\s|│)*/g, "\n$1");
14
+ module.exports = {
15
+ replace,
16
+ replaceStack
17
+ };
@@ -0,0 +1,2 @@
1
+ export declare function escapeSep(str: string): string;
2
+ export declare function escapeEOL(str: string): string;
@@ -0,0 +1,15 @@
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.escapeEOL = exports.escapeSep = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ function escapeSep(str) {
9
+ return str.split(path_1.default.win32.sep).join(path_1.default.posix.sep);
10
+ }
11
+ exports.escapeSep = escapeSep;
12
+ function escapeEOL(str) {
13
+ return str.split("\r\n").join("\n").trim();
14
+ }
15
+ exports.escapeEOL = escapeEOL;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./type";
2
2
  export * from "./test/tester";
3
3
  export * from "./test/context";
4
+ export * from "./test/simple";
4
5
  export * from "./processor";
5
6
  export * from "./reporter";
6
7
  export * from "./compare";
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./type"), exports);
18
18
  __exportStar(require("./test/tester"), exports);
19
19
  __exportStar(require("./test/context"), exports);
20
+ __exportStar(require("./test/simple"), exports);
20
21
  __exportStar(require("./processor"), exports);
21
22
  __exportStar(require("./reporter"), exports);
22
23
  __exportStar(require("./compare"), exports);
@@ -90,9 +90,8 @@ class WebpackModulePlaceholderPlugin {
90
90
  let footer = cacheEntry.footer;
91
91
  if (header === undefined) {
92
92
  const identifier = module.identifier();
93
- const moduleId = compilation.chunkGraph.getModuleId(module);
94
- header = new RawSource(`\n${Template.toNormalComment(`start::${moduleId}::${identifier}`)}\n`);
95
- footer = new RawSource(`\n${Template.toNormalComment(`end::${moduleId}::${identifier}`)}\n`);
93
+ header = new RawSource(`\n${Template.toNormalComment(`start::${identifier}`)}\n`);
94
+ footer = new RawSource(`\n${Template.toNormalComment(`end::${identifier}`)}\n`);
96
95
  cacheEntry.header = header;
97
96
  cacheEntry.footer = footer;
98
97
  }
@@ -8,16 +8,14 @@ const simple_1 = require("./simple");
8
8
  const type_1 = require("../type");
9
9
  const jest_diff_1 = require("jest-diff");
10
10
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
11
- const path_1 = __importDefault(require("path"));
12
- const CASE_CWD = path_1.default.resolve(__dirname, "../../../rspack");
13
11
  const CURRENT_CWD = process.cwd();
14
12
  const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
15
- const cwdRegExp = new RegExp(`${quoteMeta(CASE_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`, "g");
16
- const escapedCwd = JSON.stringify(CASE_CWD).slice(1, -1);
13
+ const cwdRegExp = new RegExp(`${quoteMeta(CURRENT_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`, "g");
14
+ const escapedCwd = JSON.stringify(CURRENT_CWD).slice(1, -1);
17
15
  const escapedCwdRegExp = new RegExp(`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`, "g");
18
16
  const normalize = (str) => {
19
- if (CASE_CWD.startsWith("/")) {
20
- str = str.replace(new RegExp(quoteMeta(CASE_CWD), "g"), "<cwd>");
17
+ if (CURRENT_CWD.startsWith("/")) {
18
+ str = str.replace(new RegExp(quoteMeta(CURRENT_CWD), "g"), "<cwd>");
21
19
  }
22
20
  else {
23
21
  str = str.replace(cwdRegExp, (m, g) => `<cwd>${g.replace(/\\/g, "/")}`);
@@ -51,33 +49,23 @@ class DefaultsConfigTaskProcessor extends simple_1.SimpleTaskProcessor {
51
49
  name: _defaultsConfigOptions.name
52
50
  });
53
51
  this._defaultsConfigOptions = _defaultsConfigOptions;
54
- this.defaultConfig = DefaultsConfigTaskProcessor.getDefaultConfig(CASE_CWD, {
52
+ this.defaultConfig = DefaultsConfigTaskProcessor.getDefaultConfig(CURRENT_CWD, {
55
53
  mode: "none"
56
54
  });
57
55
  }
58
- async compiler(context) {
59
- throw new Error("Not support");
60
- }
61
- async build(context) {
62
- throw new Error("Not support");
63
- }
64
- async run(env, context) {
65
- throw new Error("Not support");
66
- }
56
+ async compiler(context) { }
57
+ async build(context) { }
58
+ async run(env, context) { }
67
59
  async check(env, context) {
68
60
  const compiler = this.getCompiler(context);
69
- const config = DefaultsConfigTaskProcessor.getDefaultConfig(this._defaultsConfigOptions.cwd || CASE_CWD, compiler.getOptions());
61
+ const config = DefaultsConfigTaskProcessor.getDefaultConfig(this._defaultsConfigOptions.cwd || CURRENT_CWD, compiler.getOptions());
70
62
  const diff = (0, strip_ansi_1.default)((0, jest_diff_1.diff)(this.defaultConfig, config, { expand: false, contextLines: 0 }));
71
63
  await this._defaultsConfigOptions.diff(expect(new Diff(diff)), expect(this.defaultConfig));
72
64
  }
73
65
  async before(context) { }
74
66
  async after(context) { }
75
- async beforeAll(context) {
76
- throw new Error("Not support");
77
- }
78
- async afterAll(context) {
79
- throw new Error("Not support");
80
- }
67
+ async beforeAll(context) { }
68
+ async afterAll(context) { }
81
69
  getCompiler(context) {
82
70
  return context.getCompiler(this._options.name, this._options.compilerType);
83
71
  }
@@ -2,13 +2,10 @@ import { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type
2
2
  import { BasicTaskProcessor } from "./basic";
3
3
  export interface IRspackDiagnosticProcessorOptions {
4
4
  name: string;
5
- root: string;
6
5
  }
7
6
  export declare class RspackDiagnosticProcessor extends BasicTaskProcessor<ECompilerType.Rspack> {
8
7
  protected _diagnosticOptions: IRspackDiagnosticProcessorOptions;
9
8
  constructor(_diagnosticOptions: IRspackDiagnosticProcessorOptions);
10
- before(context: ITestContext): Promise<void>;
11
- after(context: ITestContext): Promise<void>;
12
9
  check(env: ITestEnv, context: ITestContext): Promise<void>;
13
10
  static defaultOptions(context: ITestContext): TCompilerOptions<ECompilerType.Rspack>;
14
11
  }
@@ -9,9 +9,14 @@ const basic_1 = require("./basic");
9
9
  const assert_1 = __importDefault(require("assert"));
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const fs_1 = __importDefault(require("fs"));
12
+ const helper_1 = require("../helper");
12
13
  const serializer = require("jest-serializer-path");
13
14
  const normalizePaths = serializer.normalizePaths;
14
- const CWD = process.cwd();
15
+ const rspackPath = path_1.default.resolve(__dirname, "../../../rspack");
16
+ const replacePaths = (input) => {
17
+ const rspackRoot = normalizePaths(rspackPath);
18
+ return normalizePaths(input).split(rspackRoot).join("<RSPACK_ROOT>");
19
+ };
15
20
  class RspackDiagnosticProcessor extends basic_1.BasicTaskProcessor {
16
21
  constructor(_diagnosticOptions) {
17
22
  super({
@@ -23,12 +28,6 @@ class RspackDiagnosticProcessor extends basic_1.BasicTaskProcessor {
23
28
  });
24
29
  this._diagnosticOptions = _diagnosticOptions;
25
30
  }
26
- async before(context) {
27
- process.chdir(this._diagnosticOptions.root);
28
- }
29
- async after(context) {
30
- process.chdir(CWD);
31
- }
32
31
  async check(env, context) {
33
32
  const compiler = this.getCompiler(context);
34
33
  const stats = compiler.getStats();
@@ -36,27 +35,25 @@ class RspackDiagnosticProcessor extends basic_1.BasicTaskProcessor {
36
35
  throw new Error("Stats should exists");
37
36
  }
38
37
  (0, assert_1.default)(stats.hasErrors() || stats.hasWarnings());
39
- let output = normalizePaths(stats.toString({
38
+ let output = replacePaths(stats.toString({
40
39
  all: false,
41
40
  errors: true,
42
41
  warnings: true
43
42
  }));
44
43
  // TODO: change to stats.errorStack
45
- if (context.getSource().includes("module-build-failed")) {
46
- // Replace potential loader stack
47
- output = output
48
- .replaceAll("│", "")
49
- .split(/\r?\n/)
50
- .map((s) => s.trim())
51
- .join("");
52
- }
44
+ output = output
45
+ .split("│")
46
+ .join("")
47
+ .split(/\r?\n/)
48
+ .map((s) => s.trim())
49
+ .join("");
53
50
  const errorOutputPath = path_1.default.resolve(context.getSource(), `./stats.err`);
54
- const updateSnapshot = process.argv.includes("-u") || process.argv.includes("--updateSnapshot");
55
- if (!fs_1.default.existsSync(errorOutputPath) || updateSnapshot) {
56
- fs_1.default.writeFileSync(errorOutputPath, output);
51
+ if (!fs_1.default.existsSync(errorOutputPath) || global.updateSnapshot) {
52
+ fs_1.default.writeFileSync(errorOutputPath, (0, helper_1.escapeEOL)(output));
57
53
  }
58
54
  else {
59
- expect(output).toBe(fs_1.default.readFileSync(errorOutputPath, "utf-8"));
55
+ const expectContent = fs_1.default.readFileSync(errorOutputPath, "utf-8");
56
+ expect((0, helper_1.escapeEOL)(output)).toBe((0, helper_1.escapeEOL)(expectContent));
60
57
  }
61
58
  }
62
59
  static defaultOptions(context) {
@@ -0,0 +1,23 @@
1
+ import { SimpleTaskProcessor } from "./simple";
2
+ import { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
3
+ import { StatsError, StatsWarnings } from "@rspack/core";
4
+ type TStatsDiagnostics = {
5
+ errors: StatsError[];
6
+ warnings: StatsWarnings[];
7
+ };
8
+ export interface IErrorTaskProcessorOptions<T extends ECompilerType> {
9
+ name: string;
10
+ compilerType: T;
11
+ options?: (options: TCompilerOptions<T>, context: ITestContext) => TCompilerOptions<T>;
12
+ build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
13
+ check?: (stats: TStatsDiagnostics) => Promise<void>;
14
+ }
15
+ export declare class ErrorTaskProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
16
+ protected _errorOptions: IErrorTaskProcessorOptions<T>;
17
+ constructor(_errorOptions: IErrorTaskProcessorOptions<T>);
18
+ compiler(context: ITestContext): Promise<void>;
19
+ run(env: ITestEnv, context: ITestContext): Promise<void>;
20
+ check(env: ITestEnv, context: ITestContext): Promise<void>;
21
+ static addSnapshotSerializer(): void;
22
+ }
23
+ export {};