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

fix: stats in multiple runner #6264

Merged
merged 2 commits into from
Apr 17, 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
3 changes: 2 additions & 1 deletion .github/workflows/test-ng.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
echo 'RESULT<<EOF' >> $GITHUB_ENV
echo "$OUTPUT" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
echo ${OUTPUT}

comment:
name: Write a new comment
Expand All @@ -76,7 +77,7 @@ jobs:
with:
issue-number: ${{ github.event.issue.number || github.event.pull_request.number }}
body: |
**${{ contains(needs.test.result, 'failure') && '🔴🔴🔴 Test new runner failed' || '🟢🟢🟢 Test new runner successed' }}**
**${{ contains(needs.test.outputs.testng, 'FAIL') && '🔴🔴🔴 Test new runner failed' || '🟢🟢🟢 Test new runner successed' }}**

> Task: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}

Expand Down
18 changes: 11 additions & 7 deletions packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RspackPluginInstance } from '@rspack/core';
import { Stats } from '@rspack/core';
import type { Stats as Stats_2 } from 'webpack';
import { StatsCompilation } from '@rspack/core';
import type { StatsCompilation as StatsCompilation_2 } from 'webpack';
import { WebpackOptionsNormalized } from 'webpack';

// @public (undocumented)
Expand All @@ -28,7 +29,7 @@ export class BasicRunnerFactory<T extends ECompilerType> implements TRunnerFacto
// (undocumented)
create(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
// (undocumented)
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
// (undocumented)
protected getRunnerKey(file: string): string;
// (undocumented)
Expand Down Expand Up @@ -226,13 +227,13 @@ export function formatCode(name: string, raw: string, options: IFormatCodeOption
// @public (undocumented)
export class HotRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
}

// @public (undocumented)
export class HotStepRunnerFactory<T extends ECompilerType> extends HotRunnerFactory<T> {
// (undocumented)
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
}

// @public (undocumented)
Expand Down Expand Up @@ -294,7 +295,7 @@ export interface IBasicRunnerOptions<T extends ECompilerType> {
// (undocumented)
source: string;
// (undocumented)
stats?: TCompilerStats<T>;
stats?: TCompilerStatsCompilation<T>;
// (undocumented)
testConfig: TTestConfig<T>;
}
Expand Down Expand Up @@ -714,7 +715,7 @@ export interface ITestRunner {
// @public (undocumented)
export class MultipleRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
// (undocumented)
protected getFileIndexHandler(file: string): {
getIndex: () => number[];
Expand All @@ -740,7 +741,7 @@ export class MultiTaskProcessor<T extends ECompilerType = ECompilerType.Rspack>
// @public (undocumented)
export class NormalRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
}

// @public (undocumented)
Expand Down Expand Up @@ -992,6 +993,9 @@ export type TCompilerOptions<T> = T extends ECompilerType.Rspack ? RspackOptions
// @public (undocumented)
export type TCompilerStats<T> = T extends ECompilerType.Rspack ? Stats : Stats_2;

// @public (undocumented)
export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack ? StatsCompilation : StatsCompilation_2;

// @public (undocumented)
export type TCompilerTypeId = ECompilerType.Rspack | ECompilerType.Webpack | "common";

Expand Down Expand Up @@ -1136,7 +1140,7 @@ export type TUpdateOptions = {
// @public (undocumented)
export class WatchRunnerFactory<T extends ECompilerType> extends BasicRunnerFactory<T> {
// (undocumented)
protected createRunner(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
protected createRunner(file: string, stats: TCompilerStatsCompilation<T>, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
// (undocumented)
protected getRunnerKey(file: string): string;
}
Expand Down
12 changes: 8 additions & 4 deletions packages/rspack-test-tools/src/runner/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ITestEnv,
ITestRunner,
TCompilerOptions,
TCompilerStatsCompilation,
TRunnerFactory
} from "../type";
import { WebRunner } from "./runner/web";
Expand All @@ -27,7 +28,11 @@ export class BasicRunnerFactory<T extends ECompilerType>
if (exists) {
return exists;
}
const runner = this.createRunner(file, compilerOptions, env);
const compiler = this.context.getCompiler<T>(this.name);
const stats = compiler.getStats()!.toJson({
errorDetails: true
});
const runner = this.createRunner(file, stats, compilerOptions, env);
this.context.setRunner(key, runner);
return runner;
}
Expand All @@ -38,14 +43,13 @@ export class BasicRunnerFactory<T extends ECompilerType>

protected createRunner(
file: string,
stats: TCompilerStatsCompilation<T>,
compilerOptions: TCompilerOptions<T>,
env: ITestEnv
): ITestRunner {
const compiler = this.context.getCompiler<T>(this.name);
const stats = compiler.getStats();
const runnerOptions = {
env,
stats: stats!,
stats,
name: this.name,
testConfig: this.context.getTestConfig(),
source: this.context.getSource(),
Expand Down
7 changes: 4 additions & 3 deletions packages/rspack-test-tools/src/runner/hot-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ITestEnv,
ITestRunner,
TCompilerOptions,
TCompilerStats
TCompilerStats,
TCompilerStatsCompilation
} from "../type";
import { HotRunner } from "./runner/hot";
import { HotRunnerFactory } from "./hot";
Expand All @@ -15,12 +16,12 @@ export class HotStepRunnerFactory<
> extends HotRunnerFactory<T> {
protected createRunner(
file: string,
stats: TCompilerStatsCompilation<T>,
compilerOptions: TCompilerOptions<T>,
env: ITestEnv
): ITestRunner {
const compiler = this.context.getCompiler(this.name);
const testConfig = this.context.getTestConfig();
const stats = compiler.getStats();
const source = this.context.getSource();
const dist = this.context.getDist();
const hotUpdateContext = this.context.getValue(
Expand Down Expand Up @@ -61,7 +62,7 @@ export class HotStepRunnerFactory<

return new HotRunner({
env,
stats: stats!,
stats,
name: this.name,
runInNewContext: false,
testConfig,
Expand Down
7 changes: 4 additions & 3 deletions packages/rspack-test-tools/src/runner/hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ECompilerType,
ITestEnv,
ITestRunner,
TCompilerOptions
TCompilerOptions,
TCompilerStatsCompilation
} from "../type";
import { BasicRunnerFactory } from "./basic";
import { HotRunner } from "./runner/hot";
Expand All @@ -14,12 +15,12 @@ export class HotRunnerFactory<
> extends BasicRunnerFactory<T> {
protected createRunner(
file: string,
stats: TCompilerStatsCompilation<T>,
compilerOptions: TCompilerOptions<T>,
env: ITestEnv
): ITestRunner {
const compiler = this.context.getCompiler(this.name);
const testConfig = this.context.getTestConfig();
const stats = compiler.getStats();
const source = this.context.getSource();
const dist = this.context.getDist();
const hotUpdateContext = this.context.getValue(
Expand Down Expand Up @@ -70,7 +71,7 @@ export class HotRunnerFactory<

return new HotRunner({
env,
stats: stats!,
stats,
name: this.name,
runInNewContext: false,
testConfig,
Expand Down
11 changes: 9 additions & 2 deletions packages/rspack-test-tools/src/runner/multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
ECompilerType,
ITestEnv,
ITestRunner,
TCompilerOptions
TCompilerOptions,
TCompilerStatsCompilation
} from "../type";
import { BasicRunnerFactory } from "./basic";

Expand All @@ -18,14 +19,20 @@ export class MultipleRunnerFactory<

protected createRunner(
file: string,
stats: TCompilerStatsCompilation<T>,
compilerOptions: TCompilerOptions<T>,
env: ITestEnv
): ITestRunner {
const multiCompilerOptions: TCompilerOptions<T>[] =
this.context.getValue(this.name, "multiCompilerOptions") || [];
const { getIndex, flagIndex } = this.getFileIndexHandler(file);
const [index] = getIndex();
const runner = super.createRunner(file, multiCompilerOptions[index], env);
const runner = super.createRunner(
file,
stats.children![index],
multiCompilerOptions[index],
env
);
flagIndex();
return runner;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/rspack-test-tools/src/runner/normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
ECompilerType,
ITestEnv,
ITestRunner,
TCompilerOptions
TCompilerOptions,
TCompilerStatsCompilation
} from "../type";
import { BasicRunnerFactory } from "./basic";
import { NormalRunner } from "./runner/normal";
Expand All @@ -12,6 +13,7 @@ export class NormalRunnerFactory<
> extends BasicRunnerFactory<T> {
protected createRunner(
file: string,
stats: TCompilerStatsCompilation<T>,
compilerOptions: TCompilerOptions<T>,
env: ITestEnv
): ITestRunner {
Expand Down
3 changes: 1 addition & 2 deletions packages/rspack-test-tools/src/runner/runner/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ export class BasicRunner<T extends ECompilerType = ECompilerType.Rspack>
}

protected createBaseModuleScope(): IBasicModuleScope {
const baseModuleScope = {
const baseModuleScope: IBasicModuleScope = {
console: console,
it: this._options.env.it,
beforeEach: this._options.env.beforeEach,
afterEach: this._options.env.afterEach,
expect,
jest,
__STATS__: this._options.stats,
nsObj: (m: Object) => {
Object.defineProperty(m, Symbol.toStringTag, {
value: "Module"
Expand Down
1 change: 0 additions & 1 deletion packages/rspack-test-tools/src/runner/runner/hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export class HotRunner<
moduleScope["importScripts"] = this.globalContext!["importScripts"];
moduleScope["Worker"] = this.globalContext!["Worker"];
moduleScope["EventSource"] = this.globalContext!["EventSource"];
moduleScope["STATS"] = moduleScope.__STATS__;
moduleScope["NEXT"] = this._options.next;
return moduleScope;
}
Expand Down
3 changes: 0 additions & 3 deletions packages/rspack-test-tools/src/runner/runner/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export class WatchRunner<
const moduleScope = super.createModuleScope(requireFn, m, file);
moduleScope["__dirname"] = path.dirname(file.path);
moduleScope["document"] = this.globalContext!["document"];
moduleScope["STATS_JSON"] = moduleScope.__STATS__.toJson({
errorDetails: true
} as any);
moduleScope["STATE"] = this.state;
moduleScope["WATCH_STEP"] = this._watchOptions.stepName;
return moduleScope;
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/runner/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ECompilerType,
ITestEnv,
TCompilerOptions,
TCompilerStats,
TCompilerStatsCompilation,
TTestConfig
} from "../type";

Expand Down Expand Up @@ -44,7 +44,7 @@ export interface IBasicGlobalContext {

export interface IBasicRunnerOptions<T extends ECompilerType> {
env: ITestEnv;
stats?: TCompilerStats<T>;
stats?: TCompilerStatsCompilation<T>;
name: string;
runInNewContext?: boolean;
testConfig: TTestConfig<T>;
Expand Down
7 changes: 4 additions & 3 deletions packages/rspack-test-tools/src/runner/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
ECompilerType,
ITestEnv,
ITestRunner,
TCompilerOptions
TCompilerOptions,
TCompilerStatsCompilation
} from "../type";
import { WatchRunner } from "./runner/watch";
import { BasicRunnerFactory } from "./basic";
Expand All @@ -19,6 +20,7 @@ export class WatchRunnerFactory<
}
protected createRunner(
file: string,
stats: TCompilerStatsCompilation<T>,
compilerOptions: TCompilerOptions<T>,
env: ITestEnv
): ITestRunner {
Expand All @@ -30,10 +32,9 @@ export class WatchRunnerFactory<
if (!stepName) {
throw new Error("Can not get watch step name from context");
}
const stats = compiler.getStats();
return new WatchRunner({
env,
stats: stats!,
stats,
name: this.name,
stepName,
runInNewContext:
Expand Down
10 changes: 8 additions & 2 deletions packages/rspack-test-tools/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
RspackOptions,
Compiler as RspackCompiler,
Stats as RspackStats
Stats as RspackStats,
StatsCompilation as RspackStatsCompilation
} from "@rspack/core";
import type {
Configuration as WebpackOptions,
Compiler as WebpackCompiler,
Stats as WebpackStats
Stats as WebpackStats,
StatsCompilation as WebpackStatsCompilation
} from "webpack";
import { IBasicModuleScope, TRunnerRequirer } from "./runner/type";
import EventEmitter from "events";
Expand Down Expand Up @@ -53,6 +55,10 @@ export type TCompilerStats<T> = T extends ECompilerType.Rspack
? RspackStats
: WebpackStats;

export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack
? RspackStatsCompilation
: WebpackStatsCompilation;

export interface ITestCompilerManager<T extends ECompilerType> {
getOptions(): TCompilerOptions<T>;
setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
Expand Down
Loading