@rspack-debug/test-tools 1.4.9 → 1.6.2
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/README.md +1 -1
- package/dist/case/builtin.d.ts +3 -0
- package/dist/case/builtin.js +152 -14
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +214 -12
- package/dist/case/common.d.ts +11 -0
- package/dist/case/common.js +249 -0
- package/dist/case/compiler.d.ts +17 -4
- package/dist/case/compiler.js +149 -12
- package/dist/case/config.d.ts +7 -2
- package/dist/case/config.js +106 -18
- package/dist/case/defaults.d.ts +13 -4
- package/dist/case/defaults.js +73 -18
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +121 -14
- package/dist/case/error.d.ts +15 -4
- package/dist/case/error.js +137 -12
- package/dist/case/esm-output.d.ts +1 -0
- package/dist/case/esm-output.js +117 -0
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +72 -9
- package/dist/case/hook.d.ts +36 -4
- package/dist/case/hook.js +209 -20
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +309 -13
- package/dist/case/hot.d.ts +11 -2
- package/dist/case/hot.js +217 -12
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +24 -45
- package/dist/case/index.d.ts +31 -20
- package/dist/case/index.js +50 -34
- package/dist/case/multi-compiler.d.ts +19 -0
- package/dist/case/multi-compiler.js +97 -0
- package/dist/case/{nativeWatcher.js → native-watcher.js} +12 -25
- package/dist/case/normal.d.ts +3 -0
- package/dist/case/normal.js +202 -18
- package/dist/case/runner.d.ts +19 -0
- package/dist/case/runner.js +113 -0
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +10 -14
- package/dist/case/stats-api.d.ts +8 -3
- package/dist/case/stats-api.js +69 -10
- package/dist/case/stats-output.d.ts +11 -0
- package/dist/case/stats-output.js +199 -8
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +318 -22
- package/dist/compiler.d.ts +16 -16
- package/dist/compiler.js +120 -15
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +2 -2
- 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 +1 -2
- package/dist/helper/expect/to-match-file-snapshot.js +3 -3
- 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 +15 -14
- package/dist/helper/index.d.ts +2 -1
- package/dist/helper/index.js +2 -1
- package/dist/helper/is.d.ts +2 -0
- package/dist/helper/is.js +15 -0
- 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/checkArrayExpectation.d.ts +1 -1
- package/dist/helper/legacy/checkArrayExpectation.js +8 -8
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
- package/dist/helper/legacy/createLazyTestEnv.js +3 -3
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/expectSource.d.ts +10 -0
- package/dist/helper/legacy/expectSource.js +23 -0
- package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
- package/dist/helper/legacy/findOutputFiles.js +14 -0
- package/dist/helper/legacy/regexEscape.d.ts +2 -0
- package/dist/helper/legacy/regexEscape.js +5 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/helper/read-config-file.js +12 -2
- package/dist/helper/setup-env.js +15 -2
- package/dist/helper/setup-expect.js +2 -2
- package/dist/helper/setup-wasm.js +2 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- 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 -4
- package/dist/index.js +0 -4
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
- package/dist/runner/index.d.ts +2 -9
- package/dist/runner/index.js +2 -9
- package/dist/runner/node/index.d.ts +41 -0
- package/dist/runner/node/index.js +450 -0
- package/dist/runner/web/index.d.ts +30 -0
- package/dist/runner/web/index.js +343 -0
- package/dist/test/context.d.ts +15 -18
- package/dist/test/context.js +52 -57
- package/dist/test/creator.d.ts +20 -19
- package/dist/test/creator.js +69 -57
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +44 -6
- package/dist/type.d.ts +94 -64
- package/dist/type.js +8 -12
- package/package.json +23 -62
- package/rstest.d.ts +24 -0
- package/dist/case/diff.d.ts +0 -3
- package/dist/case/diff.js +0 -126
- package/dist/compare/comparator.d.ts +0 -17
- package/dist/compare/comparator.js +0 -52
- package/dist/compare/compare.d.ts +0 -17
- package/dist/compare/compare.js +0 -175
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -239
- package/dist/compare/index.d.ts +0 -5
- package/dist/compare/index.js +0 -21
- package/dist/compare/replace-module-argument.d.ts +0 -1
- package/dist/compare/replace-module-argument.js +0 -8
- package/dist/compare/replace-runtime-module-name.d.ts +0 -1
- package/dist/compare/replace-runtime-module-name.js +0 -71
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -278
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
- package/dist/helper/legacy/supportsImportFn.js +0 -15
- 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/plugin/rspack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/rspack-diff-config-plugin.js +0 -42
- package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/webpack-diff-config-plugin.js +0 -41
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
- package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
- package/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -146
- package/dist/processor/builtin.d.ts +0 -9
- package/dist/processor/builtin.js +0 -171
- package/dist/processor/cache.d.ts +0 -20
- package/dist/processor/cache.js +0 -127
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -81
- package/dist/processor/defaults.d.ts +0 -30
- package/dist/processor/defaults.js +0 -72
- package/dist/processor/diagnostic.d.ts +0 -15
- package/dist/processor/diagnostic.js +0 -102
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/error.d.ts +0 -23
- package/dist/processor/error.js +0 -95
- package/dist/processor/hash.d.ts +0 -10
- package/dist/processor/hash.js +0 -63
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -204
- package/dist/processor/hot-incremental.d.ts +0 -14
- package/dist/processor/hot-incremental.js +0 -43
- package/dist/processor/hot-step.d.ts +0 -18
- package/dist/processor/hot-step.js +0 -304
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -140
- package/dist/processor/index.d.ts +0 -20
- package/dist/processor/index.js +0 -36
- package/dist/processor/multi.d.ts +0 -17
- package/dist/processor/multi.js +0 -73
- package/dist/processor/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -150
- package/dist/processor/simple.d.ts +0 -23
- package/dist/processor/simple.js +0 -49
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -66
- package/dist/processor/stats-api.d.ts +0 -18
- package/dist/processor/stats-api.js +0 -48
- package/dist/processor/stats.d.ts +0 -18
- package/dist/processor/stats.js +0 -206
- package/dist/processor/treeshaking.d.ts +0 -10
- package/dist/processor/treeshaking.js +0 -33
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -245
- 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/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -63
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -90
- package/dist/runner/hot-step.d.ts +0 -5
- package/dist/runner/hot-step.js +0 -87
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -83
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -38
- package/dist/runner/normal.d.ts +0 -5
- package/dist/runner/normal.js +0 -20
- package/dist/runner/runner/basic.d.ts +0 -30
- package/dist/runner/runner/basic.js +0 -107
- package/dist/runner/runner/cjs.d.ts +0 -14
- package/dist/runner/runner/cjs.js +0 -151
- package/dist/runner/runner/esm.d.ts +0 -7
- package/dist/runner/runner/esm.js +0 -125
- package/dist/runner/runner/index.d.ts +0 -8
- package/dist/runner/runner/index.js +0 -24
- package/dist/runner/runner/normal.d.ts +0 -9
- package/dist/runner/runner/normal.js +0 -23
- package/dist/runner/runner/watch.d.ts +0 -16
- package/dist/runner/runner/watch.js +0 -27
- package/dist/runner/runner/web/fake.d.ts +0 -18
- package/dist/runner/runner/web/fake.js +0 -143
- package/dist/runner/runner/web/jsdom.d.ts +0 -26
- package/dist/runner/runner/web/jsdom.js +0 -219
- package/dist/runner/runner/web.d.ts +0 -15
- package/dist/runner/runner/web.js +0 -32
- package/dist/runner/type.d.ts +0 -42
- package/dist/runner/type.js +0 -9
- package/dist/runner/watch.d.ts +0 -7
- package/dist/runner/watch.js +0 -60
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
- package/jest.d.ts +0 -25
- package/template/diff.bundle.css +0 -1
- package/template/diff.bundle.js +0 -144
- package/template/diff.html +0 -14
- package/template/editor.worker.js +0 -1
- /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
- /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
package/dist/case/normal.js
CHANGED
|
@@ -4,26 +4,210 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createNormalCase = createNormalCase;
|
|
7
|
+
exports.createHotNormalCase = createHotNormalCase;
|
|
8
|
+
exports.createDevNormalCase = createDevNormalCase;
|
|
9
|
+
exports.createProdNormalCase = createProdNormalCase;
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const
|
|
9
|
-
const runner_1 = require("../runner");
|
|
12
|
+
const core_1 = require("@rspack/core");
|
|
10
13
|
const creator_1 = require("../test/creator");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
const common_1 = require("./common");
|
|
15
|
+
const runner_1 = require("./runner");
|
|
16
|
+
const NORMAL_CASES_ROOT = node_path_1.default.resolve(__TEST_PATH__, "normalCases");
|
|
17
|
+
const createCaseOptions = (hot, mode) => {
|
|
18
|
+
return {
|
|
19
|
+
clean: true,
|
|
20
|
+
describe: false,
|
|
21
|
+
steps: ({ name }) => [
|
|
22
|
+
{
|
|
23
|
+
config: async (context) => {
|
|
24
|
+
const compiler = context.getCompiler();
|
|
25
|
+
let options = defaultOptions(context, {
|
|
26
|
+
plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
|
|
27
|
+
}, mode);
|
|
28
|
+
options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
|
|
29
|
+
overrideOptions(context, options);
|
|
30
|
+
compiler.setOptions(options);
|
|
31
|
+
},
|
|
32
|
+
compiler: async (context) => {
|
|
33
|
+
await (0, common_1.compiler)(context, name);
|
|
34
|
+
},
|
|
35
|
+
build: async (context) => {
|
|
36
|
+
await (0, common_1.build)(context, name);
|
|
37
|
+
},
|
|
38
|
+
run: async (env, context) => {
|
|
39
|
+
await (0, common_1.run)(env, context, name, findBundle);
|
|
40
|
+
},
|
|
41
|
+
check: async (env, context) => {
|
|
42
|
+
await (0, common_1.check)(env, context, name);
|
|
43
|
+
},
|
|
44
|
+
after: async (context) => {
|
|
45
|
+
await (0, common_1.afterExecute)(context, name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
runner: {
|
|
50
|
+
key: (context, name, file) => name,
|
|
51
|
+
runner: runner_1.createRunner
|
|
52
|
+
},
|
|
53
|
+
concurrent: true
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const creator = new creator_1.BasicCaseCreator(createCaseOptions(false));
|
|
27
57
|
function createNormalCase(name, src, dist) {
|
|
28
58
|
creator.create(name, src, dist);
|
|
29
59
|
}
|
|
60
|
+
const hotCreator = new creator_1.BasicCaseCreator(createCaseOptions(true));
|
|
61
|
+
function createHotNormalCase(name, src, dist) {
|
|
62
|
+
hotCreator.create(name, src, dist);
|
|
63
|
+
}
|
|
64
|
+
const devCreator = new creator_1.BasicCaseCreator(createCaseOptions(false, "development"));
|
|
65
|
+
function createDevNormalCase(name, src, dist) {
|
|
66
|
+
devCreator.create(name, src, dist);
|
|
67
|
+
}
|
|
68
|
+
const prodCreator = new creator_1.BasicCaseCreator(createCaseOptions(false, "production"));
|
|
69
|
+
function createProdNormalCase(name, src, dist) {
|
|
70
|
+
prodCreator.create(name, src, dist);
|
|
71
|
+
}
|
|
72
|
+
function findBundle(context, options) {
|
|
73
|
+
const testConfig = context.getTestConfig();
|
|
74
|
+
if (typeof testConfig.findBundle === "function") {
|
|
75
|
+
return testConfig.findBundle(0, options);
|
|
76
|
+
}
|
|
77
|
+
const filename = options.output?.filename;
|
|
78
|
+
return typeof filename === "string" ? filename : undefined;
|
|
79
|
+
}
|
|
80
|
+
function defaultOptions(context, compilerOptions, mode) {
|
|
81
|
+
let testConfig = {};
|
|
82
|
+
const testConfigPath = node_path_1.default.join(context.getSource(), "test.config.js");
|
|
83
|
+
if (node_fs_1.default.existsSync(testConfigPath)) {
|
|
84
|
+
testConfig = require(testConfigPath);
|
|
85
|
+
}
|
|
86
|
+
const TerserPlugin = require("terser-webpack-plugin");
|
|
87
|
+
const terserForTesting = new TerserPlugin({
|
|
88
|
+
parallel: false
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
amd: {},
|
|
92
|
+
context: NORMAL_CASES_ROOT,
|
|
93
|
+
entry: `./${node_path_1.default.relative(NORMAL_CASES_ROOT, context.getSource())}/`,
|
|
94
|
+
target: compilerOptions?.target || "async-node",
|
|
95
|
+
devtool: mode === "development" ? false : compilerOptions?.devtool,
|
|
96
|
+
mode: compilerOptions?.mode || mode || "none",
|
|
97
|
+
optimization: compilerOptions?.mode
|
|
98
|
+
? {
|
|
99
|
+
emitOnErrors: true,
|
|
100
|
+
minimizer: [terserForTesting],
|
|
101
|
+
minimize: false,
|
|
102
|
+
...testConfig.optimization
|
|
103
|
+
}
|
|
104
|
+
: {
|
|
105
|
+
removeAvailableModules: true,
|
|
106
|
+
removeEmptyChunks: true,
|
|
107
|
+
mergeDuplicateChunks: true,
|
|
108
|
+
// CHANGE: rspack does not support `flagIncludedChunks` yet.
|
|
109
|
+
// flagIncludedChunks: true,
|
|
110
|
+
sideEffects: true,
|
|
111
|
+
providedExports: true,
|
|
112
|
+
usedExports: true,
|
|
113
|
+
mangleExports: true,
|
|
114
|
+
// CHANGE: rspack does not support `emitOnErrors` yet.
|
|
115
|
+
emitOnErrors: true,
|
|
116
|
+
concatenateModules: !!testConfig?.optimization?.concatenateModules,
|
|
117
|
+
innerGraph: true,
|
|
118
|
+
// CHANGE: size is not supported yet
|
|
119
|
+
// moduleIds: "size",
|
|
120
|
+
// chunkIds: "size",
|
|
121
|
+
moduleIds: "named",
|
|
122
|
+
chunkIds: "named",
|
|
123
|
+
minimize: false,
|
|
124
|
+
minimizer: [terserForTesting],
|
|
125
|
+
...compilerOptions?.optimization
|
|
126
|
+
},
|
|
127
|
+
// CHANGE: rspack does not support `performance` yet.
|
|
128
|
+
// performance: {
|
|
129
|
+
// hints: false
|
|
130
|
+
// },
|
|
131
|
+
node: {
|
|
132
|
+
__dirname: "mock",
|
|
133
|
+
__filename: "mock"
|
|
134
|
+
},
|
|
135
|
+
cache: compilerOptions?.cache && {
|
|
136
|
+
// cacheDirectory,
|
|
137
|
+
...compilerOptions.cache
|
|
138
|
+
},
|
|
139
|
+
output: {
|
|
140
|
+
pathinfo: "verbose",
|
|
141
|
+
path: context.getDist(),
|
|
142
|
+
filename: compilerOptions?.module ? "bundle.mjs" : "bundle.js"
|
|
143
|
+
},
|
|
144
|
+
resolve: {
|
|
145
|
+
modules: ["web_modules", "node_modules"],
|
|
146
|
+
mainFields: ["webpack", "browser", "web", "browserify", "main"],
|
|
147
|
+
aliasFields: ["browser"],
|
|
148
|
+
extensions: [".webpack.js", ".web.js", ".js", ".json"]
|
|
149
|
+
},
|
|
150
|
+
resolveLoader: {
|
|
151
|
+
modules: ["web_loaders", "web_modules", "node_loaders", "node_modules"],
|
|
152
|
+
mainFields: ["webpackLoader", "webLoader", "loader", "main"],
|
|
153
|
+
extensions: [".webpack-loader.js", ".web-loader.js", ".loader.js", ".js"]
|
|
154
|
+
},
|
|
155
|
+
module: {
|
|
156
|
+
rules: [
|
|
157
|
+
{
|
|
158
|
+
test: /\.coffee$/,
|
|
159
|
+
loader: "coffee-loader"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
test: /\.pug/,
|
|
163
|
+
loader: "@webdiscus/pug-loader"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
test: /\.wat$/i,
|
|
167
|
+
loader: "wast-loader",
|
|
168
|
+
type: "webassembly/async"
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
plugins: (compilerOptions?.plugins || [])
|
|
173
|
+
.concat(testConfig.plugins || [])
|
|
174
|
+
.concat(function () {
|
|
175
|
+
this.hooks.compilation.tap("TestCasesTest", compilation => {
|
|
176
|
+
const hooks = [
|
|
177
|
+
// CHANGE: the following hooks are not supported yet, so comment it out
|
|
178
|
+
// "optimize",
|
|
179
|
+
// "optimizeModules",
|
|
180
|
+
// "optimizeChunks",
|
|
181
|
+
// "afterOptimizeTree",
|
|
182
|
+
// "afterOptimizeAssets"
|
|
183
|
+
];
|
|
184
|
+
for (const hook of hooks) {
|
|
185
|
+
compilation.hooks[hook].tap("TestCasesTest", () => compilation.checkConstraints());
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}),
|
|
189
|
+
experiments: {
|
|
190
|
+
css: false,
|
|
191
|
+
rspackFuture: {
|
|
192
|
+
bundlerInfo: {
|
|
193
|
+
force: false
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
asyncWebAssembly: true,
|
|
197
|
+
topLevelAwait: true,
|
|
198
|
+
inlineConst: true,
|
|
199
|
+
// CHANGE: rspack does not support `backCompat` yet.
|
|
200
|
+
// backCompat: false,
|
|
201
|
+
// CHANGE: Rspack enables `css` by default.
|
|
202
|
+
// Turning off here to fallback to webpack's default css processing logic.
|
|
203
|
+
...(compilerOptions?.module ? { outputModule: true } : {})
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function overrideOptions(context, options) {
|
|
208
|
+
if (!global.printLogger) {
|
|
209
|
+
options.infrastructureLogging = {
|
|
210
|
+
level: "error"
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StatsCompilation } from "@rspack/core";
|
|
2
|
+
import type { ITestContext, ITestEnv, ITestRunner } from "../type";
|
|
3
|
+
export type THotStepRuntimeLangData = {
|
|
4
|
+
outdatedModules: string[];
|
|
5
|
+
outdatedDependencies: Record<string, string[]>;
|
|
6
|
+
updatedModules: string[];
|
|
7
|
+
updatedRuntime: string[];
|
|
8
|
+
acceptedModules: string[];
|
|
9
|
+
disposedModules: string[];
|
|
10
|
+
};
|
|
11
|
+
export type THotStepRuntimeData = {
|
|
12
|
+
javascript: THotStepRuntimeLangData;
|
|
13
|
+
css: THotStepRuntimeLangData;
|
|
14
|
+
statusPath: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function cachedStats(context: ITestContext, name: string): () => StatsCompilation;
|
|
17
|
+
export declare function createRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
|
18
|
+
export declare function getMultiCompilerRunnerKey(context: ITestContext, name: string, file: string): string;
|
|
19
|
+
export declare function createMultiCompilerRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cachedStats = cachedStats;
|
|
4
|
+
exports.createRunner = createRunner;
|
|
5
|
+
exports.getMultiCompilerRunnerKey = getMultiCompilerRunnerKey;
|
|
6
|
+
exports.createMultiCompilerRunner = createMultiCompilerRunner;
|
|
7
|
+
const runner_1 = require("../runner");
|
|
8
|
+
const debug_1 = require("../test/debug");
|
|
9
|
+
function cachedStats(context, name) {
|
|
10
|
+
const compiler = context.getCompiler();
|
|
11
|
+
const statsGetter = (() => {
|
|
12
|
+
let cached = null;
|
|
13
|
+
return () => {
|
|
14
|
+
if (cached) {
|
|
15
|
+
return cached;
|
|
16
|
+
}
|
|
17
|
+
cached = compiler.getStats().toJson({
|
|
18
|
+
errorDetails: true
|
|
19
|
+
});
|
|
20
|
+
return cached;
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
return statsGetter;
|
|
24
|
+
}
|
|
25
|
+
function createRunner(context, name, file, env) {
|
|
26
|
+
const compiler = context.getCompiler();
|
|
27
|
+
const testConfig = context.getTestConfig();
|
|
28
|
+
const compilerOptions = compiler.getOptions();
|
|
29
|
+
const runnerOptions = {
|
|
30
|
+
runInNewContext: false,
|
|
31
|
+
cachable: true,
|
|
32
|
+
env,
|
|
33
|
+
stats: cachedStats(context, name),
|
|
34
|
+
name,
|
|
35
|
+
testConfig: context.getTestConfig(),
|
|
36
|
+
source: context.getSource(),
|
|
37
|
+
dist: context.getDist(),
|
|
38
|
+
compilerOptions
|
|
39
|
+
};
|
|
40
|
+
if (compilerOptions.target === "web" ||
|
|
41
|
+
compilerOptions.target === "webworker") {
|
|
42
|
+
return new runner_1.WebRunner({
|
|
43
|
+
...runnerOptions,
|
|
44
|
+
runInNewContext: true,
|
|
45
|
+
location: testConfig.location || "https://test.cases/path/index.html"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return new runner_1.NodeRunner(runnerOptions);
|
|
49
|
+
}
|
|
50
|
+
function getFileIndexHandler(context, name, file) {
|
|
51
|
+
const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
|
|
52
|
+
const runned = context.getValue("runned") || new Set();
|
|
53
|
+
if (typeof multiFileIndexMap[file] === "undefined") {
|
|
54
|
+
throw new Error("Unexpect file in multiple runner");
|
|
55
|
+
}
|
|
56
|
+
const indexList = multiFileIndexMap[file];
|
|
57
|
+
const seq = indexList.findIndex((index, n) => !runned.has(`${name}:${file}[${n}]`));
|
|
58
|
+
if (seq === -1) {
|
|
59
|
+
throw new Error(`File ${file} should run only ${indexList.length} times`);
|
|
60
|
+
}
|
|
61
|
+
const getIndex = () => [indexList[seq], seq];
|
|
62
|
+
const flagIndex = () => runned.add(`${name}:${file}[${seq}]`);
|
|
63
|
+
context.setValue("runned", runned);
|
|
64
|
+
return { getIndex, flagIndex };
|
|
65
|
+
}
|
|
66
|
+
function getMultiCompilerRunnerKey(context, name, file) {
|
|
67
|
+
const { getIndex } = getFileIndexHandler(context, name, file);
|
|
68
|
+
const [index, seq] = getIndex();
|
|
69
|
+
return `${name}-${index}[${seq}]`;
|
|
70
|
+
}
|
|
71
|
+
function createMultiCompilerRunner(context, name, file, env) {
|
|
72
|
+
const testConfig = context.getTestConfig();
|
|
73
|
+
const { getIndex, flagIndex } = getFileIndexHandler(context, name, file);
|
|
74
|
+
const multiCompilerOptions = context.getValue("multiCompilerOptions") || [];
|
|
75
|
+
const [index] = getIndex();
|
|
76
|
+
const compilerOptions = multiCompilerOptions[index];
|
|
77
|
+
const logs = context.getValue(debug_1.DEBUG_SCOPES.RunLogs);
|
|
78
|
+
const errors = context.getValue(debug_1.DEBUG_SCOPES.RunErrors);
|
|
79
|
+
let runner;
|
|
80
|
+
const runnerOptions = {
|
|
81
|
+
runInNewContext: false,
|
|
82
|
+
cachable: true,
|
|
83
|
+
env,
|
|
84
|
+
stats: () => {
|
|
85
|
+
const s = cachedStats(context, name)();
|
|
86
|
+
if (s.children?.length && s.children.length > 1) {
|
|
87
|
+
s.__index__ = index;
|
|
88
|
+
return s;
|
|
89
|
+
}
|
|
90
|
+
return s.children[index];
|
|
91
|
+
},
|
|
92
|
+
name,
|
|
93
|
+
testConfig: context.getTestConfig(),
|
|
94
|
+
source: context.getSource(),
|
|
95
|
+
dist: context.getDist(),
|
|
96
|
+
compilerOptions,
|
|
97
|
+
logs,
|
|
98
|
+
errors
|
|
99
|
+
};
|
|
100
|
+
if (compilerOptions.target === "web" ||
|
|
101
|
+
compilerOptions.target === "webworker") {
|
|
102
|
+
runner = new runner_1.WebRunner({
|
|
103
|
+
...runnerOptions,
|
|
104
|
+
runInNewContext: true,
|
|
105
|
+
location: testConfig.location || "https://test.cases/path/index.html"
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
runner = new runner_1.NodeRunner(runnerOptions);
|
|
110
|
+
}
|
|
111
|
+
flagIndex();
|
|
112
|
+
return runner;
|
|
113
|
+
}
|
package/dist/case/serial.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type TSerialCaseConfig = Omit<TTestConfig
|
|
1
|
+
import type { TTestConfig } from "../type";
|
|
2
|
+
export type TSerialCaseConfig = Omit<TTestConfig, "validate">;
|
|
3
3
|
export declare function createSerialCase(name: string, src: string, dist: string): void;
|
package/dist/case/serial.js
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSerialCase = createSerialCase;
|
|
4
|
-
const config_1 = require("../processor/config");
|
|
5
|
-
const runner_1 = require("../runner");
|
|
6
4
|
const creator_1 = require("../test/creator");
|
|
7
|
-
const
|
|
5
|
+
const config_1 = require("./config");
|
|
6
|
+
const runner_1 = require("./runner");
|
|
8
7
|
const creator = new creator_1.BasicCaseCreator({
|
|
9
8
|
clean: true,
|
|
10
9
|
describe: false,
|
|
11
10
|
testConfig: testConfig => {
|
|
12
11
|
const oldModuleScope = testConfig.moduleScope;
|
|
13
|
-
testConfig.moduleScope = (ms, stats) => {
|
|
12
|
+
testConfig.moduleScope = (ms, stats, compilerOptions) => {
|
|
14
13
|
let res = ms;
|
|
15
14
|
// TODO: modify runner module scope based on stats here
|
|
16
15
|
if (typeof oldModuleScope === "function") {
|
|
17
|
-
res = oldModuleScope(ms, stats);
|
|
16
|
+
res = oldModuleScope(ms, stats, compilerOptions);
|
|
18
17
|
}
|
|
19
18
|
return res;
|
|
20
19
|
};
|
|
21
20
|
},
|
|
22
|
-
steps: ({ name }) => [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
],
|
|
30
|
-
runner: runner_1.MultipleRunnerFactory
|
|
21
|
+
steps: ({ name }) => [(0, config_1.createConfigProcessor)(name)],
|
|
22
|
+
runner: {
|
|
23
|
+
key: runner_1.getMultiCompilerRunnerKey,
|
|
24
|
+
runner: runner_1.createMultiCompilerRunner
|
|
25
|
+
},
|
|
26
|
+
concurrent: 1
|
|
31
27
|
});
|
|
32
28
|
function createSerialCase(name, src, dist) {
|
|
33
29
|
creator.create(name, src, dist);
|
package/dist/case/stats-api.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export type TStatsAPICaseConfig =
|
|
1
|
+
import type { Compiler, RspackOptions, Stats } from "@rspack/core";
|
|
2
|
+
import type { ITestContext } from "../type";
|
|
3
|
+
export type TStatsAPICaseConfig = {
|
|
4
4
|
description: string;
|
|
5
|
+
options?: (context: ITestContext) => RspackOptions;
|
|
6
|
+
snapshotName?: string;
|
|
7
|
+
compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
8
|
+
build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
9
|
+
check?: (stats: Stats, compiler: Compiler) => Promise<void>;
|
|
5
10
|
};
|
|
6
11
|
export declare function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
|
package/dist/case/stats-api.js
CHANGED
|
@@ -1,21 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStatsAPICase = createStatsAPICase;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const type_1 = require("../type");
|
|
4
|
+
const memfs_1 = require("memfs");
|
|
5
|
+
const creator_1 = require("../test/creator");
|
|
7
6
|
let addedSerializer = false;
|
|
7
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
8
|
+
clean: true,
|
|
9
|
+
describe: true,
|
|
10
|
+
steps: ({ name, caseConfig }) => {
|
|
11
|
+
const config = caseConfig;
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
config: async (context) => {
|
|
15
|
+
const compiler = context.getCompiler();
|
|
16
|
+
compiler.setOptions(options(context, config.options));
|
|
17
|
+
},
|
|
18
|
+
compiler: async (context) => {
|
|
19
|
+
const compilerManager = context.getCompiler();
|
|
20
|
+
compilerManager.createCompiler();
|
|
21
|
+
compiler(context, compilerManager.getCompiler(), config.compiler);
|
|
22
|
+
},
|
|
23
|
+
build: async (context) => {
|
|
24
|
+
const compiler = context.getCompiler();
|
|
25
|
+
if (typeof config.build === "function") {
|
|
26
|
+
await config.build(context, compiler.getCompiler());
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
await compiler.build();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
run: async (env, context) => {
|
|
33
|
+
// no need to run, just check the snapshot of diagnostics
|
|
34
|
+
},
|
|
35
|
+
check: async (env, context) => {
|
|
36
|
+
await check(env, context, name, config.check);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
},
|
|
41
|
+
concurrent: true
|
|
42
|
+
});
|
|
8
43
|
function createStatsAPICase(name, src, dist, testConfig) {
|
|
9
44
|
if (!addedSerializer) {
|
|
10
45
|
addedSerializer = true;
|
|
11
46
|
}
|
|
12
47
|
const caseConfig = require(testConfig);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
name: name,
|
|
17
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
18
|
-
...caseConfig
|
|
19
|
-
}));
|
|
48
|
+
creator.create(name, src, dist, undefined, {
|
|
49
|
+
caseConfig,
|
|
50
|
+
description: () => caseConfig.description
|
|
20
51
|
});
|
|
21
52
|
}
|
|
53
|
+
function options(context, custom) {
|
|
54
|
+
const res = (custom?.(context) || {});
|
|
55
|
+
res.experiments ??= {};
|
|
56
|
+
res.experiments.css ??= true;
|
|
57
|
+
res.experiments.rspackFuture ??= {};
|
|
58
|
+
res.experiments.rspackFuture.bundlerInfo ??= {};
|
|
59
|
+
res.experiments.rspackFuture.bundlerInfo.force ??= false;
|
|
60
|
+
if (!global.printLogger) {
|
|
61
|
+
res.infrastructureLogging = {
|
|
62
|
+
level: "error"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return res;
|
|
66
|
+
}
|
|
67
|
+
async function compiler(context, compiler, custom) {
|
|
68
|
+
if (custom) {
|
|
69
|
+
await custom(context, compiler);
|
|
70
|
+
}
|
|
71
|
+
if (compiler) {
|
|
72
|
+
compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function check(env, context, name, custom) {
|
|
76
|
+
const manager = context.getCompiler();
|
|
77
|
+
const stats = manager.getStats();
|
|
78
|
+
env.expect(typeof stats).toBe("object");
|
|
79
|
+
await custom?.(stats, manager.getCompiler());
|
|
80
|
+
}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import type { RspackOptions } from "@rspack/core";
|
|
2
|
+
import type { ITestContext, ITestEnv } from "../type";
|
|
3
|
+
export declare function createStatsProcessor(name: string, defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): {
|
|
4
|
+
before: (context: ITestContext) => Promise<void>;
|
|
5
|
+
config: (context: ITestContext) => Promise<void>;
|
|
6
|
+
compiler: (context: ITestContext) => Promise<void>;
|
|
7
|
+
build: (context: ITestContext) => Promise<void>;
|
|
8
|
+
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
9
|
+
check: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
10
|
+
after: (context: ITestContext) => Promise<void>;
|
|
11
|
+
};
|
|
1
12
|
export declare function createStatsOutputCase(name: string, src: string, dist: string): void;
|