@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/test/context.js
CHANGED
|
@@ -1,74 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
TestContext: ()=>TestContext
|
|
37
|
+
});
|
|
38
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
39
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
40
|
+
const external_compiler_js_namespaceObject = require("../compiler.js");
|
|
41
|
+
const external_debug_js_namespaceObject = require("./debug.js");
|
|
10
42
|
class TestContext {
|
|
11
|
-
|
|
43
|
+
config;
|
|
44
|
+
errors = [];
|
|
45
|
+
compiler = null;
|
|
46
|
+
store = new Map();
|
|
47
|
+
runners = new Map();
|
|
48
|
+
constructor(config){
|
|
12
49
|
this.config = config;
|
|
13
|
-
this.errors = [];
|
|
14
|
-
this.compiler = null;
|
|
15
|
-
this.store = new Map();
|
|
16
|
-
this.runners = new Map();
|
|
17
50
|
}
|
|
18
51
|
getSource(sub) {
|
|
19
|
-
if (sub)
|
|
20
|
-
return node_path_1.default.resolve(this.config.src, sub);
|
|
21
|
-
}
|
|
52
|
+
if (sub) return external_node_path_default().resolve(this.config.src, sub);
|
|
22
53
|
return this.config.src;
|
|
23
54
|
}
|
|
24
55
|
getDist(sub) {
|
|
25
|
-
if (sub)
|
|
26
|
-
return node_path_1.default.resolve(this.config.dist, sub);
|
|
27
|
-
}
|
|
56
|
+
if (sub) return external_node_path_default().resolve(this.config.dist, sub);
|
|
28
57
|
return this.config.dist;
|
|
29
58
|
}
|
|
30
59
|
getTemp(sub) {
|
|
31
|
-
if (!this.config.temp)
|
|
32
|
-
|
|
33
|
-
if (sub) {
|
|
34
|
-
return node_path_1.default.resolve(this.config.temp, sub);
|
|
35
|
-
}
|
|
60
|
+
if (!this.config.temp) return null;
|
|
61
|
+
if (sub) return external_node_path_default().resolve(this.config.temp, sub);
|
|
36
62
|
return this.config.temp;
|
|
37
63
|
}
|
|
38
64
|
getCompiler() {
|
|
39
|
-
if (!this.compiler)
|
|
40
|
-
this.compiler = new compiler_1.TestCompilerManager(this);
|
|
41
|
-
}
|
|
65
|
+
if (!this.compiler) this.compiler = new external_compiler_js_namespaceObject.TestCompilerManager(this);
|
|
42
66
|
return this.compiler;
|
|
43
67
|
}
|
|
44
68
|
getRunner(file, env) {
|
|
45
|
-
if (!this.config.runnerCreator)
|
|
46
|
-
throw new Error('TestContext: Runner creator not found');
|
|
47
|
-
}
|
|
69
|
+
if (!this.config.runnerCreator) throw new Error('TestContext: Runner creator not found');
|
|
48
70
|
const runnerKey = this.config.runnerCreator.key(this, this.config.name, file);
|
|
49
71
|
let runner = this.runners.get(runnerKey);
|
|
50
72
|
if (runner) {
|
|
51
73
|
if (__DEBUG__) {
|
|
52
|
-
const getRunnerInfo = this.getValue(
|
|
74
|
+
const getRunnerInfo = this.getValue(external_debug_js_namespaceObject.DEBUG_SCOPES.RunGetRunner) || {};
|
|
53
75
|
getRunnerInfo[file] = {
|
|
54
76
|
runnerKey,
|
|
55
77
|
reused: true,
|
|
56
|
-
runnerType: runner.constructor.name
|
|
78
|
+
runnerType: runner.constructor.name
|
|
57
79
|
};
|
|
58
|
-
this.setValue(
|
|
80
|
+
this.setValue(external_debug_js_namespaceObject.DEBUG_SCOPES.RunGetRunner, getRunnerInfo);
|
|
59
81
|
}
|
|
60
82
|
return runner;
|
|
61
83
|
}
|
|
62
84
|
runner = this.config.runnerCreator.runner(this, this.config.name, file, env);
|
|
63
85
|
runner.__key__ = runnerKey;
|
|
64
86
|
if (__DEBUG__) {
|
|
65
|
-
const getRunnerInfo = this.getValue(
|
|
87
|
+
const getRunnerInfo = this.getValue(external_debug_js_namespaceObject.DEBUG_SCOPES.RunGetRunner) || {};
|
|
66
88
|
getRunnerInfo[file] = {
|
|
67
89
|
runnerKey,
|
|
68
90
|
reused: false,
|
|
69
|
-
runnerType: runner.constructor.name
|
|
91
|
+
runnerType: runner.constructor.name
|
|
70
92
|
};
|
|
71
|
-
this.setValue(
|
|
93
|
+
this.setValue(external_debug_js_namespaceObject.DEBUG_SCOPES.RunGetRunner, getRunnerInfo);
|
|
72
94
|
}
|
|
73
95
|
this.runners.set(runnerKey, runner);
|
|
74
96
|
return runner;
|
|
@@ -86,7 +108,7 @@ class TestContext {
|
|
|
86
108
|
return this.errors.length > 0;
|
|
87
109
|
}
|
|
88
110
|
emitError(err) {
|
|
89
|
-
this.errors.push(typeof err
|
|
111
|
+
this.errors.push('string' == typeof err ? new Error(err) : err);
|
|
90
112
|
}
|
|
91
113
|
getError() {
|
|
92
114
|
return this.errors;
|
|
@@ -95,9 +117,13 @@ class TestContext {
|
|
|
95
117
|
this.errors.length = 0;
|
|
96
118
|
}
|
|
97
119
|
async closeCompiler() {
|
|
98
|
-
if (this.compiler)
|
|
99
|
-
await this.compiler.close();
|
|
100
|
-
}
|
|
120
|
+
if (this.compiler) await this.compiler.close();
|
|
101
121
|
}
|
|
102
122
|
}
|
|
103
|
-
exports.TestContext = TestContext;
|
|
123
|
+
exports.TestContext = __webpack_exports__.TestContext;
|
|
124
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
125
|
+
"TestContext"
|
|
126
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
127
|
+
Object.defineProperty(exports, '__esModule', {
|
|
128
|
+
value: true
|
|
129
|
+
});
|
package/dist/test/creator.js
CHANGED
|
@@ -1,107 +1,105 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
BasicCaseCreator: ()=>BasicCaseCreator
|
|
37
|
+
});
|
|
38
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
39
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
40
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
41
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
42
|
+
const external_rimraf_namespaceObject = require("rimraf");
|
|
43
|
+
const createLazyTestEnv_js_namespaceObject = require("../helper/legacy/createLazyTestEnv.js");
|
|
44
|
+
const external_tester_js_namespaceObject = require("./tester.js");
|
|
12
45
|
const DEFAULT_MAX_CONCURRENT = Number(process.env.DEFAULT_MAX_CONCURRENT) || 5;
|
|
13
46
|
class BasicCaseCreator {
|
|
14
|
-
|
|
47
|
+
_options;
|
|
48
|
+
currentConcurrent = 0;
|
|
49
|
+
tasks = [];
|
|
50
|
+
constructor(_options){
|
|
15
51
|
this._options = _options;
|
|
16
|
-
this.currentConcurrent = 0;
|
|
17
|
-
this.tasks = [];
|
|
18
52
|
}
|
|
19
53
|
create(name, src, dist, temp, caseOptions) {
|
|
20
54
|
const options = {
|
|
21
55
|
...this._options,
|
|
22
|
-
...caseOptions
|
|
56
|
+
...caseOptions
|
|
23
57
|
};
|
|
24
58
|
const testConfig = this.readTestConfig(src);
|
|
25
|
-
if (typeof options.testConfig
|
|
26
|
-
options.testConfig(testConfig);
|
|
27
|
-
}
|
|
59
|
+
if ('function' == typeof options.testConfig) options.testConfig(testConfig);
|
|
28
60
|
const skipped = this.checkSkipped(src, testConfig, options);
|
|
29
|
-
if (skipped)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.clean([dist, temp || ''].filter(Boolean));
|
|
35
|
-
}
|
|
61
|
+
if (skipped) return void this.skip(name, skipped);
|
|
62
|
+
if (options.clean) this.clean([
|
|
63
|
+
dist,
|
|
64
|
+
temp || ''
|
|
65
|
+
].filter(Boolean));
|
|
36
66
|
const run = this.shouldRun(name);
|
|
37
67
|
const tester = this.createTester(name, src, dist, temp, testConfig, options);
|
|
38
68
|
const concurrent = testConfig.concurrent || options.concurrent;
|
|
39
|
-
if (options.describe)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
describe.skip(name, () => {
|
|
50
|
-
it.skip('skipped', () => { });
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
if (run) {
|
|
56
|
-
if (concurrent) {
|
|
57
|
-
this.describeConcurrent(name, tester, testConfig, options);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
this.describe(name, tester, testConfig, options);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
it.skip('skipped', () => { });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
69
|
+
if (options.describe) if (run) concurrent ? describe(name, ()=>this.describeConcurrent(name, tester, testConfig, options)) : describe(name, ()=>this.describe(name, tester, testConfig, options));
|
|
70
|
+
else describe.skip(name, ()=>{
|
|
71
|
+
it.skip('skipped', ()=>{});
|
|
72
|
+
});
|
|
73
|
+
else if (run) if (concurrent) this.describeConcurrent(name, tester, testConfig, options);
|
|
74
|
+
else this.describe(name, tester, testConfig, options);
|
|
75
|
+
else it.skip('skipped', ()=>{});
|
|
67
76
|
return tester;
|
|
68
77
|
}
|
|
69
78
|
shouldRun(name) {
|
|
70
|
-
|
|
71
|
-
if (typeof global.testFilter !== 'string' || !global.testFilter) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
79
|
+
if ('string' != typeof global.testFilter || !global.testFilter) return true;
|
|
74
80
|
return name.includes(global.testFilter);
|
|
75
81
|
}
|
|
76
82
|
describeConcurrent(name, tester, testConfig, options) {
|
|
77
|
-
beforeAll(async ()
|
|
83
|
+
beforeAll(async ()=>{
|
|
78
84
|
await tester.prepare();
|
|
79
85
|
});
|
|
80
86
|
let starter = null;
|
|
81
|
-
let chain = new Promise((resolve, reject)
|
|
87
|
+
let chain = new Promise((resolve, reject)=>{
|
|
82
88
|
starter = resolve;
|
|
83
89
|
});
|
|
84
90
|
const ender = this.registerConcurrentTask(name, starter, options.concurrent);
|
|
85
91
|
const env = this.createConcurrentEnv();
|
|
86
|
-
for
|
|
92
|
+
for(let index = 0; index < tester.total; index++){
|
|
87
93
|
let stepSignalResolve = null;
|
|
88
|
-
const stepSignal = new Promise((resolve, reject)
|
|
94
|
+
const stepSignal = new Promise((resolve, reject)=>{
|
|
89
95
|
stepSignalResolve = resolve;
|
|
90
|
-
}).catch(()
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const description = typeof options.description === 'function'
|
|
94
|
-
? options.description(name, index)
|
|
95
|
-
: index
|
|
96
|
-
? `step [${index}] should pass`
|
|
97
|
-
: 'should pass';
|
|
98
|
-
it(description, async () => {
|
|
96
|
+
}).catch(()=>{});
|
|
97
|
+
const description = 'function' == typeof options.description ? options.description(name, index) : index ? `step [${index}] should pass` : 'should pass';
|
|
98
|
+
it(description, async ()=>{
|
|
99
99
|
const e = await stepSignal;
|
|
100
|
-
if (e)
|
|
101
|
-
throw e;
|
|
102
|
-
}
|
|
100
|
+
if (e) throw e;
|
|
103
101
|
}, options.timeout);
|
|
104
|
-
chain = chain.then(async ()
|
|
102
|
+
chain = chain.then(async ()=>{
|
|
105
103
|
try {
|
|
106
104
|
env.clear();
|
|
107
105
|
await tester.compile();
|
|
@@ -110,70 +108,52 @@ class BasicCaseCreator {
|
|
|
110
108
|
await tester.after();
|
|
111
109
|
const context = tester.getContext();
|
|
112
110
|
if (!tester.next() && context.hasError()) {
|
|
113
|
-
const errors = context
|
|
114
|
-
.getError()
|
|
115
|
-
.map((i) => `${i.stack}`.split('\n').join('\t\n'))
|
|
116
|
-
.join('\n\n');
|
|
111
|
+
const errors = context.getError().map((i)=>`${i.stack}`.split('\n').join('\t\n')).join('\n\n');
|
|
117
112
|
throw new Error(`Case "${name}" failed at step ${tester.step + 1}:\n${errors}`);
|
|
118
113
|
}
|
|
119
114
|
stepSignalResolve();
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
115
|
+
} catch (e) {
|
|
122
116
|
stepSignalResolve(e);
|
|
123
117
|
return Promise.reject();
|
|
124
118
|
}
|
|
125
|
-
}, ()
|
|
126
|
-
// bailout
|
|
119
|
+
}, ()=>{
|
|
127
120
|
stepSignalResolve();
|
|
128
121
|
return Promise.reject();
|
|
129
122
|
});
|
|
130
123
|
}
|
|
131
|
-
chain
|
|
132
|
-
.catch(() => {
|
|
133
|
-
// bailout error
|
|
134
|
-
// prevent unhandled rejection
|
|
135
|
-
})
|
|
136
|
-
.finally(() => {
|
|
124
|
+
chain.catch(()=>{}).finally(()=>{
|
|
137
125
|
ender();
|
|
138
126
|
});
|
|
139
|
-
afterAll(async ()
|
|
127
|
+
afterAll(async ()=>{
|
|
140
128
|
await tester.resume();
|
|
141
129
|
});
|
|
142
130
|
}
|
|
143
131
|
describe(name, tester, testConfig, options) {
|
|
144
|
-
beforeAll(async ()
|
|
132
|
+
beforeAll(async ()=>{
|
|
145
133
|
await tester.prepare();
|
|
146
134
|
});
|
|
147
135
|
let bailout = false;
|
|
148
|
-
for
|
|
149
|
-
const description = typeof options.description
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
it(description, async () => {
|
|
153
|
-
if (bailout) {
|
|
154
|
-
throw `Case "${name}" step ${index + 1} bailout because ${tester.step + 1} failed`;
|
|
155
|
-
}
|
|
136
|
+
for(let index = 0; index < tester.total; index++){
|
|
137
|
+
const description = 'function' == typeof options.description ? options.description(name, index) : `step [${index}] should pass`;
|
|
138
|
+
it(description, async ()=>{
|
|
139
|
+
if (bailout) throw `Case "${name}" step ${index + 1} bailout because ${tester.step + 1} failed`;
|
|
156
140
|
const context = tester.getContext();
|
|
157
141
|
try {
|
|
158
142
|
await tester.compile();
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
143
|
+
} catch (e) {
|
|
161
144
|
bailout = true;
|
|
162
145
|
context.emitError(e);
|
|
163
146
|
}
|
|
164
147
|
await tester.check(env);
|
|
165
148
|
if (!tester.next() && context.hasError()) {
|
|
166
149
|
bailout = true;
|
|
167
|
-
const errors = context
|
|
168
|
-
.getError()
|
|
169
|
-
.map((i) => `${i.stack}`.split('\n').join('\t\n'))
|
|
170
|
-
.join('\n\n');
|
|
150
|
+
const errors = context.getError().map((i)=>`${i.stack}`.split('\n').join('\t\n')).join('\n\n');
|
|
171
151
|
throw new Error(`Case "${name}" failed at step ${tester.step + 1}:\n${errors}`);
|
|
172
152
|
}
|
|
173
153
|
}, options.timeout || 60000);
|
|
174
154
|
const env = this.createEnv(testConfig, options);
|
|
175
155
|
}
|
|
176
|
-
afterAll(async ()
|
|
156
|
+
afterAll(async ()=>{
|
|
177
157
|
await tester.resume();
|
|
178
158
|
});
|
|
179
159
|
}
|
|
@@ -182,106 +162,86 @@ class BasicCaseCreator {
|
|
|
182
162
|
const beforeTasks = [];
|
|
183
163
|
const afterTasks = [];
|
|
184
164
|
return {
|
|
185
|
-
clear: ()
|
|
165
|
+
clear: ()=>{
|
|
186
166
|
tasks.length = 0;
|
|
187
167
|
beforeTasks.length = 0;
|
|
188
168
|
afterTasks.length = 0;
|
|
189
169
|
},
|
|
190
|
-
run: async ()
|
|
191
|
-
const runFn = async (fn)
|
|
192
|
-
if (fn.length) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
reject(e);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
resolve();
|
|
200
|
-
}
|
|
201
|
-
});
|
|
170
|
+
run: async ()=>{
|
|
171
|
+
const runFn = async (fn)=>{
|
|
172
|
+
if (fn.length) await new Promise((resolve, reject)=>{
|
|
173
|
+
fn((e)=>{
|
|
174
|
+
if (e) reject(e);
|
|
175
|
+
else resolve();
|
|
202
176
|
});
|
|
203
|
-
}
|
|
177
|
+
});
|
|
204
178
|
else {
|
|
205
179
|
const res = fn();
|
|
206
|
-
if (typeof res?.then
|
|
207
|
-
await res;
|
|
208
|
-
}
|
|
180
|
+
if ('function' == typeof res?.then) await res;
|
|
209
181
|
}
|
|
210
182
|
};
|
|
211
|
-
for (const [description, fn] of tasks)
|
|
212
|
-
for (const before of beforeTasks)
|
|
213
|
-
await runFn(before);
|
|
214
|
-
}
|
|
183
|
+
for (const [description, fn] of tasks){
|
|
184
|
+
for (const before of beforeTasks)await runFn(before);
|
|
215
185
|
try {
|
|
216
186
|
await runFn(fn);
|
|
217
|
-
}
|
|
218
|
-
catch (err) {
|
|
187
|
+
} catch (err) {
|
|
219
188
|
const e = err;
|
|
220
189
|
const message = `Error: ${description} failed:\n${e.message}`;
|
|
221
190
|
e.message = message;
|
|
222
191
|
throw e;
|
|
223
192
|
}
|
|
224
|
-
for (const after of afterTasks)
|
|
225
|
-
await runFn(after);
|
|
226
|
-
}
|
|
193
|
+
for (const after of afterTasks)await runFn(after);
|
|
227
194
|
}
|
|
228
195
|
},
|
|
229
196
|
expect,
|
|
230
|
-
it: (description, fn)
|
|
231
|
-
expect(typeof description
|
|
232
|
-
expect(typeof fn
|
|
233
|
-
tasks.push([
|
|
197
|
+
it: (description, fn)=>{
|
|
198
|
+
expect('string' == typeof description);
|
|
199
|
+
expect('function' == typeof fn);
|
|
200
|
+
tasks.push([
|
|
201
|
+
description,
|
|
202
|
+
fn
|
|
203
|
+
]);
|
|
234
204
|
},
|
|
235
|
-
beforeEach: (fn)
|
|
236
|
-
expect(typeof fn
|
|
205
|
+
beforeEach: (fn)=>{
|
|
206
|
+
expect('function' == typeof fn);
|
|
237
207
|
beforeTasks.push(fn);
|
|
238
208
|
},
|
|
239
|
-
afterEach: (fn)
|
|
240
|
-
expect(typeof fn
|
|
209
|
+
afterEach: (fn)=>{
|
|
210
|
+
expect('function' == typeof fn);
|
|
241
211
|
afterTasks.push(fn);
|
|
242
212
|
},
|
|
243
|
-
rstest
|
|
213
|
+
rstest
|
|
244
214
|
};
|
|
245
215
|
}
|
|
246
216
|
createEnv(testConfig, options) {
|
|
247
|
-
if (options.runner && !testConfig.noTests)
|
|
248
|
-
return (0, createLazyTestEnv_1.default)(10000);
|
|
249
|
-
}
|
|
217
|
+
if (options.runner && !testConfig.noTests) return (0, createLazyTestEnv_js_namespaceObject.createLazyTestEnv)(10000);
|
|
250
218
|
return {
|
|
251
219
|
expect,
|
|
252
220
|
it,
|
|
253
221
|
beforeEach,
|
|
254
222
|
afterEach,
|
|
255
|
-
rstest
|
|
223
|
+
rstest
|
|
256
224
|
};
|
|
257
225
|
}
|
|
258
226
|
clean(folders) {
|
|
259
|
-
for (const f of folders)
|
|
260
|
-
(0, rimraf_1.rimrafSync)(f);
|
|
261
|
-
}
|
|
227
|
+
for (const f of folders)(0, external_rimraf_namespaceObject.rimrafSync)(f);
|
|
262
228
|
}
|
|
263
229
|
skip(name, reason) {
|
|
264
|
-
it(typeof reason
|
|
230
|
+
it('string' == typeof reason ? `filtered by ${reason}` : 'filtered', ()=>{});
|
|
265
231
|
}
|
|
266
232
|
readTestConfig(src) {
|
|
267
|
-
const testConfigFile =
|
|
268
|
-
return
|
|
233
|
+
const testConfigFile = external_node_path_default().join(src, 'test.config.js');
|
|
234
|
+
return external_node_fs_default().existsSync(testConfigFile) ? require(testConfigFile) : {};
|
|
269
235
|
}
|
|
270
236
|
checkSkipped(src, testConfig, options) {
|
|
271
|
-
const filterPath =
|
|
272
|
-
|
|
273
|
-
if (!node_fs_1.default.existsSync(filterPath)) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
// test.filter.js exists, skip if it returns false|string|array
|
|
237
|
+
const filterPath = external_node_path_default().join(src, 'test.filter.js');
|
|
238
|
+
if (!external_node_fs_default().existsSync(filterPath)) return false;
|
|
277
239
|
const filtered = require(filterPath)(options, testConfig);
|
|
278
|
-
if (typeof filtered
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
240
|
+
if ('string' == typeof filtered || Array.isArray(filtered)) return true;
|
|
281
241
|
return !filtered;
|
|
282
242
|
}
|
|
283
243
|
createTester(name, src, dist, temp, testConfig, options) {
|
|
284
|
-
return new
|
|
244
|
+
return new external_tester_js_namespaceObject.Tester({
|
|
285
245
|
name,
|
|
286
246
|
src,
|
|
287
247
|
dist,
|
|
@@ -295,28 +255,36 @@ class BasicCaseCreator {
|
|
|
295
255
|
name,
|
|
296
256
|
src,
|
|
297
257
|
dist,
|
|
298
|
-
temp
|
|
299
|
-
})
|
|
258
|
+
temp
|
|
259
|
+
})
|
|
300
260
|
});
|
|
301
261
|
}
|
|
302
262
|
tryRunTask(concurrent) {
|
|
303
|
-
while
|
|
304
|
-
this.currentConcurrent < this.getMaxConcurrent(concurrent)) {
|
|
263
|
+
while(0 !== this.tasks.length && this.currentConcurrent < this.getMaxConcurrent(concurrent)){
|
|
305
264
|
const [_name, starter] = this.tasks.shift();
|
|
306
265
|
this.currentConcurrent++;
|
|
307
266
|
starter();
|
|
308
267
|
}
|
|
309
268
|
}
|
|
310
269
|
getMaxConcurrent(concurrent) {
|
|
311
|
-
return typeof concurrent
|
|
270
|
+
return 'number' == typeof concurrent ? concurrent : DEFAULT_MAX_CONCURRENT;
|
|
312
271
|
}
|
|
313
272
|
registerConcurrentTask(name, starter, concurrent) {
|
|
314
|
-
this.tasks.push([
|
|
273
|
+
this.tasks.push([
|
|
274
|
+
name,
|
|
275
|
+
starter
|
|
276
|
+
]);
|
|
315
277
|
this.tryRunTask(concurrent);
|
|
316
|
-
return ()
|
|
278
|
+
return ()=>{
|
|
317
279
|
this.currentConcurrent--;
|
|
318
280
|
this.tryRunTask(concurrent);
|
|
319
281
|
};
|
|
320
282
|
}
|
|
321
283
|
}
|
|
322
|
-
exports.BasicCaseCreator = BasicCaseCreator;
|
|
284
|
+
exports.BasicCaseCreator = __webpack_exports__.BasicCaseCreator;
|
|
285
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
286
|
+
"BasicCaseCreator"
|
|
287
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
288
|
+
Object.defineProperty(exports, '__esModule', {
|
|
289
|
+
value: true
|
|
290
|
+
});
|