@rspack/test-tools 1.0.14 → 1.1.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.
@@ -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);
@@ -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) {
9
+ expectedModules.length === chunkModules.length;
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
+ }
@@ -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/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-beta.0",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -102,8 +102,8 @@
102
102
  "terser": "5.27.2",
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-beta.0",
106
+ "@rspack/core": "1.1.0-beta.0"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=0.7.0"
@@ -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
  }