Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Jan 9, 2025
1 parent aaec7aa commit 18b17a0
Show file tree
Hide file tree
Showing 9 changed files with 2,859 additions and 828 deletions.
46 changes: 45 additions & 1 deletion packages/rspack-test-tools/src/case/new-code-splitting.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Experiments } from "@rspack/core";
import { ConfigProcessor, IConfigProcessorOptions } from "../processor";
import {
ConfigProcessor,
IConfigProcessorOptions,
IStatsAPIProcessorOptions,
StatsAPIProcessor
} from "../processor";
import { MultipleRunnerFactory } from "../runner";
import { BasicCaseCreator } from "../test/creator";
import { ECompilerType, ITestContext, TCompilerOptions } from "../type";
import { TStatsAPICaseConfig } from "./stats-api";
import { getSimpleProcessorRunner } from "../test/simple";

export function createConfigNewCodeSplittingCase(
name: string,
Expand Down Expand Up @@ -58,3 +65,40 @@ class NewCodeSplittingProcessor<
(options.experiments as Experiments).parallelCodeSplitting ??= true;
}
}

export function createStatsAPINewCodeSplittingCase(
name: string,
src: string,
dist: string,
testConfig: string
) {
const caseConfig: TStatsAPICaseConfig = require(testConfig);
const runner = getSimpleProcessorRunner(src, dist);

it(caseConfig.description, async () => {
await runner(
name,
new NewCodeSplittingStatsAPIProcessor({
name: name,
compilerType: ECompilerType.Rspack,
...caseConfig
})
);
});
}

class NewCodeSplittingStatsAPIProcessor extends StatsAPIProcessor<ECompilerType.Rspack> {
constructor(
protected _statsAPIOptions: IStatsAPIProcessorOptions<ECompilerType.Rspack>
) {
super({
..._statsAPIOptions,
options: context => {
const res = _statsAPIOptions.options?.(context) || {};
res.experiments ??= {};
res.experiments.parallelCodeSplitting ??= true;
return res;
}
});
}
}
1 change: 1 addition & 0 deletions packages/rspack-test-tools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from "./runner";
export * from "./test/context";
export * from "./test/simple";
export * from "./test/tester";
export * from "./test/creator";
export * from "./type";
14 changes: 14 additions & 0 deletions packages/rspack-test-tools/tests/NewCodeSplitting-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require("path");
const { describeByWalk, createConfigNewCodeSplittingCase } = require("..");

function v(name) {
return path.join(__dirname, `new-code-splitting ${name}`)
}

// Run tests rspack-test-tools/tests/configCases
describeByWalk("new-code-splitting config cases", (name, src, dist) => {
createConfigNewCodeSplittingCase(name, src, dist);
}, {
source: path.resolve(__dirname, "./configCases"),
dist: path.resolve(__dirname, `./js/new-code-splitting-config`),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require("path");
const { describeByWalk, createStatsAPINewCodeSplittingCase } = require("..");

describeByWalk(path.resolve(__dirname, 'statsAPI'), (name, testConfig, dist) => {
createStatsAPINewCodeSplittingCase(name, __dirname, "none", testConfig);
}, {
absoluteDist: false,
level: 1,
type: "file",
dist: path.resolve(__dirname, `./js/new-code-splitting-stats-api`),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require("path");
const { describeByWalk, StatsProcessor, BasicCaseCreator, ECompilerType } = require("..");

const creator = new BasicCaseCreator({
clean: true,
describe: false,
steps: ({ name }) => [
new StatsProcessor({
name,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"],
overrideOptions(index, context, options) {
options.experiments ??= {};
options.experiments.parallelCodeSplitting ??= true;
return StatsProcessor.overrideOptions(index, context, options);
}
})
],
description: () => "should print correct stats for"
});

describeByWalk(path.resolve(__dirname, 'statsOutput'), (name, src, dist) => {
creator.create(name, src, dist);
}, {
level: 1,
dist: path.resolve(__dirname, `./js/new-code-splitting-stats-output`),
});
23 changes: 0 additions & 23 deletions packages/rspack-test-tools/tests/NewCodeSplitting.test.js

This file was deleted.

Loading

0 comments on commit 18b17a0

Please sign in to comment.