diff --git a/package.json b/package.json index cd9582d5882..c7a483ef5fd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/rspack/jest.config.js b/packages/rspack/jest.config.js index 5f7d1ad43f3..1c131af48f4 100644 --- a/packages/rspack/jest.config.js +++ b/packages/rspack/jest.config.js @@ -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" }, diff --git a/packages/rspack/tests/Stats.test.ts b/packages/rspack/tests/Stats.test.js similarity index 92% rename from packages/rspack/tests/Stats.test.ts rename to packages/rspack/tests/Stats.test.js index 1dbaf13a455..e16b559a4fa 100644 --- a/packages/rspack/tests/Stats.test.ts +++ b/packages/rspack/tests/Stats.test.js @@ -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", () => { @@ -223,12 +239,12 @@ 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((resolve, reject) => { + await new Promise((resolve, reject) => { compiler.build(err => { if (err) { return reject(err); @@ -236,7 +252,7 @@ describe("Stats", () => { resolve(); }); }); - const stats = await new Promise((resolve, reject) => { + const stats = await new Promise((resolve, reject) => { compiler.rebuild( new Set([path.join(__dirname, "./fixtures/a")]), new Set(), @@ -258,12 +274,12 @@ 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((resolve, reject) => { + await new Promise((resolve, reject) => { compiler.build(err => { if (err) { return reject(err); @@ -271,7 +287,7 @@ describe("Stats", () => { resolve(); }); }); - const stats = await new Promise((resolve, reject) => { + const stats = await new Promise((resolve, reject) => { compiler.rebuild( new Set([path.join(__dirname, "./fixtures/a")]), new Set(), @@ -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({}); @@ -330,7 +346,7 @@ describe("Stats", () => { plugins: [new TestPlugin()] }); - expect(stats!.entrypoints).toMatchInlineSnapshot(` + expect(stats.entrypoints).toMatchInlineSnapshot(` { "main": { "assets": [], @@ -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, diff --git a/packages/rspack/tests/__snapshots__/Stats.test.ts.snap b/packages/rspack/tests/__snapshots__/Stats.test.js.snap similarity index 100% rename from packages/rspack/tests/__snapshots__/Stats.test.ts.snap rename to packages/rspack/tests/__snapshots__/Stats.test.js.snap diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0157f53010f..5738deb559f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,6 +56,9 @@ importers: prettier: specifier: '3.2' version: 3.2.4 + prettier-2: + specifier: npm:prettier@^2 + version: /prettier@2.8.8 rimraf: specifier: 3.0.2 version: 3.0.2 @@ -13227,6 +13230,12 @@ packages: requiresBuild: true dev: true + /prettier@2.8.8: + resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} + engines: {node: '>=10.13.0'} + hasBin: true + dev: true + /prettier@3.2.4: resolution: {integrity: sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==} engines: {node: '>=14'} diff --git a/scripts/test/diff-exclude.cjs b/scripts/test/diff-exclude.cjs index 05253d5bc26..6052b5e53b3 100644 --- a/scripts/test/diff-exclude.cjs +++ b/scripts/test/diff-exclude.cjs @@ -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. diff --git a/webpack-test/Compiler.test.js b/webpack-test/Compiler.test.js index 4292bd632a4..65d04c95fdb 100644 --- a/webpack-test/Compiler.test.js +++ b/webpack-test/Compiler.test.js @@ -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); @@ -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", { @@ -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"]; @@ -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"]; @@ -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"]; @@ -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"]); @@ -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"]; @@ -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); @@ -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, @@ -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, @@ -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, @@ -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, @@ -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({ diff --git a/webpack-test/Stats.test.js b/webpack-test/Stats.test.js index b0fe2501f7a..33fcddce247 100644 --- a/webpack-test/Stats.test.js +++ b/webpack-test/Stats.test.js @@ -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) => { @@ -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: { @@ -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: { @@ -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: { diff --git a/webpack-test/jest.config.js b/webpack-test/jest.config.js index ec5912d9d97..f4d221a2eaa 100644 --- a/webpack-test/jest.config.js +++ b/webpack-test/jest.config.js @@ -53,7 +53,7 @@ module.exports = { // "/SideEffectsFlagPlugin.unittest.js", // "/SizeFormatHelpers.unittest.js", // "/SortableSet.unittest.js", - // "/Stats.test.js", + "/Stats.test.js", "/StatsTestCases.basictest.js", // "/Template.unittest.js", // "/TestCasesAllCombined.longtest.js",