@rspack/test-tools 1.0.14 → 1.1.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.
@@ -44,7 +44,7 @@ const watchCreator = new creator_1.BasicCaseCreator({
44
44
  description: (name, index) => {
45
45
  return index === 0
46
46
  ? `${name} should compile`
47
- : "should compile the next step";
47
+ : `should compile the next step ${index}`;
48
48
  },
49
49
  describe: false,
50
50
  steps: ({ name, src, temp }) => {
@@ -16,7 +16,7 @@ const creator = new creator_1.BasicCaseCreator({
16
16
  description: (name, index) => {
17
17
  return index === 0
18
18
  ? `${name} should compile`
19
- : "should compile the next step";
19
+ : `should compile the next step ${index}`;
20
20
  },
21
21
  describe: false,
22
22
  steps: ({ name, src, temp }) => {
@@ -4,3 +4,4 @@ export * from "./read-config-file";
4
4
  export * from "./update-snapshot";
5
5
  export * from "./win";
6
6
  export * from "./replace-paths";
7
+ export * from "./util/checkStats";
@@ -20,3 +20,4 @@ __exportStar(require("./read-config-file"), exports);
20
20
  __exportStar(require("./update-snapshot"), exports);
21
21
  __exportStar(require("./win"), exports);
22
22
  __exportStar(require("./replace-paths"), exports);
23
+ __exportStar(require("./util/checkStats"), exports);
@@ -23,9 +23,9 @@ async function checkSourceMap(out, outCodeMap, toSearch, _checkColumn = true //
23
23
  const map = await new sourceMap.SourceMapConsumer(outCodeMap);
24
24
  for (const id in toSearch) {
25
25
  const isSearchConfig = typeof toSearch[id] === "object" && toSearch[id] !== null;
26
- const outId = isSearchConfig ? toSearch[id].outId ?? id : id;
26
+ const outId = isSearchConfig ? (toSearch[id].outId ?? id) : id;
27
27
  const checkColumn = isSearchConfig
28
- ? toSearch[id].checkColumn ?? _checkColumn
28
+ ? (toSearch[id].checkColumn ?? _checkColumn)
29
29
  : _checkColumn;
30
30
  const inSource = isSearchConfig ? toSearch[id].inSource : toSearch[id];
31
31
  const outIndex = out.indexOf(outId);
@@ -0,0 +1,2 @@
1
+ export function checkChunkModules(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;
2
+ export function checkChunkRuntime(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ exports.checkChunkModules = function checkChunkModules(statsJson, chunkModulesMap, strict = true) {
4
+ for (const chunkId of Reflect.ownKeys(chunkModulesMap)) {
5
+ const chunk = getChunk(statsJson, chunkId);
6
+ const expectedModules = chunkModulesMap[chunkId];
7
+ const chunkModules = chunk.modules.map(m => m.identifier);
8
+ if (strict && expectedModules.length !== chunkModules.length) {
9
+ throw new Error(`expect chunk ${chunkId} has ${chunkModules.length} modules: ${chunkModules}\nbut received ${chunkModules.length} modules`);
10
+ }
11
+ for (const module of expectedModules) {
12
+ if (!chunkModules.find(moduleId => moduleId.includes(module))) {
13
+ throw new Error(`chunk ${chunkId} has no module contains id: ${module}`);
14
+ }
15
+ }
16
+ }
17
+ return true;
18
+ };
19
+ exports.checkChunkRuntime = function checkChunkModules(statsJson, chunkModulesMap, strict = true) {
20
+ for (const chunkId of Reflect.ownKeys(chunkModulesMap)) {
21
+ const chunk = getChunk(statsJson, chunkId);
22
+ const expectedRuntime = chunkModulesMap[chunkId];
23
+ const chunkRuntime = chunk.runtime;
24
+ if (strict) {
25
+ expectedRuntime.length === chunkRuntime.length;
26
+ }
27
+ for (let i = 0; i < expectedRuntime.length; i++) {
28
+ const expected = expectedRuntime[i];
29
+ const rt = chunkRuntime[i];
30
+ if (expected !== rt) {
31
+ throw new Error(`chunk ${chunkId} runtime not equal, expected: ${expectedRuntime}, but got: ${chunkRuntime}`);
32
+ }
33
+ }
34
+ }
35
+ return true;
36
+ };
37
+ function getChunk(statsJson, id) {
38
+ const chunk = statsJson.chunks.find(chunk => chunk.id.includes(id));
39
+ if (!chunk) {
40
+ throw new Error(`cannot find chunk with id: ${id}`);
41
+ }
42
+ return chunk;
43
+ }
@@ -63,6 +63,7 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
63
63
  const warnings = [];
64
64
  const compiler = this.getCompiler(context);
65
65
  const stats = compiler.getStats();
66
+ const checkStats = testConfig.checkStats || (() => true);
66
67
  if (stats) {
67
68
  node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
68
69
  preset: "verbose",
@@ -71,6 +72,9 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
71
72
  const jsonStats = stats.toJson({
72
73
  errorDetails: true
73
74
  });
75
+ if (!checkStats(this._watchOptions.stepName, jsonStats)) {
76
+ throw new Error("stats check failed");
77
+ }
74
78
  node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(jsonStats, null, 2), "utf-8");
75
79
  if (jsonStats.errors) {
76
80
  errors.push(...jsonStats.errors);
@@ -74,6 +74,9 @@ class CommonJsRunner extends basic_1.BasicRunner {
74
74
  createCjsRequirer() {
75
75
  const requireCache = Object.create(null);
76
76
  return (currentDirectory, modulePath, context = {}) => {
77
+ if (modulePath === "@rspack/test-tools") {
78
+ return require("@rspack/test-tools");
79
+ }
77
80
  const file = context.file || this.getFile(modulePath, currentDirectory);
78
81
  if (!file) {
79
82
  return this.requirers.get("miss")(currentDirectory, modulePath);
package/dist/type.d.ts CHANGED
@@ -138,6 +138,7 @@ export type TTestConfig<T extends ECompilerType> = {
138
138
  beforeExecute?: () => void;
139
139
  afterExecute?: () => void;
140
140
  moduleScope?: (ms: IBasicModuleScope, stats?: TCompilerStatsCompilation<T>) => IBasicModuleScope;
141
+ checkStats?: (stepName: string, stats: TCompilerStatsCompilation<T>) => boolean;
141
142
  findBundle?: (index: number, options: TCompilerOptions<T>) => string | string[];
142
143
  bundlePath?: string[];
143
144
  nonEsmThis?: (p: string | string[]) => Object;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.0.14",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -46,7 +46,7 @@
46
46
  "jest-serializer-path": "^0.1.15",
47
47
  "jest-snapshot": "29.7.0",
48
48
  "jsdom": "^25.0.0",
49
- "memfs": "4.8.1",
49
+ "memfs": "4.14.0",
50
50
  "mkdirp": "0.5.6",
51
51
  "path-serializer": "0.1.2",
52
52
  "pretty-format": "29.7.0",
@@ -59,12 +59,12 @@
59
59
  "devDependencies": {
60
60
  "@arco-design/web-react": "^2.56.1",
61
61
  "@monaco-editor/react": "^4.6.0",
62
- "@rspack/plugin-preact-refresh": "1.0.0",
62
+ "@rspack/plugin-preact-refresh": "1.1.0",
63
63
  "@rspack/plugin-react-refresh": "1.0.0",
64
64
  "@swc/helpers": "0.5.13",
65
65
  "@swc/plugin-remove-console": "^3.0.0",
66
66
  "@types/babel__generator": "7.6.8",
67
- "@types/babel__traverse": "7.20.5",
67
+ "@types/babel__traverse": "7.20.6",
68
68
  "@types/fs-extra": "11.0.4",
69
69
  "@types/jsdom": "^21.1.7",
70
70
  "@types/react": "^18.2.48",
@@ -78,14 +78,14 @@
78
78
  "coffee-loader": "^5.0.0",
79
79
  "coffeescript": "^2.5.1",
80
80
  "copy-webpack-plugin": "5.1.2",
81
- "core-js": "3.36.1",
81
+ "core-js": "3.38.1",
82
82
  "css-loader": "^6.11.0",
83
83
  "file-loader": "^6.2.0",
84
84
  "html-loader": "^5.0.0",
85
85
  "html-webpack-plugin": "^5.5.0",
86
86
  "less-loader": "^12.2.0",
87
87
  "lodash": "^4.17.21",
88
- "monaco-editor": "0.47.0",
88
+ "monaco-editor": "0.52.0",
89
89
  "monaco-editor-webpack-plugin": "7.1.0",
90
90
  "normalize.css": "^8.0.0",
91
91
  "postcss-loader": "^8.0.0",
@@ -99,14 +99,14 @@
99
99
  "sass-loader": "^16.0.0",
100
100
  "source-map-loader": "^5.0.0",
101
101
  "style-loader": "^4.0.0",
102
- "terser": "5.27.2",
102
+ "terser": "5.36.0",
103
103
  "typescript": "^5.6.3",
104
104
  "wast-loader": "^1.12.1",
105
- "@rspack/cli": "1.0.14",
106
- "@rspack/core": "1.0.14"
105
+ "@rspack/cli": "1.1.0",
106
+ "@rspack/core": "1.1.0"
107
107
  },
108
108
  "peerDependencies": {
109
- "@rspack/core": ">=0.7.0"
109
+ "@rspack/core": ">=1.0.0"
110
110
  },
111
111
  "scripts": {
112
112
  "build": "tsc -b ./tsconfig.build.json",
@@ -119,6 +119,6 @@
119
119
  "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 --colors --config ./jest.config.hot.js --passWithNoTests",
120
120
  "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 --colors --config ./jest.config.diff.js --passWithNoTests",
121
121
  "api-extractor": "api-extractor run --verbose",
122
- "api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md"
122
+ "api-extractor:ci": "api-extractor run --verbose || diff temp/test-tools.api.md etc/test-tools.api.md"
123
123
  }
124
124
  }