@rspack/test-tools 1.5.8 → 1.6.0-beta.1
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/builtin.js +0 -22
- package/dist/case/cache.d.ts +1 -1
- package/dist/case/cache.js +5 -5
- package/dist/case/common.d.ts +1 -0
- package/dist/case/common.js +17 -10
- package/dist/case/config.js +5 -3
- package/dist/case/diagnostic.d.ts +2 -2
- package/dist/case/diagnostic.js +2 -3
- package/dist/case/error.d.ts +1 -0
- package/dist/case/error.js +25 -6
- package/dist/case/esm-output.js +28 -2
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.js +1 -2
- package/dist/case/hook.js +3 -4
- package/dist/case/hot-step.d.ts +1 -1
- package/dist/case/hot-step.js +12 -13
- package/dist/case/hot.d.ts +5 -4
- package/dist/case/hot.js +61 -83
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +8 -27
- package/dist/case/index.d.ts +12 -1
- package/dist/case/index.js +7 -1
- package/dist/case/multi-compiler.d.ts +18 -0
- package/dist/case/multi-compiler.js +98 -0
- package/dist/case/normal.d.ts +2 -0
- package/dist/case/normal.js +22 -12
- package/dist/case/runner.d.ts +1 -1
- package/dist/case/runner.js +4 -3
- package/dist/case/stats-api.d.ts +9 -0
- package/dist/case/stats-output.js +5 -4
- package/dist/case/watch.d.ts +5 -5
- package/dist/case/watch.js +11 -16
- package/dist/compare/compare.js +6 -3
- package/dist/helper/directory.js +1 -1
- package/dist/helper/expect/error.js +1 -1
- package/dist/helper/expect/placeholder.js +7 -7
- package/dist/helper/expect/to-match-file-snapshot.d.ts +0 -1
- package/dist/helper/hot-update/loader.d.ts +2 -1
- package/dist/helper/hot-update/loader.js +5 -30
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +14 -13
- package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
- package/dist/helper/legacy/LogTestPlugin.js +35 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
- package/dist/helper/legacy/createLazyTestEnv.js +4 -3
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/read-config-file.d.ts +2 -2
- package/dist/helper/read-config-file.js +5 -2
- package/dist/helper/setup-env.js +18 -2
- package/dist/helper/util/checkStats.d.ts +0 -1
- package/dist/helper/util/checkStats.js +0 -18
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/jest/ignore-snapshot-default-reporter.d.ts +2 -0
- package/dist/jest/ignore-snapshot-default-reporter.js +57 -0
- package/dist/jest/ignore-snapshot-summary-reporter.d.ts +2 -0
- package/dist/jest/ignore-snapshot-summary-reporter.js +24 -0
- package/dist/jest/patch-node-env.d.ts +5 -0
- package/dist/jest/patch-node-env.js +18 -0
- package/dist/jest/slash.d.ts +2 -0
- package/dist/jest/slash.js +16 -0
- package/dist/runner/node/index.js +12 -3
- package/dist/runner/web/index.d.ts +20 -7
- package/dist/runner/web/index.js +293 -18
- package/dist/test/creator.js +15 -10
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +21 -4
- package/dist/type.d.ts +14 -5
- package/dist/type.js +1 -6
- package/jest.d.ts +2 -0
- package/package.json +10 -41
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -280
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsBlob.js +0 -10
- package/dist/helper/legacy/supportsClassFields.d.ts +0 -2
- package/dist/helper/legacy/supportsClassFields.js +0 -11
- package/dist/helper/legacy/supportsES6.d.ts +0 -2
- package/dist/helper/legacy/supportsES6.js +0 -11
- package/dist/helper/legacy/supportsForOf.d.ts +0 -2
- package/dist/helper/legacy/supportsForOf.js +0 -11
- package/dist/helper/legacy/supportsIteratorDestructuring.d.ts +0 -2
- package/dist/helper/legacy/supportsIteratorDestructuring.js +0 -11
- package/dist/helper/legacy/supportsLogicalAssignment.d.ts +0 -2
- package/dist/helper/legacy/supportsLogicalAssignment.js +0 -11
- package/dist/helper/legacy/supportsObjectDestructuring.d.ts +0 -2
- package/dist/helper/legacy/supportsObjectDestructuring.js +0 -11
- package/dist/helper/legacy/supportsOptionalCatchBinding.d.ts +0 -2
- package/dist/helper/legacy/supportsOptionalCatchBinding.js +0 -11
- package/dist/helper/legacy/supportsOptionalChaining.d.ts +0 -2
- package/dist/helper/legacy/supportsOptionalChaining.js +0 -11
- package/dist/helper/legacy/supportsRequireInModule.d.ts +0 -2
- package/dist/helper/legacy/supportsRequireInModule.js +0 -5
- package/dist/helper/legacy/supportsResponse.d.ts +0 -2
- package/dist/helper/legacy/supportsResponse.js +0 -10
- package/dist/helper/legacy/supportsSpread.d.ts +0 -2
- package/dist/helper/legacy/supportsSpread.js +0 -12
- package/dist/helper/legacy/supportsTemplateStrings.d.ts +0 -2
- package/dist/helper/legacy/supportsTemplateStrings.js +0 -11
- package/dist/helper/legacy/supportsWebAssembly.d.ts +0 -2
- package/dist/helper/legacy/supportsWebAssembly.js +0 -10
- package/dist/helper/legacy/supportsWorker.d.ts +0 -2
- package/dist/helper/legacy/supportsWorker.js +0 -17
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
- package/dist/helper/legacy/warmup-webpack.js +0 -26
- package/dist/helper/loaders/hot-update.d.ts +0 -1
- package/dist/helper/loaders/hot-update.js +0 -40
- package/dist/helper/plugins/hot-update.d.ts +0 -7
- package/dist/helper/plugins/hot-update.js +0 -40
- package/dist/helper/plugins/index.d.ts +0 -1
- package/dist/helper/plugins/index.js +0 -17
- package/dist/helper/util/currentWatchStep.d.ts +0 -1
- package/dist/helper/util/currentWatchStep.js +0 -2
- package/dist/helper/util/identifier.d.ts +0 -76
- package/dist/helper/util/identifier.js +0 -339
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
- package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
- package/dist/reporter/diff-html.d.ts +0 -15
- package/dist/reporter/diff-html.js +0 -69
- package/dist/reporter/diff-stats.d.ts +0 -24
- package/dist/reporter/diff-stats.js +0 -131
- package/dist/reporter/index.d.ts +0 -2
- package/dist/reporter/index.js +0 -18
- package/dist/runner/web/fake.d.ts +0 -15
- package/dist/runner/web/fake.js +0 -213
- package/dist/runner/web/jsdom.d.ts +0 -24
- package/dist/runner/web/jsdom.js +0 -228
- /package/dist/helper/legacy/{supportsBlob.d.ts → supportsTextDecoder.d.ts} +0 -0
package/dist/case/builtin.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createBuiltinCase = createBuiltinCase;
|
|
7
7
|
exports.defaultOptions = defaultOptions;
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const core_1 = require("@rspack/core");
|
|
10
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
10
|
const webpack_merge_1 = require("webpack-merge");
|
|
12
11
|
const helper_1 = require("../helper");
|
|
@@ -164,27 +163,6 @@ function defaultOptions(context) {
|
|
|
164
163
|
}
|
|
165
164
|
defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, caseOptions);
|
|
166
165
|
}
|
|
167
|
-
// TODO: remove builtin compatible code
|
|
168
|
-
const defineOptions = defaultOptions.builtins?.define;
|
|
169
|
-
if (defineOptions) {
|
|
170
|
-
defaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
|
|
171
|
-
}
|
|
172
|
-
const provideOptions = defaultOptions.builtins?.provide;
|
|
173
|
-
if (provideOptions) {
|
|
174
|
-
defaultOptions.plugins.push(new core_1.rspack.ProvidePlugin(provideOptions));
|
|
175
|
-
}
|
|
176
|
-
const htmlOptions = defaultOptions.builtins?.html;
|
|
177
|
-
if (htmlOptions) {
|
|
178
|
-
if (Array.isArray(htmlOptions)) {
|
|
179
|
-
for (const item of htmlOptions) {
|
|
180
|
-
defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(item));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(htmlOptions));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
delete defaultOptions.builtins;
|
|
188
166
|
if (!global.printLogger) {
|
|
189
167
|
defaultOptions.infrastructureLogging = {
|
|
190
168
|
level: "error"
|
package/dist/case/cache.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ECompilerType, TCompilerOptions } from "../type";
|
|
2
2
|
export declare function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], temp: string): void;
|
package/dist/case/cache.js
CHANGED
|
@@ -11,7 +11,6 @@ const hot_update_1 = require("../helper/hot-update");
|
|
|
11
11
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
12
12
|
const runner_1 = require("../runner");
|
|
13
13
|
const creator_1 = require("../test/creator");
|
|
14
|
-
const type_1 = require("../type");
|
|
15
14
|
const common_1 = require("./common");
|
|
16
15
|
const runner_2 = require("./runner");
|
|
17
16
|
const MAX_COMPILER_INDEX = 100;
|
|
@@ -41,6 +40,9 @@ function createCacheProcessor(name, src, temp, target) {
|
|
|
41
40
|
check: async (env, context) => {
|
|
42
41
|
await (0, common_1.check)(env, context, name);
|
|
43
42
|
},
|
|
43
|
+
after: async (context) => {
|
|
44
|
+
await (0, common_1.afterExecute)(context, name);
|
|
45
|
+
},
|
|
44
46
|
afterAll: async (context) => {
|
|
45
47
|
const updateIndex = updatePlugin.getUpdateIndex();
|
|
46
48
|
const totalUpdates = updatePlugin.getTotalUpdates();
|
|
@@ -98,8 +100,7 @@ function defaultOptions(context, temp, target) {
|
|
|
98
100
|
force: false
|
|
99
101
|
}
|
|
100
102
|
},
|
|
101
|
-
inlineConst: true
|
|
102
|
-
lazyBarrel: true
|
|
103
|
+
inlineConst: true
|
|
103
104
|
}
|
|
104
105
|
};
|
|
105
106
|
options.plugins ??= [];
|
|
@@ -162,8 +163,7 @@ function createRunner(context, name, file, env) {
|
|
|
162
163
|
const dist = context.getDist();
|
|
163
164
|
const updatePlugin = context.getValue(name, "hotUpdateContext");
|
|
164
165
|
const getWebRunner = () => {
|
|
165
|
-
return new runner_1.
|
|
166
|
-
dom: context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM,
|
|
166
|
+
return new runner_1.NodeRunner({
|
|
167
167
|
env,
|
|
168
168
|
stats: (0, runner_2.cachedStats)(context, name),
|
|
169
169
|
cachable: false,
|
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"));
|
|
@@ -26,7 +27,7 @@ async function config(context, name, configFiles, defaultOptions = {}) {
|
|
|
26
27
|
const compiler = getCompiler(context, name);
|
|
27
28
|
compiler.setOptions(defaultOptions);
|
|
28
29
|
if (Array.isArray(configFiles)) {
|
|
29
|
-
const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)))[0];
|
|
30
|
+
const fileOptions = (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, defaultOptions)[0];
|
|
30
31
|
compiler.mergeOptions(fileOptions);
|
|
31
32
|
}
|
|
32
33
|
return compiler.getOptions();
|
|
@@ -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,9 +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
|
-
testConfig.afterExecute(compiler.getOptions());
|
|
85
|
-
}
|
|
86
81
|
}
|
|
87
82
|
async function check(env, context, name) {
|
|
88
83
|
const testConfig = context.getTestConfig();
|
|
@@ -171,16 +166,28 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
|
|
|
171
166
|
if (testConfig.snapshotContent) {
|
|
172
167
|
content = testConfig.snapshotContent(content);
|
|
173
168
|
}
|
|
174
|
-
|
|
169
|
+
const filePath = file.replaceAll(path_1.default.sep, "/");
|
|
170
|
+
return `\`\`\`${tag} title=${filePath}\n${content}\n\`\`\``;
|
|
175
171
|
});
|
|
176
172
|
fileContents.sort();
|
|
177
173
|
const content = fileContents.join("\n\n");
|
|
178
174
|
const snapshotPath = path_1.default.isAbsolute(snapshot)
|
|
179
175
|
? snapshot
|
|
180
|
-
: path_1.default.resolve(context.getSource(),
|
|
176
|
+
: path_1.default.resolve(context.getSource(), path_1.default.join("__snapshots__", `${snapshot}${total > 1 ? `-${i}` : ""}`));
|
|
181
177
|
env.expect(content).toMatchFileSnapshot(snapshotPath);
|
|
182
178
|
}
|
|
183
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
|
+
}
|
|
184
191
|
function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
185
192
|
if (typeof multiFindBundle !== "function") {
|
|
186
193
|
return [];
|
|
@@ -211,7 +218,7 @@ function findMultiCompilerBundle(context, name, multiFindBundle) {
|
|
|
211
218
|
function configMultiCompiler(context, name, configFiles, defaultOptions, overrideOptions) {
|
|
212
219
|
const multiCompilerOptions = [];
|
|
213
220
|
const caseOptions = Array.isArray(configFiles)
|
|
214
|
-
? (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), configs => {
|
|
221
|
+
? (0, helper_1.readConfigFile)(configFiles.map(i => context.getSource(i)), context, {}, configs => {
|
|
215
222
|
return configs.flatMap(c => {
|
|
216
223
|
if (typeof c === "function") {
|
|
217
224
|
const options = {
|
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
|
}
|
|
@@ -77,8 +80,7 @@ function defaultOptions(index, context) {
|
|
|
77
80
|
force: false
|
|
78
81
|
}
|
|
79
82
|
},
|
|
80
|
-
inlineConst: true
|
|
81
|
-
lazyBarrel: true
|
|
83
|
+
inlineConst: true
|
|
82
84
|
}
|
|
83
85
|
};
|
|
84
86
|
}
|
|
@@ -116,7 +118,7 @@ function findBundle(index, context, options) {
|
|
|
116
118
|
options.output?.cssFilename) ||
|
|
117
119
|
`bundle${index}.css`);
|
|
118
120
|
if (fs_extra_1.default.existsSync(cssOutputPath)) {
|
|
119
|
-
bundlePath.push(
|
|
121
|
+
bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
bundlePath.push(`./bundle${index}${ext}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
|
|
2
|
-
export
|
|
2
|
+
export type TDiagnosticOptions = {
|
|
3
3
|
snapshot: string;
|
|
4
4
|
snapshotErrors: string;
|
|
5
5
|
snapshotWarning: string;
|
|
6
6
|
format?: (output: string) => string;
|
|
7
|
-
}
|
|
7
|
+
};
|
package/dist/case/diagnostic.js
CHANGED
|
@@ -19,7 +19,7 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
19
19
|
config: async (context) => {
|
|
20
20
|
const compiler = (0, common_1.getCompiler)(context, name);
|
|
21
21
|
let options = defaultOptions(context);
|
|
22
|
-
const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)))[0];
|
|
22
|
+
const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)), context, options)[0];
|
|
23
23
|
if (custom) {
|
|
24
24
|
options = (0, webpack_merge_1.default)(options, custom);
|
|
25
25
|
}
|
|
@@ -84,8 +84,7 @@ function defaultOptions(context) {
|
|
|
84
84
|
force: false
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
inlineConst: true
|
|
88
|
-
lazyBarrel: true
|
|
87
|
+
inlineConst: true
|
|
89
88
|
}
|
|
90
89
|
};
|
|
91
90
|
}
|
package/dist/case/error.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare class RspackStatsDiagnostics {
|
|
|
8
8
|
}
|
|
9
9
|
export type TErrorCaseConfig = {
|
|
10
10
|
description: string;
|
|
11
|
+
skip?: boolean;
|
|
11
12
|
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
|
|
12
13
|
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
|
|
13
14
|
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
|
package/dist/case/error.js
CHANGED
|
@@ -49,15 +49,29 @@ function createErrorCase(name, src, dist, testConfig) {
|
|
|
49
49
|
if (!addedSerializer) {
|
|
50
50
|
addedSerializer = true;
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
caseConfig
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const caseConfigList = require(testConfig);
|
|
53
|
+
function createCase(caseConfig) {
|
|
54
|
+
if (caseConfig.skip) {
|
|
55
|
+
it.skip(name, () => { });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
creator.create(name, src, dist, undefined, {
|
|
59
|
+
caseConfig,
|
|
60
|
+
description: () => caseConfig.description
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(caseConfigList)) {
|
|
64
|
+
for (const caseConfig of caseConfigList) {
|
|
65
|
+
createCase(caseConfig);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
createCase(caseConfigList);
|
|
70
|
+
}
|
|
57
71
|
}
|
|
58
72
|
function options(context, custom) {
|
|
59
73
|
let options = {
|
|
60
|
-
context: node_path_1.default.resolve(
|
|
74
|
+
context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__, "errors"),
|
|
61
75
|
mode: "none",
|
|
62
76
|
devtool: false,
|
|
63
77
|
optimization: {
|
|
@@ -116,6 +130,11 @@ class RspackStatsDiagnostics {
|
|
|
116
130
|
}
|
|
117
131
|
}
|
|
118
132
|
async function check(env, context, name, check) {
|
|
133
|
+
if (context.getError(name).length > 0) {
|
|
134
|
+
await check?.(new RspackStatsDiagnostics(context.getError(name), []));
|
|
135
|
+
context.clearError(name);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
119
138
|
const compiler = (0, common_1.getCompiler)(context, name);
|
|
120
139
|
const stats = compiler.getStats();
|
|
121
140
|
env.expect(typeof stats).toBe("object");
|
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
|
],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createExampleCase(name: string, src: string): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createExampleCase = createExampleCase;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const creator_1 = require("../test/creator");
|
|
9
|
+
const common_1 = require("./common");
|
|
10
|
+
function overrideOptions(index, context, options) {
|
|
11
|
+
options.context = context.getSource();
|
|
12
|
+
options.output = options.output || {};
|
|
13
|
+
options.output.pathinfo = true;
|
|
14
|
+
options.output.path = context.getDist();
|
|
15
|
+
options.output.publicPath = "dist/";
|
|
16
|
+
if (!options.entry)
|
|
17
|
+
options.entry = "./example.js";
|
|
18
|
+
if (!options.plugins)
|
|
19
|
+
options.plugins = [];
|
|
20
|
+
}
|
|
21
|
+
function createExampleProcessor(name) {
|
|
22
|
+
return {
|
|
23
|
+
config: async (context) => {
|
|
24
|
+
(0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], () => ({}), overrideOptions);
|
|
25
|
+
},
|
|
26
|
+
compiler: async (context) => {
|
|
27
|
+
await (0, common_1.compiler)(context, name);
|
|
28
|
+
},
|
|
29
|
+
build: async (context) => {
|
|
30
|
+
await (0, common_1.build)(context, name);
|
|
31
|
+
},
|
|
32
|
+
run: async (env, context) => {
|
|
33
|
+
// no need to run, just check the building
|
|
34
|
+
},
|
|
35
|
+
check: async (env, context) => {
|
|
36
|
+
const compiler = (0, common_1.getCompiler)(context, name);
|
|
37
|
+
const stats = compiler.getStats();
|
|
38
|
+
if (stats?.hasErrors()) {
|
|
39
|
+
console.log(stats.toString({
|
|
40
|
+
all: false,
|
|
41
|
+
errors: true,
|
|
42
|
+
errorDetails: true,
|
|
43
|
+
errorStacks: true
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
expect(stats?.hasErrors()).toBe(false);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
51
|
+
clean: true,
|
|
52
|
+
steps: ({ name }) => [createExampleProcessor(name)],
|
|
53
|
+
concurrent: true
|
|
54
|
+
});
|
|
55
|
+
function createExampleCase(name, src) {
|
|
56
|
+
creator.create(name, src, node_path_1.default.join(src, "dist"));
|
|
57
|
+
}
|
package/dist/case/hash.js
CHANGED
package/dist/case/hook.js
CHANGED
|
@@ -14,8 +14,8 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
|
14
14
|
const context_1 = require("../test/context");
|
|
15
15
|
const creator_1 = require("../test/creator");
|
|
16
16
|
const common_1 = require("./common");
|
|
17
|
-
const srcDir =
|
|
18
|
-
const distDir = node_path_1.default.resolve(
|
|
17
|
+
const srcDir = __TEST_FIXTURES_PATH__;
|
|
18
|
+
const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__, "hook");
|
|
19
19
|
const creator = new creator_1.BasicCaseCreator({
|
|
20
20
|
clean: true,
|
|
21
21
|
describe: true,
|
|
@@ -213,8 +213,7 @@ function defaultOptions(context, custom) {
|
|
|
213
213
|
force: false
|
|
214
214
|
}
|
|
215
215
|
},
|
|
216
|
-
inlineConst: true
|
|
217
|
-
lazyBarrel: true
|
|
216
|
+
inlineConst: true
|
|
218
217
|
}
|
|
219
218
|
};
|
|
220
219
|
if (custom) {
|
package/dist/case/hot-step.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ECompilerType, type TCompilerOptions } from "../type";
|
|
2
|
-
export declare function createHotStepCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
2
|
+
export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
package/dist/case/hot-step.js
CHANGED
|
@@ -24,9 +24,6 @@ const SELF_HANDLER = (file, options) => {
|
|
|
24
24
|
global.self[hotUpdateGlobalKey] = hotUpdateGlobal;
|
|
25
25
|
require(file);
|
|
26
26
|
delete global.self[hotUpdateGlobalKey];
|
|
27
|
-
if (!Object.keys(global.self).length) {
|
|
28
|
-
delete global.self;
|
|
29
|
-
}
|
|
30
27
|
return res;
|
|
31
28
|
};
|
|
32
29
|
const NODE_HANDLER = (file) => {
|
|
@@ -39,8 +36,8 @@ const GET_MODULE_HANDLER = {
|
|
|
39
36
|
node: NODE_HANDLER
|
|
40
37
|
};
|
|
41
38
|
const creators = new Map();
|
|
42
|
-
function createHotStepProcessor(name, target) {
|
|
43
|
-
const processor = (0, hot_1.createHotProcessor)(name, target);
|
|
39
|
+
function createHotStepProcessor(name, src, temp, target) {
|
|
40
|
+
const processor = (0, hot_1.createHotProcessor)(name, src, temp, target);
|
|
44
41
|
const entries = {};
|
|
45
42
|
const hashes = [];
|
|
46
43
|
function matchStepSnapshot(env, context, step, options, stats, runtime) {
|
|
@@ -53,7 +50,9 @@ function createHotStepProcessor(name, target) {
|
|
|
53
50
|
const hotUpdateManifest = [];
|
|
54
51
|
const changedFiles = step === 0
|
|
55
52
|
? []
|
|
56
|
-
: processor.
|
|
53
|
+
: processor.updatePlugin
|
|
54
|
+
.getModifiedFiles()
|
|
55
|
+
.map((i) => (0, helper_1.escapeSep)(node_path_1.default.relative(temp, i)));
|
|
57
56
|
changedFiles.sort();
|
|
58
57
|
const resultHashes = {
|
|
59
58
|
[lastHash || "LAST_HASH"]: "LAST_HASH",
|
|
@@ -245,7 +244,7 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
245
244
|
}
|
|
246
245
|
const originRun = processor.run;
|
|
247
246
|
processor.run = async function (env, context) {
|
|
248
|
-
context.setValue(name, "hotUpdateStepChecker", (
|
|
247
|
+
context.setValue(name, "hotUpdateStepChecker", (updateIndex, stats, runtime) => {
|
|
249
248
|
const statsJson = stats.toJson({
|
|
250
249
|
assets: true,
|
|
251
250
|
chunks: true
|
|
@@ -264,10 +263,10 @@ ${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
|
264
263
|
}
|
|
265
264
|
const compiler = context.getCompiler(name, type_1.ECompilerType.Rspack);
|
|
266
265
|
const compilerOptions = compiler.getOptions();
|
|
267
|
-
matchStepSnapshot(env, context,
|
|
266
|
+
matchStepSnapshot(env, context, updateIndex, compilerOptions, statsJson, runtime);
|
|
268
267
|
hashes.push(stats.hash);
|
|
269
268
|
});
|
|
270
|
-
context.setValue(name, "hotUpdateStepErrorChecker", (
|
|
269
|
+
context.setValue(name, "hotUpdateStepErrorChecker", (updateIndex, stats, runtime) => {
|
|
271
270
|
hashes.push(stats.hash);
|
|
272
271
|
});
|
|
273
272
|
await originRun(env, context);
|
|
@@ -312,8 +311,8 @@ function getCreator(target) {
|
|
|
312
311
|
clean: true,
|
|
313
312
|
describe: false,
|
|
314
313
|
target,
|
|
315
|
-
steps: ({ name, target }) => [
|
|
316
|
-
createHotStepProcessor(name, target)
|
|
314
|
+
steps: ({ name, target, src, temp, dist }) => [
|
|
315
|
+
createHotStepProcessor(name, src, temp || node_path_1.default.resolve(dist, "temp"), target)
|
|
317
316
|
],
|
|
318
317
|
runner: {
|
|
319
318
|
key: (context, name, file) => name,
|
|
@@ -324,7 +323,7 @@ function getCreator(target) {
|
|
|
324
323
|
}
|
|
325
324
|
return creators.get(target);
|
|
326
325
|
}
|
|
327
|
-
function createHotStepCase(name, src, dist, target) {
|
|
326
|
+
function createHotStepCase(name, src, dist, temp, target) {
|
|
328
327
|
const creator = getCreator(target);
|
|
329
|
-
creator.create(name, src, dist);
|
|
328
|
+
creator.create(name, src, dist, temp);
|
|
330
329
|
}
|
package/dist/case/hot.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HotUpdatePlugin } from "../helper/hot-update/plugin";
|
|
2
|
+
import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, ITestRunner, TCompilerOptions } from "../type";
|
|
2
3
|
type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
|
|
3
|
-
export declare function createHotProcessor(name: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
4
|
-
export declare function createHotCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
4
|
+
export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
|
|
5
|
+
export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
5
6
|
type THotProcessor = ITestProcessor & {
|
|
6
|
-
|
|
7
|
+
updatePlugin: HotUpdatePlugin;
|
|
7
8
|
};
|
|
8
9
|
export declare function createHotRunner<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
|
9
10
|
export {};
|