@rspack/test-tools 0.6.3 → 0.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/dist/case/builtin.js +1 -1
- package/dist/case/compiler.d.ts +5 -0
- package/dist/case/compiler.js +18 -0
- package/dist/case/config.js +1 -1
- package/dist/case/defaults.js +2 -2
- package/dist/case/diagnostic.js +2 -7
- package/dist/case/error.d.ts +6 -0
- package/dist/case/error.js +23 -0
- package/dist/case/hook.d.ts +1 -0
- package/dist/case/hook.js +37 -0
- package/dist/case/hot-step.js +1 -1
- package/dist/case/index.d.ts +5 -1
- package/dist/case/index.js +5 -1
- package/dist/case/normal.js +2 -2
- package/dist/case/stats-api.d.ts +6 -0
- package/dist/case/stats-api.js +23 -0
- package/dist/case/stats-output.d.ts +1 -0
- package/dist/case/{stats.js → stats-output.js} +3 -3
- package/dist/case/treeshaking.js +1 -1
- package/dist/helper/directory.d.ts +7 -3
- package/dist/helper/directory.js +60 -31
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/helper/jestFileSnapshot.d.ts +18 -0
- package/dist/helper/jestFileSnapshot.js +112 -0
- package/dist/helper/legacy/fakeSystem.d.ts +9 -0
- package/dist/helper/legacy/fakeSystem.js +124 -0
- package/dist/helper/legacy/supportsWorker.d.ts +2 -0
- package/dist/helper/legacy/supportsWorker.js +17 -0
- package/dist/helper/legacy/warmup-webpack.d.ts +1 -0
- package/dist/helper/legacy/warmup-webpack.js +26 -0
- package/dist/helper/setupTestFramework.d.ts +1 -0
- package/dist/helper/setupTestFramework.js +121 -0
- package/dist/helper/util/checkSourceMap.d.ts +1 -0
- package/dist/helper/util/checkSourceMap.js +80 -0
- package/dist/helper/util/currentWatchStep.d.ts +1 -0
- package/dist/helper/util/currentWatchStep.js +2 -0
- package/dist/helper/util/expectWarningFactory.d.ts +2 -0
- package/dist/helper/util/expectWarningFactory.js +21 -0
- package/dist/helper/util/filterUtil.d.ts +8 -0
- package/dist/helper/util/filterUtil.js +50 -0
- package/dist/helper/util/identifier.d.ts +76 -0
- package/dist/helper/util/identifier.js +345 -0
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +2 -0
- package/dist/helper/util/replaceMitteDiagnostic.js +17 -0
- package/dist/helper/win.d.ts +2 -0
- package/dist/helper/win.js +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugin/webpack-module-placeholder-plugin.js +2 -3
- package/dist/processor/defaults.js +11 -23
- package/dist/processor/diagnostic.d.ts +0 -3
- package/dist/processor/diagnostic.js +17 -20
- package/dist/processor/error.d.ts +23 -0
- package/dist/processor/error.js +142 -0
- package/dist/processor/hook.d.ts +41 -0
- package/dist/processor/hook.js +189 -0
- package/dist/processor/hot-step.d.ts +2 -1
- package/dist/processor/hot-step.js +66 -14
- package/dist/processor/index.d.ts +2 -0
- package/dist/processor/index.js +2 -0
- package/dist/processor/normal.d.ts +0 -2
- package/dist/processor/normal.js +1 -10
- package/dist/processor/simple.js +2 -6
- package/dist/processor/snapshot.js +6 -6
- package/dist/processor/stats-api.d.ts +0 -2
- package/dist/processor/stats-api.js +1 -13
- package/dist/processor/stats.js +2 -1
- package/dist/processor/watch.js +4 -4
- package/dist/runner/hot-step.js +3 -2
- package/dist/runner/runner/basic.d.ts +1 -0
- package/dist/runner/runner/basic.js +3 -0
- package/dist/runner/runner/web/jsdom.d.ts +1 -0
- package/dist/runner/runner/web/jsdom.js +11 -5
- package/dist/runner/runner/web.d.ts +1 -0
- package/dist/runner/runner/web.js +3 -0
- package/dist/runner/type.d.ts +13 -0
- package/dist/test/simple.d.ts +5 -0
- package/dist/test/simple.js +36 -0
- package/dist/type.d.ts +1 -0
- package/package.json +11 -6
- package/dist/case/stats.d.ts +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ErrorTaskProcessor = void 0;
|
|
7
|
+
const simple_1 = require("./simple");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const pretty_format_1 = __importDefault(require("pretty-format"));
|
|
10
|
+
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
11
|
+
const CWD_PATTERN = new RegExp(path_1.default.join(process.cwd(), "../../").replace(/\\/g, "/"), "gm");
|
|
12
|
+
const ERROR_STACK_PATTERN = /(?:\n\s+at\s.*)+/gm;
|
|
13
|
+
function cleanError(err) {
|
|
14
|
+
const result = {};
|
|
15
|
+
for (const key of Object.getOwnPropertyNames(err)) {
|
|
16
|
+
result[key] = err[key];
|
|
17
|
+
}
|
|
18
|
+
if (result.message) {
|
|
19
|
+
result.message = err.message.replace(ERROR_STACK_PATTERN, "");
|
|
20
|
+
}
|
|
21
|
+
if (result.stack) {
|
|
22
|
+
result.stack = result.stack.replace(ERROR_STACK_PATTERN, "");
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function serialize(received) {
|
|
27
|
+
return (0, pretty_format_1.default)(received, prettyFormatOptions)
|
|
28
|
+
.replace(CWD_PATTERN, "<cwd>")
|
|
29
|
+
.trim();
|
|
30
|
+
}
|
|
31
|
+
const prettyFormatOptions = {
|
|
32
|
+
escapeRegex: false,
|
|
33
|
+
printFunctionName: false,
|
|
34
|
+
plugins: [
|
|
35
|
+
{
|
|
36
|
+
test(val) {
|
|
37
|
+
return typeof val === "string";
|
|
38
|
+
},
|
|
39
|
+
print(val) {
|
|
40
|
+
return `"${val
|
|
41
|
+
.replace(/\\/gm, "/")
|
|
42
|
+
.replace(/"/gm, '\\"')
|
|
43
|
+
.replace(/\r?\n/gm, "\\n")}"`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
};
|
|
48
|
+
class ErrorTaskProcessor extends simple_1.SimpleTaskProcessor {
|
|
49
|
+
constructor(_errorOptions) {
|
|
50
|
+
super({
|
|
51
|
+
options: (context) => {
|
|
52
|
+
let options = {
|
|
53
|
+
context: path_1.default.resolve(__dirname, "../../tests/fixtures/errors"),
|
|
54
|
+
mode: "none",
|
|
55
|
+
devtool: false,
|
|
56
|
+
optimization: {
|
|
57
|
+
minimize: false
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
if (typeof _errorOptions.options === "function") {
|
|
61
|
+
options = (0, webpack_merge_1.default)(options, _errorOptions.options(options, context));
|
|
62
|
+
}
|
|
63
|
+
if (options.mode === "production") {
|
|
64
|
+
if (options.optimization)
|
|
65
|
+
options.optimization.minimize = true;
|
|
66
|
+
else
|
|
67
|
+
options.optimization = { minimize: true };
|
|
68
|
+
}
|
|
69
|
+
return options;
|
|
70
|
+
},
|
|
71
|
+
build: _errorOptions.build,
|
|
72
|
+
compilerType: _errorOptions.compilerType,
|
|
73
|
+
name: _errorOptions.name
|
|
74
|
+
});
|
|
75
|
+
this._errorOptions = _errorOptions;
|
|
76
|
+
}
|
|
77
|
+
async compiler(context) {
|
|
78
|
+
await super.compiler(context);
|
|
79
|
+
const compiler = this.getCompiler(context).getCompiler();
|
|
80
|
+
if (compiler) {
|
|
81
|
+
compiler.outputFileSystem = {
|
|
82
|
+
// CHANGE: rspack outputFileSystem `mkdirp` uses option `{ recursive: true }`, webpack's second parameter is alway a callback
|
|
83
|
+
mkdir(dir, maybeOptionOrCallback, maybeCallback) {
|
|
84
|
+
if (typeof maybeOptionOrCallback === "function") {
|
|
85
|
+
maybeOptionOrCallback();
|
|
86
|
+
}
|
|
87
|
+
else if (typeof maybeCallback === "function") {
|
|
88
|
+
maybeCallback();
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
writeFile(file, content, callback) {
|
|
92
|
+
callback();
|
|
93
|
+
},
|
|
94
|
+
stat(file, callback) {
|
|
95
|
+
callback(new Error("ENOENT"));
|
|
96
|
+
},
|
|
97
|
+
mkdirSync() { },
|
|
98
|
+
writeFileSync() { }
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async run(env, context) {
|
|
103
|
+
// do nothing
|
|
104
|
+
}
|
|
105
|
+
async check(env, context) {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
const compiler = this.getCompiler(context);
|
|
108
|
+
const stats = compiler.getStats();
|
|
109
|
+
expect(typeof stats).toBe("object");
|
|
110
|
+
const statsResult = stats.toJson({ errorDetails: false });
|
|
111
|
+
expect(typeof statsResult).toBe("object");
|
|
112
|
+
const { errors, warnings } = statsResult;
|
|
113
|
+
expect(Array.isArray(errors)).toBe(true);
|
|
114
|
+
expect(Array.isArray(warnings)).toBe(true);
|
|
115
|
+
await ((_b = (_a = this._errorOptions).check) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
116
|
+
errors: errors,
|
|
117
|
+
warnings: warnings
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
static addSnapshotSerializer() {
|
|
121
|
+
expect.addSnapshotSerializer({
|
|
122
|
+
test(received) {
|
|
123
|
+
return received.errors || received.warnings;
|
|
124
|
+
},
|
|
125
|
+
print(received) {
|
|
126
|
+
return serialize({
|
|
127
|
+
errors: received.errors.map(e => cleanError(e)),
|
|
128
|
+
warnings: received.warnings.map(e => cleanError(e))
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
expect.addSnapshotSerializer({
|
|
133
|
+
test(received) {
|
|
134
|
+
return received.message;
|
|
135
|
+
},
|
|
136
|
+
print(received) {
|
|
137
|
+
return serialize(cleanError(received));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.ErrorTaskProcessor = ErrorTaskProcessor;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
|
|
3
|
+
import { TTestContextOptions, TestContext } from "../test/context";
|
|
4
|
+
import { ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
|
|
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(options?: {
|
|
29
|
+
diff: {};
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
interface IHookProcessorOptions<T extends ECompilerType> extends ISnapshotProcessorOptions<T> {
|
|
33
|
+
options?: (context: ITestContext) => TCompilerOptions<T>;
|
|
34
|
+
}
|
|
35
|
+
export declare class HookTaskProcessor extends SnapshotProcessor<ECompilerType.Rspack> {
|
|
36
|
+
protected hookOptions: IHookProcessorOptions<ECompilerType.Rspack>;
|
|
37
|
+
constructor(hookOptions: IHookProcessorOptions<ECompilerType.Rspack>);
|
|
38
|
+
config(context: ITestContext): Promise<void>;
|
|
39
|
+
check(env: ITestEnv, context: HookCasesContext): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HookTaskProcessor = exports.HookCasesContext = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
10
|
+
const pretty_format_1 = require("pretty-format");
|
|
11
|
+
const jest_snapshot_1 = require("jest-snapshot");
|
|
12
|
+
const context_1 = require("../test/context");
|
|
13
|
+
const snapshot_1 = require("./snapshot");
|
|
14
|
+
const pathSerializer = require("jest-serializer-path");
|
|
15
|
+
const normalizePaths = pathSerializer.normalizePaths;
|
|
16
|
+
const srcDir = path_1.default.resolve(__dirname, "../../tests/fixtures");
|
|
17
|
+
const distDir = path_1.default.resolve(__dirname, "../../tests/js/hook");
|
|
18
|
+
const sourceSerializer = {
|
|
19
|
+
test(val) {
|
|
20
|
+
return val instanceof webpack_sources_1.Source;
|
|
21
|
+
},
|
|
22
|
+
print(val) {
|
|
23
|
+
return val.source();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const internalSerializer = {
|
|
27
|
+
test(val) {
|
|
28
|
+
return val instanceof core_1.Compiler || val instanceof core_1.Compilation;
|
|
29
|
+
},
|
|
30
|
+
print(val) {
|
|
31
|
+
return JSON.stringify(`${val.constructor.name}(internal ignored)`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const testPathSerializer = {
|
|
35
|
+
test(val) {
|
|
36
|
+
return typeof val === "string";
|
|
37
|
+
},
|
|
38
|
+
print(val) {
|
|
39
|
+
return JSON.stringify(normalizePaths(
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
val
|
|
42
|
+
.split(srcDir)
|
|
43
|
+
.join("<HOOK_SRC_DIR>")
|
|
44
|
+
.split(distDir)
|
|
45
|
+
.join("<HOOK_DIST_DIR>")));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const escapeRegex = true;
|
|
49
|
+
const printFunctionName = false;
|
|
50
|
+
const normalizeNewlines = (str) => str.replace(/\r\n|\r/g, "\n");
|
|
51
|
+
const serialize = (val, indent = 2, formatOverrides = {}) => normalizeNewlines((0, pretty_format_1.format)(val, {
|
|
52
|
+
escapeRegex,
|
|
53
|
+
indent,
|
|
54
|
+
plugins: [
|
|
55
|
+
...(0, jest_snapshot_1.getSerializers)(),
|
|
56
|
+
sourceSerializer,
|
|
57
|
+
internalSerializer,
|
|
58
|
+
testPathSerializer
|
|
59
|
+
],
|
|
60
|
+
printFunctionName,
|
|
61
|
+
...formatOverrides
|
|
62
|
+
}));
|
|
63
|
+
class HookCasesContext extends context_1.TestContext {
|
|
64
|
+
constructor(src, testName, options) {
|
|
65
|
+
super(options);
|
|
66
|
+
this.src = src;
|
|
67
|
+
this.testName = testName;
|
|
68
|
+
this.options = options;
|
|
69
|
+
this.promises = [];
|
|
70
|
+
this.count = 0;
|
|
71
|
+
this.snapshots = {};
|
|
72
|
+
this.snapshotsList = [];
|
|
73
|
+
this.snapped = this.snapped.bind(this);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Snapshot function arguments and return value.
|
|
77
|
+
* Generated snapshot is located in the same directory with the test source.
|
|
78
|
+
* @example
|
|
79
|
+
* compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
|
|
80
|
+
*/
|
|
81
|
+
snapped(cb, prefix = "") {
|
|
82
|
+
// eslint-disable-next-line
|
|
83
|
+
let context = this;
|
|
84
|
+
return function SNAPPED_HOOK(...args) {
|
|
85
|
+
let group = prefix ? prefix : context.count++;
|
|
86
|
+
context._addSnapshot(args, "input", group);
|
|
87
|
+
let output = cb.apply(this, args);
|
|
88
|
+
if (output && typeof output.then === "function") {
|
|
89
|
+
let resolve;
|
|
90
|
+
context.promises.push(new Promise(r => (resolve = r)));
|
|
91
|
+
return output
|
|
92
|
+
.then((o) => {
|
|
93
|
+
context._addSnapshot(o, "output (Promise resolved)", group);
|
|
94
|
+
return o;
|
|
95
|
+
})
|
|
96
|
+
.catch((o) => {
|
|
97
|
+
context._addSnapshot(o, "output (Promise rejected)", group);
|
|
98
|
+
return o;
|
|
99
|
+
})
|
|
100
|
+
.finally(resolve);
|
|
101
|
+
}
|
|
102
|
+
context._addSnapshot(output, "output", group);
|
|
103
|
+
return output;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
_addSnapshot(content, name, group) {
|
|
110
|
+
content = Buffer.isBuffer(content)
|
|
111
|
+
? content
|
|
112
|
+
: serialize(content, undefined, {
|
|
113
|
+
escapeString: true,
|
|
114
|
+
printBasicPrototype: true
|
|
115
|
+
}).replace(/\r\n/g, "\n");
|
|
116
|
+
(this.snapshots[group] = this.snapshots[group] || []).push([
|
|
117
|
+
content,
|
|
118
|
+
name
|
|
119
|
+
]);
|
|
120
|
+
if (!this.snapshotsList.includes(group)) {
|
|
121
|
+
this.snapshotsList.push(group);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
async collectSnapshots(options = {
|
|
128
|
+
diff: {}
|
|
129
|
+
}) {
|
|
130
|
+
await Promise.allSettled(this.promises);
|
|
131
|
+
if (!this.snapshotsList.length)
|
|
132
|
+
return;
|
|
133
|
+
let snapshots = this.snapshotsList.reduce((acc, group, index) => {
|
|
134
|
+
let block = this.snapshots[group || index].reduce((acc, [content, name]) => {
|
|
135
|
+
name = `## ${name || `test: ${index}`}\n\n`;
|
|
136
|
+
let block = "```javascript\n" + content + "\n```\n";
|
|
137
|
+
return (acc += name + block + "\n");
|
|
138
|
+
}, "");
|
|
139
|
+
group = Number.isInteger(group) ? `Group: ${index}` : group;
|
|
140
|
+
group = `# ${group}\n\n`;
|
|
141
|
+
return (acc += group + block);
|
|
142
|
+
}, "");
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
expect(snapshots).toMatchFileSnapshot(path_1.default.join(this.src, "hooks.snap.txt"), options);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.HookCasesContext = HookCasesContext;
|
|
148
|
+
class HookTaskProcessor extends snapshot_1.SnapshotProcessor {
|
|
149
|
+
constructor(hookOptions) {
|
|
150
|
+
super({
|
|
151
|
+
defaultOptions: context => {
|
|
152
|
+
return {
|
|
153
|
+
context: context.getSource(),
|
|
154
|
+
mode: "production",
|
|
155
|
+
target: "async-node",
|
|
156
|
+
devtool: false,
|
|
157
|
+
cache: false,
|
|
158
|
+
entry: "./hook",
|
|
159
|
+
output: {
|
|
160
|
+
path: context.getDist()
|
|
161
|
+
},
|
|
162
|
+
optimization: {
|
|
163
|
+
minimize: false
|
|
164
|
+
},
|
|
165
|
+
experiments: {
|
|
166
|
+
rspackFuture: {
|
|
167
|
+
newTreeshaking: true
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
...hookOptions,
|
|
173
|
+
runable: true
|
|
174
|
+
});
|
|
175
|
+
this.hookOptions = hookOptions;
|
|
176
|
+
}
|
|
177
|
+
async config(context) {
|
|
178
|
+
await super.config(context);
|
|
179
|
+
const compiler = this.getCompiler(context);
|
|
180
|
+
if (typeof this.hookOptions.options === "function") {
|
|
181
|
+
compiler.mergeOptions(this.hookOptions.options(context));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async check(env, context) {
|
|
185
|
+
await context.collectSnapshots();
|
|
186
|
+
await super.check(env, context);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.HookTaskProcessor = HookTaskProcessor;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ITestContext, ITestEnv } from "../type";
|
|
2
2
|
import { StatsCompilation } from "@rspack/core";
|
|
3
3
|
import { IRspackHotProcessorOptions, RspackHotProcessor } from "./hot";
|
|
4
|
+
import { THotStepRuntimeData } from "../runner";
|
|
4
5
|
export interface IRspackHotStepProcessorOptions extends IRspackHotProcessorOptions {
|
|
5
6
|
}
|
|
6
7
|
export declare class RspackHotStepProcessor extends RspackHotProcessor {
|
|
@@ -10,5 +11,5 @@ export declare class RspackHotStepProcessor extends RspackHotProcessor {
|
|
|
10
11
|
constructor(_hotOptions: IRspackHotProcessorOptions);
|
|
11
12
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
12
13
|
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
13
|
-
protected matchStepSnapshot(context: ITestContext, step: number, stats: StatsCompilation): void;
|
|
14
|
+
protected matchStepSnapshot(context: ITestContext, step: number, stats: StatsCompilation, runtime?: THotStepRuntimeData): void;
|
|
14
15
|
}
|
|
@@ -7,6 +7,7 @@ exports.RspackHotStepProcessor = void 0;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const hot_1 = require("./hot");
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const helper_1 = require("../helper");
|
|
10
11
|
const escapeLocalName = (str) => str.split(/[-<>:"/|?*.]/).join("_");
|
|
11
12
|
const SELF_HANDLER = (file, options) => {
|
|
12
13
|
var _a, _b, _c;
|
|
@@ -39,17 +40,17 @@ class RspackHotStepProcessor extends hot_1.RspackHotProcessor {
|
|
|
39
40
|
this.entries = {};
|
|
40
41
|
}
|
|
41
42
|
async run(env, context) {
|
|
42
|
-
context.setValue(this._options.name, "hotUpdateStepChecker", (hotUpdateContext, stats) => {
|
|
43
|
+
context.setValue(this._options.name, "hotUpdateStepChecker", (hotUpdateContext, stats, runtime) => {
|
|
43
44
|
const statsJson = stats.toJson({ assets: true, chunks: true });
|
|
44
45
|
for (let entry of ((stats === null || stats === void 0 ? void 0 : stats.compilation.chunks) || []).filter(i => i.hasRuntime())) {
|
|
45
46
|
if (!this.entries[entry.id]) {
|
|
46
47
|
this.entries[entry.id] = entry.runtime;
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
this.matchStepSnapshot(context, hotUpdateContext.updateIndex, statsJson);
|
|
50
|
+
this.matchStepSnapshot(context, hotUpdateContext.updateIndex, statsJson, runtime);
|
|
50
51
|
this.hashes.push(stats.hash);
|
|
51
52
|
});
|
|
52
|
-
context.setValue(this._options.name, "hotUpdateStepErrorChecker", (_, stats) => {
|
|
53
|
+
context.setValue(this._options.name, "hotUpdateStepErrorChecker", (_, stats, runtime) => {
|
|
53
54
|
this.hashes.push(stats.hash);
|
|
54
55
|
});
|
|
55
56
|
await super.run(env, context);
|
|
@@ -76,11 +77,8 @@ class RspackHotStepProcessor extends hot_1.RspackHotProcessor {
|
|
|
76
77
|
if (matchFailed) {
|
|
77
78
|
throw matchFailed;
|
|
78
79
|
}
|
|
79
|
-
else {
|
|
80
|
-
await super.check(env, context);
|
|
81
|
-
}
|
|
82
80
|
}
|
|
83
|
-
matchStepSnapshot(context, step, stats) {
|
|
81
|
+
matchStepSnapshot(context, step, stats, runtime) {
|
|
84
82
|
const compiler = this.getCompiler(context);
|
|
85
83
|
const compilerOptions = compiler.getOptions();
|
|
86
84
|
const getModuleHandler = GET_MODULE_HANDLER[compilerOptions.target];
|
|
@@ -90,7 +88,7 @@ class RspackHotStepProcessor extends hot_1.RspackHotProcessor {
|
|
|
90
88
|
const title = `Case ${this._options.name}: Step ${step}`;
|
|
91
89
|
const hotUpdateFile = [];
|
|
92
90
|
const hotUpdateManifest = [];
|
|
93
|
-
const changedFiles = require(context.getSource("changed-file.js")).map((i) => path_1.default.relative(context.getSource(), i));
|
|
91
|
+
const changedFiles = require(context.getSource("changed-file.js")).map((i) => (0, helper_1.escapeSep)(path_1.default.relative(context.getSource(), i)));
|
|
94
92
|
const hashes = {
|
|
95
93
|
[lastHash || "LAST_HASH"]: "LAST_HASH",
|
|
96
94
|
[stats.hash]: "CURRENT_HASH"
|
|
@@ -161,6 +159,16 @@ class RspackHotStepProcessor extends hot_1.RspackHotProcessor {
|
|
|
161
159
|
fileList.sort();
|
|
162
160
|
hotUpdateManifest.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
163
161
|
hotUpdateFile.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
162
|
+
if (runtime === null || runtime === void 0 ? void 0 : runtime.javascript) {
|
|
163
|
+
runtime.javascript.outdatedModules.sort();
|
|
164
|
+
runtime.javascript.updatedModules.sort();
|
|
165
|
+
runtime.javascript.updatedRuntime.sort();
|
|
166
|
+
runtime.javascript.acceptedModules.sort();
|
|
167
|
+
runtime.javascript.disposedModules.sort();
|
|
168
|
+
for (let value of Object.values(runtime.javascript.outdatedDependencies)) {
|
|
169
|
+
value.sort();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
164
172
|
let content = `
|
|
165
173
|
# ${title}
|
|
166
174
|
|
|
@@ -197,20 +205,64 @@ ${i.runtime.map(i => `- ${i}`).join("\n")}
|
|
|
197
205
|
\`\`\`js
|
|
198
206
|
${i.content}
|
|
199
207
|
\`\`\`
|
|
200
|
-
|
|
201
208
|
`)
|
|
202
209
|
.join("\n\n")}
|
|
203
210
|
|
|
204
|
-
|
|
211
|
+
|
|
212
|
+
${runtime
|
|
213
|
+
? `
|
|
214
|
+
## Runtime
|
|
215
|
+
### Status
|
|
216
|
+
|
|
217
|
+
\`\`\`txt
|
|
218
|
+
${runtime.statusPath.join(" => ")}
|
|
219
|
+
\`\`\`
|
|
220
|
+
|
|
221
|
+
${runtime.javascript
|
|
222
|
+
? `
|
|
223
|
+
|
|
224
|
+
### JavaScript
|
|
225
|
+
|
|
226
|
+
#### Outdated
|
|
227
|
+
|
|
228
|
+
Outdated Modules:
|
|
229
|
+
${runtime.javascript.outdatedModules.map(i => `- ${i}`).join("\n")}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
Outdated Dependencies:
|
|
233
|
+
\`\`\`json
|
|
234
|
+
${JSON.stringify(runtime.javascript.outdatedDependencies || {}, null, 2)}
|
|
235
|
+
\`\`\`
|
|
236
|
+
|
|
237
|
+
#### Updated
|
|
238
|
+
|
|
239
|
+
Updated Modules:
|
|
240
|
+
${runtime.javascript.updatedModules.map(i => `- ${i}`).join("\n")}
|
|
241
|
+
|
|
242
|
+
Updated Runtime:
|
|
243
|
+
${runtime.javascript.updatedRuntime.map(i => `- \`${i}\``).join("\n")}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
#### Callback
|
|
247
|
+
|
|
248
|
+
Accepted Callback:
|
|
249
|
+
${runtime.javascript.acceptedModules.map(i => `- ${i}`).join("\n")}
|
|
250
|
+
|
|
251
|
+
Disposed Callback:
|
|
252
|
+
${runtime.javascript.disposedModules.map(i => `- ${i}`).join("\n")}
|
|
253
|
+
`
|
|
254
|
+
: ""}
|
|
255
|
+
|
|
256
|
+
`
|
|
257
|
+
: ""}
|
|
258
|
+
|
|
259
|
+
`.trim();
|
|
205
260
|
if (!fs_extra_1.default.existsSync(snapshotPath) || global.updateSnapshot) {
|
|
206
261
|
fs_extra_1.default.ensureDirSync(path_1.default.dirname(snapshotPath));
|
|
207
262
|
fs_extra_1.default.writeFileSync(snapshotPath, content, "utf-8");
|
|
208
263
|
return;
|
|
209
264
|
}
|
|
210
|
-
const snapshotContent = fs_extra_1.default
|
|
211
|
-
.readFileSync(snapshotPath, "utf-8")
|
|
212
|
-
.replace(/\r\n/g, "\n")
|
|
213
|
-
.trim();
|
|
265
|
+
const snapshotContent = (0, helper_1.escapeEOL)(fs_extra_1.default.readFileSync(snapshotPath, "utf-8"));
|
|
214
266
|
expect(content).toBe(snapshotContent);
|
|
215
267
|
}
|
|
216
268
|
}
|
package/dist/processor/index.js
CHANGED
|
@@ -29,3 +29,5 @@ __exportStar(require("./stats-api"), exports);
|
|
|
29
29
|
__exportStar(require("./snapshot"), exports);
|
|
30
30
|
__exportStar(require("./builtin"), exports);
|
|
31
31
|
__exportStar(require("./hot-step"), exports);
|
|
32
|
+
__exportStar(require("./hook"), exports);
|
|
33
|
+
__exportStar(require("./error"), exports);
|
|
@@ -9,7 +9,5 @@ export interface IRspackNormalProcessorOptions {
|
|
|
9
9
|
export declare class RspackNormalProcessor extends BasicTaskProcessor<ECompilerType.Rspack> {
|
|
10
10
|
protected _normalOptions: IRspackNormalProcessorOptions;
|
|
11
11
|
constructor(_normalOptions: IRspackNormalProcessorOptions);
|
|
12
|
-
before(context: ITestContext): Promise<void>;
|
|
13
|
-
after(context: ITestContext): Promise<void>;
|
|
14
12
|
static defaultOptions({ compilerOptions, root }: IRspackNormalProcessorOptions): (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
|
|
15
13
|
}
|
package/dist/processor/normal.js
CHANGED
|
@@ -8,7 +8,6 @@ const type_1 = require("../type");
|
|
|
8
8
|
const basic_1 = require("./basic");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const CWD = process.cwd();
|
|
12
11
|
class RspackNormalProcessor extends basic_1.BasicTaskProcessor {
|
|
13
12
|
constructor(_normalOptions) {
|
|
14
13
|
super({
|
|
@@ -24,13 +23,6 @@ class RspackNormalProcessor extends basic_1.BasicTaskProcessor {
|
|
|
24
23
|
});
|
|
25
24
|
this._normalOptions = _normalOptions;
|
|
26
25
|
}
|
|
27
|
-
async before(context) {
|
|
28
|
-
//TODO: remove this
|
|
29
|
-
process.chdir(path_1.default.resolve(__dirname, "../../../rspack"));
|
|
30
|
-
}
|
|
31
|
-
async after(context) {
|
|
32
|
-
process.chdir(CWD);
|
|
33
|
-
}
|
|
34
26
|
static defaultOptions({ compilerOptions, root }) {
|
|
35
27
|
return (context) => {
|
|
36
28
|
var _a, _b, _c;
|
|
@@ -90,8 +82,7 @@ class RspackNormalProcessor extends basic_1.BasicTaskProcessor {
|
|
|
90
82
|
...compilerOptions.cache
|
|
91
83
|
},
|
|
92
84
|
output: {
|
|
93
|
-
|
|
94
|
-
// pathinfo: "verbose",
|
|
85
|
+
pathinfo: "verbose",
|
|
95
86
|
path: context.getDist(),
|
|
96
87
|
filename: (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.module) ? "bundle.mjs" : "bundle.js"
|
|
97
88
|
},
|
package/dist/processor/simple.js
CHANGED
|
@@ -40,12 +40,8 @@ class SimpleTaskProcessor {
|
|
|
40
40
|
const compiler = this.getCompiler(context);
|
|
41
41
|
await compiler.close();
|
|
42
42
|
}
|
|
43
|
-
async beforeAll(context) {
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
async afterAll(context) {
|
|
47
|
-
throw new Error("Not support");
|
|
48
|
-
}
|
|
43
|
+
async beforeAll(context) { }
|
|
44
|
+
async afterAll(context) { }
|
|
49
45
|
getCompiler(context) {
|
|
50
46
|
return context.getCompiler(this._options.name, this._options.compilerType);
|
|
51
47
|
}
|
|
@@ -7,6 +7,7 @@ exports.SnapshotProcessor = void 0;
|
|
|
7
7
|
const basic_1 = require("./basic");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const helper_1 = require("../helper");
|
|
10
11
|
class SnapshotProcessor extends basic_1.BasicTaskProcessor {
|
|
11
12
|
constructor(_snapshotOptions) {
|
|
12
13
|
super(_snapshotOptions);
|
|
@@ -40,17 +41,16 @@ class SnapshotProcessor extends basic_1.BasicTaskProcessor {
|
|
|
40
41
|
.toString()}\n\`\`\``;
|
|
41
42
|
});
|
|
42
43
|
fileContents.sort();
|
|
43
|
-
const content = fileContents.join("\n\n")
|
|
44
|
-
const snapshotPath = path_1.default.
|
|
44
|
+
const content = (0, helper_1.escapeEOL)(fileContents.join("\n\n"));
|
|
45
|
+
const snapshotPath = path_1.default.isAbsolute(this._snapshotOptions.snapshot)
|
|
46
|
+
? this._snapshotOptions.snapshot
|
|
47
|
+
: path_1.default.resolve(context.getSource(), `./snapshot/${this._snapshotOptions.snapshot}`);
|
|
45
48
|
if (!fs_extra_1.default.existsSync(snapshotPath) || global.updateSnapshot) {
|
|
46
49
|
fs_extra_1.default.ensureDirSync(path_1.default.dirname(snapshotPath));
|
|
47
50
|
fs_extra_1.default.writeFileSync(snapshotPath, content, "utf-8");
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
50
|
-
const snapshotContent = fs_extra_1.default
|
|
51
|
-
.readFileSync(snapshotPath, "utf-8")
|
|
52
|
-
.replace(/\r\n/g, "\n")
|
|
53
|
-
.trim();
|
|
53
|
+
const snapshotContent = (0, helper_1.escapeEOL)(fs_extra_1.default.readFileSync(snapshotPath, "utf-8"));
|
|
54
54
|
expect(content).toBe(snapshotContent);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -14,7 +14,5 @@ export declare class StatsAPITaskProcessor<T extends ECompilerType> extends Simp
|
|
|
14
14
|
compiler(context: ITestContext): Promise<void>;
|
|
15
15
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
16
16
|
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
17
|
-
before(context: ITestContext): Promise<void>;
|
|
18
|
-
after(context: ITestContext): Promise<void>;
|
|
19
17
|
static addSnapshotSerializer(): void;
|
|
20
18
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.StatsAPITaskProcessor = void 0;
|
|
7
4
|
const simple_1 = require("./simple");
|
|
8
5
|
const memfs_1 = require("memfs");
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
6
|
const serializer = require("jest-serializer-path");
|
|
11
|
-
const FAKE_CWD = path_1.default.resolve(__dirname, "../../../rspack");
|
|
12
|
-
const CWD = process.cwd();
|
|
13
7
|
class StatsAPITaskProcessor extends simple_1.SimpleTaskProcessor {
|
|
14
8
|
constructor(_statsAPIOptions) {
|
|
15
9
|
super({
|
|
@@ -28,7 +22,7 @@ class StatsAPITaskProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
28
22
|
}
|
|
29
23
|
}
|
|
30
24
|
async run(env, context) {
|
|
31
|
-
|
|
25
|
+
// do nothing
|
|
32
26
|
}
|
|
33
27
|
async check(env, context) {
|
|
34
28
|
var _a, _b;
|
|
@@ -37,12 +31,6 @@ class StatsAPITaskProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
37
31
|
expect(typeof stats).toBe("object");
|
|
38
32
|
await ((_b = (_a = this._statsAPIOptions).check) === null || _b === void 0 ? void 0 : _b.call(_a, stats, compiler.getCompiler()));
|
|
39
33
|
}
|
|
40
|
-
async before(context) {
|
|
41
|
-
process.chdir(this._statsAPIOptions.cwd || FAKE_CWD);
|
|
42
|
-
}
|
|
43
|
-
async after(context) {
|
|
44
|
-
process.chdir(CWD);
|
|
45
|
-
}
|
|
46
34
|
static addSnapshotSerializer() {
|
|
47
35
|
expect.addSnapshotSerializer(serializer);
|
|
48
36
|
}
|