diff --git a/.github/workflows/test-ng.yml b/.github/workflows/test-ng.yml index 1f06ae1bfa5..e4b1cfa2e6e 100644 --- a/.github/workflows/test-ng.yml +++ b/.github/workflows/test-ng.yml @@ -63,6 +63,7 @@ jobs: echo 'RESULT<> $GITHUB_ENV echo "$OUTPUT" >> $GITHUB_ENV echo 'EOF' >> $GITHUB_ENV + echo ${OUTPUT} comment: name: Write a new comment @@ -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}} diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index 5fecd25ea71..a5c5d198ac2 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -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) @@ -28,7 +29,7 @@ export class BasicRunnerFactory implements TRunnerFacto // (undocumented) create(file: string, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; // (undocumented) - protected createRunner(file: string, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; + protected createRunner(file: string, stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; // (undocumented) protected getRunnerKey(file: string): string; // (undocumented) @@ -226,13 +227,13 @@ export function formatCode(name: string, raw: string, options: IFormatCodeOption // @public (undocumented) export class HotRunnerFactory extends BasicRunnerFactory { // (undocumented) - protected createRunner(file: string, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; + protected createRunner(file: string, stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; } // @public (undocumented) export class HotStepRunnerFactory extends HotRunnerFactory { // (undocumented) - protected createRunner(file: string, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; + protected createRunner(file: string, stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; } // @public (undocumented) @@ -294,7 +295,7 @@ export interface IBasicRunnerOptions { // (undocumented) source: string; // (undocumented) - stats?: TCompilerStats; + stats?: TCompilerStatsCompilation; // (undocumented) testConfig: TTestConfig; } @@ -714,7 +715,7 @@ export interface ITestRunner { // @public (undocumented) export class MultipleRunnerFactory extends BasicRunnerFactory { // (undocumented) - protected createRunner(file: string, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; + protected createRunner(file: string, stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; // (undocumented) protected getFileIndexHandler(file: string): { getIndex: () => number[]; @@ -740,7 +741,7 @@ export class MultiTaskProcessor // @public (undocumented) export class NormalRunnerFactory extends BasicRunnerFactory { // (undocumented) - protected createRunner(file: string, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; + protected createRunner(file: string, stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; } // @public (undocumented) @@ -992,6 +993,9 @@ export type TCompilerOptions = T extends ECompilerType.Rspack ? RspackOptions // @public (undocumented) export type TCompilerStats = T extends ECompilerType.Rspack ? Stats : Stats_2; +// @public (undocumented) +export type TCompilerStatsCompilation = T extends ECompilerType.Rspack ? StatsCompilation : StatsCompilation_2; + // @public (undocumented) export type TCompilerTypeId = ECompilerType.Rspack | ECompilerType.Webpack | "common"; @@ -1136,7 +1140,7 @@ export type TUpdateOptions = { // @public (undocumented) export class WatchRunnerFactory extends BasicRunnerFactory { // (undocumented) - protected createRunner(file: string, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; + protected createRunner(file: string, stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv): ITestRunner; // (undocumented) protected getRunnerKey(file: string): string; } diff --git a/packages/rspack-test-tools/src/runner/basic.ts b/packages/rspack-test-tools/src/runner/basic.ts index 1ba66a76bae..f53bef545fc 100644 --- a/packages/rspack-test-tools/src/runner/basic.ts +++ b/packages/rspack-test-tools/src/runner/basic.ts @@ -4,6 +4,7 @@ import { ITestEnv, ITestRunner, TCompilerOptions, + TCompilerStatsCompilation, TRunnerFactory } from "../type"; import { WebRunner } from "./runner/web"; @@ -27,7 +28,11 @@ export class BasicRunnerFactory if (exists) { return exists; } - const runner = this.createRunner(file, compilerOptions, env); + const compiler = this.context.getCompiler(this.name); + const stats = compiler.getStats()!.toJson({ + errorDetails: true + }); + const runner = this.createRunner(file, stats, compilerOptions, env); this.context.setRunner(key, runner); return runner; } @@ -38,14 +43,13 @@ export class BasicRunnerFactory protected createRunner( file: string, + stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv ): ITestRunner { - const compiler = this.context.getCompiler(this.name); - const stats = compiler.getStats(); const runnerOptions = { env, - stats: stats!, + stats, name: this.name, testConfig: this.context.getTestConfig(), source: this.context.getSource(), diff --git a/packages/rspack-test-tools/src/runner/hot-step.ts b/packages/rspack-test-tools/src/runner/hot-step.ts index 816690bb296..1c40eee5bab 100644 --- a/packages/rspack-test-tools/src/runner/hot-step.ts +++ b/packages/rspack-test-tools/src/runner/hot-step.ts @@ -5,7 +5,8 @@ import { ITestEnv, ITestRunner, TCompilerOptions, - TCompilerStats + TCompilerStats, + TCompilerStatsCompilation } from "../type"; import { HotRunner } from "./runner/hot"; import { HotRunnerFactory } from "./hot"; @@ -15,12 +16,12 @@ export class HotStepRunnerFactory< > extends HotRunnerFactory { protected createRunner( file: string, + stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, 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( @@ -61,7 +62,7 @@ export class HotStepRunnerFactory< return new HotRunner({ env, - stats: stats!, + stats, name: this.name, runInNewContext: false, testConfig, diff --git a/packages/rspack-test-tools/src/runner/hot.ts b/packages/rspack-test-tools/src/runner/hot.ts index 8cda2b7660a..2e667bca94b 100644 --- a/packages/rspack-test-tools/src/runner/hot.ts +++ b/packages/rspack-test-tools/src/runner/hot.ts @@ -4,7 +4,8 @@ import { ECompilerType, ITestEnv, ITestRunner, - TCompilerOptions + TCompilerOptions, + TCompilerStatsCompilation } from "../type"; import { BasicRunnerFactory } from "./basic"; import { HotRunner } from "./runner/hot"; @@ -14,12 +15,12 @@ export class HotRunnerFactory< > extends BasicRunnerFactory { protected createRunner( file: string, + stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, 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( @@ -70,7 +71,7 @@ export class HotRunnerFactory< return new HotRunner({ env, - stats: stats!, + stats, name: this.name, runInNewContext: false, testConfig, diff --git a/packages/rspack-test-tools/src/runner/multiple.ts b/packages/rspack-test-tools/src/runner/multiple.ts index b5deafbc1d5..df27a4d9dee 100644 --- a/packages/rspack-test-tools/src/runner/multiple.ts +++ b/packages/rspack-test-tools/src/runner/multiple.ts @@ -2,7 +2,8 @@ import { ECompilerType, ITestEnv, ITestRunner, - TCompilerOptions + TCompilerOptions, + TCompilerStatsCompilation } from "../type"; import { BasicRunnerFactory } from "./basic"; @@ -18,6 +19,7 @@ export class MultipleRunnerFactory< protected createRunner( file: string, + stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv ): ITestRunner { @@ -25,7 +27,12 @@ export class MultipleRunnerFactory< 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; } diff --git a/packages/rspack-test-tools/src/runner/normal.ts b/packages/rspack-test-tools/src/runner/normal.ts index df99689b863..9fbf2715284 100644 --- a/packages/rspack-test-tools/src/runner/normal.ts +++ b/packages/rspack-test-tools/src/runner/normal.ts @@ -2,7 +2,8 @@ import { ECompilerType, ITestEnv, ITestRunner, - TCompilerOptions + TCompilerOptions, + TCompilerStatsCompilation } from "../type"; import { BasicRunnerFactory } from "./basic"; import { NormalRunner } from "./runner/normal"; @@ -12,6 +13,7 @@ export class NormalRunnerFactory< > extends BasicRunnerFactory { protected createRunner( file: string, + stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv ): ITestRunner { diff --git a/packages/rspack-test-tools/src/runner/runner/basic.ts b/packages/rspack-test-tools/src/runner/runner/basic.ts index e703fae8470..a7a393e92de 100644 --- a/packages/rspack-test-tools/src/runner/runner/basic.ts +++ b/packages/rspack-test-tools/src/runner/runner/basic.ts @@ -84,14 +84,13 @@ export class BasicRunner } 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" diff --git a/packages/rspack-test-tools/src/runner/runner/hot.ts b/packages/rspack-test-tools/src/runner/runner/hot.ts index 7c7c5047cd4..936d826538a 100644 --- a/packages/rspack-test-tools/src/runner/runner/hot.ts +++ b/packages/rspack-test-tools/src/runner/runner/hot.ts @@ -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; } diff --git a/packages/rspack-test-tools/src/runner/runner/watch.ts b/packages/rspack-test-tools/src/runner/runner/watch.ts index 71905025c93..f51e2f1506c 100644 --- a/packages/rspack-test-tools/src/runner/runner/watch.ts +++ b/packages/rspack-test-tools/src/runner/runner/watch.ts @@ -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; diff --git a/packages/rspack-test-tools/src/runner/type.ts b/packages/rspack-test-tools/src/runner/type.ts index 5e97536eed4..e0f340f4bc1 100644 --- a/packages/rspack-test-tools/src/runner/type.ts +++ b/packages/rspack-test-tools/src/runner/type.ts @@ -2,7 +2,7 @@ import { ECompilerType, ITestEnv, TCompilerOptions, - TCompilerStats, + TCompilerStatsCompilation, TTestConfig } from "../type"; @@ -44,7 +44,7 @@ export interface IBasicGlobalContext { export interface IBasicRunnerOptions { env: ITestEnv; - stats?: TCompilerStats; + stats?: TCompilerStatsCompilation; name: string; runInNewContext?: boolean; testConfig: TTestConfig; diff --git a/packages/rspack-test-tools/src/runner/watch.ts b/packages/rspack-test-tools/src/runner/watch.ts index 82c96599fd0..c81788e023c 100644 --- a/packages/rspack-test-tools/src/runner/watch.ts +++ b/packages/rspack-test-tools/src/runner/watch.ts @@ -2,7 +2,8 @@ import { ECompilerType, ITestEnv, ITestRunner, - TCompilerOptions + TCompilerOptions, + TCompilerStatsCompilation } from "../type"; import { WatchRunner } from "./runner/watch"; import { BasicRunnerFactory } from "./basic"; @@ -19,6 +20,7 @@ export class WatchRunnerFactory< } protected createRunner( file: string, + stats: TCompilerStatsCompilation, compilerOptions: TCompilerOptions, env: ITestEnv ): ITestRunner { @@ -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: diff --git a/packages/rspack-test-tools/src/type.ts b/packages/rspack-test-tools/src/type.ts index b789c576778..5cd468d4ee9 100644 --- a/packages/rspack-test-tools/src/type.ts +++ b/packages/rspack-test-tools/src/type.ts @@ -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"; @@ -53,6 +55,10 @@ export type TCompilerStats = T extends ECompilerType.Rspack ? RspackStats : WebpackStats; +export type TCompilerStatsCompilation = T extends ECompilerType.Rspack + ? RspackStatsCompilation + : WebpackStatsCompilation; + export interface ITestCompilerManager { getOptions(): TCompilerOptions; setOptions(newOptions: TCompilerOptions): TCompilerOptions;