Skip to content

Commit

Permalink
test: allow optional test options (#6603)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder committed May 22, 2024
1 parent 25edcdc commit 5b632e4
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 38 deletions.
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 @@ -449,7 +450,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 @@ -469,7 +470,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 @@ -487,7 +488,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 @@ -593,11 +594,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 @@ -607,7 +608,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 @@ -681,7 +682,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 @@ -844,7 +845,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 @@ -12,10 +12,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

2 comments on commit 5b632e4

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
compat ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-05-22 c7db90a) Current Change
10000_development-mode + exec 2.66 s ± 36 ms 2.55 s ± 32 ms -4.19 %
10000_development-mode_hmr + exec 740 ms ± 16 ms 697 ms ± 8 ms -5.78 %
10000_production-mode + exec 2.57 s ± 28 ms 2.44 s ± 14 ms -5.36 %
arco-pro_development-mode + exec 2.54 s ± 37 ms 2.38 s ± 69 ms -6.31 %
arco-pro_development-mode_hmr + exec 438 ms ± 3.2 ms 438 ms ± 1.7 ms -0.10 %
arco-pro_development-mode_hmr_intercept-plugin + exec 447 ms ± 2.1 ms 447 ms ± 1.6 ms +0.02 %
arco-pro_development-mode_intercept-plugin + exec 3.37 s ± 73 ms 3.14 s ± 76 ms -6.91 %
arco-pro_production-mode + exec 4.1 s ± 66 ms 3.89 s ± 96 ms -5.08 %
arco-pro_production-mode_intercept-plugin + exec 4.95 s ± 75 ms 4.63 s ± 101 ms -6.36 %
threejs_development-mode_10x + exec 2 s ± 17 ms 1.95 s ± 24 ms -2.95 %
threejs_development-mode_10x_hmr + exec 785 ms ± 7.1 ms 770 ms ± 5.8 ms -1.91 %
threejs_production-mode_10x + exec 5.33 s ± 36 ms 5.12 s ± 57 ms -3.90 %

Please sign in to comment.