@rspack/test-tools 0.5.7 → 0.5.8
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/defaults.d.ts +1 -0
- package/dist/case/defaults.js +36 -0
- package/dist/case/index.d.ts +2 -0
- package/dist/case/index.js +2 -0
- package/dist/case/treeshaking.d.ts +1 -0
- package/dist/case/treeshaking.js +33 -0
- package/dist/case/watch.js +6 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/processor/defaults.d.ts +24 -0
- package/dist/processor/defaults.js +113 -0
- package/dist/processor/index.d.ts +3 -0
- package/dist/processor/index.js +3 -0
- package/dist/processor/simple.d.ts +23 -0
- package/dist/processor/simple.js +53 -0
- package/dist/processor/stats-api.d.ts +20 -0
- package/dist/processor/stats-api.js +50 -0
- package/dist/processor/treeshaking.d.ts +14 -0
- package/dist/processor/treeshaking.js +186 -0
- package/dist/test/context.d.ts +2 -1
- package/dist/test/creator.d.ts +1 -1
- package/dist/test/creator.js +11 -8
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createDefaultsCase(src: string): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
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.createDefaultsCase = void 0;
|
|
7
|
+
const context_1 = require("../test/context");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const processor_1 = require("../processor");
|
|
10
|
+
const srcDir = path_1.default.resolve(__dirname, "../../../rspack/tests/fixtures");
|
|
11
|
+
const distDir = path_1.default.resolve(__dirname, "../../../rspack/tests/js/compiler");
|
|
12
|
+
const context = new context_1.TestContext({
|
|
13
|
+
src: srcDir,
|
|
14
|
+
dist: distDir
|
|
15
|
+
});
|
|
16
|
+
async function run(name, processor) {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
|
+
try {
|
|
19
|
+
await ((_a = processor.before) === null || _a === void 0 ? void 0 : _a.call(processor, context));
|
|
20
|
+
await ((_b = processor.config) === null || _b === void 0 ? void 0 : _b.call(processor, context));
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
context.emitError(name, e);
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
await ((_c = processor.check) === null || _c === void 0 ? void 0 : _c.call(processor, null, context));
|
|
27
|
+
await ((_d = processor.after) === null || _d === void 0 ? void 0 : _d.call(processor, context));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function createDefaultsCase(src) {
|
|
31
|
+
const caseConfig = require(src);
|
|
32
|
+
it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
|
|
33
|
+
await run(caseConfig.name, new processor_1.DefaultsConfigTaskProcessor(caseConfig));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.createDefaultsCase = createDefaultsCase;
|
package/dist/case/index.d.ts
CHANGED
package/dist/case/index.js
CHANGED
|
@@ -22,3 +22,5 @@ __exportStar(require("./hot"), exports);
|
|
|
22
22
|
__exportStar(require("./normal"), exports);
|
|
23
23
|
__exportStar(require("./stats"), exports);
|
|
24
24
|
__exportStar(require("./watch"), exports);
|
|
25
|
+
__exportStar(require("./treeshaking"), exports);
|
|
26
|
+
__exportStar(require("./defaults"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createTreeShakingCase(name: string, src: string, dist: string): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTreeShakingCase = void 0;
|
|
4
|
+
const treeshaking_1 = require("../processor/treeshaking");
|
|
5
|
+
const creator_1 = require("../test/creator");
|
|
6
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
7
|
+
clean: true,
|
|
8
|
+
describe: true,
|
|
9
|
+
description(name, step) {
|
|
10
|
+
if (step === 0) {
|
|
11
|
+
return `${name} with builtin.treeShaking should match snapshot`;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return `${name} with newTreeshaking should match snapshot`;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
steps: ({ name }) => [
|
|
18
|
+
new treeshaking_1.RspackTreeShakingProcessor({
|
|
19
|
+
name,
|
|
20
|
+
snapshot: "output.snap",
|
|
21
|
+
type: "builtin"
|
|
22
|
+
}),
|
|
23
|
+
new treeshaking_1.RspackTreeShakingProcessor({
|
|
24
|
+
name,
|
|
25
|
+
snapshot: "new_treeshaking.snap",
|
|
26
|
+
type: "new"
|
|
27
|
+
})
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
function createTreeShakingCase(name, src, dist) {
|
|
31
|
+
creator.create(name, src, dist);
|
|
32
|
+
}
|
|
33
|
+
exports.createTreeShakingCase = createTreeShakingCase;
|
package/dist/case/watch.js
CHANGED
|
@@ -9,27 +9,14 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const watch_1 = require("../processor/watch");
|
|
10
10
|
const creator_1 = require("../test/creator");
|
|
11
11
|
const runner_1 = require("../runner");
|
|
12
|
-
|
|
13
|
-
describe(name, tester, testConfig) {
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
await tester.prepare();
|
|
16
|
-
});
|
|
17
|
-
for (let index = 0; index < tester.total; index++) {
|
|
18
|
-
it(index === 0 ? `${name} should compile` : "should compile the next step", async () => {
|
|
19
|
-
await tester.compile();
|
|
20
|
-
await tester.check(env);
|
|
21
|
-
tester.next();
|
|
22
|
-
}, 5000);
|
|
23
|
-
const env = this.createEnv(testConfig);
|
|
24
|
-
}
|
|
25
|
-
afterAll(async () => {
|
|
26
|
-
await tester.resume();
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const creator = new WatchCaseCreator({
|
|
12
|
+
const creator = new creator_1.BasicCaseCreator({
|
|
31
13
|
clean: true,
|
|
32
14
|
runner: runner_1.WatchRunnerFactory,
|
|
15
|
+
description: (name, index) => {
|
|
16
|
+
return index === 0
|
|
17
|
+
? `${name} should compile`
|
|
18
|
+
: "should compile the next step";
|
|
19
|
+
},
|
|
33
20
|
describe: false,
|
|
34
21
|
steps: ({ name, src, temp }) => {
|
|
35
22
|
const runs = fs_1.default
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./type"), exports);
|
|
18
18
|
__exportStar(require("./test/tester"), exports);
|
|
19
|
+
__exportStar(require("./test/context"), exports);
|
|
19
20
|
__exportStar(require("./processor"), exports);
|
|
20
21
|
__exportStar(require("./reporter"), exports);
|
|
21
22
|
__exportStar(require("./compare"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SimpleTaskProcessor } from "./simple";
|
|
2
|
+
import { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
|
|
3
|
+
export interface IDefaultsConfigProcessorOptions {
|
|
4
|
+
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
diff: (diff: any, defaults: any) => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare class DefaultsConfigTaskProcessor extends SimpleTaskProcessor<ECompilerType.Rspack> {
|
|
10
|
+
protected _defaultsConfigOptions: IDefaultsConfigProcessorOptions;
|
|
11
|
+
private defaultConfig;
|
|
12
|
+
constructor(_defaultsConfigOptions: IDefaultsConfigProcessorOptions);
|
|
13
|
+
compiler(context: ITestContext): Promise<void>;
|
|
14
|
+
build(context: ITestContext): Promise<void>;
|
|
15
|
+
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
16
|
+
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
17
|
+
before(context: ITestContext): Promise<void>;
|
|
18
|
+
after(context: ITestContext): Promise<void>;
|
|
19
|
+
beforeAll(context: ITestContext): Promise<void>;
|
|
20
|
+
afterAll(context: ITestContext): Promise<void>;
|
|
21
|
+
protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<ECompilerType.Rspack>;
|
|
22
|
+
static getDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType.Rspack>): TCompilerOptions<ECompilerType.Rspack>;
|
|
23
|
+
static addSnapshotSerializer(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
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.DefaultsConfigTaskProcessor = void 0;
|
|
7
|
+
const simple_1 = require("./simple");
|
|
8
|
+
const type_1 = require("../type");
|
|
9
|
+
const jest_diff_1 = require("jest-diff");
|
|
10
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const CASE_CWD = path_1.default.resolve(__dirname, "../../../rspack");
|
|
13
|
+
const CURRENT_CWD = process.cwd();
|
|
14
|
+
const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
|
15
|
+
const cwdRegExp = new RegExp(`${quoteMeta(CASE_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`, "g");
|
|
16
|
+
const escapedCwd = JSON.stringify(CASE_CWD).slice(1, -1);
|
|
17
|
+
const escapedCwdRegExp = new RegExp(`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`, "g");
|
|
18
|
+
const normalize = (str) => {
|
|
19
|
+
if (CASE_CWD.startsWith("/")) {
|
|
20
|
+
str = str.replace(new RegExp(quoteMeta(CASE_CWD), "g"), "<cwd>");
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
str = str.replace(cwdRegExp, (m, g) => `<cwd>${g.replace(/\\/g, "/")}`);
|
|
24
|
+
str = str.replace(escapedCwdRegExp, (m, g) => `<cwd>${g.replace(/\\\\/g, "/")}`);
|
|
25
|
+
}
|
|
26
|
+
str = str.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, "@@ ... @@");
|
|
27
|
+
return str;
|
|
28
|
+
};
|
|
29
|
+
class Diff {
|
|
30
|
+
constructor(value) {
|
|
31
|
+
this.value = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class DefaultsConfigTaskProcessor extends simple_1.SimpleTaskProcessor {
|
|
35
|
+
constructor(_defaultsConfigOptions) {
|
|
36
|
+
super({
|
|
37
|
+
options: context => {
|
|
38
|
+
let res;
|
|
39
|
+
if (typeof _defaultsConfigOptions.options === "function") {
|
|
40
|
+
res = _defaultsConfigOptions.options(context);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
res = {};
|
|
44
|
+
}
|
|
45
|
+
if (!("mode" in res)) {
|
|
46
|
+
res.mode = "none";
|
|
47
|
+
}
|
|
48
|
+
return res;
|
|
49
|
+
},
|
|
50
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
51
|
+
name: _defaultsConfigOptions.name
|
|
52
|
+
});
|
|
53
|
+
this._defaultsConfigOptions = _defaultsConfigOptions;
|
|
54
|
+
this.defaultConfig = DefaultsConfigTaskProcessor.getDefaultConfig(CASE_CWD, {
|
|
55
|
+
mode: "none"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async compiler(context) {
|
|
59
|
+
throw new Error("Not support");
|
|
60
|
+
}
|
|
61
|
+
async build(context) {
|
|
62
|
+
throw new Error("Not support");
|
|
63
|
+
}
|
|
64
|
+
async run(env, context) {
|
|
65
|
+
throw new Error("Not support");
|
|
66
|
+
}
|
|
67
|
+
async check(env, context) {
|
|
68
|
+
const compiler = this.getCompiler(context);
|
|
69
|
+
const config = DefaultsConfigTaskProcessor.getDefaultConfig(this._defaultsConfigOptions.cwd || CASE_CWD, compiler.getOptions());
|
|
70
|
+
const diff = (0, strip_ansi_1.default)((0, jest_diff_1.diff)(this.defaultConfig, config, { expand: false, contextLines: 0 }));
|
|
71
|
+
await this._defaultsConfigOptions.diff(expect(new Diff(diff)), expect(this.defaultConfig));
|
|
72
|
+
}
|
|
73
|
+
async before(context) { }
|
|
74
|
+
async after(context) { }
|
|
75
|
+
async beforeAll(context) {
|
|
76
|
+
throw new Error("Not support");
|
|
77
|
+
}
|
|
78
|
+
async afterAll(context) {
|
|
79
|
+
throw new Error("Not support");
|
|
80
|
+
}
|
|
81
|
+
getCompiler(context) {
|
|
82
|
+
return context.getCompiler(this._options.name, this._options.compilerType);
|
|
83
|
+
}
|
|
84
|
+
static getDefaultConfig(cwd, config) {
|
|
85
|
+
process.chdir(cwd);
|
|
86
|
+
const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require("@rspack/core").config;
|
|
87
|
+
config = getNormalizedWebpackOptions(config);
|
|
88
|
+
applyWebpackOptionsDefaults(config);
|
|
89
|
+
// make snapshot stable
|
|
90
|
+
config.experiments.rspackFuture.bundlerInfo.version = "$version$";
|
|
91
|
+
process.chdir(CURRENT_CWD);
|
|
92
|
+
return config;
|
|
93
|
+
}
|
|
94
|
+
static addSnapshotSerializer() {
|
|
95
|
+
expect.addSnapshotSerializer({
|
|
96
|
+
test(value) {
|
|
97
|
+
return value instanceof Diff;
|
|
98
|
+
},
|
|
99
|
+
print(received) {
|
|
100
|
+
return normalize(received.value);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
expect.addSnapshotSerializer({
|
|
104
|
+
test(value) {
|
|
105
|
+
return typeof value === "string";
|
|
106
|
+
},
|
|
107
|
+
print(received) {
|
|
108
|
+
return JSON.stringify(normalize(received));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.DefaultsConfigTaskProcessor = DefaultsConfigTaskProcessor;
|
package/dist/processor/index.js
CHANGED
|
@@ -23,3 +23,6 @@ __exportStar(require("./hot"), exports);
|
|
|
23
23
|
__exportStar(require("./hash"), exports);
|
|
24
24
|
__exportStar(require("./stats"), exports);
|
|
25
25
|
__exportStar(require("./watch"), exports);
|
|
26
|
+
__exportStar(require("./simple"), exports);
|
|
27
|
+
__exportStar(require("./defaults"), exports);
|
|
28
|
+
__exportStar(require("./stats-api"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
|
|
2
|
+
export interface ISimpleProcessorOptions<T extends ECompilerType = ECompilerType.Rspack> {
|
|
3
|
+
options?: (context: ITestContext) => TCompilerOptions<T>;
|
|
4
|
+
compilerType: T;
|
|
5
|
+
name: string;
|
|
6
|
+
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
7
|
+
compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
8
|
+
check?: (context: ITestContext, compiler: TCompiler<T>, stats: TCompilerStats<T>) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare class SimpleTaskProcessor<T extends ECompilerType = ECompilerType.Rspack> implements ITestProcessor {
|
|
11
|
+
protected _options: ISimpleProcessorOptions<T>;
|
|
12
|
+
constructor(_options: ISimpleProcessorOptions<T>);
|
|
13
|
+
config(context: ITestContext): Promise<void>;
|
|
14
|
+
compiler(context: ITestContext): Promise<void>;
|
|
15
|
+
build(context: ITestContext): Promise<void>;
|
|
16
|
+
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
17
|
+
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
18
|
+
before(context: ITestContext): Promise<void>;
|
|
19
|
+
after(context: ITestContext): Promise<void>;
|
|
20
|
+
beforeAll(context: ITestContext): Promise<void>;
|
|
21
|
+
afterAll(context: ITestContext): Promise<void>;
|
|
22
|
+
protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleTaskProcessor = void 0;
|
|
4
|
+
class SimpleTaskProcessor {
|
|
5
|
+
constructor(_options) {
|
|
6
|
+
this._options = _options;
|
|
7
|
+
}
|
|
8
|
+
async config(context) {
|
|
9
|
+
const compiler = this.getCompiler(context);
|
|
10
|
+
if (typeof this._options.options === "function") {
|
|
11
|
+
compiler.setOptions(this._options.options(context));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async compiler(context) {
|
|
15
|
+
const compiler = this.getCompiler(context);
|
|
16
|
+
const instance = compiler.createCompiler();
|
|
17
|
+
if (typeof this._options.compiler === "function") {
|
|
18
|
+
await this._options.compiler(context, instance);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async build(context) {
|
|
22
|
+
const compiler = this.getCompiler(context);
|
|
23
|
+
if (typeof this._options.build === "function") {
|
|
24
|
+
await this._options.build(context, compiler.getCompiler());
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
await compiler.build();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async run(env, context) { }
|
|
31
|
+
async check(env, context) {
|
|
32
|
+
const compiler = this.getCompiler(context);
|
|
33
|
+
const stats = compiler.getStats();
|
|
34
|
+
if (typeof this._options.check === "function") {
|
|
35
|
+
await this._options.check(context, compiler.getCompiler(), stats);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async before(context) { }
|
|
39
|
+
async after(context) {
|
|
40
|
+
const compiler = this.getCompiler(context);
|
|
41
|
+
await compiler.close();
|
|
42
|
+
}
|
|
43
|
+
async beforeAll(context) {
|
|
44
|
+
throw new Error("Not support");
|
|
45
|
+
}
|
|
46
|
+
async afterAll(context) {
|
|
47
|
+
throw new Error("Not support");
|
|
48
|
+
}
|
|
49
|
+
getCompiler(context) {
|
|
50
|
+
return context.getCompiler(this._options.name, this._options.compilerType);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.SimpleTaskProcessor = SimpleTaskProcessor;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SimpleTaskProcessor } from "./simple";
|
|
2
|
+
import { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
|
|
3
|
+
export interface IStatsAPITaskProcessorOptions<T extends ECompilerType> {
|
|
4
|
+
options?: (context: ITestContext) => TCompilerOptions<T>;
|
|
5
|
+
name: string;
|
|
6
|
+
cwd?: string;
|
|
7
|
+
compilerType: T;
|
|
8
|
+
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
9
|
+
check?: (stats: TCompilerStats<T>, compiler: TCompiler<T>) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare class StatsAPITaskProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
|
|
12
|
+
protected _statsAPIOptions: IStatsAPITaskProcessorOptions<T>;
|
|
13
|
+
constructor(_statsAPIOptions: IStatsAPITaskProcessorOptions<T>);
|
|
14
|
+
compiler(context: ITestContext): Promise<void>;
|
|
15
|
+
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
16
|
+
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
17
|
+
before(context: ITestContext): Promise<void>;
|
|
18
|
+
after(context: ITestContext): Promise<void>;
|
|
19
|
+
static addSnapshotSerializer(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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.StatsAPITaskProcessor = void 0;
|
|
7
|
+
const simple_1 = require("./simple");
|
|
8
|
+
const memfs_1 = require("memfs");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const serializer = require("jest-serializer-path");
|
|
11
|
+
const FAKE_CWD = path_1.default.resolve(__dirname, "../../../rspack");
|
|
12
|
+
const CWD = process.cwd();
|
|
13
|
+
class StatsAPITaskProcessor extends simple_1.SimpleTaskProcessor {
|
|
14
|
+
constructor(_statsAPIOptions) {
|
|
15
|
+
super({
|
|
16
|
+
options: _statsAPIOptions.options,
|
|
17
|
+
build: _statsAPIOptions.build,
|
|
18
|
+
compilerType: _statsAPIOptions.compilerType,
|
|
19
|
+
name: _statsAPIOptions.name
|
|
20
|
+
});
|
|
21
|
+
this._statsAPIOptions = _statsAPIOptions;
|
|
22
|
+
}
|
|
23
|
+
async compiler(context) {
|
|
24
|
+
await super.compiler(context);
|
|
25
|
+
const compiler = this.getCompiler(context).getCompiler();
|
|
26
|
+
if (compiler) {
|
|
27
|
+
compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async run(env, context) {
|
|
31
|
+
throw new Error("Not support");
|
|
32
|
+
}
|
|
33
|
+
async check(env, context) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const compiler = this.getCompiler(context);
|
|
36
|
+
const stats = compiler.getStats();
|
|
37
|
+
expect(typeof stats).toBe("object");
|
|
38
|
+
await ((_b = (_a = this._statsAPIOptions).check) === null || _b === void 0 ? void 0 : _b.call(_a, stats, compiler.getCompiler()));
|
|
39
|
+
}
|
|
40
|
+
async before(context) {
|
|
41
|
+
process.chdir(this._statsAPIOptions.cwd || FAKE_CWD);
|
|
42
|
+
}
|
|
43
|
+
async after(context) {
|
|
44
|
+
process.chdir(CWD);
|
|
45
|
+
}
|
|
46
|
+
static addSnapshotSerializer() {
|
|
47
|
+
expect.addSnapshotSerializer(serializer);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.StatsAPITaskProcessor = StatsAPITaskProcessor;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BasicTaskProcessor } from "./basic";
|
|
2
|
+
import { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
|
|
3
|
+
export interface IRspackTreeShakingProcessorOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
snapshot: string;
|
|
6
|
+
type: "new" | "builtin";
|
|
7
|
+
}
|
|
8
|
+
export declare class RspackTreeShakingProcessor extends BasicTaskProcessor<ECompilerType.Rspack> {
|
|
9
|
+
protected _treeShakingOptions: IRspackTreeShakingProcessorOptions;
|
|
10
|
+
constructor(_treeShakingOptions: IRspackTreeShakingProcessorOptions);
|
|
11
|
+
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
12
|
+
static defaultOptions(context: ITestContext): TCompilerOptions<ECompilerType.Rspack>;
|
|
13
|
+
static overrideOptions(type: IRspackTreeShakingProcessorOptions["type"]): (context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>) => void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
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.RspackTreeShakingProcessor = void 0;
|
|
7
|
+
const basic_1 = require("./basic");
|
|
8
|
+
const type_1 = require("../type");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
|
+
const webpack_merge_1 = require("webpack-merge");
|
|
12
|
+
const core_1 = require("@rspack/core");
|
|
13
|
+
class RspackTreeShakingProcessor extends basic_1.BasicTaskProcessor {
|
|
14
|
+
constructor(_treeShakingOptions) {
|
|
15
|
+
super({
|
|
16
|
+
compilerType: type_1.ECompilerType.Rspack,
|
|
17
|
+
defaultOptions: RspackTreeShakingProcessor.defaultOptions,
|
|
18
|
+
overrideOptions: RspackTreeShakingProcessor.overrideOptions(_treeShakingOptions.type),
|
|
19
|
+
name: _treeShakingOptions.name,
|
|
20
|
+
runable: false
|
|
21
|
+
});
|
|
22
|
+
this._treeShakingOptions = _treeShakingOptions;
|
|
23
|
+
}
|
|
24
|
+
async check(env, context) {
|
|
25
|
+
const compiler = this.getCompiler(context);
|
|
26
|
+
const stats = compiler.getStats();
|
|
27
|
+
const c = compiler.getCompiler();
|
|
28
|
+
if (!stats || !c)
|
|
29
|
+
return;
|
|
30
|
+
if (stats.hasErrors()) {
|
|
31
|
+
throw new Error(`Failed to compile in fixture ${this._options.name}, Errors: ${stats.toJson({ errors: true, all: false }).errors}`);
|
|
32
|
+
}
|
|
33
|
+
const fileContents = Object.entries(c.compilation.assets)
|
|
34
|
+
.filter(([file]) => file.endsWith(".js") && !file.includes("runtime.js"))
|
|
35
|
+
.map(([file, source]) => {
|
|
36
|
+
const tag = path_1.default.extname(file).slice(1) || "txt";
|
|
37
|
+
return `\`\`\`${tag} title=${file}\n${source.source().toString()}\n\`\`\``;
|
|
38
|
+
});
|
|
39
|
+
fileContents.sort();
|
|
40
|
+
const content = `---\nsource: crates/rspack_testing/src/run_fixture.rs\n---\n${fileContents.join("\n\n")}\n`;
|
|
41
|
+
const updateSnapshot = process.argv.includes("-u") || process.argv.includes("--updateSnapshot");
|
|
42
|
+
const snapshotPath = path_1.default.resolve(context.getSource(), `./snapshot/${this._treeShakingOptions.snapshot}`);
|
|
43
|
+
if (!fs_extra_1.default.existsSync(snapshotPath) || updateSnapshot) {
|
|
44
|
+
fs_extra_1.default.writeFileSync(snapshotPath, content, "utf-8");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const snapshotContent = fs_extra_1.default.readFileSync(snapshotPath, "utf-8");
|
|
48
|
+
expect(content).toBe(snapshotContent);
|
|
49
|
+
}
|
|
50
|
+
static defaultOptions(context) {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
let defaultOptions = {
|
|
53
|
+
entry: {
|
|
54
|
+
main: {
|
|
55
|
+
import: "./index",
|
|
56
|
+
runtime: "runtime"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
output: {
|
|
60
|
+
filename: "[name].js",
|
|
61
|
+
chunkFilename: "[name].js",
|
|
62
|
+
cssFilename: "[name].css",
|
|
63
|
+
cssChunkFilename: "[name].css",
|
|
64
|
+
sourceMapFilename: "[file].map",
|
|
65
|
+
chunkLoadingGlobal: "webpackChunkwebpack",
|
|
66
|
+
chunkLoading: "jsonp",
|
|
67
|
+
uniqueName: "__rspack_test__",
|
|
68
|
+
enabledLibraryTypes: ["system"],
|
|
69
|
+
strictModuleErrorHandling: false,
|
|
70
|
+
iife: true,
|
|
71
|
+
module: false,
|
|
72
|
+
asyncChunks: true,
|
|
73
|
+
scriptType: false,
|
|
74
|
+
globalObject: "self",
|
|
75
|
+
importFunctionName: "import"
|
|
76
|
+
},
|
|
77
|
+
module: {
|
|
78
|
+
rules: [
|
|
79
|
+
{
|
|
80
|
+
test: /\.json$/,
|
|
81
|
+
type: "json"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
test: /\.mjs$/,
|
|
85
|
+
type: "js/esm"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
test: /\.cjs$/,
|
|
89
|
+
type: "js/dynamic"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
test: /\.js$/,
|
|
93
|
+
type: "js/auto"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
test: /\.css$/,
|
|
97
|
+
type: "css"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
test: /\.wasm$/,
|
|
101
|
+
type: "webassembly/async"
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
node: {
|
|
106
|
+
__dirname: "mock",
|
|
107
|
+
__filename: "mock",
|
|
108
|
+
global: "warn"
|
|
109
|
+
},
|
|
110
|
+
optimization: {
|
|
111
|
+
minimize: false,
|
|
112
|
+
removeAvailableModules: true,
|
|
113
|
+
removeEmptyChunks: true,
|
|
114
|
+
moduleIds: "named",
|
|
115
|
+
chunkIds: "named",
|
|
116
|
+
sideEffects: false,
|
|
117
|
+
mangleExports: false,
|
|
118
|
+
usedExports: false,
|
|
119
|
+
concatenateModules: false,
|
|
120
|
+
nodeEnv: false
|
|
121
|
+
},
|
|
122
|
+
devtool: false,
|
|
123
|
+
context: context.getSource(),
|
|
124
|
+
plugins: []
|
|
125
|
+
};
|
|
126
|
+
const testConfigFile = context.getSource("test.config.js");
|
|
127
|
+
if (fs_extra_1.default.existsSync(testConfigFile)) {
|
|
128
|
+
defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, require(testConfigFile));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const testConfigJson = context.getSource("test.config.json");
|
|
132
|
+
if (fs_extra_1.default.existsSync(testConfigJson)) {
|
|
133
|
+
const content = fs_extra_1.default
|
|
134
|
+
.readFileSync(testConfigJson, "utf-8")
|
|
135
|
+
.split(`"true"`)
|
|
136
|
+
.join("true")
|
|
137
|
+
.split(`"false"`)
|
|
138
|
+
.join("false");
|
|
139
|
+
const json = JSON.parse(content);
|
|
140
|
+
defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, json);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// TODO: remove these after modify all test.config.json
|
|
144
|
+
const defineOptions = (_a = defaultOptions.builtins) === null || _a === void 0 ? void 0 : _a.define;
|
|
145
|
+
if (defineOptions) {
|
|
146
|
+
defaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
|
|
147
|
+
(_b = defaultOptions.builtins) === null || _b === void 0 ? true : delete _b.define;
|
|
148
|
+
}
|
|
149
|
+
const rules = (_c = defaultOptions.module) === null || _c === void 0 ? void 0 : _c.rules;
|
|
150
|
+
if (rules) {
|
|
151
|
+
defaultOptions.module.rules = rules.map((rule) => {
|
|
152
|
+
var _a;
|
|
153
|
+
if (typeof ((_a = rule.test) === null || _a === void 0 ? void 0 : _a.type) === "string") {
|
|
154
|
+
if (rule.test.type === "regexp") {
|
|
155
|
+
rule.test = new RegExp(rule.test.matcher);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (typeof rule.sideEffect === "boolean") {
|
|
159
|
+
rule.sideEffects = rule.sideEffect;
|
|
160
|
+
delete rule.sideEffect;
|
|
161
|
+
}
|
|
162
|
+
return rule;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return defaultOptions;
|
|
166
|
+
}
|
|
167
|
+
static overrideOptions(type) {
|
|
168
|
+
return (context, options) => {
|
|
169
|
+
var _a, _b, _c, _d;
|
|
170
|
+
var _e;
|
|
171
|
+
options.target = options.target || ["web", "es2022"];
|
|
172
|
+
if (type === "new") {
|
|
173
|
+
(_a = options.optimization) !== null && _a !== void 0 ? _a : (options.optimization = {});
|
|
174
|
+
options.optimization.providedExports = true;
|
|
175
|
+
options.optimization.innerGraph = true;
|
|
176
|
+
options.optimization.usedExports = true;
|
|
177
|
+
(_b = options.experiments) !== null && _b !== void 0 ? _b : (options.experiments = {});
|
|
178
|
+
(_c = (_e = options.experiments).rspackFuture) !== null && _c !== void 0 ? _c : (_e.rspackFuture = {});
|
|
179
|
+
options.experiments.rspackFuture.newTreeshaking = true;
|
|
180
|
+
(_d = options.builtins) !== null && _d !== void 0 ? _d : (options.builtins = {});
|
|
181
|
+
options.builtins.treeShaking = false;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.RspackTreeShakingProcessor = RspackTreeShakingProcessor;
|
package/dist/test/context.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ITestCompilerManager, ECompilerType, ITestContext, ITesterConfig, ITestRunner, TTestConfig, TRunnerFactory } from "../type";
|
|
2
|
+
export type TTestContextOptions = Omit<ITesterConfig, "name" | "steps">;
|
|
2
3
|
export declare class TestContext implements ITestContext {
|
|
3
4
|
private config;
|
|
4
5
|
protected errors: Map<string, Error[]>;
|
|
@@ -6,7 +7,7 @@ export declare class TestContext implements ITestContext {
|
|
|
6
7
|
protected store: Map<string, Record<string, unknown>>;
|
|
7
8
|
protected runners: Map<string, ITestRunner>;
|
|
8
9
|
protected runnerFactory: TRunnerFactory<ECompilerType> | null;
|
|
9
|
-
constructor(config:
|
|
10
|
+
constructor(config: TTestContextOptions);
|
|
10
11
|
getSource(sub?: string): string;
|
|
11
12
|
getDist(sub?: string): string;
|
|
12
13
|
getTemp(sub?: string): string | null;
|
package/dist/test/creator.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
|
|
|
10
10
|
dist: string;
|
|
11
11
|
temp: string | void;
|
|
12
12
|
}) => ITestProcessor[];
|
|
13
|
-
description?: (name: string) => string;
|
|
13
|
+
description?: (name: string, step: number) => string;
|
|
14
14
|
runner?: new (name: string, context: ITestContext) => TRunnerFactory<ECompilerType>;
|
|
15
15
|
[key: string]: unknown;
|
|
16
16
|
}
|
package/dist/test/creator.js
CHANGED
|
@@ -35,17 +35,20 @@ class BasicCaseCreator {
|
|
|
35
35
|
beforeAll(async () => {
|
|
36
36
|
await tester.prepare();
|
|
37
37
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
for (let index = 0; index < tester.total; index++) {
|
|
39
|
+
const description = typeof this._options.description === "function"
|
|
40
|
+
? this._options.description(name, index)
|
|
41
|
+
: `${name}${index ? `[${index}]` : ""} should compile`;
|
|
42
|
+
it(description, async () => {
|
|
43
|
+
await tester.compile();
|
|
44
|
+
await tester.check(env);
|
|
45
|
+
tester.next();
|
|
46
|
+
}, this._options.timeout || 30000);
|
|
47
|
+
const env = this.createEnv(testConfig);
|
|
48
|
+
}
|
|
45
49
|
afterAll(async () => {
|
|
46
50
|
await tester.resume();
|
|
47
51
|
});
|
|
48
|
-
const env = this.createEnv(testConfig);
|
|
49
52
|
}
|
|
50
53
|
createEnv(testConfig) {
|
|
51
54
|
if (typeof this._options.runner === "function" && !testConfig.noTest) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
"glob": "^10.3.10",
|
|
40
40
|
"jest-diff": "^29.7.0",
|
|
41
41
|
"jest-serializer-path": "^0.1.15",
|
|
42
|
+
"memfs": "4.7.7",
|
|
42
43
|
"webpack": "^5.90.1",
|
|
43
44
|
"webpack-merge": "5.9.0",
|
|
44
45
|
"webpack-sources": "3.2.3",
|
|
45
46
|
"which-module": "2.0.1",
|
|
46
|
-
"@rspack/core": "0.5.
|
|
47
|
+
"@rspack/core": "0.5.8"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@arco-design/web-react": "^2.56.1",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"react": "18.0.0",
|
|
63
64
|
"react-dom": "18.0.0",
|
|
64
65
|
"react-refresh": "0.14.0",
|
|
65
|
-
"@rspack/cli": "0.5.
|
|
66
|
+
"@rspack/cli": "0.5.8"
|
|
66
67
|
},
|
|
67
68
|
"scripts": {
|
|
68
69
|
"build": "tsc -b ./tsconfig.build.json",
|