Skip to content

Commit

Permalink
test: export runner (#6630)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder authored May 27, 2024
1 parent 4755f5d commit f3af7b1
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
175 changes: 175 additions & 0 deletions packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { Compiler } from '@rspack/core';
import { Compiler as Compiler_2 } from 'webpack';
import type { Configuration } from 'webpack';
import EventEmitter from 'events';
import { IBasicGlobalContext as IBasicGlobalContext_2 } from '../type';
import { IBasicGlobalContext as IBasicGlobalContext_3 } from '../../type';
import { IBasicModuleScope as IBasicModuleScope_2 } from '../../type';
import { ITestCompilerManager as ITestCompilerManager_2 } from '../type';
import { RspackOptions } from '@rspack/core';
import { RspackOptionsNormalized } from '@rspack/core';
Expand All @@ -21,6 +24,7 @@ import { StatsCompilation } from '@rspack/core';
import type { StatsCompilation as StatsCompilation_2 } from 'webpack';
import { StatsError } from '@rspack/core';
import { StatsWarnings } from '@rspack/core';
import { TRunnerRequirer as TRunnerRequirer_2 } from '..';
import { WebpackOptionsNormalized } from 'webpack';

// @public (undocumented)
Expand Down Expand Up @@ -50,6 +54,39 @@ export class BasicProcessor<T extends ECompilerType> implements ITestProcessor {
run(env: ITestEnv, context: ITestContext): Promise<void>;
}

// @public (undocumented)
export abstract class BasicRunner<T extends ECompilerType = ECompilerType.Rspack> implements ITestRunner {
constructor(_options: IBasicRunnerOptions<T>);
// (undocumented)
protected baseModuleScope: IBasicModuleScope | null;
// (undocumented)
protected abstract createBaseModuleScope(): IBasicModuleScope;
// (undocumented)
protected abstract createGlobalContext(): IBasicGlobalContext;
// (undocumented)
protected abstract createModuleScope(requireFn: TRunnerRequirer, m: TModuleObject, file: TBasicRunnerFile): IBasicModuleScope;
// (undocumented)
protected createRunner(): void;
// (undocumented)
protected getFile(modulePath: string[] | string, currentDirectory: string): TBasicRunnerFile | null;
// (undocumented)
getGlobal(name: string): unknown;
// (undocumented)
getRequire(): TRunnerRequirer;
// (undocumented)
protected globalContext: IBasicGlobalContext | null;
// (undocumented)
protected _options: IBasicRunnerOptions<T>;
// (undocumented)
protected postExecute(m: Object, file: TBasicRunnerFile): void;
// (undocumented)
protected preExecute(code: string, file: TBasicRunnerFile): void;
// (undocumented)
protected requirers: Map<string, TRunnerRequirer>;
// (undocumented)
run(file: string): Promise<unknown>;
}

// @public (undocumented)
export class BasicRunnerFactory<T extends ECompilerType> implements TRunnerFactory<T> {
constructor(name: string, context: ITestContext);
Expand All @@ -74,6 +111,22 @@ export class BuiltinProcessor<T extends ECompilerType> extends SnapshotProcessor
static defaultOptions<T extends ECompilerType>(this: BuiltinProcessor<T>, context: ITestContext): TCompilerOptions<T>;
}

// @public (undocumented)
export class CommonJsRunner<T extends ECompilerType = ECompilerType.Rspack> extends BasicRunner<T> {
// (undocumented)
protected createBaseModuleScope(): IBasicModuleScope;
// (undocumented)
protected createCjsRequirer(): TRunnerRequirer;
// (undocumented)
protected createGlobalContext(): IBasicGlobalContext;
// (undocumented)
protected createMissRequirer(): TRunnerRequirer;
// (undocumented)
protected createModuleScope(requireFn: TRunnerRequirer, m: TModuleObject, file: TBasicRunnerFile): IBasicModuleScope;
// (undocumented)
protected createRunner(): void;
}

// @public (undocumented)
export function compareContent(sourceContent: string | false, distContent: string | false, compareOptions: ICompareOptions): TCompareResult;

Expand Down Expand Up @@ -300,6 +353,37 @@ export function escapeEOL(str: string): string;
// @public (undocumented)
export function escapeSep(str: string): string;

// @public (undocumented)
export class EsmRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
// (undocumented)
protected createEsmRequirer(): TRunnerRequirer;
// (undocumented)
protected createRunner(): void;
}

// @public (undocumented)
export class FakeDocumentWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
constructor(_webOptions: IBasicRunnerOptions<T>);
// (undocumented)
protected createBaseModuleScope(): IBasicModuleScope_2;
// (undocumented)
protected createGlobalContext(): IBasicGlobalContext_3;
// (undocumented)
protected createJsonRequirer(): TRunnerRequirer;
// (undocumented)
protected createModuleScope(requireFn: TRunnerRequirer, m: any, file: TBasicRunnerFile): IBasicModuleScope_2;
// (undocumented)
protected createRunner(): void;
// (undocumented)
protected postExecute(_: Object, file: TBasicRunnerFile): void;
// (undocumented)
protected preExecute(_: string, file: TBasicRunnerFile): void;
// (undocumented)
run(file: string): Promise<unknown>;
// (undocumented)
protected _webOptions: IBasicRunnerOptions<T>;
}

// @public (undocumented)
export function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;

Expand Down Expand Up @@ -447,6 +531,26 @@ export interface IBasicProcessorOptions<T extends ECompilerType> {
runable: boolean;
}

// @public (undocumented)
export interface IBasicRunnerOptions<T extends ECompilerType> {
// (undocumented)
compilerOptions: TCompilerOptions<T>;
// (undocumented)
dist: string;
// (undocumented)
env: ITestEnv;
// (undocumented)
name: string;
// (undocumented)
runInNewContext?: boolean;
// (undocumented)
source: string;
// (undocumented)
stats?: TCompilerStatsCompilation<T>;
// (undocumented)
testConfig: TTestConfig<T>;
}

// @public (undocumented)
export interface IBuiltinProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "runable"> {
}
Expand Down Expand Up @@ -873,10 +977,45 @@ export interface IWatchProcessorOptions<T extends ECompilerType> extends IMultiT
tempDir: string;
}

// @public (undocumented)
interface IWatchRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends IBasicRunnerOptions<T> {
// (undocumented)
stepName: string;
}

// @public (undocumented)
export interface IWatchStepProcessorOptions<T extends ECompilerType> extends Omit<IWatchProcessorOptions<T>, "experiments" | "optimization"> {
}

// @public (undocumented)
export interface IWebRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends IBasicRunnerOptions<T> {
// (undocumented)
dom: "fake" | "jsdom";
}

// @public (undocumented)
export class JSDOMWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
constructor(_webOptions: IBasicRunnerOptions<T>);
// (undocumented)
protected createBaseModuleScope(): IBasicModuleScope_2;
// (undocumented)
protected createJSDOMRequirer(): TRunnerRequirer;
// (undocumented)
protected createResourceLoader(): {
fetch(url: string, _: {
element: HTMLScriptElement;
}): any;
};
// (undocumented)
protected createRunner(): void;
// (undocumented)
getGlobal(name: string): unknown;
// (undocumented)
run(file: string): Promise<unknown>;
// (undocumented)
protected _webOptions: IBasicRunnerOptions<T>;
}

// @public (undocumented)
export class MultipleRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
Expand Down Expand Up @@ -912,6 +1051,16 @@ export class NormalProcessor<T extends ECompilerType> extends BasicProcessor<T>
protected _normalOptions: INormalProcessorOptions<T>;
}

// @public (undocumented)
export class NormalRunner<T extends ECompilerType = ECompilerType.Rspack> extends EsmRunner<T> {
// (undocumented)
protected createBaseModuleScope(): IBasicModuleScope;
// (undocumented)
protected createModuleScope(requireFn: TRunnerRequirer, m: {
exports: unknown;
}, file: TBasicRunnerFile): IBasicModuleScope;
}

// @public (undocumented)
export class NormalRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
Expand Down Expand Up @@ -1293,6 +1442,17 @@ export class WatchProcessor<T extends ECompilerType> extends MultiTaskProcessor<
protected _watchOptions: IWatchProcessorOptions<T>;
}

// @public (undocumented)
export class WatchRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
constructor(_watchOptions: IWatchRunnerOptions<T>);
// (undocumented)
protected createGlobalContext(): IBasicGlobalContext_2;
// (undocumented)
protected createModuleScope(requireFn: TRunnerRequirer, m: any, file: TBasicRunnerFile): IBasicModuleScope;
// (undocumented)
protected _watchOptions: IWatchRunnerOptions<T>;
}

// @public (undocumented)
export class WatchRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
Expand Down Expand Up @@ -1328,6 +1488,21 @@ export class WebpackModulePlaceholderPlugin {
apply(compiler: any): void;
}

// @public (undocumented)
export class WebRunner<T extends ECompilerType = ECompilerType.Rspack> implements ITestRunner {
constructor(_webOptions: IWebRunnerOptions<T>);
// (undocumented)
getGlobal(name: string): unknown;
// (undocumented)
getRequire(): TRunnerRequirer_2;
// (undocumented)
protected originMethods: Partial<CommonJsRunner>;
// (undocumented)
run(file: string): Promise<unknown>;
// (undocumented)
protected _webOptions: IWebRunnerOptions<T>;
}

// (No @packageDocumentation comment for this package)

```
1 change: 1 addition & 0 deletions packages/rspack-test-tools/src/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export * from "./hot";
export * from "./hot-step";
export * from "./multiple";
export * from "./normal";
export * from "./runner";
export * from "./type";
export * from "./watch";
8 changes: 8 additions & 0 deletions packages/rspack-test-tools/src/runner/runner/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from "./basic";
export * from "./cjs";
export * from "./esm";
export * from "./normal";
export * from "./watch";
export * from "./web";
export * from "./web/fake";
export * from "./web/jsdom";

2 comments on commit f3af7b1

@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-27 89c6913) Current Change
10000_development-mode + exec 2.6 s ± 33 ms 2.61 s ± 23 ms +0.52 %
10000_development-mode_hmr + exec 731 ms ± 9.7 ms 730 ms ± 9.7 ms -0.15 %
10000_production-mode + exec 2.53 s ± 15 ms 2.54 s ± 18 ms +0.47 %
arco-pro_development-mode + exec 2.41 s ± 46 ms 2.36 s ± 53 ms -2.00 %
arco-pro_development-mode_hmr + exec 441 ms ± 2.2 ms 441 ms ± 2.9 ms -0.04 %
arco-pro_development-mode_hmr_intercept-plugin + exec 451 ms ± 4.4 ms 451 ms ± 2.7 ms +0.04 %
arco-pro_development-mode_intercept-plugin + exec 3.19 s ± 60 ms 3.18 s ± 76 ms -0.29 %
arco-pro_production-mode + exec 3.97 s ± 74 ms 3.98 s ± 32 ms +0.09 %
arco-pro_production-mode_intercept-plugin + exec 4.75 s ± 84 ms 4.79 s ± 74 ms +0.80 %
threejs_development-mode_10x + exec 1.96 s ± 16 ms 1.97 s ± 18 ms +0.70 %
threejs_development-mode_10x_hmr + exec 760 ms ± 6.6 ms 765 ms ± 9.2 ms +0.69 %
threejs_production-mode_10x + exec 5.28 s ± 23 ms 5.3 s ± 25 ms +0.48 %

@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

Please sign in to comment.