@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/serial.js
CHANGED
|
@@ -1,30 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createSerialCase: ()=>createSerialCase
|
|
28
|
+
});
|
|
29
|
+
const creator_js_namespaceObject = require("../test/creator.js");
|
|
30
|
+
const external_config_js_namespaceObject = require("./config.js");
|
|
31
|
+
const external_runner_js_namespaceObject = require("./runner.js");
|
|
32
|
+
const creator = new creator_js_namespaceObject.BasicCaseCreator({
|
|
8
33
|
clean: true,
|
|
9
34
|
describe: false,
|
|
10
|
-
testConfig: (testConfig)
|
|
35
|
+
testConfig: (testConfig)=>{
|
|
11
36
|
const oldModuleScope = testConfig.moduleScope;
|
|
12
|
-
testConfig.moduleScope = (ms, stats, compilerOptions)
|
|
37
|
+
testConfig.moduleScope = (ms, stats, compilerOptions)=>{
|
|
13
38
|
let res = ms;
|
|
14
|
-
|
|
15
|
-
if (typeof oldModuleScope === 'function') {
|
|
16
|
-
res = oldModuleScope(ms, stats, compilerOptions);
|
|
17
|
-
}
|
|
39
|
+
if ('function' == typeof oldModuleScope) res = oldModuleScope(ms, stats, compilerOptions);
|
|
18
40
|
return res;
|
|
19
41
|
};
|
|
20
42
|
},
|
|
21
|
-
steps: ({ name })
|
|
43
|
+
steps: ({ name })=>[
|
|
44
|
+
(0, external_config_js_namespaceObject.createConfigProcessor)(name)
|
|
45
|
+
],
|
|
22
46
|
runner: {
|
|
23
|
-
key:
|
|
24
|
-
runner:
|
|
47
|
+
key: external_runner_js_namespaceObject.getMultiCompilerRunnerKey,
|
|
48
|
+
runner: external_runner_js_namespaceObject.createMultiCompilerRunner
|
|
25
49
|
},
|
|
26
|
-
concurrent: 1
|
|
50
|
+
concurrent: 1
|
|
27
51
|
});
|
|
28
52
|
function createSerialCase(name, src, dist) {
|
|
29
53
|
creator.create(name, src, dist);
|
|
30
54
|
}
|
|
55
|
+
exports.createSerialCase = __webpack_exports__.createSerialCase;
|
|
56
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
57
|
+
"createSerialCase"
|
|
58
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
|
+
Object.defineProperty(exports, '__esModule', {
|
|
60
|
+
value: true
|
|
61
|
+
});
|
package/dist/case/stats-api.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Compiler, RspackOptions, Stats } from '@rspack/core';
|
|
2
|
-
import type { ITestContext } from '../type';
|
|
2
|
+
import type { ITestContext, MaybePromise } from '../type';
|
|
3
3
|
export type TStatsAPICaseConfig = {
|
|
4
4
|
description: string;
|
|
5
5
|
options?: (context: ITestContext) => RspackOptions;
|
|
6
6
|
snapshotName?: string;
|
|
7
|
-
compiler?: (context: ITestContext, compiler: Compiler) =>
|
|
8
|
-
build?: (context: ITestContext, compiler: Compiler) =>
|
|
9
|
-
check?: (stats: Stats, compiler: Compiler) =>
|
|
7
|
+
compiler?: (context: ITestContext, compiler: Compiler) => MaybePromise<void>;
|
|
8
|
+
build?: (context: ITestContext, compiler: Compiler) => MaybePromise<void>;
|
|
9
|
+
check?: (stats: Stats, compiler: Compiler) => MaybePromise<void>;
|
|
10
10
|
};
|
|
11
11
|
export declare function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
|
package/dist/case/stats-api.js
CHANGED
|
@@ -1,80 +1,93 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createStatsAPICase: ()=>createStatsAPICase
|
|
28
|
+
});
|
|
29
|
+
const external_memfs_namespaceObject = require("memfs");
|
|
30
|
+
const creator_js_namespaceObject = require("../test/creator.js");
|
|
6
31
|
let addedSerializer = false;
|
|
7
|
-
const creator = new
|
|
32
|
+
const creator = new creator_js_namespaceObject.BasicCaseCreator({
|
|
8
33
|
clean: true,
|
|
9
34
|
describe: true,
|
|
10
|
-
steps: ({ name, caseConfig })
|
|
35
|
+
steps: ({ name, caseConfig })=>{
|
|
11
36
|
const config = caseConfig;
|
|
12
37
|
return [
|
|
13
38
|
{
|
|
14
|
-
config:
|
|
39
|
+
config: (context)=>{
|
|
15
40
|
const compiler = context.getCompiler();
|
|
16
41
|
compiler.setOptions(options(context, config.options));
|
|
17
42
|
},
|
|
18
|
-
compiler: async (context)
|
|
43
|
+
compiler: async (context)=>{
|
|
19
44
|
const compilerManager = context.getCompiler();
|
|
20
45
|
compilerManager.createCompiler();
|
|
21
|
-
|
|
46
|
+
await stats_api_compiler(context, compilerManager.getCompiler(), config.compiler);
|
|
22
47
|
},
|
|
23
|
-
build: async (context)
|
|
48
|
+
build: async (context)=>{
|
|
24
49
|
const compiler = context.getCompiler();
|
|
25
|
-
if (typeof config.build
|
|
26
|
-
|
|
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
|
|
50
|
+
if ('function' == typeof config.build) await config.build(context, compiler.getCompiler());
|
|
51
|
+
else await compiler.build();
|
|
34
52
|
},
|
|
35
|
-
|
|
53
|
+
run: async (env, context)=>{},
|
|
54
|
+
check: async (env, context)=>{
|
|
36
55
|
await check(env, context, name, config.check);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
39
58
|
];
|
|
40
59
|
},
|
|
41
|
-
concurrent: true
|
|
60
|
+
concurrent: true
|
|
42
61
|
});
|
|
43
62
|
function createStatsAPICase(name, src, dist, testConfig) {
|
|
44
|
-
if (!addedSerializer)
|
|
45
|
-
addedSerializer = true;
|
|
46
|
-
}
|
|
63
|
+
if (!addedSerializer) addedSerializer = true;
|
|
47
64
|
const caseConfig = require(testConfig);
|
|
48
|
-
creator.create(name, src, dist,
|
|
65
|
+
creator.create(name, src, dist, void 0, {
|
|
49
66
|
caseConfig,
|
|
50
|
-
description: ()
|
|
67
|
+
description: ()=>caseConfig.description
|
|
51
68
|
});
|
|
52
69
|
}
|
|
53
70
|
function options(context, custom) {
|
|
54
|
-
const res =
|
|
71
|
+
const res = custom?.(context) || {};
|
|
55
72
|
res.output ??= {};
|
|
56
73
|
res.module ??= {};
|
|
57
|
-
res.module.defaultRules ??= [
|
|
74
|
+
res.module.defaultRules ??= [
|
|
75
|
+
'...'
|
|
76
|
+
];
|
|
58
77
|
res.module.defaultRules.push({
|
|
59
78
|
test: /\.css$/,
|
|
60
|
-
type: 'css/auto'
|
|
79
|
+
type: 'css/auto'
|
|
61
80
|
});
|
|
62
81
|
res.output.bundlerInfo ??= {};
|
|
63
82
|
res.output.bundlerInfo.force ??= false;
|
|
64
|
-
if (!global.printLogger) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
}
|
|
83
|
+
if (!global.printLogger) res.infrastructureLogging = {
|
|
84
|
+
level: 'error'
|
|
85
|
+
};
|
|
69
86
|
return res;
|
|
70
87
|
}
|
|
71
|
-
async function
|
|
72
|
-
if (custom)
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
if (compiler) {
|
|
76
|
-
compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
|
|
77
|
-
}
|
|
88
|
+
async function stats_api_compiler(context, compiler, custom) {
|
|
89
|
+
if (custom) await custom(context, compiler);
|
|
90
|
+
if (compiler) compiler.outputFileSystem = (0, external_memfs_namespaceObject.createFsFromVolume)(new external_memfs_namespaceObject.Volume());
|
|
78
91
|
}
|
|
79
92
|
async function check(env, context, name, custom) {
|
|
80
93
|
const manager = context.getCompiler();
|
|
@@ -82,3 +95,10 @@ async function check(env, context, name, custom) {
|
|
|
82
95
|
env.expect(typeof stats).toBe('object');
|
|
83
96
|
await custom?.(stats, manager.getCompiler());
|
|
84
97
|
}
|
|
98
|
+
exports.createStatsAPICase = __webpack_exports__.createStatsAPICase;
|
|
99
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
100
|
+
"createStatsAPICase"
|
|
101
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
102
|
+
Object.defineProperty(exports, '__esModule', {
|
|
103
|
+
value: true
|
|
104
|
+
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { RspackOptions } from '@rspack/core';
|
|
2
2
|
import type { ITestContext, ITestEnv } from '../type';
|
|
3
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) =>
|
|
5
|
-
config: (context: ITestContext) =>
|
|
4
|
+
before: (context: ITestContext) => void;
|
|
5
|
+
config: (context: ITestContext) => void;
|
|
6
6
|
compiler: (context: ITestContext) => Promise<void>;
|
|
7
7
|
build: (context: ITestContext) => Promise<void>;
|
|
8
8
|
run: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
9
9
|
check: (env: ITestEnv, context: ITestContext) => Promise<void>;
|
|
10
|
-
after: (context: ITestContext) =>
|
|
10
|
+
after: (context: ITestContext) => void;
|
|
11
11
|
};
|
|
12
12
|
export declare function createStatsOutputCase(name: string, src: string, dist: string): void;
|
|
@@ -1,77 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
createStatsOutputCase: ()=>createStatsOutputCase,
|
|
37
|
+
createStatsProcessor: ()=>createStatsProcessor
|
|
38
|
+
});
|
|
39
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
40
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
41
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
42
|
+
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
43
|
+
const placeholder_js_namespaceObject = require("../helper/expect/placeholder.js");
|
|
44
|
+
const captureStdio_js_namespaceObject = require("../helper/legacy/captureStdio.js");
|
|
45
|
+
const creator_js_namespaceObject = require("../test/creator.js");
|
|
46
|
+
const external_common_js_namespaceObject = require("./common.js");
|
|
14
47
|
const REG_ERROR_CASE = /error$/;
|
|
15
48
|
function createStatsProcessor(name, defaultOptions, overrideOptions) {
|
|
16
49
|
const writeStatsOuptut = false;
|
|
17
50
|
const snapshotName = 'stats.txt';
|
|
18
51
|
let stderr = null;
|
|
19
52
|
return {
|
|
20
|
-
before:
|
|
21
|
-
stderr = (0,
|
|
53
|
+
before: (context)=>{
|
|
54
|
+
stderr = (0, captureStdio_js_namespaceObject.captureStdio)(process.stderr, true);
|
|
22
55
|
},
|
|
23
|
-
config:
|
|
24
|
-
(0,
|
|
56
|
+
config: (context)=>{
|
|
57
|
+
(0, external_common_js_namespaceObject.configMultiCompiler)(context, name, [
|
|
58
|
+
'rspack.config.js',
|
|
59
|
+
'webpack.config.js'
|
|
60
|
+
], defaultOptions, overrideOptions);
|
|
25
61
|
},
|
|
26
|
-
compiler: async (context)
|
|
27
|
-
const c = await (0,
|
|
62
|
+
compiler: async (context)=>{
|
|
63
|
+
const c = await (0, external_common_js_namespaceObject.compiler)(context, name);
|
|
28
64
|
await statsCompiler(context, c);
|
|
29
65
|
},
|
|
30
|
-
build: async (context)
|
|
31
|
-
await (0,
|
|
32
|
-
},
|
|
33
|
-
run: async (env, context) => {
|
|
34
|
-
// no need to run, just check snapshot
|
|
66
|
+
build: async (context)=>{
|
|
67
|
+
await (0, external_common_js_namespaceObject.build)(context, name);
|
|
35
68
|
},
|
|
36
|
-
|
|
69
|
+
run: async (env, context)=>{},
|
|
70
|
+
check: async (env, context)=>{
|
|
37
71
|
await check(env, context, name, writeStatsOuptut, snapshotName, stderr);
|
|
38
72
|
},
|
|
39
|
-
after:
|
|
73
|
+
after: (context)=>{
|
|
40
74
|
stderr.restore();
|
|
41
|
-
}
|
|
75
|
+
}
|
|
42
76
|
};
|
|
43
77
|
}
|
|
44
|
-
const creator = new
|
|
78
|
+
const creator = new creator_js_namespaceObject.BasicCaseCreator({
|
|
45
79
|
clean: true,
|
|
46
80
|
describe: false,
|
|
47
|
-
steps: ({ name })
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
description: ()
|
|
81
|
+
steps: ({ name })=>[
|
|
82
|
+
createStatsProcessor(name, stats_output_defaultOptions, stats_output_overrideOptions)
|
|
83
|
+
],
|
|
84
|
+
description: ()=>'should print correct stats for'
|
|
51
85
|
});
|
|
52
86
|
function createStatsOutputCase(name, src, dist) {
|
|
53
87
|
creator.create(name, src, dist);
|
|
54
88
|
}
|
|
55
|
-
function
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
89
|
+
function stats_output_defaultOptions(index, context) {
|
|
90
|
+
if (external_fs_extra_default().existsSync(external_node_path_default().join(context.getSource(), 'rspack.config.js')) || external_fs_extra_default().existsSync(external_node_path_default().join(context.getSource(), 'webpack.config.js'))) return {
|
|
91
|
+
output: {
|
|
92
|
+
bundlerInfo: {
|
|
93
|
+
force: false
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
module: {
|
|
97
|
+
defaultRules: [
|
|
98
|
+
'...',
|
|
99
|
+
{
|
|
100
|
+
test: /\.css$/i,
|
|
101
|
+
type: 'css/auto'
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
};
|
|
75
106
|
return {
|
|
76
107
|
context: context.getSource(),
|
|
77
108
|
mode: 'development',
|
|
@@ -80,94 +111,69 @@ function defaultOptions(index, context) {
|
|
|
80
111
|
filename: 'bundle.js',
|
|
81
112
|
path: context.getDist(),
|
|
82
113
|
bundlerInfo: {
|
|
83
|
-
force: false
|
|
84
|
-
}
|
|
114
|
+
force: false
|
|
115
|
+
}
|
|
85
116
|
},
|
|
86
117
|
module: {
|
|
87
118
|
defaultRules: [
|
|
88
119
|
{
|
|
89
120
|
test: /\.css$/i,
|
|
90
|
-
type: 'css/auto'
|
|
91
|
-
}
|
|
92
|
-
]
|
|
121
|
+
type: 'css/auto'
|
|
122
|
+
}
|
|
123
|
+
]
|
|
93
124
|
},
|
|
94
125
|
optimization: {
|
|
95
|
-
minimize: false
|
|
96
|
-
}
|
|
126
|
+
minimize: false
|
|
127
|
+
}
|
|
97
128
|
};
|
|
98
129
|
}
|
|
99
|
-
function
|
|
100
|
-
if (!options.context)
|
|
101
|
-
|
|
102
|
-
if (!options.output)
|
|
103
|
-
|
|
104
|
-
if (!options.
|
|
105
|
-
|
|
106
|
-
if (!options.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
options.optimization = {};
|
|
110
|
-
if (options.optimization.minimize === undefined) {
|
|
111
|
-
options.optimization.minimize = false;
|
|
112
|
-
}
|
|
113
|
-
if (!global.printLogger) {
|
|
114
|
-
options.infrastructureLogging = {
|
|
115
|
-
level: 'error',
|
|
116
|
-
};
|
|
117
|
-
}
|
|
130
|
+
function stats_output_overrideOptions(index, context, options) {
|
|
131
|
+
if (!options.context) options.context = context.getSource();
|
|
132
|
+
if (!options.output) options.output = options.output || {};
|
|
133
|
+
if (!options.output.path) options.output.path = context.getDist();
|
|
134
|
+
if (!options.plugins) options.plugins = [];
|
|
135
|
+
if (!options.optimization) options.optimization = {};
|
|
136
|
+
if (void 0 === options.optimization.minimize) options.optimization.minimize = false;
|
|
137
|
+
if (!global.printLogger) options.infrastructureLogging = {
|
|
138
|
+
level: 'error'
|
|
139
|
+
};
|
|
118
140
|
}
|
|
119
141
|
class RspackStats {
|
|
120
|
-
|
|
142
|
+
value;
|
|
143
|
+
constructor(value){
|
|
121
144
|
this.value = value;
|
|
122
145
|
}
|
|
123
146
|
}
|
|
124
|
-
|
|
147
|
+
function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
|
|
125
148
|
const compiler = context.getCompiler();
|
|
126
149
|
const options = compiler.getOptions();
|
|
127
150
|
const stats = compiler.getStats();
|
|
128
|
-
if (!stats || !compiler)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
throw new Error(stats.toString({
|
|
140
|
-
all: false,
|
|
141
|
-
errors: true,
|
|
142
|
-
// errorStack: true,
|
|
143
|
-
// errorDetails: true
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
146
|
-
else if (writeStatsOuptut) {
|
|
147
|
-
fs_extra_1.default.writeFileSync(node_path_1.default.join(context.getDist(), 'stats.txt'), stats.toString({
|
|
148
|
-
preset: 'verbose',
|
|
149
|
-
// context: context.getSource(),
|
|
150
|
-
colors: false,
|
|
151
|
-
}), 'utf-8');
|
|
152
|
-
}
|
|
151
|
+
if (!stats || !compiler) return;
|
|
152
|
+
for (const compilation of [].concat(stats.stats || stats).map((s)=>s.compilation))compilation.logging.delete('webpack.Compilation.ModuleProfile');
|
|
153
|
+
if (REG_ERROR_CASE.test(name)) env.expect(stats.hasErrors()).toBe(true);
|
|
154
|
+
else if (stats.hasErrors()) throw new Error(stats.toString({
|
|
155
|
+
all: false,
|
|
156
|
+
errors: true
|
|
157
|
+
}));
|
|
158
|
+
else if (writeStatsOuptut) external_fs_extra_default().writeFileSync(external_node_path_default().join(context.getDist(), 'stats.txt'), stats.toString({
|
|
159
|
+
preset: 'verbose',
|
|
160
|
+
colors: false
|
|
161
|
+
}), 'utf-8');
|
|
153
162
|
let toStringOptions = {
|
|
154
163
|
context: context.getSource(),
|
|
155
|
-
colors: false
|
|
164
|
+
colors: false
|
|
156
165
|
};
|
|
157
166
|
let hasColorSetting = false;
|
|
158
|
-
if (
|
|
167
|
+
if (void 0 !== options.stats) {
|
|
159
168
|
toStringOptions = options.stats;
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
hasColorSetting =
|
|
165
|
-
}
|
|
166
|
-
if (Array.isArray(options) && !toStringOptions.children) {
|
|
167
|
-
toStringOptions.children = options.map((o) => o.stats);
|
|
169
|
+
if (null === toStringOptions || 'object' != typeof toStringOptions) toStringOptions = {
|
|
170
|
+
preset: toStringOptions
|
|
171
|
+
};
|
|
172
|
+
if (!toStringOptions.context) toStringOptions.context = context.getSource();
|
|
173
|
+
hasColorSetting = void 0 !== toStringOptions.colors;
|
|
168
174
|
}
|
|
169
|
-
|
|
170
|
-
for (const { compilation: s } of [].concat(stats.stats || stats))
|
|
175
|
+
if (Array.isArray(options) && !toStringOptions.children) toStringOptions.children = options.map((o)=>o.stats);
|
|
176
|
+
for (const { compilation: s } of [].concat(stats.stats || stats)){
|
|
171
177
|
env.expect(s.startTime).toBeGreaterThan(0);
|
|
172
178
|
env.expect(s.endTime).toBeGreaterThan(0);
|
|
173
179
|
s.endTime = new Date('04/20/1970, 12:42:42 PM').getTime();
|
|
@@ -176,51 +182,40 @@ async function check(env, context, name, writeStatsOuptut, snapshot, stderr) {
|
|
|
176
182
|
let actual = stats.toString(toStringOptions);
|
|
177
183
|
env.expect(typeof actual).toBe('string');
|
|
178
184
|
actual = stderr.toString() + actual;
|
|
179
|
-
if (!hasColorSetting)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// CHANGE: The time unit display in Rspack is second
|
|
183
|
-
.replace(/[.0-9]+(\s?s)/g, 'X$1')
|
|
184
|
-
// CHANGE: Replace bundle size, since bundle sizes may differ between platforms
|
|
185
|
-
.replace(/[0-9]+(\.[0-9]+)? KiB/g, 'xx KiB')
|
|
186
|
-
.replace(/[0-9]+(\.[0-9]+)? bytes/g, 'xx bytes')
|
|
187
|
-
.replace(/[0-9]+(\.[0-9]+)? ms/g, 'xx ms');
|
|
188
|
-
}
|
|
189
|
-
actual = actual
|
|
190
|
-
.split('\n')
|
|
191
|
-
.filter((line) => !line.includes('@rstest/core/dist'))
|
|
192
|
-
.join('\n');
|
|
193
|
-
const snapshotPath = node_path_1.default.isAbsolute(snapshot)
|
|
194
|
-
? snapshot
|
|
195
|
-
: node_path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}`);
|
|
185
|
+
if (!hasColorSetting) actual = actual.replace(/\u001b\[[0-9;]*m/g, '').replace(/[.0-9]+(\s?s)/g, 'X$1').replace(/[0-9]+(\.[0-9]+)? KiB/g, 'xx KiB').replace(/[0-9]+(\.[0-9]+)? bytes/g, 'xx bytes').replace(/[0-9]+(\.[0-9]+)? ms/g, 'xx ms');
|
|
186
|
+
actual = actual.split('\n').filter((line)=>!line.includes('@rstest/core/dist')).join('\n');
|
|
187
|
+
const snapshotPath = external_node_path_default().isAbsolute(snapshot) ? snapshot : external_node_path_default().resolve(context.getSource(), `./__snapshots__/${snapshot}`);
|
|
196
188
|
env.expect(new RspackStats(actual)).toMatchFileSnapshotSync(snapshotPath);
|
|
197
189
|
const testConfig = context.getTestConfig();
|
|
198
|
-
if (typeof testConfig?.validate
|
|
199
|
-
testConfig.validate(stats, stderr.toString());
|
|
200
|
-
}
|
|
190
|
+
if ('function' == typeof testConfig?.validate) testConfig.validate(stats, stderr.toString());
|
|
201
191
|
}
|
|
202
|
-
|
|
203
|
-
const compilers = compiler.compilers
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
for (const compiler of compilers)
|
|
207
|
-
if (!compiler.inputFileSystem)
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
192
|
+
function statsCompiler(context, compiler) {
|
|
193
|
+
const compilers = compiler.compilers ? compiler.compilers : [
|
|
194
|
+
compiler
|
|
195
|
+
];
|
|
196
|
+
for (const compiler of compilers){
|
|
197
|
+
if (!compiler.inputFileSystem) continue;
|
|
210
198
|
const ifs = compiler.inputFileSystem;
|
|
211
199
|
const inputFileSystem = Object.create(ifs);
|
|
212
200
|
compiler.inputFileSystem = inputFileSystem;
|
|
213
|
-
inputFileSystem.readFile = (...args)
|
|
201
|
+
inputFileSystem.readFile = (...args)=>{
|
|
214
202
|
const callback = args.pop();
|
|
215
203
|
ifs.readFile.apply(ifs, args.concat([
|
|
216
|
-
(err, result)
|
|
217
|
-
if (err)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString('utf-8')));
|
|
222
|
-
},
|
|
204
|
+
(err, result)=>{
|
|
205
|
+
if (err) return callback(err);
|
|
206
|
+
if (!/\.(js|json|txt)$/.test(args[0])) return callback(null, result);
|
|
207
|
+
callback(null, (0, placeholder_js_namespaceObject.normalizePlaceholder)(result.toString('utf-8')));
|
|
208
|
+
}
|
|
223
209
|
]));
|
|
224
210
|
};
|
|
225
211
|
}
|
|
226
212
|
}
|
|
213
|
+
exports.createStatsOutputCase = __webpack_exports__.createStatsOutputCase;
|
|
214
|
+
exports.createStatsProcessor = __webpack_exports__.createStatsProcessor;
|
|
215
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
216
|
+
"createStatsOutputCase",
|
|
217
|
+
"createStatsProcessor"
|
|
218
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
219
|
+
Object.defineProperty(exports, '__esModule', {
|
|
220
|
+
value: true
|
|
221
|
+
});
|