@rspack/test-tools 1.3.0-beta.0 → 1.3.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.
- package/dist/plugin/index.d.ts +1 -0
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +4 -0
- package/dist/plugin/lazy-compilation-test-plugin.js +67 -0
- package/dist/processor/hot-step.js +5 -1
- package/dist/processor/hot.d.ts +1 -0
- package/dist/processor/hot.js +7 -0
- package/dist/runner/hot.js +1 -0
- package/dist/type.d.ts +1 -0
- package/package.json +7 -5
package/dist/plugin/index.d.ts
CHANGED
package/dist/plugin/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./rspack-diff-config-plugin"), exports);
|
|
18
18
|
__exportStar(require("./webpack-diff-config-plugin"), exports);
|
|
19
19
|
__exportStar(require("./webpack-module-placeholder-plugin"), exports);
|
|
20
|
+
__exportStar(require("./lazy-compilation-test-plugin"), exports);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LazyCompilationTestPlugin = void 0;
|
|
4
|
+
const node_http_1 = require("node:http");
|
|
5
|
+
const core_1 = require("@rspack/core");
|
|
6
|
+
class LazyCompilationTestPlugin {
|
|
7
|
+
apply(compiler) {
|
|
8
|
+
const options = compiler.options.experiments.lazyCompilation;
|
|
9
|
+
if (!options) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let middleware;
|
|
13
|
+
const server = (0, node_http_1.createServer)();
|
|
14
|
+
const sockets = new Set();
|
|
15
|
+
const promise = new Promise((resolve, reject) => {
|
|
16
|
+
server.on("listening", () => {
|
|
17
|
+
const addr = server.address();
|
|
18
|
+
if (typeof addr === "string")
|
|
19
|
+
throw new Error("addr must not be a string");
|
|
20
|
+
const protocol = "http";
|
|
21
|
+
const urlBase = addr.address === "::" || addr.address === "0.0.0.0"
|
|
22
|
+
? `${protocol}://localhost:${addr.port}`
|
|
23
|
+
: addr.family === "IPv6"
|
|
24
|
+
? `${protocol}://[${addr.address}]:${addr.port}`
|
|
25
|
+
: `${protocol}://${addr.address}:${addr.port}`;
|
|
26
|
+
middleware = core_1.experiments.lazyCompilationMiddleware(compiler, {
|
|
27
|
+
// @ts-expect-error cacheable is hidden config only for tests
|
|
28
|
+
cacheable: false,
|
|
29
|
+
serverUrl: urlBase,
|
|
30
|
+
...options
|
|
31
|
+
});
|
|
32
|
+
resolve(null);
|
|
33
|
+
});
|
|
34
|
+
server.on("request", (req, res) => {
|
|
35
|
+
middleware(req, res, () => { });
|
|
36
|
+
});
|
|
37
|
+
server.on("connection", socket => {
|
|
38
|
+
sockets.add(socket);
|
|
39
|
+
socket.on("close", () => {
|
|
40
|
+
sockets.delete(socket);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
server.on("error", e => {
|
|
44
|
+
reject(e);
|
|
45
|
+
});
|
|
46
|
+
server.listen();
|
|
47
|
+
});
|
|
48
|
+
let initialized = false;
|
|
49
|
+
compiler.hooks.beforeCompile.tapAsync("LazyCompilationTestPlugin", async (_, done) => {
|
|
50
|
+
if (initialized) {
|
|
51
|
+
return done();
|
|
52
|
+
}
|
|
53
|
+
await promise;
|
|
54
|
+
initialized = true;
|
|
55
|
+
done();
|
|
56
|
+
});
|
|
57
|
+
compiler.hooks.shutdown.tapAsync("LazyCompilationTestPlugin", done => {
|
|
58
|
+
server.close(() => {
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
for (const socket of sockets) {
|
|
62
|
+
socket.destroy(new Error("Server is disposing"));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.LazyCompilationTestPlugin = LazyCompilationTestPlugin;
|
|
@@ -288,7 +288,11 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
288
288
|
`
|
|
289
289
|
: ""}
|
|
290
290
|
|
|
291
|
-
|
|
291
|
+
`
|
|
292
|
+
.replaceAll(/%3A(\d+)%2F/g, (match, capture) => {
|
|
293
|
+
return match.replace(capture, "PORT");
|
|
294
|
+
})
|
|
295
|
+
.trim();
|
|
292
296
|
env.expect(content).toMatchFileSnapshot(snapshotPath);
|
|
293
297
|
}
|
|
294
298
|
}
|
package/dist/processor/hot.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ECompilerType, type ITestContext, type ITestEnv, type ITestRunner, type
|
|
|
2
2
|
import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
|
|
3
3
|
export interface IHotProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
|
|
4
4
|
target: TCompilerOptions<T>["target"];
|
|
5
|
+
checkSteps?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export declare class HotProcessor<T extends ECompilerType> extends BasicProcessor<T> {
|
|
7
8
|
protected _hotOptions: IHotProcessorOptions<T>;
|
package/dist/processor/hot.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.HotProcessor = void 0;
|
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const core_1 = require("@rspack/core");
|
|
9
9
|
const plugins_1 = require("../helper/plugins");
|
|
10
|
+
const plugin_1 = require("../plugin");
|
|
10
11
|
const type_1 = require("../type");
|
|
11
12
|
const basic_1 = require("./basic");
|
|
12
13
|
class HotProcessor extends basic_1.BasicProcessor {
|
|
@@ -60,6 +61,9 @@ class HotProcessor extends basic_1.BasicProcessor {
|
|
|
60
61
|
}
|
|
61
62
|
async afterAll(context) {
|
|
62
63
|
await super.afterAll(context);
|
|
64
|
+
if (context.getTestConfig().checkSteps === false) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
63
67
|
if (this.updateOptions.updateIndex + 1 !==
|
|
64
68
|
this.updateOptions.totalUpdates) {
|
|
65
69
|
throw new Error(`Should run all hot steps (${this.updateOptions.updateIndex + 1} / ${this.updateOptions.totalUpdates}): ${this._options.name}`);
|
|
@@ -126,6 +130,9 @@ class HotProcessor extends basic_1.BasicProcessor {
|
|
|
126
130
|
level: "error"
|
|
127
131
|
};
|
|
128
132
|
}
|
|
133
|
+
if (options.experiments?.lazyCompilation) {
|
|
134
|
+
options.plugins.push(new plugin_1.LazyCompilationTestPlugin());
|
|
135
|
+
}
|
|
129
136
|
}
|
|
130
137
|
}
|
|
131
138
|
exports.HotProcessor = HotProcessor;
|
package/dist/runner/hot.js
CHANGED
|
@@ -61,6 +61,7 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
61
61
|
name: this.name,
|
|
62
62
|
runInNewContext: false,
|
|
63
63
|
testConfig: {
|
|
64
|
+
documentType: testConfig.documentType || type_1.EDocumentType.Fake,
|
|
64
65
|
...testConfig,
|
|
65
66
|
moduleScope(ms, stats) {
|
|
66
67
|
const moduleScope = typeof testConfig.moduleScope === "function"
|
package/dist/type.d.ts
CHANGED
|
@@ -148,6 +148,7 @@ export type TTestConfig<T extends ECompilerType> = {
|
|
|
148
148
|
modules?: Record<string, Object>;
|
|
149
149
|
timeout?: number;
|
|
150
150
|
concurrent?: boolean;
|
|
151
|
+
checkSteps?: boolean;
|
|
151
152
|
};
|
|
152
153
|
export type TTestFilter<T extends ECompilerType> = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig<T>) => boolean | string;
|
|
153
154
|
export interface ITestRunner {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.3.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"fs-extra": "^11.3.0",
|
|
43
43
|
"glob": "^11.0.1",
|
|
44
44
|
"graceful-fs": "^4.2.11",
|
|
45
|
+
"iconv-lite": "^0.6.3",
|
|
45
46
|
"jest-diff": "^29.7.0",
|
|
46
47
|
"jest-snapshot": "29.7.0",
|
|
47
48
|
"jsdom": "^26.0.0",
|
|
@@ -60,12 +61,12 @@
|
|
|
60
61
|
"@rspack/plugin-preact-refresh": "1.1.2",
|
|
61
62
|
"@rspack/plugin-react-refresh": "^1.0.1",
|
|
62
63
|
"@swc/helpers": "0.5.15",
|
|
63
|
-
"@swc/plugin-remove-console": "^
|
|
64
|
+
"@swc/plugin-remove-console": "^7.0.0",
|
|
64
65
|
"@types/babel__generator": "7.6.8",
|
|
65
66
|
"@types/babel__traverse": "7.20.6",
|
|
66
67
|
"@types/fs-extra": "11.0.4",
|
|
67
68
|
"@types/jsdom": "^21.1.7",
|
|
68
|
-
"@types/react": "^19.0.
|
|
69
|
+
"@types/react": "^19.0.11",
|
|
69
70
|
"@types/react-dom": "^19.0.4",
|
|
70
71
|
"@types/webpack": "5.28.5",
|
|
71
72
|
"@types/webpack-sources": "3.2.3",
|
|
@@ -96,8 +97,9 @@
|
|
|
96
97
|
"typescript": "^5.7.3",
|
|
97
98
|
"wast-loader": "^1.14.1",
|
|
98
99
|
"worker-rspack-loader": "^3.1.2",
|
|
99
|
-
"@rspack/cli": "1.3.0
|
|
100
|
-
"@rspack/core": "1.3.0
|
|
100
|
+
"@rspack/cli": "1.3.0",
|
|
101
|
+
"@rspack/core": "1.3.0",
|
|
102
|
+
"@rspack/test-tools": "1.3.0"
|
|
101
103
|
},
|
|
102
104
|
"peerDependencies": {
|
|
103
105
|
"@rspack/core": ">=1.0.0"
|