Skip to content

Commit

Permalink
chore: migrate test diagnostic (#6348)
Browse files Browse the repository at this point in the history
* chore: move config case of context module

* chore: migrate diagnostic cases
  • Loading branch information
LingyuCoder authored Apr 24, 2024
1 parent bb7b1c2 commit d578fc7
Show file tree
Hide file tree
Showing 132 changed files with 20 additions and 126 deletions.
6 changes: 0 additions & 6 deletions packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ export interface IRspackConfigProcessorOptions<T extends ECompilerType.Rspack> {
export interface IRspackDiagnosticProcessorOptions {
// (undocumented)
name: string;
// (undocumented)
root: string;
}

// @public (undocumented)
Expand Down Expand Up @@ -767,10 +765,6 @@ export class RspackConfigProcessor extends MultiTaskProcessor<ECompilerType.Rspa
export class RspackDiagnosticProcessor extends BasicTaskProcessor<ECompilerType.Rspack> {
constructor(_diagnosticOptions: IRspackDiagnosticProcessorOptions);
// (undocumented)
after(context: ITestContext): Promise<void>;
// (undocumented)
before(context: ITestContext): Promise<void>;
// (undocumented)
check(env: ITestEnv, context: ITestContext): Promise<void>;
// (undocumented)
static defaultOptions(context: ITestContext): TCompilerOptions<ECompilerType.Rspack>;
Expand Down
3 changes: 2 additions & 1 deletion packages/rspack-test-tools/jest.config.compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
"<rootDir>/tests/TestCasesNormal.basictest.js",
"<rootDir>/tests/HotTestCasesWeb.test.js",
"<rootDir>/tests/HotTestCasesNode.test.js",
"<rootDir>/tests/HotTestCasesWebWorker.test.js"
"<rootDir>/tests/HotTestCasesWebWorker.test.js",
"<rootDir>/tests/Diagnostics.test.js"
]
};
1 change: 1 addition & 0 deletions packages/rspack-test-tools/jest.config.legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
"HotTestCasesWeb.test.js",
"HotTestCasesWebWorker.test.js",
"HotTestCasesNode.test.js",
"Diagnostics.test.js",
".difftest.js"
]
};
3 changes: 1 addition & 2 deletions packages/rspack-test-tools/src/case/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const creator = new BasicCaseCreator({
describe: true,
steps: ({ name }) => [
new RspackDiagnosticProcessor({
name,
root: path.resolve(__dirname, "../../../rspack")
name
})
]
});
Expand Down
28 changes: 12 additions & 16 deletions packages/rspack-test-tools/src/processor/diagnostic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { readConfigFile } from "../helper";
import {
ECompilerType,
ITestContext,
Expand All @@ -11,14 +10,21 @@ import path from "path";
import fs from "fs";
const serializer = require("jest-serializer-path");
const normalizePaths = serializer.normalizePaths;
const rspackPath = path.resolve(__dirname, "../../../rspack");

const replacePaths = (input: string) => {
const rspackRoot = normalizePaths(rspackPath);
return normalizePaths(input).split(rspackRoot).join("<RSPACK_ROOT>");
};

declare var global: {
updateSnapshot: boolean;
};

export interface IRspackDiagnosticProcessorOptions {
name: string;
root: string;
}

const CWD = process.cwd();

export class RspackDiagnosticProcessor extends BasicTaskProcessor<ECompilerType.Rspack> {
constructor(protected _diagnosticOptions: IRspackDiagnosticProcessorOptions) {
super({
Expand All @@ -30,22 +36,14 @@ export class RspackDiagnosticProcessor extends BasicTaskProcessor<ECompilerType.
});
}

async before(context: ITestContext) {
process.chdir(this._diagnosticOptions.root);
}

async after(context: ITestContext) {
process.chdir(CWD);
}

async check(env: ITestEnv, context: ITestContext) {
const compiler = this.getCompiler(context);
const stats = compiler.getStats();
if (!stats) {
throw new Error("Stats should exists");
}
assert(stats.hasErrors() || stats.hasWarnings());
let output = normalizePaths(
let output = replacePaths(
stats.toString({
all: false,
errors: true,
Expand All @@ -63,9 +61,7 @@ export class RspackDiagnosticProcessor extends BasicTaskProcessor<ECompilerType.
}

const errorOutputPath = path.resolve(context.getSource(), `./stats.err`);
const updateSnapshot =
process.argv.includes("-u") || process.argv.includes("--updateSnapshot");
if (!fs.existsSync(errorOutputPath) || updateSnapshot) {
if (!fs.existsSync(errorOutputPath) || global.updateSnapshot) {
fs.writeFileSync(errorOutputPath, output);
} else {
expect(output).toBe(fs.readFileSync(errorOutputPath, "utf-8"));
Expand Down
9 changes: 2 additions & 7 deletions packages/rspack-test-tools/tests/Diagnostics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ const path = require("path");
const { describeByWalk, createDiagnosticCase } = require("..");

const NAME = "HotTestCases";
const caseDir = path.resolve(__dirname, "../../rspack/tests/diagnostics");
const caseDir = path.resolve(__dirname, "./diagnostics");

describeByWalk(NAME, caseDir, "", (name, src, dist) => {
createDiagnosticCase(
name,
src,
path.join(src, "dist"),
path.resolve(__dirname, "../../rspack")
);
createDiagnosticCase(name, src, path.join(src, "dist"));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR in ./logo.svg× Module build failed:╰─▶ × Error: Failed to loadat Object.<anonymous>.module.exports (<PROJECT_ROOT>/tests/diagnostics/module-build-failed/asset-module-build-failed/my-loader.js:2:8)at LOADER_EXECUTION (<RSPACK_ROOT>/dist/loader-runner/index.js:617:23)at runSyncOrAsync (<RSPACK_ROOT>/dist/loader-runner/index.js:618:11)at <RSPACK_ROOT>/dist/loader-runner/index.js:722:9at handleResult (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:126:5)at loadLoader (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:107:16)at iterateNormalLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:711:5)at <RSPACK_ROOT>/dist/loader-runner/index.js:538:13at new Promise (<anonymous>)at runLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:513:12)help: File was processed with this loader: '<PROJECT_ROOT>/tests/diagnostics/module-build-failed/asset-module-build-failed/my-loader.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR in ./lib.js× Module build failed:╰─▶ × Error: Failed to loadat Object.<anonymous>.module.exports (<PROJECT_ROOT>/tests/diagnostics/module-build-failed/loader-throw-error/my-loader.js:2:9)at LOADER_EXECUTION (<RSPACK_ROOT>/dist/loader-runner/index.js:617:23)at runSyncOrAsync (<RSPACK_ROOT>/dist/loader-runner/index.js:618:11)at <RSPACK_ROOT>/dist/loader-runner/index.js:722:9at handleResult (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:126:5)at loadLoader (<RSPACK_ROOT>/dist/loader-runner/loadLoader.js:107:16)at iterateNormalLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:711:5)at <RSPACK_ROOT>/dist/loader-runner/index.js:538:13at new Promise (<anonymous>)at runLoaders (<RSPACK_ROOT>/dist/loader-runner/index.js:513:12)help: File was processed with this loader: '<PROJECT_ROOT>/tests/diagnostics/module-build-failed/loader-throw-error/my-loader.js'
92 changes: 0 additions & 92 deletions packages/rspack/tests/Diagnostics.test.js

This file was deleted.

This file was deleted.

This file was deleted.

2 comments on commit d578fc7

@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-04-24 332b127) Current Change
10000_development-mode + exec 2.66 s ± 28 ms 2.72 s ± 47 ms +2.06 %
10000_development-mode_hmr + exec 682 ms ± 3.7 ms 701 ms ± 9.8 ms +2.84 %
10000_production-mode + exec 2.46 s ± 31 ms 2.57 s ± 20 ms +4.17 %
arco-pro_development-mode + exec 2.48 s ± 86 ms 2.5 s ± 89 ms +0.76 %
arco-pro_development-mode_hmr + exec 429 ms ± 1.2 ms 430 ms ± 4.2 ms +0.17 %
arco-pro_development-mode_hmr_intercept-plugin + exec 441 ms ± 5.4 ms 441 ms ± 3.9 ms +0.02 %
arco-pro_development-mode_intercept-plugin + exec 3.22 s ± 88 ms 3.25 s ± 60 ms +0.87 %
arco-pro_production-mode + exec 3.95 s ± 74 ms 4 s ± 38 ms +1.30 %
arco-pro_production-mode_intercept-plugin + exec 4.66 s ± 238 ms 4.81 s ± 101 ms +3.13 %
threejs_development-mode_10x + exec 2.05 s ± 16 ms 2.06 s ± 24 ms +0.21 %
threejs_development-mode_10x_hmr + exec 753 ms ± 13 ms 752 ms ± 5.3 ms -0.19 %
threejs_production-mode_10x + exec 5.14 s ± 40 ms 5.28 s ± 35 ms +2.87 %

@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, self-hosted, Linux, ci ❌ failure
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ✅ success
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ✅ success

Please sign in to comment.