Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: allow optional test options #6603

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export function describeByWalk(testFile: string, createCase: (name: string, src:
source?: string;
dist?: string;
absoluteDist?: boolean;
describe?: jest.Describe;
}): void;

// @public (undocumented)
Expand Down Expand Up @@ -447,7 +448,7 @@ export interface IBasicProcessorOptions<T extends ECompilerType> {
}

// @public (undocumented)
export interface IBuiltinProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "defaultOptions" | "runable"> {
export interface IBuiltinProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "runable"> {
}

// @public (undocumented)
Expand All @@ -467,7 +468,7 @@ export interface ICompareOptions {
}

// @public (undocumented)
export interface IConfigProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "defaultOptions" | "overrideOptions" | "findBundle"> {
export interface IConfigProcessorOptions<T extends ECompilerType> extends IMultiTaskProcessorOptions<T> {
}

// @public (undocumented)
Expand All @@ -485,7 +486,7 @@ export interface IDefaultsConfigProcessorOptions<T extends ECompilerType> {
}

// @public (undocumented)
export interface IDiagnosticProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "defaultOptions" | "runable"> {
export interface IDiagnosticProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
// (undocumented)
snapshot: string;
}
Expand Down Expand Up @@ -591,11 +592,11 @@ export interface IFormatCodeOptions {
}

// @public (undocumented)
export interface IHashProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "defaultOptions" | "overrideOptions" | "runable"> {
export interface IHashProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
}

// @public (undocumented)
export interface IHookProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "defaultOptions"> {
export interface IHookProcessorOptions<T extends ECompilerType> extends ISnapshotProcessorOptions<T> {
// (undocumented)
check?: (context: ITestContext) => Promise<void>;
// (undocumented)
Expand All @@ -605,7 +606,7 @@ export interface IHookProcessorOptions<T extends ECompilerType> extends Omit<ISn
}

// @public (undocumented)
export interface IHotProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "defaultOptions" | "overrideOptions" | "runable" | "findBundle"> {
export interface IHotProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
// (undocumented)
target: TCompilerOptions<T>["target"];
}
Expand Down Expand Up @@ -679,7 +680,7 @@ export interface IStatsAPIProcessorOptions<T extends ECompilerType> {
}

// @public (undocumented)
export interface IStatsProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "defaultOptions" | "overrideOptions" | "runable"> {
export interface IStatsProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
}

// @public (undocumented)
Expand Down Expand Up @@ -842,7 +843,7 @@ export interface ITestRunner {
}

// @public (undocumented)
export interface IWatchProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "overrideOptinos" | "findBundle"> {
export interface IWatchProcessorOptions<T extends ECompilerType> extends IMultiTaskProcessorOptions<T> {
// (undocumented)
experiments?: TRspackExperiments;
// (undocumented)
Expand Down
8 changes: 5 additions & 3 deletions packages/rspack-test-tools/src/helper/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export function describeByWalk(
source?: string;
dist?: string;
absoluteDist?: boolean;
describe?: jest.Describe;
} = {}
) {
const describeFn = options.describe || describe;
const testBasename = path
.basename(testFile)
.replace(/\.(diff|hot)?test\.js/, "");
.replace(/\.(diff|hot)?test\.(j|t)s/, "");
const testId = testBasename.charAt(0).toLowerCase() + testBasename.slice(1);
const sourceBase =
options.source || path.join(path.dirname(testFile), `${testId}Cases`);
Expand Down Expand Up @@ -51,7 +53,7 @@ export function describeByWalk(
const name = escapeSep(
path.join(testId, caseName).split(".").shift()!
);
describe(name, () => {
describeFn(name, () => {
let source = path.join(sourceBase, caseName);
let dist = "";
if (absoluteDist) {
Expand All @@ -70,7 +72,7 @@ export function describeByWalk(
});
}

describe(testId, () => {
describeFn(testId, () => {
describeDirectory("", level);
});
}
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/processor/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ECompilerType, ITestContext, TCompilerOptions } from "../type";
import { ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";

export interface IBuiltinProcessorOptions<T extends ECompilerType>
extends Omit<ISnapshotProcessorOptions<T>, "defaultOptions" | "runable"> {}
extends Omit<ISnapshotProcessorOptions<T>, "runable"> {}

export class BuiltinProcessor<
T extends ECompilerType
Expand Down
5 changes: 1 addition & 4 deletions packages/rspack-test-tools/src/processor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { ECompilerType, ITestContext, TCompilerOptions } from "../type";
import { IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";

export interface IConfigProcessorOptions<T extends ECompilerType>
extends Omit<
IMultiTaskProcessorOptions<T>,
"defaultOptions" | "overrideOptions" | "findBundle"
> {}
extends IMultiTaskProcessorOptions<T> {}

export class ConfigProcessor<
T extends ECompilerType
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/processor/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare var global: {
};

export interface IDiagnosticProcessorOptions<T extends ECompilerType>
extends Omit<IBasicProcessorOptions<T>, "defaultOptions" | "runable"> {
extends Omit<IBasicProcessorOptions<T>, "runable"> {
snapshot: string;
}

Expand Down
5 changes: 1 addition & 4 deletions packages/rspack-test-tools/src/processor/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
import { IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";

export interface IHashProcessorOptions<T extends ECompilerType>
extends Omit<
IMultiTaskProcessorOptions<T>,
"defaultOptions" | "overrideOptions" | "runable"
> {}
extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {}

const REG_ERROR_CASE = /error$/;

Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/processor/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class HookCasesContext extends TestContext {
}

export interface IHookProcessorOptions<T extends ECompilerType>
extends Omit<ISnapshotProcessorOptions<T>, "defaultOptions"> {
extends ISnapshotProcessorOptions<T> {
options?: (context: ITestContext) => TCompilerOptions<T>;
compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
check?: (context: ITestContext) => Promise<void>;
Expand Down
5 changes: 1 addition & 4 deletions packages/rspack-test-tools/src/processor/hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import {
import { BasicProcessor, IBasicProcessorOptions } from "./basic";

export interface IHotProcessorOptions<T extends ECompilerType>
extends Omit<
IBasicProcessorOptions<T>,
"defaultOptions" | "overrideOptions" | "runable" | "findBundle"
> {
extends Omit<IBasicProcessorOptions<T>, "runable"> {
target: TCompilerOptions<T>["target"];
}

Expand Down
5 changes: 1 addition & 4 deletions packages/rspack-test-tools/src/processor/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import {
import { IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";

export interface IStatsProcessorOptions<T extends ECompilerType>
extends Omit<
IMultiTaskProcessorOptions<T>,
"defaultOptions" | "overrideOptions" | "runable"
> {}
extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {}

const REG_ERROR_CASE = /error$/;
const quoteMeta = (str: string) => {
Expand Down
5 changes: 1 addition & 4 deletions packages/rspack-test-tools/src/processor/treeshaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { BuiltinProcessor } from "./builtin";
import { ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";

export interface ITreeShakingProcessorOptions<T extends ECompilerType>
extends Omit<
ISnapshotProcessorOptions<T>,
"defaultOptions" | "overrideOptions" | "runable"
> {}
extends Omit<ISnapshotProcessorOptions<T>, "runable"> {}

export class TreeShakingProcessor<
T extends ECompilerType
Expand Down
5 changes: 1 addition & 4 deletions packages/rspack-test-tools/src/processor/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ type TRspackExperiments = TCompilerOptions<ECompilerType>["experiments"];
type TRspackOptimization = TCompilerOptions<ECompilerType>["optimization"];

export interface IWatchProcessorOptions<T extends ECompilerType>
extends Omit<
IMultiTaskProcessorOptions<T>,
"overrideOptinos" | "findBundle"
> {
extends IMultiTaskProcessorOptions<T> {
stepName: string;
tempDir: string;
experiments?: TRspackExperiments;
Expand Down
Loading