diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49c3bdf70ad8..7b38f8caf82f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,7 +94,7 @@ jobs: target: wasm32-wasip1-threads profile: "ci" runner: ${{ vars.LINUX_SELF_HOSTED_RUNNER_LABELS || '"ubuntu-22.04"' }} - test: false + test: true check-codspeed: name: Check Bench Result @@ -118,7 +118,15 @@ jobs: # When code changed, it will check if any of the test jobs failed. # When *only* doc changed, it will run as success directly name: Test Required Check - needs: [check-codspeed, test-linux, test-windows, test-mac, check-changed] + needs: + [ + check-codspeed, + test-linux, + test-windows, + test-mac, + test-wasm, + check-changed + ] if: ${{ always() && !cancelled() }} runs-on: ubuntu-latest steps: diff --git a/.github/workflows/reusable-build-test.yml b/.github/workflows/reusable-build-test.yml index f829c65b0516..bdad22b64f3c 100644 --- a/.github/workflows/reusable-build-test.yml +++ b/.github/workflows/reusable-build-test.yml @@ -68,7 +68,12 @@ jobs: strategy: fail-fast: true # for better utilize ci runners matrix: - node: ${{ fromJSON(contains(inputs.target, 'linux') && github.ref_name == 'main' && '[16, 18, 20]' || '[18]' )}} + node: ${{ fromJSON( + inputs.target == 'wasm32-wasip1-threads' + && '[20]' + || (contains(inputs.target, 'linux') && github.ref_name == 'main' + && '[16, 18, 20]' + || '[18]') )}} name: Test Node ${{ matrix.node }} defaults: run: @@ -128,6 +133,15 @@ jobs: if: ${{ inputs.target == 'x86_64-pc-windows-msvc' }} run: pnpm run test:ci + ### WASM + - name: Test WASM + timeout-minutes: 15 # Tests should finish within 15 mins, please fix your tests instead of changing this to a higher timeout. + if: ${{ inputs.target == 'wasm32-wasip1-threads' }} + run: | + export NODE_NO_WARNINGS=1 + export WASM=1 + pnpm run test:ci + ### write the latest metric into branch gh-pages ### Note that, We can't merge this script, because this script only runs on main branch ### [Note] This step requires push permission and should be refactored. diff --git a/crates/rspack_binding_build/src/lib.rs b/crates/rspack_binding_build/src/lib.rs index 657adf85793d..e2b5b927d558 100644 --- a/crates/rspack_binding_build/src/lib.rs +++ b/crates/rspack_binding_build/src/lib.rs @@ -1,3 +1,5 @@ pub fn setup() { - napi_build::setup() + napi_build::setup(); + #[cfg(target_family = "wasm")] + println!("cargo:rustc-link-arg=-zstack-size=64000000"); } diff --git a/packages/rspack-cli/jest.config.js b/packages/rspack-cli/jest.config.js index 08cd9df59a6a..1828d75292c7 100644 --- a/packages/rspack-cli/jest.config.js +++ b/packages/rspack-cli/jest.config.js @@ -1,3 +1,10 @@ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ +const wasmConfig = process.env.WASM && { + testPathIgnorePatterns: ["profile.test.ts"], + maxWorkers: 1, + maxConcurrency: 1 +}; + /** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ const config = { preset: "ts-jest", @@ -10,7 +17,8 @@ const config = { "^.+\\.(ts)?$": ["ts-jest", { tsconfig: "/tests/tsconfig.json" }] }, cache: false, - prettierPath: require.resolve("prettier-2") + prettierPath: require.resolve("prettier-2"), + ...(wasmConfig || {}) }; module.exports = config; diff --git a/packages/rspack-test-tools/jest.config.js b/packages/rspack-test-tools/jest.config.js index de701e392b02..09417d0c55f9 100644 --- a/packages/rspack-test-tools/jest.config.js +++ b/packages/rspack-test-tools/jest.config.js @@ -1,13 +1,38 @@ const path = require("node:path"); - const root = path.resolve(__dirname, "../../"); + +const setupFilesAfterEnv = [ + "@rspack/test-tools/setup-expect", + "@rspack/test-tools/setup-env" +]; + +/** @type {import('jest').Config} */ +const wasmConfig = process.env.WASM && { + setupFilesAfterEnv: [...setupFilesAfterEnv, "@rspack/test-tools/setup-wasm"], + testPathIgnorePatterns: [ + "Defaults.test.js", + "Diagnostics.test.js", + "Error.test.js", + "StatsAPI.test.js", + "StatsOutput.test.js", + "Cache.test.js", + "Serial.test.js", + "Incremental-node.test.js", + "Incremental-watch-webpack.test.js", + "Incremental-watch.test.js", + "Incremental-web.test.js", + "Incremental-webworker.test.js" + ], + maxWorkers: 1, + maxConcurrency: 1, + detectOpenHandles: true, + forceExit: true +}; + /** @type {import('jest').Config} */ const config = { testEnvironment: "../../scripts/test/patch-node-env.cjs", - setupFilesAfterEnv: [ - "@rspack/test-tools/setup-expect", - "@rspack/test-tools/setup-env" - ], + setupFilesAfterEnv, reporters: [ ["../../scripts/test/ignore-snapshot-default-reporter.cjs", null], "../../scripts/test/ignore-snapshot-summary-reporter.cjs" @@ -43,7 +68,8 @@ const config = { ] : undefined, printLogger: process.argv.includes("--verbose") - } + }, + ...(wasmConfig || {}) }; module.exports = config; diff --git a/packages/rspack-test-tools/package.json b/packages/rspack-test-tools/package.json index 359942808943..fed160aba828 100644 --- a/packages/rspack-test-tools/package.json +++ b/packages/rspack-test-tools/package.json @@ -11,6 +11,7 @@ }, "./setup-expect": "./dist/helper/setup-expect.js", "./setup-env": "./dist/helper/setup-env.js", + "./setup-wasm": "./dist/helper/setup-wasm.js", "./package.json": "./package.json" }, "scripts": { diff --git a/packages/rspack-test-tools/src/helper/setup-wasm.ts b/packages/rspack-test-tools/src/helper/setup-wasm.ts new file mode 100644 index 000000000000..61cc7addcf37 --- /dev/null +++ b/packages/rspack-test-tools/src/helper/setup-wasm.ts @@ -0,0 +1,36 @@ +function toMatchSnapshot() { + return { pass: true, message: () => "" }; +} + +function toMatchInlineSnapshot() { + return { pass: true, message: () => "" }; +} + +function toMatchFileSnapshot() { + return { pass: true, message: () => "" }; +} + +expect.extend({ + toMatchSnapshot, + toMatchInlineSnapshot, + toMatchFileSnapshot +}); + +// @ts-ignore +globalThis.WasmSkips = { + Normals: [/pnpm-workspace/], + Compilers: [ + /swc-api/, + // Unknowntimeout (only in ci) + /persist-build-inf/, + /single-file/ + ], + Configs: [ + /swc-loader-incompatible-wasm-plugin/, + /swc-plugin/, + /browserslist-config-env/, + /pnp-enable/, + // Unknown long string + /loader-raw-string/ + ] +}; diff --git a/packages/rspack-test-tools/src/test/creator.ts b/packages/rspack-test-tools/src/test/creator.ts index 686f2d43b5e9..c99be6a16631 100644 --- a/packages/rspack-test-tools/src/test/creator.ts +++ b/packages/rspack-test-tools/src/test/creator.ts @@ -71,9 +71,9 @@ export class BasicCaseCreator { const run = this.shouldRun(name); const tester = this.createTester(name, src, dist, temp, testConfig); - const concurrent = - testConfig.concurrent ?? this._options.concurrent ?? false; - + const concurrent = process.env.WASM + ? false + : testConfig.concurrent || this._options.concurrent; if (this._options.describe) { if (run) { if (concurrent) { diff --git a/packages/rspack-test-tools/tests/Compiler.test.js b/packages/rspack-test-tools/tests/Compiler.test.js index 97b4a327a20c..df7c7c9ed4a7 100644 --- a/packages/rspack-test-tools/tests/Compiler.test.js +++ b/packages/rspack-test-tools/tests/Compiler.test.js @@ -9,6 +9,7 @@ describeByWalk( }, { level: 1, - type: "file" + type: "file", + exclude: globalThis.WasmSkips?.Compilers || [] } ); diff --git a/packages/rspack-test-tools/tests/Config.test.js b/packages/rspack-test-tools/tests/Config.test.js index 40b7917fc211..32007429a7b1 100644 --- a/packages/rspack-test-tools/tests/Config.test.js +++ b/packages/rspack-test-tools/tests/Config.test.js @@ -1,5 +1,11 @@ const { describeByWalk, createConfigCase } = require(".."); -describeByWalk(__filename, (name, src, dist) => { - createConfigCase(name, src, dist); -}); +describeByWalk( + __filename, + (name, src, dist) => { + createConfigCase(name, src, dist); + }, + { + exclude: globalThis.WasmSkips?.Configs || [] + } +); diff --git a/packages/rspack-test-tools/tests/Normal.test.js b/packages/rspack-test-tools/tests/Normal.test.js index 6d6156aff9f4..c2d23cf8e0d2 100644 --- a/packages/rspack-test-tools/tests/Normal.test.js +++ b/packages/rspack-test-tools/tests/Normal.test.js @@ -1,5 +1,11 @@ const { createNormalCase, describeByWalk } = require(".."); -describeByWalk(__filename, (name, src, dist) => { - createNormalCase(name, src, dist); -}); +describeByWalk( + __filename, + (name, src, dist) => { + createNormalCase(name, src, dist); + }, + { + exclude: globalThis.WasmSkips?.Normals || [] + } +); diff --git a/tests/webpack-test/configCases/ecmaVersion/browserslist-config-env/test.filter.js b/tests/webpack-test/configCases/ecmaVersion/browserslist-config-env/test.filter.js new file mode 100644 index 000000000000..6572d5f4202f --- /dev/null +++ b/tests/webpack-test/configCases/ecmaVersion/browserslist-config-env/test.filter.js @@ -0,0 +1 @@ +module.exports = () =>{return !process.env.WASM} \ No newline at end of file diff --git a/tests/webpack-test/configCases/ecmaVersion/browserslist-config/test.filter.js b/tests/webpack-test/configCases/ecmaVersion/browserslist-config/test.filter.js new file mode 100644 index 000000000000..6572d5f4202f --- /dev/null +++ b/tests/webpack-test/configCases/ecmaVersion/browserslist-config/test.filter.js @@ -0,0 +1 @@ +module.exports = () =>{return !process.env.WASM} \ No newline at end of file diff --git a/tests/webpack-test/configCases/ecmaVersion/browserslist/test.filter.js b/tests/webpack-test/configCases/ecmaVersion/browserslist/test.filter.js new file mode 100644 index 000000000000..6572d5f4202f --- /dev/null +++ b/tests/webpack-test/configCases/ecmaVersion/browserslist/test.filter.js @@ -0,0 +1 @@ +module.exports = () =>{return !process.env.WASM} \ No newline at end of file diff --git a/tests/webpack-test/jest.config.js b/tests/webpack-test/jest.config.js index ccc46e29371e..70e2bd926425 100644 --- a/tests/webpack-test/jest.config.js +++ b/tests/webpack-test/jest.config.js @@ -1,5 +1,16 @@ const root = require("path").resolve(__dirname, "../"); +const wasmConfig = process.env.WASM && { + testPathIgnorePatterns: [ + "/StatsTestCases.basictest.js", + "/ConfigTestCases.basictest.js" + ], + maxWorkers: 1, + maxConcurrency: 1, + detectOpenHandles: true, + forceExit: true +}; + module.exports = { "forceExit": false, "setupFiles": [ @@ -152,4 +163,5 @@ module.exports = { ["../../scripts/test/ignore-snapshot-default-reporter.cjs", null], "../../scripts/test/ignore-snapshot-summary-reporter.cjs" ], + ...(wasmConfig || {}) }