Skip to content

Commit 01a62d0

Browse files
committed
test: use single file tests as jest entries
1 parent e350b76 commit 01a62d0

File tree

125 files changed

+864
-909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+864
-909
lines changed

packages/rspack-test-tools/etc/test-tools.api.md

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ import type { Stats } from '@rspack/core';
2020
import type { Stats as Stats_2 } from 'webpack';
2121
import type { StatsCompilation } from '@rspack/core';
2222
import type { StatsCompilation as StatsCompilation_2 } from 'webpack';
23+
import type { StatsError } from '@rspack/core';
2324
import type { WebpackOptionsNormalized } from 'webpack';
2425

26+
// @public (undocumented)
27+
export function basename(filename: string): string;
28+
2529
// @public (undocumented)
2630
export class BasicCaseCreator<T extends ECompilerType> {
2731
constructor(_options: IBasicCaseCreatorOptions<T>);
@@ -61,6 +65,9 @@ export class BasicCaseCreator<T extends ECompilerType> {
6165
protected tryRunTask(concurrent?: number): void;
6266
}
6367

68+
// @public (undocumented)
69+
export function casename(filename: string): string;
70+
6471
// @public (undocumented)
6572
export function checkChunkModules(statsJson: any, chunkModulesMap: any, strict?: boolean): boolean;
6673

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

85-
// @public (undocumented)
86-
export function createCompilerCase(name: string, src: string, dist: string, testConfig: string): void;
87-
8892
// @public (undocumented)
8993
export function createConfigCase(name: string, src: string, dist: string): void;
9094

91-
// @public (undocumented)
92-
export function createDefaultsCase(name: string, src: string): void;
93-
9495
// @public (undocumented)
9596
export function createDiagnosticCase(name: string, src: string, dist: string): void;
9697

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

100-
// @public (undocumented)
101-
export function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
102-
103101
// @public (undocumented)
104102
export function createHashCase(name: string, src: string, dist: string): void;
105103

@@ -127,9 +125,6 @@ export function createNormalCase(name: string, src: string, dist: string): void;
127125
// @public (undocumented)
128126
export function createSerialCase(name: string, src: string, dist: string): void;
129127

130-
// @public (undocumented)
131-
export function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
132-
133128
// @public (undocumented)
134129
export function createStatsOutputCase(name: string, src: string, dist: string): void;
135130

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

140+
// @public (undocumented)
141+
export function defineCompileCase(name: string, caseConfigList: TCompilerCaseConfig | TCompilerCaseConfig[]): void;
142+
143+
// @public (undocumented)
144+
export function defineDefaultsCase(name: string, caseConfig: TDefaultsCaseConfig): void;
145+
146+
// @public (undocumented)
147+
export function defineErrorCase(name: string, caseConfig: TErrorCaseConfig): void;
148+
149+
// @public (undocumented)
150+
export function defineStatsAPICase(name: string, caseConfig: TStatsAPICaseConfig): void;
151+
145152
// @public (undocumented)
146153
export function describeByWalk(testFile: string, createCase: (name: string, src: string, dist: string) => void, options?: {
147154
type?: "file" | "directory";
@@ -233,7 +240,7 @@ export function escapeSep(str: string): string;
233240
export function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;
234241

235242
// @public (undocumented)
236-
export function getRspackDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
243+
export function getRspackDefaultConfig(context: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
237244

238245
// @public (undocumented)
239246
export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
@@ -672,6 +679,22 @@ export class RspackDiffConfigPlugin implements RspackPluginInstance {
672679
name: string;
673680
}
674681

682+
// @public (undocumented)
683+
class RspackStatsDiagnostics {
684+
constructor(errors: StatsError[], warnings: StatsError[]);
685+
// (undocumented)
686+
errors: StatsError[];
687+
// (undocumented)
688+
warnings: StatsError[];
689+
}
690+
691+
// @public (undocumented)
692+
class RspackTestDiff {
693+
constructor(value: string);
694+
// (undocumented)
695+
value: string;
696+
}
697+
675698
// @public (undocumented)
676699
export type TCaseSummary = Record<TCaseSummaryId, number>;
677700

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

726+
// @public (undocumented)
727+
type TCompilerCaseConfig = {
728+
description: string;
729+
error?: boolean;
730+
skip?: boolean;
731+
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
732+
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
733+
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
734+
check?: ({ context, stats, files, compiler, compilation }: {
735+
context: ITestContext;
736+
stats?: TCompilerStatsCompilation<ECompilerType.Rspack>;
737+
files?: Record<string, string>;
738+
compiler: TCompiler<ECompilerType.Rspack>;
739+
compilation?: TCompilation<ECompilerType.Rspack>;
740+
}) => Promise<void>;
741+
compilerCallback?: (error: Error | null, stats: TCompilerStats<ECompilerType.Rspack> | null) => void;
742+
};
743+
703744
// @public (undocumented)
704745
export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
705746

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

765+
// @public (undocumented)
766+
type TDefaultsCaseConfig = {
767+
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
768+
cwd?: string;
769+
diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<TCompilerOptions<ECompilerType.Rspack>>) => Promise<void>;
770+
description: string;
771+
};
772+
724773
// @public (undocumented)
725774
export type TDiffStats = {
726775
root: string;
@@ -738,6 +787,15 @@ export type TDiffStatsItem = {
738787
// @public (undocumented)
739788
export type TDimenTypeId = "modules" | "lines" | "lines-in-common";
740789

790+
// @public (undocumented)
791+
type TErrorCaseConfig = {
792+
description: string;
793+
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
794+
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
795+
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
796+
check?: (stats: RspackStatsDiagnostics) => Promise<void>;
797+
};
798+
741799
// @public (undocumented)
742800
export class TestContext implements ITestContext {
743801
constructor(config: TTestContextOptions);
@@ -848,6 +906,16 @@ export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] |
848906
esmMode?: EEsmMode;
849907
}) => Object | Promise<Object>;
850908

909+
// @public (undocumented)
910+
type TStatsAPICaseConfig = {
911+
description: string;
912+
options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
913+
snapshotName?: string;
914+
compiler?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
915+
build?: (context: ITestContext, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
916+
check?: (stats: TCompilerStats<ECompilerType.Rspack>, compiler: TCompiler<ECompilerType.Rspack>) => Promise<void>;
917+
};
918+
851919
// @public (undocumented)
852920
export type TTestConfig<T extends ECompilerType> = {
853921
documentType?: EDocumentType;

packages/rspack-test-tools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"./setup-expect": "./dist/helper/setup-expect.js",
1313
"./setup-env": "./dist/helper/setup-env.js",
1414
"./setup-wasm": "./dist/helper/setup-wasm.js",
15+
"./setup": "./dist/setup.js",
1516
"./package.json": "./package.json",
1617
"./helper/*": "./dist/helper/*.js",
1718
"./helper/legacy/*": "./dist/helper/legacy/*.js",
@@ -114,4 +115,4 @@
114115
"peerDependencies": {
115116
"@rspack/core": ">=1.0.0"
116117
}
117-
}
118+
}

packages/rspack-test-tools/src/case/compiler.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from "node:path";
12
import type { OutputFileSystem } from "@rspack/core";
23
import { BasicCaseCreator } from "../test/creator";
34
import type {
@@ -158,15 +159,18 @@ const creator = new BasicCaseCreator({
158159
concurrent: false
159160
});
160161

161-
export function createCompilerCase(
162+
const srcDir = path.resolve(
163+
__dirname,
164+
"../../../../tests/rspack-test/fixtures"
165+
);
166+
const distDir = path.resolve(
167+
__dirname,
168+
"../../../../tests/rspack-test/js/compiler"
169+
);
170+
export function defineCompileCase(
162171
name: string,
163-
src: string,
164-
dist: string,
165-
testConfig: string
172+
caseConfigList: TCompilerCaseConfig | TCompilerCaseConfig[]
166173
) {
167-
let caseConfigList: TCompilerCaseConfig | TCompilerCaseConfig[] = require(
168-
testConfig
169-
);
170174
if (!Array.isArray(caseConfigList)) {
171175
caseConfigList = [caseConfigList];
172176
}
@@ -176,10 +180,16 @@ export function createCompilerCase(
176180
it.skip(`${name}[${i}]`, () => {});
177181
continue;
178182
}
179-
creator.create(`${name}[${i}]`, src, dist, undefined, {
180-
caseConfig,
181-
description: () => caseConfig.description
182-
});
183+
creator.create(
184+
`${name}[${i}]`,
185+
srcDir,
186+
path.join(distDir, name),
187+
undefined,
188+
{
189+
caseConfig,
190+
description: () => caseConfig.description
191+
}
192+
);
183193
}
184194
}
185195

0 commit comments

Comments
 (0)