Skip to content

Commit

Permalink
chore: align stats test (#5789)
Browse files Browse the repository at this point in the history
* chore: align stats tests

* chore: webpack

* chore: prettier

* chore: diff
  • Loading branch information
h-a-n-a authored Feb 27, 2024
1 parent 398f12f commit 9ee47af
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 35 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"npm-run-all": "4.1.5",
"oxlint": "0.2.10",
"prettier": "3.2",
"prettier-2": "npm:prettier@^2",
"rimraf": "3.0.2",
"ts-jest": "29.1.2",
"typescript": "5.0.2",
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const config = {
],
testTimeout: process.env.CI ? 60000 : 30000,
cache: false,
prettierPath: require.resolve("prettier-2"),
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import * as util from "util";
import path from "path";
import { Compiler, rspack, RspackOptions, Stats } from "../src";
import serializer from "jest-serializer-path";
"use strict";

require("./helpers/warmup-webpack");

const { createFsFromVolume, Volume } = require("memfs");
const path = require("path");
const { Stats } = require("../dist");
const serializer = require("jest-serializer-path");

// CHANGE: required for additional tests
expect.addSnapshotSerializer(serializer);

const compile = async (options: RspackOptions) => {
return util.promisify(rspack)(options);
const compile = options => {
return new Promise((resolve, reject) => {
const webpack = require("..");
const compiler = webpack(options);
compiler.outputFileSystem = createFsFromVolume(new Volume());
compiler.run((err, stats) => {
if (err) {
reject(err);
} else {
resolve(stats);
}
});
});
};

describe("Stats", () => {
Expand Down Expand Up @@ -223,20 +239,20 @@ describe("Stats", () => {
});

it("should not have any cache hits log when cache is disabled", async () => {
const compiler = rspack({
const compiler = require("../dist")({
context: __dirname,
entry: "./fixtures/abc",
cache: false
});
await new Promise<void>((resolve, reject) => {
await new Promise((resolve, reject) => {
compiler.build(err => {
if (err) {
return reject(err);
}
resolve();
});
});
const stats = await new Promise<string>((resolve, reject) => {
const stats = await new Promise((resolve, reject) => {
compiler.rebuild(
new Set([path.join(__dirname, "./fixtures/a")]),
new Set(),
Expand All @@ -258,20 +274,20 @@ describe("Stats", () => {
});

it("should have any cache hits log of modules in incremental rebuild mode", async () => {
const compiler = rspack({
const compiler = require("../dist")({
context: __dirname,
entry: "./fixtures/abc",
cache: true
});
await new Promise<void>((resolve, reject) => {
await new Promise((resolve, reject) => {
compiler.build(err => {
if (err) {
return reject(err);
}
resolve();
});
});
const stats = await new Promise<string>((resolve, reject) => {
const stats = await new Promise((resolve, reject) => {
compiler.rebuild(
new Set([path.join(__dirname, "./fixtures/a")]),
new Set(),
Expand Down Expand Up @@ -316,7 +332,7 @@ describe("Stats", () => {
let stats;

class TestPlugin {
apply(compiler: Compiler) {
apply(compiler) {
compiler.hooks.thisCompilation.tap("custom", compilation => {
compilation.hooks.optimizeModules.tap("test plugin", () => {
stats = compiler.compilation.getStats().toJson({});
Expand All @@ -330,7 +346,7 @@ describe("Stats", () => {
plugins: [new TestPlugin()]
});

expect(stats!.entrypoints).toMatchInlineSnapshot(`
expect(stats.entrypoints).toMatchInlineSnapshot(`
{
"main": {
"assets": [],
Expand All @@ -348,7 +364,7 @@ describe("Stats", () => {
let statsJson;

class TestPlugin {
apply(compiler: Compiler) {
apply(compiler) {
compiler.hooks.thisCompilation.tap(TestPlugin.name, compilation => {
compilation.hooks.processAssets.tapAsync(
TestPlugin.name,
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scripts/test/diff-exclude.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const UNALIGNED_FIXTURES = [
"HotTestCases.template.js",
"HotTestCasesNode.test.js",
"MultiCompiler.test.js",
"Compiler.test.js"
"Compiler.test.js",
"Stats.test.js"
];

// Only different in comments. For example, license information difference.
Expand Down
26 changes: 13 additions & 13 deletions webpack-test/Compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { Stats } = require("..");
const { createFsFromVolume, Volume } = require("memfs");
const captureStdio = require("./helpers/captureStdio");
const deprecationTracking = require("./helpers/deprecationTracking");
const { normalizeFilteredTestName } = require("./lib/util/filterUtil");
const { normalizeFilteredTestName, FilteredStatus } = require("./lib/util/filterUtil");

describe("Compiler", () => {
jest.setTimeout(20000);
Expand Down Expand Up @@ -97,7 +97,7 @@ describe("Compiler", () => {
});

// CHANGE: skip due to Rspack defaults to numerical module ids, unlike webpack's string-based ids
it.skip(normalizeFilteredTestName("TODO", "should compile a single file to deep output"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a single file to deep output"), done => {
compile(
"./c",
{
Expand All @@ -118,7 +118,7 @@ describe("Compiler", () => {
});

// CHANGE: skip due to Rspack defaults to numerical module ids, unlike webpack's string-based ids
it.skip(normalizeFilteredTestName("TODO", "should compile a single file"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a single file"), done => {
compile("./c", {}, (stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
Expand All @@ -137,7 +137,7 @@ describe("Compiler", () => {
});

// CHANGE: skip with custom test name for tracking alignment status
it.skip(normalizeFilteredTestName("TODO", "should compile a complex file"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a complex file"), done => {
compile("./main1", {}, (stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
Expand All @@ -159,7 +159,7 @@ describe("Compiler", () => {
});

// CHANGE: skip with custom test name for tracking alignment status
it.skip(normalizeFilteredTestName("TODO", "should compile a file with transitive dependencies"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a file with transitive dependencies"), done => {
compile("./abc", {}, (stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
Expand All @@ -183,7 +183,7 @@ describe("Compiler", () => {
});

// CHANGE: skip with custom test name for tracking alignment status
it.skip(normalizeFilteredTestName("TODO", "should compile a file with multiple chunks"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should compile a file with multiple chunks"), done => {
compile("./chunks", {}, (stats, files) => {
expect(stats.chunks).toHaveLength(2);
expect(Object.keys(files)).toEqual(["/main.js", "/394.js"]);
Expand All @@ -210,7 +210,7 @@ describe("Compiler", () => {

// CHANGE: skip with custom test name for tracking alignment status
// cspell:word asmjs
it.skip(normalizeFilteredTestName("TODO", "should not evaluate constants in asm.js"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should not evaluate constants in asm.js"), done => {
compile("./asmjs", {}, (stats, files) => {
expect(Object.keys(files)).toEqual(["/main.js"]);
const bundle = files["/main.js"];
Expand Down Expand Up @@ -271,7 +271,7 @@ describe("Compiler", () => {
});
describe("isChild", () => {
// CHANGE: skip with custom test name for tracking alignment status
it.skip(normalizeFilteredTestName("TODO", "returns booleanized this.parentCompilation"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "returns booleanized this.parentCompilation"), done => {
compiler.parentCompilation = "stringyStringString";
const response1 = compiler.isChild();
expect(response1).toBe(true);
Expand Down Expand Up @@ -555,7 +555,7 @@ describe("Compiler", () => {
});
// CHANGE: skip with custom test name for tracking alignment status
// CHANGE: skip due to panic occurred at runtime
it.skip(normalizeFilteredTestName("TODO", "should run again correctly after first closed watch"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should run again correctly after first closed watch"), done => {
const webpack = require("..");
compiler = webpack({
context: __dirname,
Expand Down Expand Up @@ -598,7 +598,7 @@ describe("Compiler", () => {

// CHANGE: skip with custom test name for tracking alignment status
// CHANGE: skip due to panic occurred at runtime
it.skip(normalizeFilteredTestName("TODO", "should watch again correctly after first closed watch"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should watch again correctly after first closed watch"), done => {
const webpack = require("..");
compiler = webpack({
context: __dirname,
Expand Down Expand Up @@ -700,7 +700,7 @@ describe("Compiler", () => {
});
// CHANGE: skip with custom test name for tracking alignment status
// CHANGE: skip due to panic occurred at runtime
it.skip(normalizeFilteredTestName("TODO", "should call afterDone hook after other callbacks (watch)"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should call afterDone hook after other callbacks (watch)"), done => {
const webpack = require("..");
compiler = webpack({
context: __dirname,
Expand Down Expand Up @@ -791,7 +791,7 @@ describe("Compiler", () => {
});
// CHANGE: skip with custom test name for tracking alignment status
// CHANGE: skip due to panic occurred at runtime
it.skip(normalizeFilteredTestName("TODO", "should use cache on second run call"), done => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should use cache on second run call"), done => {
const webpack = require("..");
compiler = webpack({
context: __dirname,
Expand Down Expand Up @@ -838,7 +838,7 @@ describe("Compiler", () => {
});
// CHANGE: skip with custom test name for tracking alignment status
// CHANGE: skip as rspack does not currently emit correct error code
it.skip(normalizeFilteredTestName("TODO", "should deprecate when watch option is used without callback"), () => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should deprecate when watch option is used without callback"), () => {
const tracker = deprecationTracking.start();
const webpack = require("..");
compiler = webpack({
Expand Down
12 changes: 7 additions & 5 deletions webpack-test/Stats.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use strict";

// require("./helpers/warmup-webpack");
require("./helpers/warmup-webpack");

const { createFsFromVolume, Volume } = require("memfs");
const { normalizeFilteredTestName, FilteredStatus } = require("./lib/util/filterUtil");

const compile = options => {
return new Promise((resolve, reject) => {
const webpack = require("@rspack/core").rspack;
const webpack = require("..");
const compiler = webpack(options);
compiler.outputFileSystem = createFsFromVolume(new Volume());
compiler.run((err, stats) => {
Expand Down Expand Up @@ -63,7 +64,8 @@ describe("Stats", () => {
).toEqual({});
});
describe("chunkGroups", () => {
it("should be empty when there is no additional chunks", async () => {
// CHANGE: skipped as rspack generates additional chunk
it.skip(normalizeFilteredTestName(FilteredStatus.TODO,"should be empty when there is no additional chunks"), async () => {
const stats = await compile({
context: __dirname,
entry: {
Expand Down Expand Up @@ -111,7 +113,7 @@ describe("Stats", () => {
}
`);
});
it("should contain additional chunks", async () => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should contain additional chunks"), async () => {
const stats = await compile({
context: __dirname,
entry: {
Expand Down Expand Up @@ -172,7 +174,7 @@ describe("Stats", () => {
}
`);
});
it("should contain assets", async () => {
it.skip(normalizeFilteredTestName(FilteredStatus.TODO, "should contain assets"), async () => {
const stats = await compile({
context: __dirname,
entry: {
Expand Down
2 changes: 1 addition & 1 deletion webpack-test/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
// "<rootDir>/SideEffectsFlagPlugin.unittest.js",
// "<rootDir>/SizeFormatHelpers.unittest.js",
// "<rootDir>/SortableSet.unittest.js",
// "<rootDir>/Stats.test.js",
"<rootDir>/Stats.test.js",
"<rootDir>/StatsTestCases.basictest.js",
// "<rootDir>/Template.unittest.js",
// "<rootDir>/TestCasesAllCombined.longtest.js",
Expand Down

1 comment on commit 9ee47af

@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-02-27 e84bdc0) Current Change
10000_development-mode + exec 1.69 s ± 12 ms 1.73 s ± 45 ms +2.74 %
10000_development-mode_hmr + exec 924 ms ± 8.8 ms 922 ms ± 12 ms -0.14 %
10000_production-mode + exec 2.64 s ± 19 ms 2.68 s ± 100 ms +1.54 %
arco-pro_development-mode + exec 2.45 s ± 23 ms 2.47 s ± 50 ms +0.75 %
arco-pro_development-mode_hmr + exec 861 ms ± 7.2 ms 853 ms ± 10 ms -0.95 %
arco-pro_production-mode + exec 4.06 s ± 39 ms 4.14 s ± 51 ms +1.97 %
threejs_development-mode_10x + exec 1.9 s ± 26 ms 1.93 s ± 23 ms +1.44 %
threejs_development-mode_10x_hmr + exec 1.13 s ± 11 ms 1.12 s ± 6.2 ms -0.63 %
threejs_production-mode_10x + exec 5.78 s ± 149 ms 5.68 s ± 66 ms -1.85 %

Please sign in to comment.