@rspack-debug/test-tools 1.4.11 → 1.6.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/README.md +1 -1
- package/dist/case/builtin.d.ts +3 -0
- package/dist/case/builtin.js +152 -14
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +214 -12
- package/dist/case/common.d.ts +11 -0
- package/dist/case/common.js +249 -0
- package/dist/case/compiler.d.ts +17 -4
- package/dist/case/compiler.js +149 -12
- package/dist/case/config.d.ts +7 -2
- package/dist/case/config.js +106 -18
- package/dist/case/defaults.d.ts +13 -4
- package/dist/case/defaults.js +73 -18
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +121 -14
- package/dist/case/error.d.ts +15 -4
- package/dist/case/error.js +137 -12
- package/dist/case/esm-output.d.ts +1 -0
- package/dist/case/esm-output.js +117 -0
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +72 -9
- package/dist/case/hook.d.ts +36 -4
- package/dist/case/hook.js +209 -20
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +309 -13
- package/dist/case/hot.d.ts +11 -2
- package/dist/case/hot.js +217 -12
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +24 -45
- package/dist/case/index.d.ts +31 -20
- package/dist/case/index.js +50 -34
- package/dist/case/multi-compiler.d.ts +19 -0
- package/dist/case/multi-compiler.js +97 -0
- package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
- package/dist/case/normal.d.ts +3 -0
- package/dist/case/normal.js +202 -18
- package/dist/case/runner.d.ts +19 -0
- package/dist/case/runner.js +113 -0
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +10 -14
- package/dist/case/stats-api.d.ts +8 -3
- package/dist/case/stats-api.js +69 -10
- package/dist/case/stats-output.d.ts +11 -0
- package/dist/case/stats-output.js +199 -8
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +318 -22
- package/dist/compiler.d.ts +16 -16
- package/dist/compiler.js +120 -15
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +6 -2
- package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
- package/dist/helper/disable-iconv-lite-warning.js +12 -0
- package/dist/helper/expect/error.js +1 -1
- package/dist/helper/expect/placeholder.js +7 -7
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
- package/dist/helper/expect/to-match-file-snapshot.js +3 -3
- package/dist/helper/hot-update/loader.d.ts +2 -1
- package/dist/helper/hot-update/loader.js +5 -30
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +14 -13
- package/dist/helper/index.d.ts +2 -1
- package/dist/helper/index.js +2 -1
- package/dist/helper/is.d.ts +2 -0
- package/dist/helper/is.js +15 -0
- package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
- package/dist/helper/legacy/LogTestPlugin.js +35 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
- package/dist/helper/legacy/checkArrayExpectation.js +8 -8
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
- package/dist/helper/legacy/createLazyTestEnv.js +3 -3
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/expectSource.d.ts +10 -0
- package/dist/helper/legacy/expectSource.js +23 -0
- package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
- package/dist/helper/legacy/findOutputFiles.js +14 -0
- package/dist/helper/legacy/regexEscape.d.ts +2 -0
- package/dist/helper/legacy/regexEscape.js +5 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/helper/read-config-file.js +12 -2
- package/dist/helper/setup-env.js +26 -4
- package/dist/helper/setup-expect.js +2 -2
- package/dist/helper/setup-wasm.js +2 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/helper/util/checkStats.d.ts +0 -1
- package/dist/helper/util/checkStats.js +0 -18
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.js +1 -4
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
- package/dist/runner/index.d.ts +2 -9
- package/dist/runner/index.js +2 -9
- package/dist/runner/node/index.d.ts +41 -0
- package/dist/runner/node/index.js +450 -0
- package/dist/runner/web/index.d.ts +30 -0
- package/dist/runner/web/index.js +343 -0
- package/dist/test/context.d.ts +15 -18
- package/dist/test/context.js +52 -57
- package/dist/test/creator.d.ts +20 -19
- package/dist/test/creator.js +69 -57
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +44 -6
- package/dist/type.d.ts +94 -64
- package/dist/type.js +8 -12
- package/package.json +22 -61
- package/rstest.d.ts +24 -0
- package/dist/case/diff.d.ts +0 -3
- package/dist/case/diff.js +0 -126
- package/dist/compare/comparator.d.ts +0 -17
- package/dist/compare/comparator.js +0 -52
- package/dist/compare/compare.d.ts +0 -17
- package/dist/compare/compare.js +0 -175
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -239
- package/dist/compare/index.d.ts +0 -5
- package/dist/compare/index.js +0 -21
- package/dist/compare/replace-module-argument.d.ts +0 -1
- package/dist/compare/replace-module-argument.js +0 -8
- package/dist/compare/replace-runtime-module-name.d.ts +0 -1
- package/dist/compare/replace-runtime-module-name.js +0 -71
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -278
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
- package/dist/helper/legacy/supportsImportFn.js +0 -15
- package/dist/helper/legacy/supportsWorker.js +0 -17
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
- package/dist/helper/legacy/warmup-webpack.js +0 -26
- package/dist/helper/loaders/hot-update.d.ts +0 -1
- package/dist/helper/loaders/hot-update.js +0 -40
- package/dist/helper/plugins/hot-update.d.ts +0 -7
- package/dist/helper/plugins/hot-update.js +0 -40
- package/dist/helper/plugins/index.d.ts +0 -1
- package/dist/helper/plugins/index.js +0 -17
- package/dist/helper/util/currentWatchStep.d.ts +0 -1
- package/dist/helper/util/currentWatchStep.js +0 -2
- package/dist/helper/util/identifier.d.ts +0 -76
- package/dist/helper/util/identifier.js +0 -339
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
- package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
- package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/rspack-diff-config-plugin.js +0 -42
- package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/webpack-diff-config-plugin.js +0 -41
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
- package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
- package/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -146
- package/dist/processor/builtin.d.ts +0 -9
- package/dist/processor/builtin.js +0 -171
- package/dist/processor/cache.d.ts +0 -20
- package/dist/processor/cache.js +0 -128
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -81
- package/dist/processor/defaults.d.ts +0 -30
- package/dist/processor/defaults.js +0 -72
- package/dist/processor/diagnostic.d.ts +0 -15
- package/dist/processor/diagnostic.js +0 -102
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/error.d.ts +0 -23
- package/dist/processor/error.js +0 -95
- package/dist/processor/hash.d.ts +0 -10
- package/dist/processor/hash.js +0 -63
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -204
- package/dist/processor/hot-incremental.d.ts +0 -14
- package/dist/processor/hot-incremental.js +0 -43
- package/dist/processor/hot-step.d.ts +0 -18
- package/dist/processor/hot-step.js +0 -304
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -140
- package/dist/processor/index.d.ts +0 -20
- package/dist/processor/index.js +0 -36
- package/dist/processor/multi.d.ts +0 -17
- package/dist/processor/multi.js +0 -73
- package/dist/processor/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -150
- package/dist/processor/simple.d.ts +0 -23
- package/dist/processor/simple.js +0 -49
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -66
- package/dist/processor/stats-api.d.ts +0 -18
- package/dist/processor/stats-api.js +0 -48
- package/dist/processor/stats.d.ts +0 -18
- package/dist/processor/stats.js +0 -206
- package/dist/processor/treeshaking.d.ts +0 -10
- package/dist/processor/treeshaking.js +0 -33
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -241
- package/dist/reporter/diff-html.d.ts +0 -15
- package/dist/reporter/diff-html.js +0 -69
- package/dist/reporter/diff-stats.d.ts +0 -24
- package/dist/reporter/diff-stats.js +0 -131
- package/dist/reporter/index.d.ts +0 -2
- package/dist/reporter/index.js +0 -18
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -63
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -90
- package/dist/runner/hot-step.d.ts +0 -5
- package/dist/runner/hot-step.js +0 -87
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -83
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -38
- package/dist/runner/normal.d.ts +0 -5
- package/dist/runner/normal.js +0 -20
- package/dist/runner/runner/basic.d.ts +0 -30
- package/dist/runner/runner/basic.js +0 -107
- package/dist/runner/runner/cjs.d.ts +0 -14
- package/dist/runner/runner/cjs.js +0 -151
- package/dist/runner/runner/esm.d.ts +0 -7
- package/dist/runner/runner/esm.js +0 -125
- package/dist/runner/runner/index.d.ts +0 -8
- package/dist/runner/runner/index.js +0 -24
- package/dist/runner/runner/normal.d.ts +0 -9
- package/dist/runner/runner/normal.js +0 -23
- package/dist/runner/runner/watch.d.ts +0 -16
- package/dist/runner/runner/watch.js +0 -27
- package/dist/runner/runner/web/fake.d.ts +0 -18
- package/dist/runner/runner/web/fake.js +0 -143
- package/dist/runner/runner/web/jsdom.d.ts +0 -26
- package/dist/runner/runner/web/jsdom.js +0 -219
- package/dist/runner/runner/web.d.ts +0 -15
- package/dist/runner/runner/web.js +0 -32
- package/dist/runner/type.d.ts +0 -42
- package/dist/runner/type.js +0 -9
- package/dist/runner/watch.d.ts +0 -7
- package/dist/runner/watch.js +0 -60
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
- package/jest.d.ts +0 -25
- package/template/diff.bundle.css +0 -1
- package/template/diff.bundle.js +0 -144
- package/template/diff.html +0 -14
- package/template/editor.worker.js +0 -1
- /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
- /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
package/dist/case/hash.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createHashCase = createHashCase;
|
|
4
|
-
const processor_1 = require("../processor");
|
|
5
4
|
const creator_1 = require("../test/creator");
|
|
6
|
-
const
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
const REG_ERROR_CASE = /error$/;
|
|
7
7
|
class HashCaseCreator extends creator_1.BasicCaseCreator {
|
|
8
|
-
describe(name, tester, testConfig) {
|
|
8
|
+
describe(name, tester, testConfig, options) {
|
|
9
9
|
it(`should print correct hash for ${name}`, async () => {
|
|
10
10
|
await tester.prepare();
|
|
11
11
|
await tester.compile();
|
|
12
|
-
await tester.check(this.createEnv(testConfig));
|
|
12
|
+
await tester.check(this.createEnv(testConfig, options));
|
|
13
13
|
await tester.resume();
|
|
14
14
|
}, 30000);
|
|
15
15
|
}
|
|
@@ -18,13 +18,76 @@ const creator = new HashCaseCreator({
|
|
|
18
18
|
clean: true,
|
|
19
19
|
describe: false,
|
|
20
20
|
steps: ({ name }) => [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
{
|
|
22
|
+
config: async (context) => {
|
|
23
|
+
(0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions, overrideOptions);
|
|
24
|
+
},
|
|
25
|
+
compiler: async (context) => {
|
|
26
|
+
await (0, common_1.compiler)(context, name);
|
|
27
|
+
},
|
|
28
|
+
build: async (context) => {
|
|
29
|
+
await (0, common_1.build)(context, name);
|
|
30
|
+
},
|
|
31
|
+
run: async (env, context) => {
|
|
32
|
+
// no need to run, just check snapshot
|
|
33
|
+
},
|
|
34
|
+
check: async (env, context) => {
|
|
35
|
+
await check(env, context, name);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
26
38
|
]
|
|
27
39
|
});
|
|
28
40
|
function createHashCase(name, src, dist) {
|
|
29
41
|
creator.create(name, src, dist);
|
|
30
42
|
}
|
|
43
|
+
function defaultOptions(index, context) {
|
|
44
|
+
return {
|
|
45
|
+
context: context.getSource(),
|
|
46
|
+
output: {
|
|
47
|
+
path: context.getDist()
|
|
48
|
+
},
|
|
49
|
+
experiments: {
|
|
50
|
+
css: true,
|
|
51
|
+
rspackFuture: {
|
|
52
|
+
bundlerInfo: {
|
|
53
|
+
force: false
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
inlineConst: true
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function overrideOptions(index, context, options) {
|
|
61
|
+
if (!options.entry) {
|
|
62
|
+
options.entry = "./index.js";
|
|
63
|
+
}
|
|
64
|
+
if (!global.printLogger) {
|
|
65
|
+
options.infrastructureLogging = {
|
|
66
|
+
level: "error"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function check(env, context, name) {
|
|
71
|
+
const compiler = context.getCompiler();
|
|
72
|
+
const stats = compiler.getStats();
|
|
73
|
+
const testConfig = context.getTestConfig();
|
|
74
|
+
if (!stats) {
|
|
75
|
+
throw new Error("No stats found\n" +
|
|
76
|
+
context
|
|
77
|
+
.getError()
|
|
78
|
+
.map(e => e.stack)
|
|
79
|
+
.join("\n"));
|
|
80
|
+
}
|
|
81
|
+
if (REG_ERROR_CASE.test(name)) {
|
|
82
|
+
env.expect(stats.hasErrors());
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
env.expect(!stats.hasErrors());
|
|
86
|
+
}
|
|
87
|
+
if (typeof testConfig.validate === "function") {
|
|
88
|
+
testConfig.validate(stats);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error("HashTestCases should have test.config.js and a validate method");
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/case/hook.d.ts
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { Compiler, type RspackOptions } from "@rspack/core";
|
|
2
|
+
import { TestContext, type TTestContextOptions } from "../test/context";
|
|
3
|
+
import type { ITestContext, ITestEnv } from "../type";
|
|
4
|
+
export declare function createHookCase(name: string, src: string, dist: string, source: string): void;
|
|
5
|
+
export declare class HookCasesContext extends TestContext {
|
|
6
|
+
protected src: string;
|
|
7
|
+
protected testName: string;
|
|
8
|
+
protected options: TTestContextOptions;
|
|
9
|
+
protected promises: Promise<void>[];
|
|
10
|
+
protected count: number;
|
|
11
|
+
protected snapshots: Record<string | number, Array<[string | Buffer, string]>>;
|
|
12
|
+
protected snapshotsList: Array<string | number>;
|
|
13
|
+
constructor(src: string, testName: string, options: TTestContextOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Snapshot function arguments and return value.
|
|
16
|
+
* Generated snapshot is located in the same directory with the test source.
|
|
17
|
+
* @example
|
|
18
|
+
* compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
|
|
19
|
+
*/
|
|
20
|
+
snapped(cb: (...args: unknown[]) => Promise<unknown>, prefix?: string): (this: any, ...args: unknown[]) => Promise<unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
_addSnapshot(content: unknown, name: string, group: string | number): void;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
collectSnapshots(env: ITestEnv, options?: {
|
|
29
|
+
diff: {};
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export type THookCaseConfig = {
|
|
33
|
+
options?: (context: ITestContext) => RspackOptions;
|
|
34
|
+
compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
|
|
35
|
+
check?: (context: ITestContext) => Promise<void>;
|
|
36
|
+
snapshotFileFilter?: (file: string) => boolean;
|
|
4
37
|
description: string;
|
|
5
38
|
};
|
|
6
|
-
export declare function createHookCase(name: string, src: string, dist: string, source: string): void;
|
package/dist/case/hook.js
CHANGED
|
@@ -3,33 +3,222 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HookCasesContext = void 0;
|
|
6
7
|
exports.createHookCase = createHookCase;
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
10
|
+
const jest_snapshot_1 = require("jest-snapshot");
|
|
11
|
+
const path_serializer_1 = require("path-serializer");
|
|
12
|
+
const pretty_format_1 = require("pretty-format");
|
|
13
|
+
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
14
|
+
const context_1 = require("../test/context");
|
|
15
|
+
const creator_1 = require("../test/creator");
|
|
16
|
+
const common_1 = require("./common");
|
|
17
|
+
const srcDir = __TEST_FIXTURES_PATH__;
|
|
18
|
+
const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__, "hook");
|
|
19
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
20
|
+
clean: true,
|
|
21
|
+
describe: true,
|
|
22
|
+
createContext: (config) => new HookCasesContext(config.src, config.name, config),
|
|
23
|
+
steps: ({ name, caseConfig: _caseConfig, src }) => {
|
|
24
|
+
const caseConfig = _caseConfig;
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
config: async (context) => {
|
|
28
|
+
const compiler = context.getCompiler();
|
|
29
|
+
const options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], defaultOptions(context, caseConfig.options));
|
|
30
|
+
if (!global.printLogger) {
|
|
31
|
+
options.infrastructureLogging = {
|
|
32
|
+
level: "error"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
compiler.setOptions(options);
|
|
36
|
+
},
|
|
37
|
+
compiler: async (context) => {
|
|
38
|
+
const c = await (0, common_1.compiler)(context, name);
|
|
39
|
+
if (caseConfig.compiler) {
|
|
40
|
+
await caseConfig.compiler(context, c);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
build: async (context) => {
|
|
44
|
+
await (0, common_1.build)(context, name);
|
|
45
|
+
},
|
|
46
|
+
run: async (env, context) => {
|
|
47
|
+
// no need to run, just check snapshot
|
|
48
|
+
},
|
|
49
|
+
check: async (env, context) => {
|
|
50
|
+
await (0, common_1.checkSnapshot)(env, context, name, node_path_1.default.join(src, "output.snap.txt"), caseConfig.snapshotFileFilter);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
13
56
|
function createHookCase(name, src, dist, source) {
|
|
14
57
|
const caseConfig = require(node_path_1.default.join(src, "test.js"));
|
|
15
58
|
const testName = node_path_1.default.basename(name.slice(0, name.indexOf(node_path_1.default.extname(name))));
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
59
|
+
creator.create(name, src, dist, undefined, {
|
|
60
|
+
caseConfig,
|
|
61
|
+
description: () => caseConfig.description,
|
|
62
|
+
createContext: (config) => new HookCasesContext(src, testName, {
|
|
19
63
|
src: source,
|
|
20
64
|
dist: dist,
|
|
21
|
-
|
|
65
|
+
name: name
|
|
22
66
|
})
|
|
23
67
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
68
|
+
}
|
|
69
|
+
const sourceSerializer = {
|
|
70
|
+
test(val) {
|
|
71
|
+
return val instanceof core_1.sources.Source;
|
|
72
|
+
},
|
|
73
|
+
print(val) {
|
|
74
|
+
return val.source();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const internalSerializer = {
|
|
78
|
+
test(val) {
|
|
79
|
+
return val instanceof core_1.Compiler || val instanceof core_1.Compilation;
|
|
80
|
+
},
|
|
81
|
+
print(val) {
|
|
82
|
+
return JSON.stringify(`${val.constructor.name}(internal ignored)`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const testPathSerializer = (0, path_serializer_1.createSnapshotSerializer)({
|
|
86
|
+
replace: [
|
|
87
|
+
{
|
|
88
|
+
match: srcDir,
|
|
89
|
+
mark: "<HOOK_SRC_DIR>"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
match: distDir,
|
|
93
|
+
mark: "<HOOK_DIST_DIR>"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
const escapeRegex = true;
|
|
98
|
+
const printFunctionName = false;
|
|
99
|
+
const normalizeNewlines = (str) => str.replace(/\r\n|\r/g, "\n");
|
|
100
|
+
const serialize = (val, indent = 2, formatOverrides = {}) => normalizeNewlines((0, pretty_format_1.format)(val, {
|
|
101
|
+
escapeRegex,
|
|
102
|
+
indent,
|
|
103
|
+
plugins: [
|
|
104
|
+
...(0, jest_snapshot_1.getSerializers)(),
|
|
105
|
+
sourceSerializer,
|
|
106
|
+
internalSerializer,
|
|
107
|
+
testPathSerializer
|
|
108
|
+
],
|
|
109
|
+
printFunctionName,
|
|
110
|
+
...formatOverrides
|
|
111
|
+
}));
|
|
112
|
+
class HookCasesContext extends context_1.TestContext {
|
|
113
|
+
constructor(src, testName, options) {
|
|
114
|
+
super(options);
|
|
115
|
+
this.src = src;
|
|
116
|
+
this.testName = testName;
|
|
117
|
+
this.options = options;
|
|
118
|
+
this.promises = [];
|
|
119
|
+
this.count = 0;
|
|
120
|
+
this.snapshots = {};
|
|
121
|
+
this.snapshotsList = [];
|
|
122
|
+
this.snapped = this.snapped.bind(this);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Snapshot function arguments and return value.
|
|
126
|
+
* Generated snapshot is located in the same directory with the test source.
|
|
127
|
+
* @example
|
|
128
|
+
* compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
|
|
129
|
+
*/
|
|
130
|
+
snapped(cb, prefix = "") {
|
|
131
|
+
// eslint-disable-next-line
|
|
132
|
+
const context = this;
|
|
133
|
+
return function SNAPPED_HOOK(...args) {
|
|
134
|
+
const group = prefix ? prefix : context.count++;
|
|
135
|
+
context._addSnapshot(args, "input", group);
|
|
136
|
+
const output = cb.apply(this, args);
|
|
137
|
+
if (output && typeof output.then === "function") {
|
|
138
|
+
let resolve;
|
|
139
|
+
context.promises.push(new Promise(r => (resolve = r)));
|
|
140
|
+
return output
|
|
141
|
+
.then((o) => {
|
|
142
|
+
context._addSnapshot(o, "output (Promise resolved)", group);
|
|
143
|
+
return o;
|
|
144
|
+
})
|
|
145
|
+
.catch((o) => {
|
|
146
|
+
context._addSnapshot(o, "output (Promise rejected)", group);
|
|
147
|
+
return o;
|
|
148
|
+
})
|
|
149
|
+
.finally(resolve);
|
|
150
|
+
}
|
|
151
|
+
context._addSnapshot(output, "output", group);
|
|
152
|
+
return output;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
_addSnapshot(content, name, group) {
|
|
159
|
+
const normalizedContent = Buffer.isBuffer(content)
|
|
160
|
+
? content
|
|
161
|
+
: serialize(content, undefined, {
|
|
162
|
+
escapeString: true,
|
|
163
|
+
printBasicPrototype: true
|
|
164
|
+
}).replace(/\r\n/g, "\n");
|
|
165
|
+
(this.snapshots[group] = this.snapshots[group] || []).push([
|
|
166
|
+
normalizedContent,
|
|
167
|
+
name
|
|
168
|
+
]);
|
|
169
|
+
if (!this.snapshotsList.includes(group)) {
|
|
170
|
+
this.snapshotsList.push(group);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
async collectSnapshots(env, options = {
|
|
177
|
+
diff: {}
|
|
178
|
+
}) {
|
|
179
|
+
await Promise.allSettled(this.promises);
|
|
180
|
+
if (!this.snapshotsList.length)
|
|
181
|
+
return;
|
|
182
|
+
const snapshots = this.snapshotsList.reduce((acc, group, index) => {
|
|
183
|
+
const block = this.snapshots[group || index].reduce((acc, [content, name]) => {
|
|
184
|
+
name = `## ${name || `test: ${index}`}\n\n`;
|
|
185
|
+
const block = `\`\`\`javascript\n${content}\n\`\`\`\n`;
|
|
186
|
+
return `${acc}${name + block}\n`;
|
|
187
|
+
}, "");
|
|
188
|
+
return `${acc}# ${Number.isInteger(group) ? `Group: ${index}` : group}\n\n${block}`;
|
|
189
|
+
}, "");
|
|
190
|
+
env
|
|
191
|
+
.expect(snapshots)
|
|
192
|
+
.toMatchFileSnapshotSync(node_path_1.default.join(this.src, "hooks.snap.txt"), options);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.HookCasesContext = HookCasesContext;
|
|
196
|
+
function defaultOptions(context, custom) {
|
|
197
|
+
let defaultOptions = {
|
|
198
|
+
context: context.getSource(),
|
|
199
|
+
mode: "production",
|
|
200
|
+
target: "async-node",
|
|
201
|
+
devtool: false,
|
|
202
|
+
cache: false,
|
|
203
|
+
entry: "./hook",
|
|
204
|
+
output: {
|
|
205
|
+
path: context.getDist()
|
|
206
|
+
},
|
|
207
|
+
optimization: {
|
|
208
|
+
minimize: false
|
|
209
|
+
},
|
|
210
|
+
experiments: {
|
|
211
|
+
css: true,
|
|
212
|
+
rspackFuture: {
|
|
213
|
+
bundlerInfo: {
|
|
214
|
+
force: false
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
inlineConst: true
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
if (custom) {
|
|
221
|
+
defaultOptions = (0, webpack_merge_1.default)(defaultOptions, custom(context));
|
|
222
|
+
}
|
|
223
|
+
return defaultOptions;
|
|
35
224
|
}
|
package/dist/case/hot-step.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createHotStepCase(name: string, src: string, dist: string, target:
|
|
1
|
+
import type { RspackOptions } from "@rspack/core";
|
|
2
|
+
export declare function createHotStepCase(name: string, src: string, dist: string, temp: string, target: RspackOptions["target"]): void;
|