Skip to content

Commit

Permalink
fix: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Jan 13, 2025
1 parent 249c2e4 commit 4a23903
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 2,345 deletions.
2 changes: 1 addition & 1 deletion crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct ChunkGraphChunk {
///
/// use `LinkedHashMap` to keep the ordered from entry array.
pub(super) entry_modules: IdentifierLinkedMap<ChunkGroupUkey>,
pub modules: IdentifierSet,
pub(super) modules: IdentifierSet,
pub(super) runtime_modules: Vec<ModuleIdentifier>,

pub(super) source_types_by_module: Option<IdentifierMap<FxHashSet<SourceType>>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_plugin_css/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl CssPlugin {
})
.collect::<Vec<_>>();

if modules_by_chunk_group.len() <= 1 {
if modules_by_chunk_group.len() == 1 {
let mut ret = modules_by_chunk_group
.into_iter()
.next()
Expand Down
60 changes: 60 additions & 0 deletions packages/rspack-test-tools/etc/test-tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ import type { StatsError } from '@rspack/core';
import { TRunnerRequirer as TRunnerRequirer_2 } from '..';
import type { WebpackOptionsNormalized } from 'webpack';

// @public (undocumented)
export class BasicCaseCreator<T extends ECompilerType> {
constructor(_options: IBasicCaseCreatorOptions<T>);
// (undocumented)
protected checkSkipped(src: string, testConfig: TTestConfig<T>): boolean | string;
// (undocumented)
protected clean(folders: string[]): void;
// (undocumented)
create(name: string, src: string, dist: string, temp?: string): ITester | undefined;
// (undocumented)
protected createEnv(testConfig: TTestConfig<T>): ITestEnv;
// (undocumented)
protected createTester(name: string, src: string, dist: string, temp: string | void, testConfig: TTestConfig<T>): ITester;
// (undocumented)
protected describe(name: string, tester: ITester, testConfig: TTestConfig<T>): void;
// (undocumented)
protected _options: IBasicCaseCreatorOptions<T>;
// (undocumented)
protected readTestConfig(src: string): TTestConfig<T>;
// (undocumented)
protected skip(name: string, reason: string | boolean): void;
}

// @public (undocumented)
export class BasicProcessor<T extends ECompilerType> implements ITestProcessor {
constructor(_options: IBasicProcessorOptions<T>);
Expand Down Expand Up @@ -191,6 +214,9 @@ export function createCompilerCase(name: string, src: string, dist: string, test
// @public (undocumented)
export function createConfigCase(name: string, src: string, dist: string): void;

// @public (undocumented)
export function createConfigNewCodeSplittingCase(name: string, src: string, dist: string): void;

// @public (undocumented)
export function createDefaultsCase(name: string, src: string): void;

Expand Down Expand Up @@ -224,6 +250,9 @@ export function createNormalCase(name: string, src: string, dist: string): void;
// @public (undocumented)
export function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;

// @public (undocumented)
export function createStatsAPINewCodeSplittingCase(name: string, src: string, dist: string, testConfig: string): void;

// @public (undocumented)
export function createStatsOutputCase(name: string, src: string, dist: string): void;

Expand Down Expand Up @@ -538,6 +567,33 @@ export class HotStepRunnerFactory<T extends ECompilerType> extends HotRunnerFact
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
}

// @public (undocumented)
export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
// (undocumented)
[key: string]: unknown;
// (undocumented)
clean?: boolean;
// (undocumented)
contextValue?: Record<string, unknown>;
// (undocumented)
describe?: boolean;
// (undocumented)
description?: (name: string, step: number) => string;
// (undocumented)
runner?: new (name: string, context: ITestContext) => TRunnerFactory<ECompilerType>;
// (undocumented)
steps: (creatorConfig: IBasicCaseCreatorOptions<T> & {
name: string;
src: string;
dist: string;
temp: string | void;
}) => ITestProcessor[];
// (undocumented)
testConfig?: (testConfig: TTestConfig<T>) => void;
// (undocumented)
timeout?: number;
}

// @public (undocumented)
export interface IBasicGlobalContext {
// (undocumented)
Expand Down Expand Up @@ -870,10 +926,14 @@ export interface IStatsAPIProcessorOptions<T extends ECompilerType> {
name: string;
// (undocumented)
options?: (context: ITestContext) => TCompilerOptions<T>;
// (undocumented)
snapshotName?: string;
}

// @public (undocumented)
export interface IStatsProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
// (undocumented)
snapshotName?: string;
}

// @public (undocumented)
Expand Down
15 changes: 10 additions & 5 deletions packages/rspack-test-tools/src/case/new-code-splitting.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { Experiments } from "@rspack/core";
import type { Experiments } from "@rspack/core";
import {
ConfigProcessor,
IConfigProcessorOptions,
IStatsAPIProcessorOptions,
type IConfigProcessorOptions,
type 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";
import {
ECompilerType,
type ITestContext,
type TCompilerOptions
} from "../type";
import type { TStatsAPICaseConfig } from "./stats-api";

export function createConfigNewCodeSplittingCase(
name: string,
Expand Down Expand Up @@ -80,6 +84,7 @@ export function createStatsAPINewCodeSplittingCase(
name,
new NewCodeSplittingStatsAPIProcessor({
name: name,
snapshotName: "NewCodeSplittingStatsOutput",
compilerType: ECompilerType.Rspack,
...caseConfig
})
Expand Down
1 change: 1 addition & 0 deletions packages/rspack-test-tools/src/processor/stats-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IStatsAPIProcessorOptions<T extends ECompilerType> {
options?: (context: ITestContext) => TCompilerOptions<T>;
name: string;
compilerType: T;
snapshotName?: string;
compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
check?: (stats: TCompilerStats<T>, compiler: TCompiler<T>) => Promise<void>;
Expand Down
13 changes: 11 additions & 2 deletions packages/rspack-test-tools/src/processor/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import type {
import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";

export interface IStatsProcessorOptions<T extends ECompilerType>
extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {}
extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
snapshotName?: string;
}

const REG_ERROR_CASE = /error$/;

Expand All @@ -25,13 +27,15 @@ export class StatsProcessor<
T extends ECompilerType
> extends MultiTaskProcessor<T> {
private stderr: any;
private snapshotName?: string;
constructor(_statsOptions: IStatsProcessorOptions<T>) {
super({
defaultOptions: StatsProcessor.defaultOptions<T>,
overrideOptions: StatsProcessor.overrideOptions<T>,
runable: false,
..._statsOptions
});
this.snapshotName = _statsOptions.snapshotName;
}

async before(context: ITestContext) {
Expand Down Expand Up @@ -158,7 +162,12 @@ export class StatsProcessor<
// CHANGE: The time unit display in Rspack is second
.replace(/[.0-9]+(\s?s)/g, "X$1");
}
env.expect(new RspackStats(actual)).toMatchSnapshot();

if (this.snapshotName) {
env.expect(new RspackStats(actual)).toMatchSnapshot(this.snapshotName);
} else {
env.expect(new RspackStats(actual)).toMatchSnapshot();
}
const testConfig = context.getTestConfig();
if (typeof testConfig?.validate === "function") {
testConfig.validate(stats, this.stderr.toString());
Expand Down
13 changes: 4 additions & 9 deletions packages/rspack-test-tools/src/test/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
TTestConfig
} from "../type";
import { Tester } from "./tester";
import { FilteredStatus } from "../helper/util/filterUtil";

export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
clean?: boolean;
Expand Down Expand Up @@ -150,14 +149,10 @@ export class BasicCaseCreator<T extends ECompilerType> {
testConfig: TTestConfig<T>
): boolean | string {
const filterPath = path.join(src, "test.filter.js");
let flag = true;
if (fs.existsSync(filterPath)) {
flag = require(filterPath)(testConfig);
}
let shouldRun =
flag === true ||
(Array.isArray(flag) && flag.includes(FilteredStatus.PARTIAL_PASS));
return !shouldRun;
return (
fs.existsSync(filterPath) &&
!require(filterPath)(this._options, testConfig)
);
}

protected createTester(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
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`),
exclude: [/esm-external/]
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const creator = new BasicCaseCreator({
name,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"],
snapshotName: 'NewCodeSplittingStatsOutput',
overrideOptions(index, context, options) {
options.experiments ??= {};
options.experiments.parallelCodeSplitting ??= true;
Expand Down
Loading

0 comments on commit 4a23903

Please sign in to comment.