@rspack/test-tools 1.7.0-beta.1 → 1.7.0
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.d.ts +2 -2
- package/dist/case/builtin.js +58 -58
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +34 -34
- package/dist/case/common.d.ts +2 -2
- package/dist/case/common.js +45 -45
- package/dist/case/compiler.d.ts +3 -3
- package/dist/case/compiler.js +21 -21
- package/dist/case/config.d.ts +3 -3
- package/dist/case/config.js +19 -19
- package/dist/case/defaults.d.ts +2 -2
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +29 -29
- package/dist/case/error.d.ts +2 -2
- package/dist/case/error.js +21 -21
- package/dist/case/esm-output.js +28 -28
- package/dist/case/example.js +7 -7
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +16 -16
- package/dist/case/hook.d.ts +3 -3
- package/dist/case/hook.js +42 -42
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +46 -46
- package/dist/case/hot.d.ts +5 -5
- package/dist/case/hot.js +43 -43
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +9 -9
- package/dist/case/index.d.ts +31 -31
- package/dist/case/multi-compiler.d.ts +3 -3
- package/dist/case/multi-compiler.js +15 -15
- package/dist/case/native-watcher.js +6 -6
- package/dist/case/normal.js +46 -46
- package/dist/case/runner.d.ts +2 -2
- package/dist/case/runner.js +22 -15
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +4 -4
- package/dist/case/stats-api.d.ts +2 -2
- package/dist/case/stats-api.js +7 -7
- package/dist/case/stats-output.d.ts +2 -2
- package/dist/case/stats-output.js +45 -45
- package/dist/case/treeshaking.js +6 -6
- package/dist/case/watch.d.ts +1 -1
- package/dist/case/watch.js +59 -59
- package/dist/compiler.d.ts +3 -3
- package/dist/compiler.js +31 -31
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +15 -15
- package/dist/helper/disable-iconv-lite-warning.js +3 -3
- package/dist/helper/expect/diff.js +8 -8
- package/dist/helper/expect/error.js +9 -9
- package/dist/helper/expect/placeholder.js +9 -9
- package/dist/helper/expect/rspack.js +5 -5
- package/dist/helper/expect/to-be-typeof.js +2 -2
- package/dist/helper/expect/to-end-with.js +3 -3
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -1
- package/dist/helper/expect/to-match-file-snapshot.js +23 -23
- package/dist/helper/hot-update/index.d.ts +1 -1
- package/dist/helper/hot-update/loader.js +1 -1
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +15 -15
- package/dist/helper/index.d.ts +8 -8
- package/dist/helper/is.js +2 -2
- package/dist/helper/legacy/EventSourceForNode.js +8 -8
- package/dist/helper/legacy/LogTestPlugin.js +18 -18
- package/dist/helper/legacy/asModule.js +6 -6
- package/dist/helper/legacy/captureStdio.js +6 -6
- package/dist/helper/legacy/checkArrayExpectation.js +24 -24
- package/dist/helper/legacy/copyDiff.js +5 -5
- package/dist/helper/legacy/createFakeWorker.js +13 -13
- package/dist/helper/legacy/createLazyTestEnv.js +12 -12
- package/dist/helper/legacy/currentScript.js +1 -1
- package/dist/helper/legacy/deprecationTracking.js +5 -5
- package/dist/helper/legacy/expectSource.js +5 -5
- package/dist/helper/legacy/fakeSystem.js +14 -14
- package/dist/helper/legacy/findOutputFiles.js +4 -4
- package/dist/helper/legacy/parseResource.js +4 -4
- package/dist/helper/legacy/regexEscape.js +2 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +2 -2
- package/dist/helper/legacy/supportsTextDecoder.js +2 -2
- package/dist/helper/legacy/supportsUsing.js +1 -1
- package/dist/helper/legacy/urlToRelativePath.js +3 -3
- package/dist/helper/parse-modules.js +13 -13
- package/dist/helper/read-config-file.d.ts +2 -2
- package/dist/helper/read-config-file.js +3 -3
- package/dist/helper/serializers.d.ts +1 -1
- package/dist/helper/serializers.js +11 -11
- package/dist/helper/setup-env.js +17 -17
- package/dist/helper/setup-expect.js +1 -1
- package/dist/helper/setup-wasm.js +4 -4
- package/dist/helper/stringify-config.d.ts +1 -1
- package/dist/helper/stringify-config.js +3 -3
- package/dist/helper/update-snapshot.js +1 -1
- package/dist/helper/util/checkSourceMap.js +16 -17
- package/dist/helper/util/checkStats.js +3 -3
- package/dist/helper/util/expectWarningFactory.js +2 -2
- package/dist/helper/util/filterUtil.js +9 -9
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.js +13 -13
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/node/index.d.ts +2 -2
- package/dist/runner/node/index.js +75 -74
- package/dist/runner/web/index.d.ts +2 -2
- package/dist/runner/web/index.js +45 -45
- package/dist/test/context.d.ts +2 -2
- package/dist/test/context.js +4 -4
- package/dist/test/creator.d.ts +1 -1
- package/dist/test/creator.js +28 -28
- package/dist/test/debug.d.ts +1 -1
- package/dist/test/debug.js +31 -31
- package/dist/test/tester.d.ts +1 -1
- package/dist/test/tester.js +11 -11
- package/dist/type.d.ts +3 -3
- package/package.json +3 -3
- package/rstest.d.ts +12 -12
package/dist/case/esm-output.js
CHANGED
|
@@ -11,12 +11,12 @@ const runner_1 = require("./runner");
|
|
|
11
11
|
const creator = new creator_1.BasicCaseCreator({
|
|
12
12
|
clean: true,
|
|
13
13
|
describe: false,
|
|
14
|
-
testConfig: testConfig => {
|
|
14
|
+
testConfig: (testConfig) => {
|
|
15
15
|
const oldModuleScope = testConfig.moduleScope;
|
|
16
16
|
testConfig.moduleScope = (ms, stats) => {
|
|
17
17
|
let res = ms;
|
|
18
18
|
// TODO: modify runner module scope based on stats here
|
|
19
|
-
if (typeof oldModuleScope ===
|
|
19
|
+
if (typeof oldModuleScope === 'function') {
|
|
20
20
|
res = oldModuleScope(ms, stats);
|
|
21
21
|
}
|
|
22
22
|
return res;
|
|
@@ -25,11 +25,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
25
25
|
steps: ({ name }) => [
|
|
26
26
|
{
|
|
27
27
|
config: async (context) => {
|
|
28
|
-
(0, common_1.configMultiCompiler)(context, name, [
|
|
28
|
+
(0, common_1.configMultiCompiler)(context, name, ['rspack.config.cjs', 'rspack.config.js', 'webpack.config.js'], defaultOptions, (_index, context, options) => {
|
|
29
29
|
const testConfig = context.getTestConfig();
|
|
30
30
|
if (testConfig.esmLibPluginOptions) {
|
|
31
31
|
let target;
|
|
32
|
-
const otherPlugins = options.plugins?.filter(plugin => {
|
|
32
|
+
const otherPlugins = options.plugins?.filter((plugin) => {
|
|
33
33
|
const isTarget = plugin instanceof core_1.default.experiments.EsmLibraryPlugin;
|
|
34
34
|
if (isTarget) {
|
|
35
35
|
target = plugin;
|
|
@@ -40,8 +40,8 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
40
40
|
...otherPlugins,
|
|
41
41
|
new core_1.default.experiments.EsmLibraryPlugin({
|
|
42
42
|
...target.options,
|
|
43
|
-
...testConfig.esmLibPluginOptions
|
|
44
|
-
})
|
|
43
|
+
...testConfig.esmLibPluginOptions,
|
|
44
|
+
}),
|
|
45
45
|
];
|
|
46
46
|
}
|
|
47
47
|
});
|
|
@@ -55,11 +55,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
55
55
|
run: async (env, context) => {
|
|
56
56
|
await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (_index, context, options) => {
|
|
57
57
|
const testConfig = context.getTestConfig();
|
|
58
|
-
if (typeof testConfig.findBundle ===
|
|
58
|
+
if (typeof testConfig.findBundle === 'function') {
|
|
59
59
|
return testConfig.findBundle(_index, options);
|
|
60
60
|
}
|
|
61
|
-
if (options.output?.filename ===
|
|
62
|
-
return [
|
|
61
|
+
if (options.output?.filename === '[name].mjs') {
|
|
62
|
+
return ['main.mjs'];
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
65
|
return [options.output.filename];
|
|
@@ -68,53 +68,53 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
68
68
|
},
|
|
69
69
|
check: async (env, context) => {
|
|
70
70
|
await (0, common_1.check)(env, context, name);
|
|
71
|
-
await (0, common_1.checkSnapshot)(env, context, name,
|
|
71
|
+
await (0, common_1.checkSnapshot)(env, context, name, 'esm.snap.txt');
|
|
72
72
|
},
|
|
73
73
|
after: async (context) => {
|
|
74
74
|
await (0, common_1.afterExecute)(context, name);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
77
|
],
|
|
78
78
|
runner: {
|
|
79
79
|
key: runner_1.getMultiCompilerRunnerKey,
|
|
80
|
-
runner: runner_1.createMultiCompilerRunner
|
|
80
|
+
runner: runner_1.createMultiCompilerRunner,
|
|
81
81
|
},
|
|
82
|
-
concurrent: 1
|
|
82
|
+
concurrent: 1,
|
|
83
83
|
});
|
|
84
84
|
const defaultOptions = (_index, context) => ({
|
|
85
85
|
context: context.getSource(),
|
|
86
|
-
mode:
|
|
87
|
-
target:
|
|
86
|
+
mode: 'production',
|
|
87
|
+
target: 'async-node',
|
|
88
88
|
devtool: false,
|
|
89
|
-
entry:
|
|
89
|
+
entry: './index.js',
|
|
90
90
|
cache: false,
|
|
91
91
|
output: {
|
|
92
92
|
path: context.getDist(),
|
|
93
|
-
filename:
|
|
93
|
+
filename: '[name].mjs',
|
|
94
94
|
pathinfo: true,
|
|
95
|
-
module: true
|
|
95
|
+
module: true,
|
|
96
96
|
},
|
|
97
97
|
bail: true,
|
|
98
98
|
optimization: {
|
|
99
99
|
minimize: false,
|
|
100
|
-
moduleIds:
|
|
101
|
-
chunkIds:
|
|
102
|
-
runtimeChunk:
|
|
100
|
+
moduleIds: 'named',
|
|
101
|
+
chunkIds: 'named',
|
|
102
|
+
runtimeChunk: 'single',
|
|
103
103
|
},
|
|
104
104
|
externals: {
|
|
105
|
-
fs:
|
|
106
|
-
path:
|
|
105
|
+
fs: 'module-import fs',
|
|
106
|
+
path: 'module-import path',
|
|
107
107
|
},
|
|
108
108
|
plugins: [new core_1.default.experiments.EsmLibraryPlugin()],
|
|
109
109
|
experiments: {
|
|
110
110
|
css: true,
|
|
111
111
|
rspackFuture: {
|
|
112
112
|
bundlerInfo: {
|
|
113
|
-
force: false
|
|
114
|
-
}
|
|
113
|
+
force: false,
|
|
114
|
+
},
|
|
115
115
|
},
|
|
116
|
-
outputModule: true
|
|
117
|
-
}
|
|
116
|
+
outputModule: true,
|
|
117
|
+
},
|
|
118
118
|
});
|
|
119
119
|
function createEsmOutputCase(name, src, dist) {
|
|
120
120
|
creator.create(name, src, dist);
|
package/dist/case/example.js
CHANGED
|
@@ -12,16 +12,16 @@ function overrideOptions(index, context, options) {
|
|
|
12
12
|
options.output = options.output || {};
|
|
13
13
|
options.output.pathinfo = true;
|
|
14
14
|
options.output.path = context.getDist();
|
|
15
|
-
options.output.publicPath =
|
|
15
|
+
options.output.publicPath = 'dist/';
|
|
16
16
|
if (!options.entry)
|
|
17
|
-
options.entry =
|
|
17
|
+
options.entry = './example.js';
|
|
18
18
|
if (!options.plugins)
|
|
19
19
|
options.plugins = [];
|
|
20
20
|
}
|
|
21
21
|
function createExampleProcessor(name) {
|
|
22
22
|
return {
|
|
23
23
|
config: async (context) => {
|
|
24
|
-
(0, common_1.configMultiCompiler)(context, name, [
|
|
24
|
+
(0, common_1.configMultiCompiler)(context, name, ['rspack.config.js', 'webpack.config.js'], () => ({}), overrideOptions);
|
|
25
25
|
},
|
|
26
26
|
compiler: async (context) => {
|
|
27
27
|
await (0, common_1.compiler)(context, name);
|
|
@@ -40,18 +40,18 @@ function createExampleProcessor(name) {
|
|
|
40
40
|
all: false,
|
|
41
41
|
errors: true,
|
|
42
42
|
errorDetails: true,
|
|
43
|
-
errorStack: true
|
|
43
|
+
errorStack: true,
|
|
44
44
|
}));
|
|
45
45
|
}
|
|
46
46
|
expect(stats?.hasErrors()).toBe(false);
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
const creator = new creator_1.BasicCaseCreator({
|
|
51
51
|
clean: true,
|
|
52
52
|
steps: ({ name }) => [createExampleProcessor(name)],
|
|
53
|
-
concurrent: true
|
|
53
|
+
concurrent: true,
|
|
54
54
|
});
|
|
55
55
|
function createExampleCase(name, src) {
|
|
56
|
-
creator.create(name, src, node_path_1.default.join(src,
|
|
56
|
+
creator.create(name, src, node_path_1.default.join(src, 'dist'));
|
|
57
57
|
}
|
package/dist/case/hash.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { TTestConfig } from
|
|
2
|
-
export type THashCaseConfig = Pick<TTestConfig,
|
|
1
|
+
import type { TTestConfig } from '../type';
|
|
2
|
+
export type THashCaseConfig = Pick<TTestConfig, 'validate'>;
|
|
3
3
|
export declare function createHashCase(name: string, src: string, dist: string): void;
|
package/dist/case/hash.js
CHANGED
|
@@ -20,7 +20,7 @@ const creator = new HashCaseCreator({
|
|
|
20
20
|
steps: ({ name }) => [
|
|
21
21
|
{
|
|
22
22
|
config: async (context) => {
|
|
23
|
-
(0, common_1.configMultiCompiler)(context, name, [
|
|
23
|
+
(0, common_1.configMultiCompiler)(context, name, ['rspack.config.js', 'webpack.config.js'], defaultOptions, overrideOptions);
|
|
24
24
|
},
|
|
25
25
|
compiler: async (context) => {
|
|
26
26
|
await (0, common_1.compiler)(context, name);
|
|
@@ -33,9 +33,9 @@ const creator = new HashCaseCreator({
|
|
|
33
33
|
},
|
|
34
34
|
check: async (env, context) => {
|
|
35
35
|
await check(env, context, name);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
]
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
39
|
});
|
|
40
40
|
function createHashCase(name, src, dist) {
|
|
41
41
|
creator.create(name, src, dist);
|
|
@@ -44,25 +44,25 @@ function defaultOptions(index, context) {
|
|
|
44
44
|
return {
|
|
45
45
|
context: context.getSource(),
|
|
46
46
|
output: {
|
|
47
|
-
path: context.getDist()
|
|
47
|
+
path: context.getDist(),
|
|
48
48
|
},
|
|
49
49
|
experiments: {
|
|
50
50
|
css: true,
|
|
51
51
|
rspackFuture: {
|
|
52
52
|
bundlerInfo: {
|
|
53
|
-
force: false
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
53
|
+
force: false,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
function overrideOptions(index, context, options) {
|
|
60
60
|
if (!options.entry) {
|
|
61
|
-
options.entry =
|
|
61
|
+
options.entry = './index.js';
|
|
62
62
|
}
|
|
63
63
|
if (!global.printLogger) {
|
|
64
64
|
options.infrastructureLogging = {
|
|
65
|
-
level:
|
|
65
|
+
level: 'error',
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -71,11 +71,11 @@ async function check(env, context, name) {
|
|
|
71
71
|
const stats = compiler.getStats();
|
|
72
72
|
const testConfig = context.getTestConfig();
|
|
73
73
|
if (!stats) {
|
|
74
|
-
throw new Error(
|
|
74
|
+
throw new Error('No stats found\n' +
|
|
75
75
|
context
|
|
76
76
|
.getError()
|
|
77
|
-
.map(e => e.stack)
|
|
78
|
-
.join(
|
|
77
|
+
.map((e) => e.stack)
|
|
78
|
+
.join('\n'));
|
|
79
79
|
}
|
|
80
80
|
if (REG_ERROR_CASE.test(name)) {
|
|
81
81
|
env.expect(stats.hasErrors());
|
|
@@ -83,10 +83,10 @@ async function check(env, context, name) {
|
|
|
83
83
|
else {
|
|
84
84
|
env.expect(!stats.hasErrors());
|
|
85
85
|
}
|
|
86
|
-
if (typeof testConfig.validate ===
|
|
86
|
+
if (typeof testConfig.validate === 'function') {
|
|
87
87
|
testConfig.validate(stats);
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
throw new Error(
|
|
90
|
+
throw new Error('HashTestCases should have test.config.js and a validate method');
|
|
91
91
|
}
|
|
92
92
|
}
|
package/dist/case/hook.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Compiler, type RspackOptions } from
|
|
2
|
-
import { TestContext, type TTestContextOptions } from
|
|
3
|
-
import type { ITestContext, ITestEnv } from
|
|
1
|
+
import { Compiler, type RspackOptions } from '@rspack/core';
|
|
2
|
+
import { TestContext, type TTestContextOptions } from '../test/context';
|
|
3
|
+
import type { ITestContext, ITestEnv } from '../type';
|
|
4
4
|
export declare function createHookCase(name: string, src: string, dist: string, source: string): void;
|
|
5
5
|
export declare class HookCasesContext extends TestContext {
|
|
6
6
|
protected src: string;
|
package/dist/case/hook.js
CHANGED
|
@@ -15,7 +15,7 @@ const context_1 = require("../test/context");
|
|
|
15
15
|
const creator_1 = require("../test/creator");
|
|
16
16
|
const common_1 = require("./common");
|
|
17
17
|
const srcDir = __TEST_FIXTURES_PATH__;
|
|
18
|
-
const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__,
|
|
18
|
+
const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__, 'hook');
|
|
19
19
|
const creator = new creator_1.BasicCaseCreator({
|
|
20
20
|
clean: true,
|
|
21
21
|
describe: true,
|
|
@@ -26,10 +26,10 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
26
26
|
{
|
|
27
27
|
config: async (context) => {
|
|
28
28
|
const compiler = context.getCompiler();
|
|
29
|
-
const options = await (0, common_1.config)(context, name, [
|
|
29
|
+
const options = await (0, common_1.config)(context, name, ['rspack.config.js', 'webpack.config.js'], defaultOptions(context, caseConfig.options));
|
|
30
30
|
if (!global.printLogger) {
|
|
31
31
|
options.infrastructureLogging = {
|
|
32
|
-
level:
|
|
32
|
+
level: 'error',
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
compiler.setOptions(options);
|
|
@@ -47,14 +47,14 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
47
47
|
// no need to run, just check snapshot
|
|
48
48
|
},
|
|
49
49
|
check: async (env, context) => {
|
|
50
|
-
await (0, common_1.checkSnapshot)(env, context, name, node_path_1.default.join(src,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
50
|
+
await (0, common_1.checkSnapshot)(env, context, name, node_path_1.default.join(src, 'output.snap.txt'), caseConfig.snapshotFileFilter);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
53
|
];
|
|
54
|
-
}
|
|
54
|
+
},
|
|
55
55
|
});
|
|
56
56
|
function createHookCase(name, src, dist, source) {
|
|
57
|
-
const caseConfig = require(node_path_1.default.join(src,
|
|
57
|
+
const caseConfig = require(node_path_1.default.join(src, 'test.js'));
|
|
58
58
|
const testName = node_path_1.default.basename(name.slice(0, name.indexOf(node_path_1.default.extname(name))));
|
|
59
59
|
creator.create(name, src, dist, undefined, {
|
|
60
60
|
caseConfig,
|
|
@@ -62,8 +62,8 @@ function createHookCase(name, src, dist, source) {
|
|
|
62
62
|
createContext: (config) => new HookCasesContext(src, testName, {
|
|
63
63
|
src: source,
|
|
64
64
|
dist: dist,
|
|
65
|
-
name: name
|
|
66
|
-
})
|
|
65
|
+
name: name,
|
|
66
|
+
}),
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
const sourceSerializer = {
|
|
@@ -72,7 +72,7 @@ const sourceSerializer = {
|
|
|
72
72
|
},
|
|
73
73
|
print(val) {
|
|
74
74
|
return val.source();
|
|
75
|
-
}
|
|
75
|
+
},
|
|
76
76
|
};
|
|
77
77
|
const internalSerializer = {
|
|
78
78
|
test(val) {
|
|
@@ -80,23 +80,23 @@ const internalSerializer = {
|
|
|
80
80
|
},
|
|
81
81
|
print(val) {
|
|
82
82
|
return JSON.stringify(`${val.constructor.name}(internal ignored)`);
|
|
83
|
-
}
|
|
83
|
+
},
|
|
84
84
|
};
|
|
85
85
|
const testPathSerializer = (0, path_serializer_1.createSnapshotSerializer)({
|
|
86
86
|
replace: [
|
|
87
87
|
{
|
|
88
88
|
match: srcDir,
|
|
89
|
-
mark:
|
|
89
|
+
mark: '<HOOK_SRC_DIR>',
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
92
|
match: distDir,
|
|
93
|
-
mark:
|
|
94
|
-
}
|
|
95
|
-
]
|
|
93
|
+
mark: '<HOOK_DIST_DIR>',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
96
|
});
|
|
97
97
|
const escapeRegex = true;
|
|
98
98
|
const printFunctionName = false;
|
|
99
|
-
const normalizeNewlines = (str) => str.replace(/\r\n|\r/g,
|
|
99
|
+
const normalizeNewlines = (str) => str.replace(/\r\n|\r/g, '\n');
|
|
100
100
|
const serialize = (val, indent = 2, formatOverrides = {}) => normalizeNewlines((0, pretty_format_1.format)(val, {
|
|
101
101
|
escapeRegex,
|
|
102
102
|
indent,
|
|
@@ -104,10 +104,10 @@ const serialize = (val, indent = 2, formatOverrides = {}) => normalizeNewlines((
|
|
|
104
104
|
...(0, jest_snapshot_1.getSerializers)(),
|
|
105
105
|
sourceSerializer,
|
|
106
106
|
internalSerializer,
|
|
107
|
-
testPathSerializer
|
|
107
|
+
testPathSerializer,
|
|
108
108
|
],
|
|
109
109
|
printFunctionName,
|
|
110
|
-
...formatOverrides
|
|
110
|
+
...formatOverrides,
|
|
111
111
|
}));
|
|
112
112
|
class HookCasesContext extends context_1.TestContext {
|
|
113
113
|
constructor(src, testName, options) {
|
|
@@ -127,28 +127,28 @@ class HookCasesContext extends context_1.TestContext {
|
|
|
127
127
|
* @example
|
|
128
128
|
* compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
|
|
129
129
|
*/
|
|
130
|
-
snapped(cb, prefix =
|
|
130
|
+
snapped(cb, prefix = '') {
|
|
131
131
|
// eslint-disable-next-line
|
|
132
132
|
const context = this;
|
|
133
133
|
return function SNAPPED_HOOK(...args) {
|
|
134
134
|
const group = prefix ? prefix : context.count++;
|
|
135
|
-
context._addSnapshot(args,
|
|
135
|
+
context._addSnapshot(args, 'input', group);
|
|
136
136
|
const output = cb.apply(this, args);
|
|
137
|
-
if (output && typeof output.then ===
|
|
137
|
+
if (output && typeof output.then === 'function') {
|
|
138
138
|
let resolve;
|
|
139
|
-
context.promises.push(new Promise(r => (resolve = r)));
|
|
139
|
+
context.promises.push(new Promise((r) => (resolve = r)));
|
|
140
140
|
return output
|
|
141
141
|
.then((o) => {
|
|
142
|
-
context._addSnapshot(o,
|
|
142
|
+
context._addSnapshot(o, 'output (Promise resolved)', group);
|
|
143
143
|
return o;
|
|
144
144
|
})
|
|
145
145
|
.catch((o) => {
|
|
146
|
-
context._addSnapshot(o,
|
|
146
|
+
context._addSnapshot(o, 'output (Promise rejected)', group);
|
|
147
147
|
return o;
|
|
148
148
|
})
|
|
149
149
|
.finally(resolve);
|
|
150
150
|
}
|
|
151
|
-
context._addSnapshot(output,
|
|
151
|
+
context._addSnapshot(output, 'output', group);
|
|
152
152
|
return output;
|
|
153
153
|
};
|
|
154
154
|
}
|
|
@@ -160,11 +160,11 @@ class HookCasesContext extends context_1.TestContext {
|
|
|
160
160
|
? content
|
|
161
161
|
: serialize(content, undefined, {
|
|
162
162
|
escapeString: true,
|
|
163
|
-
printBasicPrototype: true
|
|
164
|
-
}).replace(/\r\n/g,
|
|
163
|
+
printBasicPrototype: true,
|
|
164
|
+
}).replace(/\r\n/g, '\n');
|
|
165
165
|
(this.snapshots[group] = this.snapshots[group] || []).push([
|
|
166
166
|
normalizedContent,
|
|
167
|
-
name
|
|
167
|
+
name,
|
|
168
168
|
]);
|
|
169
169
|
if (!this.snapshotsList.includes(group)) {
|
|
170
170
|
this.snapshotsList.push(group);
|
|
@@ -174,7 +174,7 @@ class HookCasesContext extends context_1.TestContext {
|
|
|
174
174
|
* @internal
|
|
175
175
|
*/
|
|
176
176
|
async collectSnapshots(env, options = {
|
|
177
|
-
diff: {}
|
|
177
|
+
diff: {},
|
|
178
178
|
}) {
|
|
179
179
|
await Promise.allSettled(this.promises);
|
|
180
180
|
if (!this.snapshotsList.length)
|
|
@@ -184,37 +184,37 @@ class HookCasesContext extends context_1.TestContext {
|
|
|
184
184
|
name = `## ${name || `test: ${index}`}\n\n`;
|
|
185
185
|
const block = `\`\`\`javascript\n${content}\n\`\`\`\n`;
|
|
186
186
|
return `${acc}${name + block}\n`;
|
|
187
|
-
},
|
|
187
|
+
}, '');
|
|
188
188
|
return `${acc}# ${Number.isInteger(group) ? `Group: ${index}` : group}\n\n${block}`;
|
|
189
|
-
},
|
|
189
|
+
}, '');
|
|
190
190
|
env
|
|
191
191
|
.expect(snapshots)
|
|
192
|
-
.toMatchFileSnapshotSync(node_path_1.default.join(this.src,
|
|
192
|
+
.toMatchFileSnapshotSync(node_path_1.default.join(this.src, 'hooks.snap.txt'), options);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
exports.HookCasesContext = HookCasesContext;
|
|
196
196
|
function defaultOptions(context, custom) {
|
|
197
197
|
let defaultOptions = {
|
|
198
198
|
context: context.getSource(),
|
|
199
|
-
mode:
|
|
200
|
-
target:
|
|
199
|
+
mode: 'production',
|
|
200
|
+
target: 'async-node',
|
|
201
201
|
devtool: false,
|
|
202
202
|
cache: false,
|
|
203
|
-
entry:
|
|
203
|
+
entry: './hook',
|
|
204
204
|
output: {
|
|
205
|
-
path: context.getDist()
|
|
205
|
+
path: context.getDist(),
|
|
206
206
|
},
|
|
207
207
|
optimization: {
|
|
208
|
-
minimize: false
|
|
208
|
+
minimize: false,
|
|
209
209
|
},
|
|
210
210
|
experiments: {
|
|
211
211
|
css: true,
|
|
212
212
|
rspackFuture: {
|
|
213
213
|
bundlerInfo: {
|
|
214
|
-
force: false
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
214
|
+
force: false,
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
218
|
};
|
|
219
219
|
if (custom) {
|
|
220
220
|
defaultOptions = (0, webpack_merge_1.default)(defaultOptions, custom(context));
|
package/dist/case/hot-step.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RspackOptions } from
|
|
2
|
-
export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: RspackOptions[
|
|
1
|
+
import type { RspackOptions } from '@rspack/core';
|
|
2
|
+
export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: RspackOptions['target']): void;
|