Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
with:
target: aarch64-apple-darwin
profile: "ci"
runner: ${{ vars.MACOS_RUNNER_LABELS || '"macos-latest"' }}
runner: ${{ vars.MAC_SELF_HOSTED_RUNNER_LABELS || '"macos-latest"' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use self hosted mac runner to prevent timeout

test: true

test-wasm:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"prepare": "is-ci || husky",
"test:diff": "pnpm --filter \"@rspack/*\" test:diff",
"test:hot": "pnpm --filter \"@rspack/*\" test:hot",
"test:unit": "pnpm --parallel --filter \"@rspack/*\" test",
"test:unit": "pnpm --sequential --filter \"@rspack/*\" test",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use sequential to prevent OOM

"test:e2e": "pnpm --filter \"e2e-test\" test",
"test:ci": "cross-env NODE_OPTIONS=--max_old_space_size=8192 pnpm run build:js && pnpm run test:unit && pnpm test:webpack",
"test:webpack": "pnpm --filter \"webpack-test\" test:metric",
Expand Down Expand Up @@ -104,4 +104,4 @@
"esbuild"
]
}
}
}
100 changes: 85 additions & 15 deletions packages/rspack-test-tools/etc/test-tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import type { Stats } from '@rspack/core';
import type { Stats as Stats_2 } from 'webpack';
import type { StatsCompilation } from '@rspack/core';
import type { StatsCompilation as StatsCompilation_2 } from 'webpack';
import type { StatsError } from '@rspack/core';
import type { WebpackOptionsNormalized } from 'webpack';

// @public (undocumented)
export function basename(filename: string): string;

// @public (undocumented)
export class BasicCaseCreator<T extends ECompilerType> {
constructor(_options: IBasicCaseCreatorOptions<T>);
Expand Down Expand Up @@ -61,6 +65,9 @@ export class BasicCaseCreator<T extends ECompilerType> {
protected tryRunTask(concurrent?: number): void;
}

// @public (undocumented)
export function casename(filename: string): string;

// @public (undocumented)
export function checkChunkModules(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;

Expand All @@ -82,24 +89,15 @@ export function createBuiltinCase(name: string, src: string, dist: string): void
// @public (undocumented)
export function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], temp: string): void;

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

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

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

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

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

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

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

Expand Down Expand Up @@ -127,9 +125,6 @@ export function createNormalCase(name: string, src: string, dist: string): void;
// @public (undocumented)
export function createSerialCase(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 createStatsOutputCase(name: string, src: string, dist: string): void;

Expand All @@ -142,6 +137,18 @@ export function createWatchCase(name: string, src: string, dist: string, temp: s
// @public (undocumented)
export function createWatchIncrementalCase(name: string, src: string, dist: string, temp: string, options?: WatchIncrementalOptions): void;

// @public (undocumented)
export function defineCompileCase(name: string, caseConfigList: TCompilerCaseConfig | TCompilerCaseConfig[]): void;

// @public (undocumented)
export function defineDefaultsCase(name: string, caseConfig: TDefaultsCaseConfig): void;

// @public (undocumented)
export function defineErrorCase(name: string, caseConfig: TErrorCaseConfig): void;

// @public (undocumented)
export function defineStatsAPICase(name: string, caseConfig: TStatsAPICaseConfig): void;

// @public (undocumented)
export function describeByWalk(testFile: string, createCase: (name: string, src: string, dist: string) => void, options?: {
type?: "file" | "directory";
Expand Down Expand Up @@ -233,7 +240,7 @@ export function escapeSep(str: string): string;
export function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;

// @public (undocumented)
export function getRspackDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
export function getRspackDefaultConfig(context: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;

// @public (undocumented)
export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
Expand All @@ -248,8 +255,6 @@ export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
// (undocumented)
createContext?: (config: ITesterConfig) => ITestContext;
// (undocumented)
describe?: boolean;
// (undocumented)
description?: (name: string, step: number) => string;
// (undocumented)
runner?: TTestRunnerCreator;
Expand Down Expand Up @@ -501,6 +506,8 @@ export interface ITester {
// (undocumented)
check(env: ITestEnv): Promise<void>;
// (undocumented)
close(): Promise<void>;
// (undocumented)
compile(): Promise<void>;
// (undocumented)
getContext(): ITestContext;
Expand Down Expand Up @@ -672,6 +679,22 @@ export class RspackDiffConfigPlugin implements RspackPluginInstance {
name: string;
}

// @public (undocumented)
class RspackStatsDiagnostics {
constructor(errors: StatsError[], warnings: StatsError[]);
// (undocumented)
errors: StatsError[];
// (undocumented)
warnings: StatsError[];
}

// @public (undocumented)
class RspackTestDiff {
constructor(value: string);
// (undocumented)
value: string;
}

// @public (undocumented)
export type TCaseSummary = Record<TCaseSummaryId, number>;

Expand Down Expand Up @@ -700,6 +723,24 @@ export type TCompilation<T> = T extends ECompilerType.Rspack ? Compilation : Com
// @public (undocumented)
export type TCompiler<T> = T extends ECompilerType.Rspack ? Compiler : Compiler_2;

// @public (undocumented)
type TCompilerCaseConfig = {
description: string;
error?: boolean;
skip?: boolean;
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
check?: ({ context, stats, files, compiler, compilation }: {
context: ITestContext;
stats?: TCompilerStatsCompilation<ECompilerType.Rspack>;
files?: Record<string, string>;
compiler: TCompiler<ECompilerType.Rspack>;
compilation?: TCompilation<ECompilerType.Rspack>;
}) => Promise<void>;
compilerCallback?: (error: Error | null, stats: TCompilerStats<ECompilerType.Rspack> | null) => void;
};

// @public (undocumented)
export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;

Expand All @@ -721,6 +762,14 @@ export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack ? Stat
// @public (undocumented)
export type TCompilerTypeId = ECompilerType.Rspack | ECompilerType.Webpack | "common";

// @public (undocumented)
type TDefaultsCaseConfig = {
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
cwd?: string;
diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<TCompilerOptions<ECompilerType.Rspack>>) => Promise<void>;
description: string;
};

// @public (undocumented)
export type TDiffStats = {
root: string;
Expand All @@ -738,6 +787,15 @@ export type TDiffStatsItem = {
// @public (undocumented)
export type TDimenTypeId = "modules" | "lines" | "lines-in-common";

// @public (undocumented)
type TErrorCaseConfig = {
description: string;
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
check?: (stats: RspackStatsDiagnostics) => Promise<void>;
};

// @public (undocumented)
export class TestContext implements ITestContext {
constructor(config: TTestContextOptions);
Expand Down Expand Up @@ -785,6 +843,8 @@ export class Tester implements ITester {
// (undocumented)
check(env: ITestEnv): Promise<void>;
// (undocumented)
close(): Promise<void>;
// (undocumented)
compile(): Promise<void>;
// (undocumented)
getContext(): ITestContext;
Expand Down Expand Up @@ -848,6 +908,16 @@ export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] |
esmMode?: EEsmMode;
}) => Object | Promise<Object>;

// @public (undocumented)
type TStatsAPICaseConfig = {
description: string;
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
snapshotName?: string;
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
check?: (stats: TCompilerStats<ECompilerType.Rspack>, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
};

// @public (undocumented)
export type TTestConfig<T extends ECompilerType> = {
documentType?: EDocumentType;
Expand Down
3 changes: 2 additions & 1 deletion packages/rspack-test-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"./setup-expect": "./dist/helper/setup-expect.js",
"./setup-env": "./dist/helper/setup-env.js",
"./setup-wasm": "./dist/helper/setup-wasm.js",
"./setup": "./dist/setup.js",
"./package.json": "./package.json",
"./helper/*": "./dist/helper/*.js",
"./helper/legacy/*": "./dist/helper/legacy/*.js",
Expand Down Expand Up @@ -109,4 +110,4 @@
"peerDependencies": {
"@rspack/core": ">=1.0.0"
}
}
}
1 change: 0 additions & 1 deletion packages/rspack-test-tools/src/case/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { build, checkSnapshot, compiler, getCompiler } from "./common";

const creator = new BasicCaseCreator({
clean: true,
describe: false,
description(name) {
return `${name} should match snapshot`;
},
Expand Down
1 change: 0 additions & 1 deletion packages/rspack-test-tools/src/case/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function getCreator(target: TTarget) {
target,
new BasicCaseCreator({
clean: true,
describe: true,
target,
steps: ({ name, src, target, temp }) => [
createCacheProcessor(name, src, temp!, target as TTarget)
Expand Down
36 changes: 21 additions & 15 deletions packages/rspack-test-tools/src/case/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "node:path";
import type { OutputFileSystem } from "@rspack/core";
import { BasicCaseCreator } from "../test/creator";
import type {
Expand Down Expand Up @@ -142,31 +143,30 @@ function createCompilerProcessor(
compiler: c
});
}
},
after: async (context: ITestContext) => {
await context.closeCompiler(name);
}
} as ITestProcessor;
}

const creator = new BasicCaseCreator({
clean: true,
describe: false,
steps: ({ name, caseConfig }) => {
return [createCompilerProcessor(name, caseConfig as TCompilerCaseConfig)];
},
concurrent: false
});

export function createCompilerCase(
const srcDir = path.resolve(
__dirname,
"../../../../tests/rspack-test/fixtures"
);
const distDir = path.resolve(
__dirname,
"../../../../tests/rspack-test/js/compiler"
);
export function defineCompileCase(
name: string,
src: string,
dist: string,
testConfig: string
caseConfigList: TCompilerCaseConfig | TCompilerCaseConfig[]
) {
let caseConfigList: TCompilerCaseConfig | TCompilerCaseConfig[] = require(
testConfig
);
if (!Array.isArray(caseConfigList)) {
caseConfigList = [caseConfigList];
}
Expand All @@ -176,10 +176,16 @@ export function createCompilerCase(
it.skip(`${name}[${i}]`, () => {});
continue;
}
creator.create(`${name}[${i}]`, src, dist, undefined, {
caseConfig,
description: () => caseConfig.description
});
creator.create(
`${name}[${i}]`,
srcDir,
path.join(distDir, name),
undefined,
{
caseConfig,
description: () => caseConfig.description
}
);
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/rspack-test-tools/src/case/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export function createConfigProcessor(name: string): ITestProcessor {

const creator = new BasicCaseCreator({
clean: true,
describe: false,
testConfig: testConfig => {
const oldModuleScope = testConfig.moduleScope;
testConfig.moduleScope = (ms, stats, compilerOptions) => {
Expand Down
Loading
Loading