@rspack-canary/test-tools 1.6.0-canary-beafb11e-20251019174144 → 1.6.0-canary-0eb13821-20251021173640
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/case/cache.js +3 -0
- package/dist/case/common.d.ts +1 -0
- package/dist/case/common.js +15 -12
- package/dist/case/config.js +4 -1
- package/dist/case/esm-output.js +28 -2
- package/dist/case/hot.d.ts +1 -1
- package/dist/case/hot.js +4 -3
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +1 -20
- package/dist/case/normal.js +3 -0
- package/dist/case/runner.d.ts +1 -1
- package/dist/case/runner.js +4 -3
- package/dist/case/watch.d.ts +3 -1
- package/dist/case/watch.js +5 -4
- package/dist/helper/hot-update/plugin.js +1 -1
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
- package/dist/helper/legacy/createLazyTestEnv.js +3 -1
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/setup-env.js +15 -0
- package/dist/runner/node/index.js +7 -3
- package/dist/runner/web/index.d.ts +20 -7
- package/dist/runner/web/index.js +293 -18
- package/dist/test/creator.js +13 -7
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +5 -0
- package/dist/type.d.ts +5 -5
- package/dist/type.js +1 -6
- package/jest.d.ts +2 -0
- package/package.json +3 -3
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -280
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/runner/web/fake.d.ts +0 -15
- package/dist/runner/web/fake.js +0 -215
- package/dist/runner/web/jsdom.d.ts +0 -24
- package/dist/runner/web/jsdom.js +0 -241
package/dist/case/cache.js
CHANGED
|
@@ -40,6 +40,9 @@ function createCacheProcessor(name, src, temp, target) {
|
|
|
40
40
|
check: async (env, context) => {
|
|
41
41
|
await (0, common_1.check)(env, context, name);
|
|
42
42
|
},
|
|
43
|
+
after: async (context) => {
|
|
44
|
+
await (0, common_1.afterExecute)(context, name);
|
|
45
|
+
},
|
|
43
46
|
afterAll: async (context) => {
|
|
44
47
|
const updateIndex = updatePlugin.getUpdateIndex();
|
|
45
48
|
const totalUpdates = updatePlugin.getTotalUpdates();
|
package/dist/case/common.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export declare function build<T extends ECompilerType = ECompilerType.Rspack>(co
|
|
|
6
6
|
export declare function run<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): Promise<void>;
|
|
7
7
|
export declare function check<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
|
|
8
8
|
export declare function checkSnapshot<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): Promise<void>;
|
|
9
|
+
export declare function afterExecute(context: ITestContext, name: string): Promise<void>;
|
|
9
10
|
export declare function findMultiCompilerBundle<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): string[];
|
|
10
11
|
export declare function configMultiCompiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => TCompilerOptions<T>, overrideOptions: (index: number, context: ITestContext, options: TCompilerOptions<T>) => void): void;
|
package/dist/case/common.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.build = build;
|
|
|
10
10
|
exports.run = run;
|
|
11
11
|
exports.check = check;
|
|
12
12
|
exports.checkSnapshot = checkSnapshot;
|
|
13
|
+
exports.afterExecute = afterExecute;
|
|
13
14
|
exports.findMultiCompilerBundle = findMultiCompilerBundle;
|
|
14
15
|
exports.configMultiCompiler = configMultiCompiler;
|
|
15
16
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -45,9 +46,6 @@ async function run(env, context, name, findBundle) {
|
|
|
45
46
|
const testConfig = context.getTestConfig();
|
|
46
47
|
if (testConfig.noTests)
|
|
47
48
|
return;
|
|
48
|
-
if (testConfig.documentType) {
|
|
49
|
-
context.setValue(name, "documentType", testConfig.documentType);
|
|
50
|
-
}
|
|
51
49
|
const compiler = getCompiler(context, name);
|
|
52
50
|
if (typeof testConfig.beforeExecute === "function") {
|
|
53
51
|
testConfig.beforeExecute(compiler.getOptions());
|
|
@@ -80,13 +78,6 @@ async function run(env, context, name, findBundle) {
|
|
|
80
78
|
}
|
|
81
79
|
const results = context.getValue(name, "modules") || [];
|
|
82
80
|
await Promise.all(results);
|
|
83
|
-
if (typeof testConfig.afterExecute === "function") {
|
|
84
|
-
let options = compiler.getOptions();
|
|
85
|
-
if (Array.isArray(options) && options.length === 1) {
|
|
86
|
-
options = options[0];
|
|
87
|
-
}
|
|
88
|
-
testConfig.afterExecute(options);
|
|
89
|
-
}
|
|
90
81
|
}
|
|
91
82
|
async function check(env, context, name) {
|
|
92
83
|
const testConfig = context.getTestConfig();
|
|
@@ -175,16 +166,28 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
|
|
|
175
166
|
if (testConfig.snapshotContent) {
|
|
176
167
|
content = testConfig.snapshotContent(content);
|
|
177
168
|
}
|
|
178
|
-
|
|
169
|
+
const filePath = file.replaceAll(path_1.default.sep, "/");
|
|
170
|
+
return `\`\`\`${tag} title=${filePath}\n${content}\n\`\`\``;
|
|
179
171
|
});
|
|
180
172
|
fileContents.sort();
|
|
181
173
|
const content = fileContents.join("\n\n");
|
|
182
174
|
const snapshotPath = path_1.default.isAbsolute(snapshot)
|
|
183
175
|
? snapshot
|
|
184
|
-
: path_1.default.resolve(context.getSource(),
|
|
176
|
+
: path_1.default.resolve(context.getSource(), path_1.default.join("__snapshots__", `${snapshot}${total > 1 ? `-${i}` : ""}`));
|
|
185
177
|
env.expect(content).toMatchFileSnapshot(snapshotPath);
|
|
186
178
|
}
|
|
187
179
|
}
|
|
180
|
+
async function afterExecute(context, name) {
|
|
181
|
+
const compiler = getCompiler(context, name);
|
|
182
|
+
const testConfig = context.getTestConfig();
|
|
183
|
+
if (typeof testConfig.afterExecute === "function") {
|
|
184
|
+
let options = compiler.getOptions();
|
|
185
|
+
if (Array.isArray(options) && options.length === 1) {
|
|
186
|
+
options = options[0];
|
|
187
|
+
}
|
|
188
|
+
testConfig.afterExecute(options);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
188
191
|
function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
189
192
|
if (typeof multiFindBundle !== "function") {
|
|
190
193
|
return [];
|
package/dist/case/config.js
CHANGED
|
@@ -30,6 +30,9 @@ function createConfigProcessor(name) {
|
|
|
30
30
|
},
|
|
31
31
|
check: async (env, context) => {
|
|
32
32
|
await (0, common_1.check)(env, context, name);
|
|
33
|
+
},
|
|
34
|
+
after: async (context) => {
|
|
35
|
+
await (0, common_1.afterExecute)(context, name);
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
38
|
}
|
|
@@ -115,7 +118,7 @@ function findBundle(index, context, options) {
|
|
|
115
118
|
options.output?.cssFilename) ||
|
|
116
119
|
`bundle${index}.css`);
|
|
117
120
|
if (fs_extra_1.default.existsSync(cssOutputPath)) {
|
|
118
|
-
bundlePath.push(
|
|
121
|
+
bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
bundlePath.push(`./bundle${index}${ext}`);
|
package/dist/case/esm-output.js
CHANGED
|
@@ -25,7 +25,26 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
25
25
|
steps: ({ name }) => [
|
|
26
26
|
{
|
|
27
27
|
config: async (context) => {
|
|
28
|
-
(0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, () => {
|
|
28
|
+
(0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, (_index, context, options) => {
|
|
29
|
+
const testConfig = context.getTestConfig();
|
|
30
|
+
if (testConfig.esmLibPluginOptions) {
|
|
31
|
+
let target;
|
|
32
|
+
const otherPlugins = options.plugins?.filter(plugin => {
|
|
33
|
+
const isTarget = plugin instanceof core_1.default.experiments.EsmLibraryPlugin;
|
|
34
|
+
if (isTarget) {
|
|
35
|
+
target = plugin;
|
|
36
|
+
}
|
|
37
|
+
return !isTarget;
|
|
38
|
+
});
|
|
39
|
+
options.plugins = [
|
|
40
|
+
...otherPlugins,
|
|
41
|
+
new core_1.default.experiments.EsmLibraryPlugin({
|
|
42
|
+
...target.options,
|
|
43
|
+
...testConfig.esmLibPluginOptions
|
|
44
|
+
})
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
29
48
|
},
|
|
30
49
|
compiler: async (context) => {
|
|
31
50
|
await (0, common_1.compiler)(context, name);
|
|
@@ -34,7 +53,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
34
53
|
await (0, common_1.build)(context, name);
|
|
35
54
|
},
|
|
36
55
|
run: async (env, context) => {
|
|
37
|
-
await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (_index,
|
|
56
|
+
await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (_index, context, options) => {
|
|
57
|
+
const testConfig = context.getTestConfig();
|
|
58
|
+
if (typeof testConfig.findBundle === "function") {
|
|
59
|
+
return testConfig.findBundle(_index, options);
|
|
60
|
+
}
|
|
38
61
|
if (options.output?.filename === "[name].mjs") {
|
|
39
62
|
return ["main.mjs"];
|
|
40
63
|
}
|
|
@@ -46,6 +69,9 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
46
69
|
check: async (env, context) => {
|
|
47
70
|
await (0, common_1.check)(env, context, name);
|
|
48
71
|
await (0, common_1.checkSnapshot)(env, context, name, "esm.snap.txt");
|
|
72
|
+
},
|
|
73
|
+
after: async (context) => {
|
|
74
|
+
await (0, common_1.afterExecute)(context, name);
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
77
|
],
|
package/dist/case/hot.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HotUpdatePlugin } from "../helper/hot-update/plugin";
|
|
2
|
-
import {
|
|
2
|
+
import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, ITestRunner, TCompilerOptions } from "../type";
|
|
3
3
|
type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
|
|
4
4
|
export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
5
5
|
export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
package/dist/case/hot.js
CHANGED
|
@@ -14,7 +14,6 @@ const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkA
|
|
|
14
14
|
const plugin_2 = require("../plugin");
|
|
15
15
|
const runner_1 = require("../runner");
|
|
16
16
|
const creator_1 = require("../test/creator");
|
|
17
|
-
const type_1 = require("../type");
|
|
18
17
|
const common_1 = require("./common");
|
|
19
18
|
const runner_2 = require("./runner");
|
|
20
19
|
const creators = new Map();
|
|
@@ -48,6 +47,9 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
|
|
|
48
47
|
check: async (env, context) => {
|
|
49
48
|
await (0, common_1.check)(env, context, name);
|
|
50
49
|
},
|
|
50
|
+
after: async (context) => {
|
|
51
|
+
await (0, common_1.afterExecute)(context, name);
|
|
52
|
+
},
|
|
51
53
|
afterAll: async (context) => {
|
|
52
54
|
if (context.getTestConfig().checkSteps === false) {
|
|
53
55
|
return;
|
|
@@ -205,7 +207,6 @@ function createHotRunner(context, name, file, env) {
|
|
|
205
207
|
name: name,
|
|
206
208
|
runInNewContext: false,
|
|
207
209
|
testConfig: {
|
|
208
|
-
documentType: testConfig.documentType || type_1.EDocumentType.JSDOM,
|
|
209
210
|
...testConfig,
|
|
210
211
|
moduleScope(ms, stats, options) {
|
|
211
212
|
const moduleScope = ms;
|
|
@@ -225,7 +226,7 @@ function createHotRunner(context, name, file, env) {
|
|
|
225
226
|
if (compilerOptions.target === "web" ||
|
|
226
227
|
compilerOptions.target === "webworker") {
|
|
227
228
|
runner = new runner_1.WebRunner({
|
|
228
|
-
|
|
229
|
+
location: testConfig.location || "https://test.cases/path/index.html",
|
|
229
230
|
...commonOptions
|
|
230
231
|
});
|
|
231
232
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ECompilerType, TCompilerOptions } from "../type";
|
|
2
2
|
export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
|
|
3
3
|
export type WatchIncrementalOptions = {
|
|
4
4
|
ignoreNotFriendlyForIncrementalWarnings?: boolean;
|
package/dist/case/incremental.js
CHANGED
|
@@ -8,30 +8,11 @@ exports.createWatchIncrementalCase = createWatchIncrementalCase;
|
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const creator_1 = require("../test/creator");
|
|
11
|
-
const type_1 = require("../type");
|
|
12
11
|
const hot_1 = require("./hot");
|
|
13
12
|
const watch_1 = require("./watch");
|
|
14
13
|
const hotCreators = new Map();
|
|
15
14
|
function createHotIncrementalProcessor(name, src, temp, target, webpackCases) {
|
|
16
|
-
|
|
17
|
-
const originalBefore = processor.before;
|
|
18
|
-
processor.before = async (context) => {
|
|
19
|
-
await originalBefore?.(context);
|
|
20
|
-
context.setValue(name, "documentType", webpackCases ? type_1.EDocumentType.JSDOM : type_1.EDocumentType.JSDOM);
|
|
21
|
-
};
|
|
22
|
-
const originalAfterAll = processor.afterAll;
|
|
23
|
-
processor.afterAll = async function (context) {
|
|
24
|
-
try {
|
|
25
|
-
await originalAfterAll?.(context);
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
const isFake = context.getValue(name, "documentType") === type_1.EDocumentType.Fake;
|
|
29
|
-
if (isFake && /Should run all hot steps/.test(e.message))
|
|
30
|
-
return;
|
|
31
|
-
throw e;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
return processor;
|
|
15
|
+
return (0, hot_1.createHotProcessor)(name, src, temp, target, true);
|
|
35
16
|
}
|
|
36
17
|
function getHotCreator(target, webpackCases) {
|
|
37
18
|
const key = JSON.stringify({ target, webpackCases });
|
package/dist/case/normal.js
CHANGED
package/dist/case/runner.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ECompilerType, ITestContext, ITestEnv, ITestRunner, TCompilerStatsCompilation } from "../type";
|
|
2
2
|
export type THotStepRuntimeLangData = {
|
|
3
3
|
outdatedModules: string[];
|
|
4
4
|
outdatedDependencies: Record<string, string[]>;
|
package/dist/case/runner.js
CHANGED
|
@@ -5,7 +5,6 @@ exports.createRunner = createRunner;
|
|
|
5
5
|
exports.getMultiCompilerRunnerKey = getMultiCompilerRunnerKey;
|
|
6
6
|
exports.createMultiCompilerRunner = createMultiCompilerRunner;
|
|
7
7
|
const runner_1 = require("../runner");
|
|
8
|
-
const type_1 = require("../type");
|
|
9
8
|
const common_1 = require("./common");
|
|
10
9
|
function cachedStats(context, name) {
|
|
11
10
|
const compiler = context.getCompiler(name);
|
|
@@ -25,6 +24,7 @@ function cachedStats(context, name) {
|
|
|
25
24
|
}
|
|
26
25
|
function createRunner(context, name, file, env) {
|
|
27
26
|
const compiler = (0, common_1.getCompiler)(context, name);
|
|
27
|
+
const testConfig = context.getTestConfig();
|
|
28
28
|
const compilerOptions = compiler.getOptions();
|
|
29
29
|
const runnerOptions = {
|
|
30
30
|
runInNewContext: false,
|
|
@@ -42,7 +42,7 @@ function createRunner(context, name, file, env) {
|
|
|
42
42
|
return new runner_1.WebRunner({
|
|
43
43
|
...runnerOptions,
|
|
44
44
|
runInNewContext: true,
|
|
45
|
-
|
|
45
|
+
location: testConfig.location || "https://test.cases/path/index.html"
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
return new runner_1.NodeRunner(runnerOptions);
|
|
@@ -69,6 +69,7 @@ function getMultiCompilerRunnerKey(context, name, file) {
|
|
|
69
69
|
return `${name}-${index}[${seq}]`;
|
|
70
70
|
}
|
|
71
71
|
function createMultiCompilerRunner(context, name, file, env) {
|
|
72
|
+
const testConfig = context.getTestConfig();
|
|
72
73
|
const { getIndex, flagIndex } = getFileIndexHandler(context, name, file);
|
|
73
74
|
const multiCompilerOptions = context.getValue(name, "multiCompilerOptions") || [];
|
|
74
75
|
const [index] = getIndex();
|
|
@@ -97,7 +98,7 @@ function createMultiCompilerRunner(context, name, file, env) {
|
|
|
97
98
|
runner = new runner_1.WebRunner({
|
|
98
99
|
...runnerOptions,
|
|
99
100
|
runInNewContext: true,
|
|
100
|
-
|
|
101
|
+
location: testConfig.location || "https://test.cases/path/index.html"
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
else {
|
package/dist/case/watch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ECompilerType, ITestContext, ITestEnv, ITestRunner } from "../type";
|
|
2
2
|
export declare function createWatchInitialProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
|
|
3
3
|
incremental?: boolean | undefined;
|
|
4
4
|
nativeWatcher?: boolean | undefined;
|
|
@@ -9,6 +9,7 @@ export declare function createWatchInitialProcessor(name: string, tempDir: strin
|
|
|
9
9
|
build: (context: ITestContext) => Promise<void>;
|
|
10
10
|
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
11
11
|
check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
12
|
+
after: (context: ITestContext) => Promise<void>;
|
|
12
13
|
};
|
|
13
14
|
export declare function createWatchStepProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
|
|
14
15
|
incremental?: boolean | undefined;
|
|
@@ -20,6 +21,7 @@ export declare function createWatchStepProcessor(name: string, tempDir: string,
|
|
|
20
21
|
build: (context: ITestContext) => Promise<void>;
|
|
21
22
|
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
22
23
|
check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
24
|
+
after: (context: ITestContext) => Promise<void>;
|
|
23
25
|
};
|
|
24
26
|
export declare function createWatchCase(name: string, src: string, dist: string, temp: string): void;
|
|
25
27
|
export declare function getWatchRunnerKey(context: ITestContext, name: string, file: string): string;
|
package/dist/case/watch.js
CHANGED
|
@@ -17,7 +17,6 @@ const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkA
|
|
|
17
17
|
const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
|
|
18
18
|
const runner_1 = require("../runner");
|
|
19
19
|
const creator_1 = require("../test/creator");
|
|
20
|
-
const type_1 = require("../type");
|
|
21
20
|
const common_1 = require("./common");
|
|
22
21
|
function createWatchInitialProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
|
|
23
22
|
const watchContext = {
|
|
@@ -158,6 +157,9 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
158
157
|
if (testConfig.writeStatsJson) {
|
|
159
158
|
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.json`));
|
|
160
159
|
}
|
|
160
|
+
},
|
|
161
|
+
after: async (context) => {
|
|
162
|
+
await (0, common_1.afterExecute)(context, name);
|
|
161
163
|
}
|
|
162
164
|
};
|
|
163
165
|
}
|
|
@@ -321,9 +323,7 @@ function createWatchRunner(context, name, file, env) {
|
|
|
321
323
|
: compilerOptions.target === "web" ||
|
|
322
324
|
compilerOptions.target === "webworker";
|
|
323
325
|
const testConfig = context.getTestConfig();
|
|
324
|
-
const documentType = context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM;
|
|
325
326
|
return new runner_1.WebRunner({
|
|
326
|
-
dom: documentType,
|
|
327
327
|
env,
|
|
328
328
|
stats: cachedWatchStats(context, name),
|
|
329
329
|
name: name,
|
|
@@ -342,6 +342,7 @@ function createWatchRunner(context, name, file, env) {
|
|
|
342
342
|
},
|
|
343
343
|
source: context.getSource(),
|
|
344
344
|
dist: context.getDist(),
|
|
345
|
-
compilerOptions
|
|
345
|
+
compilerOptions,
|
|
346
|
+
location: testConfig.location || "https://test.cases/path/index.html"
|
|
346
347
|
});
|
|
347
348
|
}
|
|
@@ -49,7 +49,7 @@ class HotUpdatePlugin {
|
|
|
49
49
|
const { content, command } = this.getContent(filePath, this.updateIndex);
|
|
50
50
|
// match command
|
|
51
51
|
if (command === "delete") {
|
|
52
|
-
await fs_extra_1.default.
|
|
52
|
+
await fs_extra_1.default.remove(filePath);
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
if (command === "force_write") {
|
package/dist/helper/setup-env.js
CHANGED
|
@@ -6,6 +6,21 @@ const path = require("node:path");
|
|
|
6
6
|
if (process.env.RSPACK_BINDING_BUILDER_TESTING) {
|
|
7
7
|
process.env.RSPACK_BINDING = path.resolve(__dirname, "../../node_modules/@rspack/binding-testing");
|
|
8
8
|
}
|
|
9
|
+
if (process.env.RSTEST) {
|
|
10
|
+
global.printLogger ??= process.env.printLogger === "true";
|
|
11
|
+
global.__TEST_FIXTURES_PATH__ ??= process.env.__TEST_FIXTURES_PATH__;
|
|
12
|
+
global.updateSnapshot ??= process.env.updateSnapshot === "true";
|
|
13
|
+
global.testFilter ??= process.env.testFilter;
|
|
14
|
+
global.__TEST_PATH__ ??= process.env.__TEST_PATH__;
|
|
15
|
+
global.__TEST_DIST_PATH__ ??= process.env.__TEST_DIST_PATH__;
|
|
16
|
+
global.__ROOT_PATH__ ??= process.env.__ROOT_PATH__;
|
|
17
|
+
global.__RSPACK_PATH__ ??= process.env.__RSPACK_PATH__;
|
|
18
|
+
global.__RSPACK_TEST_TOOLS_PATH__ ??= process.env.__RSPACK_TEST_TOOLS_PATH__;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Compatible with wasm tests (lazyTestEnv)
|
|
22
|
+
global.rstest = jest;
|
|
23
|
+
}
|
|
9
24
|
if (process.env.ALTERNATIVE_SORT) {
|
|
10
25
|
const oldSort = Array.prototype.sort;
|
|
11
26
|
Array.prototype.sort = function (cmp) {
|
|
@@ -308,7 +308,7 @@ class NodeRunner {
|
|
|
308
308
|
};
|
|
309
309
|
this.requireCache[file.path] = m;
|
|
310
310
|
if (!this._options.runInNewContext) {
|
|
311
|
-
file.content = `Object.assign(global, _globalAssign)
|
|
311
|
+
file.content = `Object.assign(global, _globalAssign);${file.content}`;
|
|
312
312
|
}
|
|
313
313
|
const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
|
|
314
314
|
if (this._options.testConfig.moduleScope) {
|
|
@@ -357,6 +357,12 @@ class NodeRunner {
|
|
|
357
357
|
if (file.content.includes("__STATS__")) {
|
|
358
358
|
esmContext.__STATS__ = this._options.stats?.();
|
|
359
359
|
}
|
|
360
|
+
if (file.content.includes("__STATS_I__")) {
|
|
361
|
+
const statsIndex = this._options.stats?.()?.__index__;
|
|
362
|
+
if (typeof statsIndex === "number") {
|
|
363
|
+
esmContext.__STATS_I__ = statsIndex;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
360
366
|
let esm = esmCache.get(file.path);
|
|
361
367
|
if (!esm) {
|
|
362
368
|
esm = new node_vm_1.SourceTextModule(file.content, {
|
|
@@ -390,8 +396,6 @@ class NodeRunner {
|
|
|
390
396
|
}), referencingModule.context, true);
|
|
391
397
|
});
|
|
392
398
|
}
|
|
393
|
-
if (esm.instantiate)
|
|
394
|
-
esm.instantiate();
|
|
395
399
|
await esm.evaluate();
|
|
396
400
|
if (context.esmMode === type_1.EEsmMode.Evaluated) {
|
|
397
401
|
return esm;
|
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import type { ECompilerType, TRunnerFile, TRunnerRequirer } from "../../type";
|
|
2
|
+
import { type INodeRunnerOptions, NodeRunner } from "../node";
|
|
3
3
|
export interface IWebRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends INodeRunnerOptions<T> {
|
|
4
|
-
|
|
4
|
+
location: string;
|
|
5
5
|
}
|
|
6
|
-
export declare class WebRunner<T extends ECompilerType = ECompilerType.Rspack>
|
|
6
|
+
export declare class WebRunner<T extends ECompilerType = ECompilerType.Rspack> extends NodeRunner<T> {
|
|
7
7
|
protected _webOptions: IWebRunnerOptions<T>;
|
|
8
|
-
|
|
9
|
-
private implement;
|
|
8
|
+
private dom;
|
|
10
9
|
constructor(_webOptions: IWebRunnerOptions<T>);
|
|
11
10
|
run(file: string): Promise<unknown>;
|
|
12
|
-
getRequire(): import("../../type").TRunnerRequirer;
|
|
13
11
|
getGlobal(name: string): unknown;
|
|
12
|
+
protected createResourceLoader(): {
|
|
13
|
+
fetch(url: string, _: {
|
|
14
|
+
element: HTMLScriptElement;
|
|
15
|
+
}): any;
|
|
16
|
+
};
|
|
17
|
+
private urlToPath;
|
|
18
|
+
protected createBaseModuleScope(): import("../../type").IModuleScope;
|
|
19
|
+
protected getModuleContent(file: TRunnerFile): [
|
|
20
|
+
{
|
|
21
|
+
exports: Record<string, unknown>;
|
|
22
|
+
},
|
|
23
|
+
string
|
|
24
|
+
];
|
|
25
|
+
protected createJSDOMRequirer(): TRunnerRequirer;
|
|
26
|
+
protected createRunner(): void;
|
|
14
27
|
}
|