@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
@@ -10,6 +10,7 @@ const multi_1 = require("./multi");
10
10
  const fs_1 = __importDefault(require("fs"));
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
13
+ const helper_1 = require("../helper");
13
14
  const REG_ERROR_CASE = /error$/;
14
15
  const quoteMeta = (str) => {
15
16
  return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
@@ -47,7 +48,7 @@ class RspackStatsProcessor extends multi_1.MultiTaskProcessor {
47
48
  return callback(err);
48
49
  if (!/\.(js|json|txt)$/.test(args[0]))
49
50
  return callback(null, result);
50
- callback(null, result.toString("utf-8").replace(/\r/g, ""));
51
+ callback(null, (0, helper_1.escapeEOL)(result.toString("utf-8")));
51
52
  }
52
53
  ]));
53
54
  };
@@ -10,7 +10,8 @@ const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = __importDefault(require("fs"));
11
11
  const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
12
12
  const compiler_1 = require("../compiler");
13
- const currentWatchStepModulePath = path_1.default.resolve(__dirname, "../../../rspack/tests/helpers/currentWatchStep");
13
+ // This file is used to port step number to webpack.config.js
14
+ const currentWatchStepModulePath = path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
14
15
  class RspackWatchProcessor extends multi_1.MultiTaskProcessor {
15
16
  constructor(_watchOptions) {
16
17
  super({
@@ -72,9 +73,8 @@ class RspackWatchProcessor extends multi_1.MultiTaskProcessor {
72
73
  options.output = {};
73
74
  if (!options.output.path)
74
75
  options.output.path = context.getDist();
75
- // CHANGE: The pathinfo is currently not supported in rspack
76
- // if (typeof options.output.pathinfo === "undefined")
77
- // options.output.pathinfo = true;
76
+ if (typeof options.output.pathinfo === "undefined")
77
+ options.output.pathinfo = true;
78
78
  if (!options.output.filename)
79
79
  options.output.filename = "bundle.js";
80
80
  if (options.cache && options.cache.type === "filesystem") {
@@ -25,7 +25,7 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
25
25
  const checker = this.context.getValue(this.name, ((_a = jsonStats.errors) === null || _a === void 0 ? void 0 : _a.length)
26
26
  ? "hotUpdateStepErrorChecker"
27
27
  : "hotUpdateStepChecker");
28
- checker(hotUpdateContext, stats);
28
+ checker(hotUpdateContext, stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
29
29
  callback(null, jsonStats);
30
30
  }
31
31
  catch (e) {
@@ -34,7 +34,7 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
34
34
  })
35
35
  .catch(callback);
36
36
  };
37
- return new web_1.WebRunner({
37
+ const runner = new web_1.WebRunner({
38
38
  dom: "jsdom",
39
39
  env,
40
40
  stats,
@@ -54,6 +54,7 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
54
54
  dist,
55
55
  compilerOptions
56
56
  });
57
+ return runner;
57
58
  }
58
59
  }
59
60
  exports.HotStepRunnerFactory = HotStepRunnerFactory;
@@ -18,6 +18,7 @@ export declare abstract class BasicRunner<T extends ECompilerType = ECompilerTyp
18
18
  constructor(_options: IBasicRunnerOptions<T>);
19
19
  run(file: string): Promise<unknown>;
20
20
  getRequire(): TRunnerRequirer;
21
+ getGlobal(name: string): unknown;
21
22
  protected abstract createGlobalContext(): IBasicGlobalContext;
22
23
  protected abstract createBaseModuleScope(): IBasicModuleScope;
23
24
  protected abstract createModuleScope(requireFn: TRunnerRequirer, m: TModuleObject, file: TBasicRunnerFile): IBasicModuleScope;
@@ -49,6 +49,9 @@ class BasicRunner {
49
49
  getRequire() {
50
50
  return this.requirers.get("entry");
51
51
  }
52
+ getGlobal(name) {
53
+ return (this.globalContext || {})[name];
54
+ }
52
55
  getFile(modulePath, currentDirectory) {
53
56
  if (Array.isArray(modulePath)) {
54
57
  return {
@@ -7,6 +7,7 @@ export declare class JSDOMWebRunner<T extends ECompilerType = ECompilerType.Rspa
7
7
  private dom;
8
8
  constructor(_webOptions: IBasicRunnerOptions<T>);
9
9
  run(file: string): Promise<unknown>;
10
+ getGlobal(name: string): unknown;
10
11
  protected createResourceLoader(): {
11
12
  fetch(url: string, _: {
12
13
  element: HTMLScriptElement;
@@ -11,6 +11,7 @@ const path_1 = __importDefault(require("path"));
11
11
  const EventSourceForNode_1 = __importDefault(require("../../../helper/legacy/EventSourceForNode"));
12
12
  const urlToRelativePath_1 = __importDefault(require("../../../helper/legacy/urlToRelativePath"));
13
13
  const cjs_1 = require("../cjs");
14
+ const helper_1 = require("../../../helper");
14
15
  class JSDOMWebRunner extends cjs_1.CommonJsRunner {
15
16
  constructor(_webOptions) {
16
17
  super(_webOptions);
@@ -29,6 +30,7 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
29
30
  runScripts: "dangerously",
30
31
  virtualConsole
31
32
  });
33
+ this.dom.window.console = console;
32
34
  // compat with FakeDocument
33
35
  this.dom.window.eval(`
34
36
  Object.defineProperty(document.head, "_children", {
@@ -63,6 +65,9 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
63
65
  }
64
66
  return super.run(file);
65
67
  }
68
+ getGlobal(name) {
69
+ return this.dom.window[name];
70
+ }
66
71
  createResourceLoader() {
67
72
  const urlToPath = (url) => {
68
73
  if (url.startsWith("https://test.cases/path/"))
@@ -141,9 +146,10 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
141
146
  if (this._options.testConfig.moduleScope) {
142
147
  this._options.testConfig.moduleScope(currentModuleScope);
143
148
  }
149
+ const scopeKey = (0, helper_1.escapeSep)(file.path);
144
150
  const args = Object.keys(currentModuleScope);
145
151
  const argValues = args
146
- .map(arg => `window["${file.path}"]["${arg}"]`)
152
+ .map(arg => `window["${scopeKey}"]["${arg}"]`)
147
153
  .join(", ");
148
154
  const code = `
149
155
  // hijack document.currentScript for auto public path
@@ -154,7 +160,7 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
154
160
  get(target, prop, receiver) {
155
161
  if (prop === "currentScript") {
156
162
  var script = target.createElement("script");
157
- script.src = "https://test.cases/path/${file.subPath}index.js";
163
+ script.src = "https://test.cases/path/${(0, helper_1.escapeSep)(file.subPath)}index.js";
158
164
  return script;
159
165
  }
160
166
  return Reflect.get(target, prop, receiver);
@@ -164,12 +170,12 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
164
170
  return Reflect.get(target, prop, receiver);
165
171
  }
166
172
  });
167
- (function(window, self, globalThis, ${args.join(", ")}) {
173
+ (function(window, self, globalThis, console, ${args.join(", ")}) {
168
174
  ${file.content}
169
- })($$g$$, $$g$$, $$g$$, ${argValues});
175
+ })($$g$$, $$g$$, $$g$$, window["console"], ${argValues});
170
176
  `;
171
177
  this.preExecute(code, file);
172
- this.dom.window[file.path] = currentModuleScope;
178
+ this.dom.window[scopeKey] = currentModuleScope;
173
179
  this.dom.window.eval(code);
174
180
  this.postExecute(m, file);
175
181
  return m.exports;
@@ -11,4 +11,5 @@ export declare class WebRunner<T extends ECompilerType = ECompilerType.Rspack> i
11
11
  constructor(_webOptions: IWebRunnerOptions<T>);
12
12
  run(file: string): Promise<unknown>;
13
13
  getRequire(): import("..").TRunnerRequirer;
14
+ getGlobal(name: string): unknown;
14
15
  }
@@ -24,5 +24,8 @@ class WebRunner {
24
24
  getRequire() {
25
25
  return this.implement.getRequire();
26
26
  }
27
+ getGlobal(name) {
28
+ return this.implement.getGlobal(name);
29
+ }
27
30
  }
28
31
  exports.WebRunner = WebRunner;
@@ -30,3 +30,16 @@ export interface IBasicGlobalContext {
30
30
  export type TModuleObject = {
31
31
  exports: unknown;
32
32
  };
33
+ export type THotStepRuntimeLangData = {
34
+ outdatedModules: string[];
35
+ outdatedDependencies: Record<string, string[]>;
36
+ updatedModules: string[];
37
+ updatedRuntime: string[];
38
+ acceptedModules: string[];
39
+ disposedModules: string[];
40
+ };
41
+ export type THotStepRuntimeData = {
42
+ javascript: THotStepRuntimeLangData;
43
+ css: THotStepRuntimeLangData;
44
+ statusPath: string[];
45
+ };
@@ -0,0 +1,5 @@
1
+ import { ITestContext, ITestEnv, ITestProcessor } from "../type";
2
+ export declare function getSimpleProcessorRunner(src: string, dist: string, options?: {
3
+ env?: () => ITestEnv;
4
+ context?: (src: string, dist: string) => ITestContext;
5
+ }): (name: string, processor: ITestProcessor) => Promise<void>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSimpleProcessorRunner = void 0;
4
+ const context_1 = require("./context");
5
+ const CONTEXT_MAP = new Map();
6
+ function getSimpleProcessorRunner(src, dist, options = {}) {
7
+ const createEnv = options.env || (() => ({ it, beforeEach, afterEach }));
8
+ const createContext = options.context ||
9
+ ((src, dist) => new context_1.TestContext({ src, dist }));
10
+ const key = `src: ${src}, dist: ${dist}`;
11
+ if (!CONTEXT_MAP.has(key)) {
12
+ const context = createContext(src, dist);
13
+ const runner = async function run(name, processor) {
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
15
+ try {
16
+ await ((_a = processor.beforeAll) === null || _a === void 0 ? void 0 : _a.call(processor, context));
17
+ await ((_b = processor.before) === null || _b === void 0 ? void 0 : _b.call(processor, context));
18
+ await ((_c = processor.config) === null || _c === void 0 ? void 0 : _c.call(processor, context));
19
+ await ((_d = processor.compiler) === null || _d === void 0 ? void 0 : _d.call(processor, context));
20
+ await ((_e = processor.build) === null || _e === void 0 ? void 0 : _e.call(processor, context));
21
+ }
22
+ catch (e) {
23
+ context.emitError(name, e);
24
+ }
25
+ finally {
26
+ await ((_f = processor.run) === null || _f === void 0 ? void 0 : _f.call(processor, createEnv(), context));
27
+ await ((_g = processor.check) === null || _g === void 0 ? void 0 : _g.call(processor, createEnv(), context));
28
+ await ((_h = processor.after) === null || _h === void 0 ? void 0 : _h.call(processor, context));
29
+ await ((_j = processor.afterAll) === null || _j === void 0 ? void 0 : _j.call(processor, context));
30
+ }
31
+ };
32
+ CONTEXT_MAP.set(key, runner);
33
+ }
34
+ return CONTEXT_MAP.get(key);
35
+ }
36
+ exports.getSimpleProcessorRunner = getSimpleProcessorRunner;
package/dist/type.d.ts CHANGED
@@ -139,6 +139,7 @@ export type TTestFilter<T extends ECompilerType> = (creatorConfig: Record<string
139
139
  export interface ITestRunner {
140
140
  run(file: string): Promise<unknown>;
141
141
  getRequire(): TRunnerRequirer;
142
+ getGlobal(name: string): unknown;
142
143
  }
143
144
  export type TCompilerFactory<T extends ECompilerType> = (options: TCompilerOptions<T> | TCompilerOptions<T>[]) => TCompiler<T>;
144
145
  export interface TRunnerFactory<T extends ECompilerType> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "webpack-merge": "5.9.0",
45
45
  "webpack-sources": "3.2.3",
46
46
  "which-module": "2.0.1",
47
- "@rspack/core": "0.6.3"
47
+ "@rspack/core": "0.6.4"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@arco-design/web-react": "^2.56.1",
@@ -56,6 +56,8 @@
56
56
  "@types/webpack": "5.28.5",
57
57
  "@types/webpack-sources": "3.2.3",
58
58
  "core-js": "3.36.1",
59
+ "filenamify": "4.3.0",
60
+ "mkdirp": "0.5.6",
59
61
  "monaco-editor": "0.47.0",
60
62
  "monaco-editor-webpack-plugin": "7.1.0",
61
63
  "normalize.css": "^8.0.0",
@@ -63,16 +65,19 @@
63
65
  "react": "18.0.0",
64
66
  "react-dom": "18.0.0",
65
67
  "react-refresh": "0.14.0",
66
- "@rspack/cli": "0.6.3"
68
+ "@rspack/cli": "0.6.4",
69
+ "@rspack/plugin-minify": "0.6.4"
67
70
  },
68
71
  "scripts": {
69
72
  "build": "tsc -b ./tsconfig.build.json",
70
73
  "build:viewer": "rspack build",
71
74
  "dev:viewer": "rspack serve",
72
75
  "dev": "tsc -b -w",
73
- "test": "cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.compat.js",
74
- "test:ng": "cross-env SNAPSHOT=legacy NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.legacy.js",
75
- "test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.diff.js",
76
+ "test": "sh -c 'run-s \"test:* -- $*\"' sh",
77
+ "testu": "sh -c 'run-s \"test:* -- $*\"' sh -u",
78
+ "test:base": "cross-env NODE_OPTIONS=--openssl-legacy-provider NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.js --passWithNoTests",
79
+ "test:hot": "cross-env RSPACK_HOT_TEST=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.hot.js --passWithNoTests",
80
+ "test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.diff.js --passWithNoTests",
76
81
  "api-extractor": "api-extractor run --verbose",
77
82
  "api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
78
83
  }
@@ -1 +0,0 @@
1
- export declare function createStatsCase(name: string, src: string, dist: string): void;