@rspack/test-tools 2.0.2 → 2.0.4
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 +106 -66
- package/dist/case/cache.js +136 -122
- package/dist/case/common.d.ts +4 -4
- package/dist/case/common.js +162 -157
- package/dist/case/compiler.d.ts +4 -4
- package/dist/case/compiler.js +75 -64
- package/dist/case/config.js +112 -74
- package/dist/case/defaults.js +136 -83
- package/dist/case/diagnostic.js +112 -84
- package/dist/case/error.d.ts +4 -4
- package/dist/case/error.js +105 -89
- package/dist/case/esm-output.js +118 -87
- package/dist/case/example.js +73 -35
- package/dist/case/hash.js +74 -59
- package/dist/case/hook.js +151 -138
- package/dist/case/hot-step.js +130 -161
- package/dist/case/hot.js +148 -134
- package/dist/case/incremental.js +91 -58
- package/dist/case/index.js +134 -51
- package/dist/case/multi-compiler.d.ts +4 -4
- package/dist/case/multi-compiler.js +81 -56
- package/dist/case/native-watcher.js +62 -30
- package/dist/case/normal.js +253 -185
- package/dist/case/runner.js +80 -51
- package/dist/case/serial.js +47 -16
- package/dist/case/stats-api.d.ts +4 -4
- package/dist/case/stats-api.js +63 -43
- package/dist/case/stats-output.d.ts +3 -3
- package/dist/case/stats-output.js +147 -152
- package/dist/case/treeshaking.js +66 -35
- package/dist/case/watch.d.ts +3 -19
- package/dist/case/watch.js +204 -224
- package/dist/compiler.js +222 -195
- package/dist/helper/directory.js +83 -71
- package/dist/helper/disable-iconv-lite-warning.js +35 -9
- package/dist/helper/expect/diff.js +39 -10
- package/dist/helper/expect/error.js +62 -30
- package/dist/helper/expect/placeholder.js +47 -21
- package/dist/helper/expect/rspack.js +35 -13
- package/dist/helper/expect/to-be-typeof.js +39 -7
- package/dist/helper/expect/to-end-with.js +40 -8
- package/dist/helper/expect/to-match-file-snapshot.js +103 -80
- package/dist/helper/hot-update/index.js +35 -4
- package/dist/helper/hot-update/loader.d.ts +1 -0
- package/dist/helper/hot-update/loader.js +39 -4
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +87 -74
- package/dist/helper/index.js +138 -24
- package/dist/helper/is.js +51 -10
- package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
- package/dist/helper/legacy/EventSourceForNode.js +83 -37
- package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
- package/dist/helper/legacy/LogTestPlugin.js +39 -6
- package/dist/helper/legacy/asModule.d.ts +3 -3
- package/dist/helper/legacy/asModule.js +68 -19
- package/dist/helper/legacy/captureStdio.d.ts +1 -2
- package/dist/helper/legacy/captureStdio.js +69 -29
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
- package/dist/helper/legacy/checkArrayExpectation.js +132 -121
- package/dist/helper/legacy/copyDiff.d.ts +1 -2
- package/dist/helper/legacy/copyDiff.js +86 -42
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
- package/dist/helper/legacy/createFakeWorker.js +90 -47
- package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
- package/dist/helper/legacy/createLazyTestEnv.js +70 -59
- package/dist/helper/legacy/currentScript.d.ts +2 -2
- package/dist/helper/legacy/currentScript.js +35 -2
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
- package/dist/helper/legacy/deprecationTracking.js +53 -28
- package/dist/helper/legacy/expectSource.d.ts +3 -2
- package/dist/helper/legacy/expectSource.js +42 -18
- package/dist/helper/legacy/fakeSystem.d.ts +12 -9
- package/dist/helper/legacy/fakeSystem.js +68 -58
- package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
- package/dist/helper/legacy/findOutputFiles.js +60 -13
- package/dist/helper/legacy/parseResource.d.ts +1 -1
- package/dist/helper/legacy/parseResource.js +36 -6
- package/dist/helper/legacy/regexEscape.d.ts +1 -2
- package/dist/helper/legacy/regexEscape.js +39 -5
- package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
- package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
- package/dist/helper/legacy/supportsTextDecoder.js +40 -6
- package/dist/helper/legacy/supportsUsing.d.ts +1 -2
- package/dist/helper/legacy/supportsUsing.js +40 -7
- package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
- package/dist/helper/legacy/urlToRelativePath.js +56 -7
- package/dist/helper/parse-modules.js +52 -42
- package/dist/helper/read-config-file.js +60 -18
- package/dist/helper/serializers.js +62 -33
- package/dist/helper/setup-env.js +81 -91
- package/dist/helper/setup-expect.js +13 -13
- package/dist/helper/setup-wasm.js +18 -9
- package/dist/helper/stringify-config.js +44 -26
- package/dist/helper/update-snapshot.js +35 -3
- package/dist/helper/util/checkSourceMap.js +119 -80
- package/dist/helper/util/checkStats.d.ts +1 -1
- package/dist/helper/util/checkStats.js +42 -17
- package/dist/helper/util/expectWarningFactory.d.ts +1 -2
- package/dist/helper/util/expectWarningFactory.js +41 -8
- package/dist/helper/util/filterUtil.d.ts +9 -8
- package/dist/helper/util/filterUtil.js +63 -23
- package/dist/helper/win.js +46 -7
- package/dist/index.js +115 -23
- package/dist/plugin/index.js +55 -14
- package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
- package/dist/reporter/index.js +55 -14
- package/dist/reporter/streamed-events-reporter.js +51 -77
- package/dist/runner/index.js +62 -15
- package/dist/runner/node/index.js +365 -431
- package/dist/runner/web/index.js +278 -263
- package/dist/test/context.js +67 -41
- package/dist/test/creator.js +135 -167
- package/dist/test/debug.js +89 -58
- package/dist/test/tester.js +94 -74
- package/dist/type.d.ts +10 -9
- package/dist/type.js +43 -9
- package/package.json +21 -20
package/dist/case/watch.js
CHANGED
|
@@ -1,23 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
createWatchCase: ()=>createWatchCase,
|
|
37
|
+
createWatchInitialProcessor: ()=>createWatchInitialProcessor,
|
|
38
|
+
createWatchRunner: ()=>createWatchRunner,
|
|
39
|
+
createWatchStepProcessor: ()=>createWatchStepProcessor,
|
|
40
|
+
getWatchRunnerKey: ()=>getWatchRunnerKey
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
45
|
+
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
46
|
+
const external_rspack_merge_namespaceObject = require("rspack-merge");
|
|
47
|
+
var external_rspack_merge_default = /*#__PURE__*/ __webpack_require__.n(external_rspack_merge_namespaceObject);
|
|
48
|
+
const external_compiler_js_namespaceObject = require("../compiler.js");
|
|
49
|
+
const index_js_namespaceObject = require("../helper/index.js");
|
|
50
|
+
const checkArrayExpectation_js_namespaceObject = require("../helper/legacy/checkArrayExpectation.js");
|
|
51
|
+
const copyDiff_js_namespaceObject = require("../helper/legacy/copyDiff.js");
|
|
52
|
+
const external_runner_index_js_namespaceObject = require("../runner/index.js");
|
|
53
|
+
const creator_js_namespaceObject = require("../test/creator.js");
|
|
54
|
+
const external_common_js_namespaceObject = require("./common.js");
|
|
21
55
|
function createWatchInitialProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
|
|
22
56
|
const watchContext = {
|
|
23
57
|
currentTriggerFilename: null,
|
|
@@ -25,126 +59,111 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
25
59
|
step,
|
|
26
60
|
tempDir,
|
|
27
61
|
nativeWatcher,
|
|
28
|
-
watchState
|
|
62
|
+
watchState
|
|
29
63
|
};
|
|
30
64
|
return {
|
|
31
|
-
before:
|
|
65
|
+
before: (context)=>{
|
|
32
66
|
context.setValue('watchContext', watchContext);
|
|
33
67
|
},
|
|
34
|
-
config:
|
|
68
|
+
config: (context)=>{
|
|
35
69
|
const testConfig = context.getTestConfig();
|
|
36
70
|
const multiCompilerOptions = [];
|
|
37
|
-
const caseOptions = (0,
|
|
38
|
-
|
|
39
|
-
|
|
71
|
+
const caseOptions = (0, index_js_namespaceObject.readConfigFile)([
|
|
72
|
+
'rspack.config.js',
|
|
73
|
+
'webpack.config.js'
|
|
74
|
+
].map((i)=>context.getSource(i)), context, {});
|
|
75
|
+
for (const [index, options] of caseOptions.entries()){
|
|
76
|
+
const compilerOptions = external_rspack_merge_default()(defaultOptions({
|
|
40
77
|
incremental,
|
|
41
|
-
ignoreNotFriendlyForIncrementalWarnings: testConfig.ignoreNotFriendlyForIncrementalWarnings
|
|
78
|
+
ignoreNotFriendlyForIncrementalWarnings: testConfig.ignoreNotFriendlyForIncrementalWarnings
|
|
42
79
|
}), options);
|
|
43
80
|
overrideOptions(index, context, compilerOptions, tempDir, nativeWatcher);
|
|
44
81
|
multiCompilerOptions.push(compilerOptions);
|
|
45
82
|
}
|
|
46
|
-
const compilerOptions = multiCompilerOptions.length
|
|
47
|
-
? multiCompilerOptions[0]
|
|
48
|
-
: multiCompilerOptions;
|
|
83
|
+
const compilerOptions = 1 === multiCompilerOptions.length ? multiCompilerOptions[0] : multiCompilerOptions;
|
|
49
84
|
const compiler = context.getCompiler();
|
|
50
85
|
compiler.setOptions(compilerOptions);
|
|
51
86
|
context.setValue('multiCompilerOptions', multiCompilerOptions);
|
|
52
87
|
},
|
|
53
|
-
compiler: async (context)
|
|
54
|
-
const c = await (0,
|
|
55
|
-
c.hooks.invalid.tap('WatchTestCasesTest', (filename, mtime)
|
|
88
|
+
compiler: async (context)=>{
|
|
89
|
+
const c = await (0, external_common_js_namespaceObject.compiler)(context, name);
|
|
90
|
+
c.hooks.invalid.tap('WatchTestCasesTest', (filename, mtime)=>{
|
|
56
91
|
watchContext.currentTriggerFilename = filename;
|
|
57
92
|
});
|
|
58
93
|
},
|
|
59
|
-
build: async (context)
|
|
94
|
+
build: async (context)=>{
|
|
60
95
|
const compiler = context.getCompiler();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
96
|
+
external_fs_extra_default().mkdirSync(watchContext.tempDir, {
|
|
97
|
+
recursive: true
|
|
98
|
+
});
|
|
99
|
+
(0, copyDiff_js_namespaceObject.copyDiff)(external_node_path_default().join(context.getSource(), watchContext.step), watchContext.tempDir, true);
|
|
100
|
+
const pkgJsonFile = external_node_path_default().join(watchContext.tempDir, 'package.json');
|
|
101
|
+
if (!external_fs_extra_default().existsSync(pkgJsonFile)) {
|
|
102
|
+
external_fs_extra_default().writeJsonSync(pkgJsonFile, {
|
|
103
|
+
name,
|
|
104
|
+
version: '0.0.1'
|
|
105
|
+
});
|
|
106
|
+
const longTimeAgo = Date.now() - 86400000;
|
|
107
|
+
external_fs_extra_default().utimesSync(pkgJsonFile, Date.now() - longTimeAgo, Date.now() - longTimeAgo);
|
|
68
108
|
}
|
|
69
|
-
const task = new Promise((resolve, reject)
|
|
70
|
-
compiler.getEmitter().once(
|
|
71
|
-
if (e)
|
|
72
|
-
return reject(e);
|
|
109
|
+
const task = new Promise((resolve, reject)=>{
|
|
110
|
+
compiler.getEmitter().once(external_compiler_js_namespaceObject.ECompilerEvent.Build, (e, stats)=>{
|
|
111
|
+
if (e) return reject(e);
|
|
73
112
|
resolve(stats);
|
|
74
113
|
});
|
|
75
114
|
});
|
|
76
115
|
compiler.watch();
|
|
77
116
|
await task;
|
|
78
117
|
},
|
|
79
|
-
run: async (env, context)
|
|
80
|
-
await (0,
|
|
118
|
+
run: async (env, context)=>{
|
|
119
|
+
await (0, external_common_js_namespaceObject.run)(env, context, name, (context)=>(0, external_common_js_namespaceObject.findMultiCompilerBundle)(context, name, (index, context, options)=>findBundle(index, context, options, step)));
|
|
81
120
|
},
|
|
82
|
-
check: async (env, context)
|
|
121
|
+
check: async (env, context)=>{
|
|
83
122
|
const testConfig = context.getTestConfig();
|
|
84
|
-
if (testConfig.noTests)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}));
|
|
123
|
+
if (testConfig.noTests) return;
|
|
124
|
+
const errors = (context.getError() || []).map((e)=>({
|
|
125
|
+
message: e.message,
|
|
126
|
+
stack: e.stack
|
|
127
|
+
}));
|
|
90
128
|
const warnings = [];
|
|
91
129
|
const compiler = context.getCompiler();
|
|
92
130
|
const stats = compiler.getStats();
|
|
93
131
|
const options = compiler.getOptions();
|
|
94
|
-
const checkStats = testConfig.checkStats || (()
|
|
132
|
+
const checkStats = testConfig.checkStats || (()=>true);
|
|
95
133
|
if (stats) {
|
|
96
|
-
if (testConfig.writeStatsOuptut) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
const getJsonStats = (() => {
|
|
134
|
+
if (testConfig.writeStatsOuptut) external_fs_extra_default().writeFileSync(external_node_path_default().join(context.getDist(), 'stats.txt'), stats.toString({
|
|
135
|
+
preset: 'verbose',
|
|
136
|
+
colors: false
|
|
137
|
+
}), 'utf-8');
|
|
138
|
+
const getJsonStats = (()=>{
|
|
103
139
|
let cached = null;
|
|
104
|
-
return ()
|
|
105
|
-
if (!cached) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
}
|
|
140
|
+
return ()=>{
|
|
141
|
+
if (!cached) cached = stats.toJson({
|
|
142
|
+
assets: true,
|
|
143
|
+
chunks: true,
|
|
144
|
+
chunkModules: true,
|
|
145
|
+
modules: true,
|
|
146
|
+
entrypoints: true,
|
|
147
|
+
chunkGroups: true,
|
|
148
|
+
errorDetails: true
|
|
149
|
+
});
|
|
116
150
|
return cached;
|
|
117
151
|
};
|
|
118
152
|
})();
|
|
119
|
-
const getStringStats = (()
|
|
153
|
+
const getStringStats = (()=>{
|
|
120
154
|
let cached = null;
|
|
121
|
-
return ()
|
|
122
|
-
if (!cached) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
});
|
|
126
|
-
}
|
|
155
|
+
return ()=>{
|
|
156
|
+
if (!cached) cached = stats.toString({
|
|
157
|
+
logging: 'verbose'
|
|
158
|
+
});
|
|
127
159
|
return cached;
|
|
128
160
|
};
|
|
129
161
|
})();
|
|
130
162
|
if (checkStats.length > 1) {
|
|
131
|
-
if (!checkStats(watchContext.step, getJsonStats(), getStringStats()))
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
// @ts-expect-error only one param
|
|
137
|
-
if (!checkStats(watchContext.step)) {
|
|
138
|
-
throw new Error('stats check failed');
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (testConfig.writeStatsJson) {
|
|
142
|
-
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), 'stats.json'), JSON.stringify(getJsonStats(), null, 2), 'utf-8');
|
|
143
|
-
}
|
|
144
|
-
if (fs_extra_1.default.existsSync(context.getSource(`${watchContext.step}/errors.js`)) ||
|
|
145
|
-
fs_extra_1.default.existsSync(context.getSource(`${watchContext.step}/warnings.js`)) ||
|
|
146
|
-
stats.hasErrors() ||
|
|
147
|
-
stats.hasWarnings()) {
|
|
163
|
+
if (!checkStats(watchContext.step, getJsonStats(), getStringStats())) throw new Error('stats check failed');
|
|
164
|
+
} else if (!checkStats(watchContext.step)) throw new Error('stats check failed');
|
|
165
|
+
if (testConfig.writeStatsJson) external_fs_extra_default().writeFileSync(external_node_path_default().join(context.getDist(), 'stats.json'), JSON.stringify(getJsonStats(), null, 2), 'utf-8');
|
|
166
|
+
if (external_fs_extra_default().existsSync(context.getSource(`${watchContext.step}/errors.js`)) || external_fs_extra_default().existsSync(context.getSource(`${watchContext.step}/warnings.js`)) || stats.hasErrors() || stats.hasWarnings()) {
|
|
148
167
|
const statsJson = stats.toJson({
|
|
149
168
|
assets: true,
|
|
150
169
|
chunks: true,
|
|
@@ -152,149 +171,108 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
|
|
|
152
171
|
modules: true,
|
|
153
172
|
entrypoints: true,
|
|
154
173
|
chunkGroups: true,
|
|
155
|
-
errorDetails: true
|
|
174
|
+
errorDetails: true
|
|
156
175
|
});
|
|
157
|
-
if (statsJson.errors)
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
if (statsJson.warnings) {
|
|
161
|
-
warnings.push(...statsJson.warnings);
|
|
162
|
-
}
|
|
176
|
+
if (statsJson.errors) errors.push(...statsJson.errors);
|
|
177
|
+
if (statsJson.warnings) warnings.push(...statsJson.warnings);
|
|
163
178
|
}
|
|
164
179
|
}
|
|
165
|
-
await (0,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (testConfig.writeStatsOuptut) {
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
if (testConfig.writeStatsJson) {
|
|
176
|
-
fs_extra_1.default.renameSync(node_path_1.default.join(context.getDist(), 'stats.json'), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.json`));
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
after: async (context) => {
|
|
180
|
-
await (0, common_1.afterExecute)(context, name);
|
|
180
|
+
await (0, checkArrayExpectation_js_namespaceObject.checkArrayExpectation)(external_node_path_default().join(context.getSource(), watchContext.step), {
|
|
181
|
+
errors
|
|
182
|
+
}, 'error', 'errors', 'Error', options);
|
|
183
|
+
await (0, checkArrayExpectation_js_namespaceObject.checkArrayExpectation)(external_node_path_default().join(context.getSource(), watchContext.step), {
|
|
184
|
+
warnings
|
|
185
|
+
}, 'warning', 'warnings', 'Warning', options);
|
|
186
|
+
if (external_fs_extra_default().existsSync(context.getSource('errors.js'))) context.clearError();
|
|
187
|
+
if (testConfig.writeStatsOuptut) external_fs_extra_default().renameSync(external_node_path_default().join(context.getDist(), 'stats.txt'), external_node_path_default().join(context.getDist(), `stats.${watchContext.step}.txt`));
|
|
188
|
+
if (testConfig.writeStatsJson) external_fs_extra_default().renameSync(external_node_path_default().join(context.getDist(), 'stats.json'), external_node_path_default().join(context.getDist(), `stats.${watchContext.step}.json`));
|
|
181
189
|
},
|
|
190
|
+
after: async (context)=>{
|
|
191
|
+
await (0, external_common_js_namespaceObject.afterExecute)(context, name);
|
|
192
|
+
}
|
|
182
193
|
};
|
|
183
194
|
}
|
|
184
195
|
function createWatchStepProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
|
|
185
|
-
const processor = createWatchInitialProcessor(name, tempDir, step, watchState, {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
};
|
|
189
|
-
processor.build = async (context)
|
|
196
|
+
const processor = createWatchInitialProcessor(name, tempDir, step, watchState, {
|
|
197
|
+
incremental
|
|
198
|
+
});
|
|
199
|
+
processor.compiler = (context)=>{};
|
|
200
|
+
processor.build = async (context)=>{
|
|
190
201
|
const compiler = context.getCompiler();
|
|
191
|
-
const task = new Promise((resolve, reject)
|
|
192
|
-
compiler.getEmitter().once(
|
|
193
|
-
if (e)
|
|
194
|
-
return reject(e);
|
|
202
|
+
const task = new Promise((resolve, reject)=>{
|
|
203
|
+
compiler.getEmitter().once(external_compiler_js_namespaceObject.ECompilerEvent.Build, (e, stats)=>{
|
|
204
|
+
if (e) return reject(e);
|
|
195
205
|
resolve(stats);
|
|
196
206
|
});
|
|
197
207
|
});
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
// So we need to wait a while to ensure the watcher is ready.
|
|
202
|
-
// If we don't wait, copyDiff will happen before the watcher is ready,
|
|
203
|
-
// which will cause the compiler not rebuild when the files change.
|
|
204
|
-
// The timeout is set to 400ms for windows OS and 100ms for other OS.
|
|
205
|
-
// TODO: This is a workaround, we can remove it when notify support windows better.
|
|
206
|
-
const timeout = nativeWatcher && process.platform === 'win32' ? 400 : 100;
|
|
207
|
-
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
208
|
-
(0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), step), tempDir, false);
|
|
208
|
+
const timeout = nativeWatcher && 'win32' === process.platform ? 400 : 100;
|
|
209
|
+
await new Promise((resolve)=>setTimeout(resolve, timeout));
|
|
210
|
+
(0, copyDiff_js_namespaceObject.copyDiff)(external_node_path_default().join(context.getSource(), step), tempDir, false);
|
|
209
211
|
await task;
|
|
210
212
|
};
|
|
211
213
|
return processor;
|
|
212
214
|
}
|
|
213
|
-
const creator = new
|
|
215
|
+
const creator = new creator_js_namespaceObject.BasicCaseCreator({
|
|
214
216
|
clean: true,
|
|
215
217
|
runner: {
|
|
216
218
|
key: getWatchRunnerKey,
|
|
217
|
-
runner: createWatchRunner
|
|
218
|
-
},
|
|
219
|
-
description: (name, index) => {
|
|
220
|
-
return index === 0
|
|
221
|
-
? `${name} should compile`
|
|
222
|
-
: `should compile step ${index}`;
|
|
219
|
+
runner: createWatchRunner
|
|
223
220
|
},
|
|
221
|
+
description: (name, index)=>0 === index ? `${name} should compile` : `should compile step ${index}`,
|
|
224
222
|
describe: false,
|
|
225
|
-
steps: ({ name, src, temp })
|
|
223
|
+
steps: ({ name, src, temp })=>{
|
|
226
224
|
const watchState = {};
|
|
227
|
-
const runs =
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
.map((name) => ({ name }));
|
|
232
|
-
return runs.map((run, index) => index === 0
|
|
233
|
-
? createWatchInitialProcessor(name, temp, run.name, watchState)
|
|
234
|
-
: createWatchStepProcessor(name, temp, run.name, watchState));
|
|
225
|
+
const runs = external_fs_extra_default().readdirSync(src).sort().filter((name)=>external_fs_extra_default().statSync(external_node_path_default().join(src, name)).isDirectory()).map((name)=>({
|
|
226
|
+
name
|
|
227
|
+
}));
|
|
228
|
+
return runs.map((run, index)=>0 === index ? createWatchInitialProcessor(name, temp, run.name, watchState) : createWatchStepProcessor(name, temp, run.name, watchState));
|
|
235
229
|
},
|
|
236
|
-
concurrent: true
|
|
230
|
+
concurrent: true
|
|
237
231
|
});
|
|
238
232
|
function createWatchCase(name, src, dist, temp) {
|
|
239
233
|
creator.create(name, src, dist, temp);
|
|
240
234
|
}
|
|
241
235
|
function overrideOptions(index, context, options, tempDir, nativeWatcher) {
|
|
242
|
-
if (!options.mode)
|
|
243
|
-
|
|
244
|
-
if (!options.
|
|
245
|
-
|
|
246
|
-
if (!options.
|
|
247
|
-
|
|
248
|
-
if (!options.
|
|
249
|
-
|
|
250
|
-
if (!options.
|
|
251
|
-
options.devtool = false;
|
|
252
|
-
if (!options.output)
|
|
253
|
-
options.output = {};
|
|
254
|
-
if (!options.output.path)
|
|
255
|
-
options.output.path = context.getDist();
|
|
256
|
-
if (typeof options.output.pathinfo === 'undefined')
|
|
257
|
-
options.output.pathinfo = false;
|
|
258
|
-
if (!options.output.filename)
|
|
259
|
-
options.output.filename = 'bundle.js';
|
|
236
|
+
if (!options.mode) options.mode = 'development';
|
|
237
|
+
if (!options.context) options.context = tempDir;
|
|
238
|
+
if (!options.entry) options.entry = './index.js';
|
|
239
|
+
if (!options.target) options.target = 'async-node';
|
|
240
|
+
if (!options.devtool) options.devtool = false;
|
|
241
|
+
if (!options.output) options.output = {};
|
|
242
|
+
if (!options.output.path) options.output.path = context.getDist();
|
|
243
|
+
if (void 0 === options.output.pathinfo) options.output.pathinfo = false;
|
|
244
|
+
if (!options.output.filename) options.output.filename = 'bundle.js';
|
|
260
245
|
options.optimization ??= {};
|
|
261
246
|
options.experiments ??= {};
|
|
262
247
|
options.module ??= {};
|
|
263
|
-
options.module.defaultRules ??= [
|
|
248
|
+
options.module.defaultRules ??= [
|
|
249
|
+
'...'
|
|
250
|
+
];
|
|
264
251
|
options.module.defaultRules.push({
|
|
265
252
|
test: /\.css$/,
|
|
266
|
-
type: 'css/auto'
|
|
253
|
+
type: 'css/auto'
|
|
267
254
|
});
|
|
268
|
-
if (nativeWatcher)
|
|
269
|
-
options.experiments.nativeWatcher ??= true;
|
|
270
|
-
}
|
|
255
|
+
if (nativeWatcher) options.experiments.nativeWatcher ??= true;
|
|
271
256
|
options.output ??= {};
|
|
272
257
|
options.output.bundlerInfo ??= {};
|
|
273
258
|
options.output.bundlerInfo.force ??= false;
|
|
274
|
-
// test incremental: "safe" here, we test default incremental in Incremental-*.test.js
|
|
275
259
|
options.incremental ??= 'safe';
|
|
276
|
-
if (!global.printLogger) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
};
|
|
280
|
-
}
|
|
260
|
+
if (!global.printLogger) options.infrastructureLogging = {
|
|
261
|
+
level: 'error'
|
|
262
|
+
};
|
|
281
263
|
}
|
|
282
264
|
function findBundle(index, context, options, stepName) {
|
|
283
265
|
const testConfig = context.getTestConfig();
|
|
284
|
-
if (typeof testConfig.findBundle
|
|
285
|
-
return testConfig.findBundle(index, options, stepName);
|
|
286
|
-
}
|
|
266
|
+
if ('function' == typeof testConfig.findBundle) return testConfig.findBundle(index, options, stepName);
|
|
287
267
|
return './bundle.js';
|
|
288
268
|
}
|
|
289
|
-
function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWarnings = false
|
|
290
|
-
if (incremental) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
};
|
|
297
|
-
}
|
|
269
|
+
function defaultOptions({ incremental = false, ignoreNotFriendlyForIncrementalWarnings = false } = {}) {
|
|
270
|
+
if (incremental) return {
|
|
271
|
+
incremental: 'advance',
|
|
272
|
+
ignoreWarnings: ignoreNotFriendlyForIncrementalWarnings ? [
|
|
273
|
+
/is not friendly for incremental/
|
|
274
|
+
] : void 0
|
|
275
|
+
};
|
|
298
276
|
return {};
|
|
299
277
|
}
|
|
300
278
|
function getWatchRunnerKey(context, name, file) {
|
|
@@ -306,19 +284,17 @@ function cachedWatchStats(context, name) {
|
|
|
306
284
|
const compiler = context.getCompiler();
|
|
307
285
|
const watchContext = context.getValue('watchContext');
|
|
308
286
|
const stepName = watchContext?.step;
|
|
309
|
-
const statsGetter = (()
|
|
287
|
+
const statsGetter = (()=>{
|
|
310
288
|
const cached = {};
|
|
311
|
-
return ()
|
|
312
|
-
if (cached[stepName])
|
|
313
|
-
return cached[stepName];
|
|
314
|
-
}
|
|
289
|
+
return ()=>{
|
|
290
|
+
if (cached[stepName]) return cached[stepName];
|
|
315
291
|
cached[stepName] = compiler.getStats().toJson({
|
|
316
292
|
entrypoints: true,
|
|
317
293
|
assets: true,
|
|
318
294
|
chunks: true,
|
|
319
295
|
chunkModules: true,
|
|
320
296
|
modules: true,
|
|
321
|
-
errorDetails: true
|
|
297
|
+
errorDetails: true
|
|
322
298
|
});
|
|
323
299
|
return cached[stepName];
|
|
324
300
|
};
|
|
@@ -330,40 +306,44 @@ function createWatchRunner(context, name, file, env) {
|
|
|
330
306
|
const compilerOptions = compiler.getOptions();
|
|
331
307
|
const watchContext = context.getValue('watchContext');
|
|
332
308
|
const stepName = watchContext?.step;
|
|
333
|
-
if (!stepName)
|
|
334
|
-
throw new Error('Can not get watch step name from context');
|
|
335
|
-
}
|
|
309
|
+
if (!stepName) throw new Error('Can not get watch step name from context');
|
|
336
310
|
const state = watchContext?.watchState;
|
|
337
|
-
if (!state)
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
const isWeb = Array.isArray(compilerOptions)
|
|
341
|
-
? compilerOptions.some((option) => {
|
|
342
|
-
return option.target === 'web' || option.target === 'webworker';
|
|
343
|
-
})
|
|
344
|
-
: compilerOptions.target === 'web' ||
|
|
345
|
-
compilerOptions.target === 'webworker';
|
|
311
|
+
if (!state) throw new Error('Can not get watch state from context');
|
|
312
|
+
const isWeb = Array.isArray(compilerOptions) ? compilerOptions.some((option)=>'web' === option.target || 'webworker' === option.target) : 'web' === compilerOptions.target || 'webworker' === compilerOptions.target;
|
|
346
313
|
const testConfig = context.getTestConfig();
|
|
347
|
-
return new
|
|
314
|
+
return new external_runner_index_js_namespaceObject.WebRunner({
|
|
348
315
|
env,
|
|
349
316
|
stats: cachedWatchStats(context, name),
|
|
350
317
|
name: name,
|
|
351
318
|
runInNewContext: isWeb,
|
|
352
319
|
cachable: false,
|
|
353
320
|
testConfig: {
|
|
354
|
-
...
|
|
355
|
-
moduleScope: (ms, stats, options)
|
|
321
|
+
...testConfig || {},
|
|
322
|
+
moduleScope: (ms, stats, options)=>{
|
|
356
323
|
ms.STATE = state;
|
|
357
324
|
ms.WATCH_STEP = stepName;
|
|
358
|
-
if (typeof testConfig.moduleScope
|
|
359
|
-
return testConfig.moduleScope(ms, stats, options);
|
|
360
|
-
}
|
|
325
|
+
if ('function' == typeof testConfig.moduleScope) return testConfig.moduleScope(ms, stats, options);
|
|
361
326
|
return ms;
|
|
362
|
-
}
|
|
327
|
+
}
|
|
363
328
|
},
|
|
364
329
|
source: context.getSource(),
|
|
365
330
|
dist: context.getDist(),
|
|
366
331
|
compilerOptions,
|
|
367
|
-
location: testConfig.location || 'https://test.cases/path/index.html'
|
|
332
|
+
location: testConfig.location || 'https://test.cases/path/index.html'
|
|
368
333
|
});
|
|
369
334
|
}
|
|
335
|
+
exports.createWatchCase = __webpack_exports__.createWatchCase;
|
|
336
|
+
exports.createWatchInitialProcessor = __webpack_exports__.createWatchInitialProcessor;
|
|
337
|
+
exports.createWatchRunner = __webpack_exports__.createWatchRunner;
|
|
338
|
+
exports.createWatchStepProcessor = __webpack_exports__.createWatchStepProcessor;
|
|
339
|
+
exports.getWatchRunnerKey = __webpack_exports__.getWatchRunnerKey;
|
|
340
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
341
|
+
"createWatchCase",
|
|
342
|
+
"createWatchInitialProcessor",
|
|
343
|
+
"createWatchRunner",
|
|
344
|
+
"createWatchStepProcessor",
|
|
345
|
+
"getWatchRunnerKey"
|
|
346
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
347
|
+
Object.defineProperty(exports, '__esModule', {
|
|
348
|
+
value: true
|
|
349
|
+
});
|