From b31e78e21c4c97b97a36fe174479473e2db85a76 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Wed, 21 May 2025 15:47:18 +0800 Subject: [PATCH 01/14] feat: add nextjs eco ci --- .github/workflows/ci.yml | 2 ++ .../workflows/ecosystem-ci-from-commit.yml | 1 + .github/workflows/ecosystem-ci-from-pr.yml | 1 + .github/workflows/ecosystem-ci-selected.yml | 1 + tests/nextjs.ts | 22 +++++++++++++++++++ 5 files changed, 27 insertions(+) create mode 100644 tests/nextjs.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2282b830..df24644c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,8 @@ jobs: os: ubuntu-22.04 - suite: plugin os: ubuntu-22.04 + - suite: nextjs + os: ubuntu-22.04 - suite: lynx-stack os: ubuntu-22.04 fail-fast: false diff --git a/.github/workflows/ecosystem-ci-from-commit.yml b/.github/workflows/ecosystem-ci-from-commit.yml index d02a6693..87797535 100644 --- a/.github/workflows/ecosystem-ci-from-commit.yml +++ b/.github/workflows/ecosystem-ci-from-commit.yml @@ -32,6 +32,7 @@ on: - examples - devserver - plugin + - nextjs suiteRefType: description: "type of suite ref to use" required: true diff --git a/.github/workflows/ecosystem-ci-from-pr.yml b/.github/workflows/ecosystem-ci-from-pr.yml index a47d1fe4..fbc418e1 100644 --- a/.github/workflows/ecosystem-ci-from-pr.yml +++ b/.github/workflows/ecosystem-ci-from-pr.yml @@ -37,6 +37,7 @@ on: - examples - devserver - plugin + - nextjs suiteRefType: description: "type of suite ref to use" required: true diff --git a/.github/workflows/ecosystem-ci-selected.yml b/.github/workflows/ecosystem-ci-selected.yml index 8121cb25..870ec69d 100644 --- a/.github/workflows/ecosystem-ci-selected.yml +++ b/.github/workflows/ecosystem-ci-selected.yml @@ -44,6 +44,7 @@ on: - examples - devserver - plugin + - nextjs suiteRefType: description: "type of suite ref to use" required: true diff --git a/tests/nextjs.ts b/tests/nextjs.ts new file mode 100644 index 00000000..a52e2fc6 --- /dev/null +++ b/tests/nextjs.ts @@ -0,0 +1,22 @@ +import { runInRepo, execa } from '../utils' +import { RunOptions } from '../types' + +export async function test(options: RunOptions) { + await runInRepo({ + ...options, + repo: 'vercel/next.js', + branch: 'main', + build: ['build'], + test: async () => { + const env = { + ...process.env, + NEXT_RSPACK: '1', + NEXT_TEST_USE_RSPACK: '1', + }; + await execa('node run-tests.js --timings --type production', { + env, + shell: true, + }) + }, + }) +} From 68be5beabbf7481c4760952a1aaf748d4bb61d83 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Wed, 21 May 2025 17:07:42 +0800 Subject: [PATCH 02/14] fix --- tests/nextjs.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index a52e2fc6..e27bef95 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -2,6 +2,7 @@ import { runInRepo, execa } from '../utils' import { RunOptions } from '../types' export async function test(options: RunOptions) { + const pwd = options.workspace; await runInRepo({ ...options, repo: 'vercel/next.js', @@ -10,6 +11,7 @@ export async function test(options: RunOptions) { test: async () => { const env = { ...process.env, + NEXT_EXTERNAL_TESTS_FILTERS: `${pwd}/test/rspack-build-tests-manifest.json`, NEXT_RSPACK: '1', NEXT_TEST_USE_RSPACK: '1', }; From b0f1d59b14448451a6ee44f14677e976711555c7 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Wed, 21 May 2025 17:11:07 +0800 Subject: [PATCH 03/14] feat: add development ci --- tests/nextjs.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index e27bef95..8a05786a 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -11,7 +11,7 @@ export async function test(options: RunOptions) { test: async () => { const env = { ...process.env, - NEXT_EXTERNAL_TESTS_FILTERS: `${pwd}/test/rspack-build-tests-manifest.json`, + NEXT_EXTERNAL_TESTS_FILTERS: `${pwd}/next.js/test/rspack-build-tests-manifest.json`, NEXT_RSPACK: '1', NEXT_TEST_USE_RSPACK: '1', }; @@ -19,6 +19,10 @@ export async function test(options: RunOptions) { env, shell: true, }) + await execa('node run-tests.js --timings --type development', { + env, + shell: true, + }) }, }) } From 4e3d530c843497a4fc5cd637c4e48ad56b648eae Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Wed, 21 May 2025 18:02:09 +0800 Subject: [PATCH 04/14] fix --- tests/nextjs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index 8a05786a..4f26ab0f 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -6,7 +6,7 @@ export async function test(options: RunOptions) { await runInRepo({ ...options, repo: 'vercel/next.js', - branch: 'main', + branch: 'canary', build: ['build'], test: async () => { const env = { From f39b1aa4cc3fdf8c33c71531feaf8c738fa3dd01 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Wed, 21 May 2025 20:44:18 +0800 Subject: [PATCH 05/14] feat: shard run nextjs test --- .github/workflows/ci.yml | 2 ++ ecosystem-ci.ts | 41 +++++++++++++++++++++++++++++++++++++++- tests/nextjs.ts | 24 +++++++++++++---------- types.d.ts | 7 +++++++ 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df24644c..808db0f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,7 @@ jobs: os: ubuntu-22.04 - suite: nextjs os: ubuntu-22.04 + shard: [1/7, 2/7, 3/7, 4/7, 5/7, 6/7, 7/7] - suite: lynx-stack os: ubuntu-22.04 fail-fast: false @@ -79,4 +80,5 @@ jobs: - run: >- pnpm tsx ecosystem-ci.ts run-suites + --shard ${{ matrix.shard }} ${{ matrix.suite }} diff --git a/ecosystem-ci.ts b/ecosystem-ci.ts index 0f68a1e3..8a4a0156 100644 --- a/ecosystem-ci.ts +++ b/ecosystem-ci.ts @@ -12,7 +12,7 @@ import { parseMajorVersion, ignorePrecoded, } from './utils' -import { CommandOptions, RunOptions } from './types' +import { CommandOptions, RunOptions, ShardPair } from './types' const cli = cac() cli @@ -89,9 +89,14 @@ cli .option('--suite-branch ', 'suite branch to use') .option('--suite-tag ', 'suite tag to use') .option('--suite-commit ', 'suite commit sha to use') + .option( + '--shard', + 'Shard tests and execute only the selected shard, specify in the form "current/all". 1-based, for example "3/5"', + ) .action(async (suites, options: CommandOptions) => { const { root, rspackPath, workspace } = await setupEnvironment() const suitesToRun = getSuitesToRun(suites, root) + const shardPair = options.shard ? parseShardPair(options.shard) : undefined; const runOptions: RunOptions = { ...options, root, @@ -101,6 +106,7 @@ cli suiteBranch: ignorePrecoded(options.suiteBranch), suiteTag: ignorePrecoded(options.suiteTag), suiteCommit: ignorePrecoded(options.suiteCommit), + shardPair } for (const suite of suitesToRun) { await run(suite, runOptions) @@ -197,3 +203,36 @@ function getSuitesToRun(suites: string[], root: string) { } return suitesToRun } + +const parseShardPair = (pair: string): ShardPair => { + const shardPair = pair + .split('/') + .filter((d) => /^\d+$/.test(d)) + .map((d) => Number.parseInt(d, 10)) + .filter((shard) => !Number.isNaN(shard)) + + const [shardIndex, shardCount] = shardPair + + if (shardPair.length !== 2) { + throw new Error( + 'The shard option requires a string in the format of /.', + ) + } + + if (shardIndex === 0 || shardCount === 0) { + throw new Error( + 'The shard option requires 1-based values, received 0 or lower in the pair.', + ) + } + + if (shardIndex > shardCount) { + throw new Error( + 'The shard option / requires to be lower or equal than .', + ) + } + + return { + shardCount, + shardIndex, + } +} diff --git a/tests/nextjs.ts b/tests/nextjs.ts index 4f26ab0f..9e71976c 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -2,7 +2,8 @@ import { runInRepo, execa } from '../utils' import { RunOptions } from '../types' export async function test(options: RunOptions) { - const pwd = options.workspace; + const { workspace, shardPair } = options; + await runInRepo({ ...options, repo: 'vercel/next.js', @@ -11,18 +12,21 @@ export async function test(options: RunOptions) { test: async () => { const env = { ...process.env, - NEXT_EXTERNAL_TESTS_FILTERS: `${pwd}/next.js/test/rspack-build-tests-manifest.json`, + NEXT_EXTERNAL_TESTS_FILTERS: `${workspace}/next.js/test/rspack-build-tests-manifest.json`, NEXT_RSPACK: '1', NEXT_TEST_USE_RSPACK: '1', }; - await execa('node run-tests.js --timings --type production', { - env, - shell: true, - }) - await execa('node run-tests.js --timings --type development', { - env, - shell: true, - }) + if (shardPair) { + await execa(`node run-tests.js --timings -g ${ shardPair } --type production`, { + env, + shell: true, + }) + } else { + await execa('node run-tests.js --timings --type production', { + env, + shell: true, + }) + } }, }) } diff --git a/types.d.ts b/types.d.ts index 75697846..be7dcc6a 100644 --- a/types.d.ts +++ b/types.d.ts @@ -8,6 +8,11 @@ export interface EnvironmentData { env: NodeJS.ProcessEnv } +interface ShardPair { + shardCount: number; + shardIndex: number; +} + export interface RunOptions { workspace: string root: string @@ -26,6 +31,7 @@ export interface RunOptions { suiteBranch?: string suiteTag?: string suiteCommit?: string + shardPair?: ShardPair } type Task = string | (() => Promise) @@ -41,6 +47,7 @@ export interface CommandOptions { suiteBranch?: string suiteTag?: string suiteCommit?: string + shard?: string, } export interface RepoOptions { From ca6d8af8d1dc8378a8a9c500284f254dbaa0d478 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Thu, 22 May 2025 09:23:56 +0800 Subject: [PATCH 06/14] u --- .github/workflows/ci.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 808db0f2..04466791 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,25 @@ jobs: os: ubuntu-22.04 - suite: nextjs os: ubuntu-22.04 - shard: [1/7, 2/7, 3/7, 4/7, 5/7, 6/7, 7/7] + shard: 1/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 2/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 3/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 4/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 5/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 6/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 7/7 - suite: lynx-stack os: ubuntu-22.04 fail-fast: false @@ -80,5 +98,5 @@ jobs: - run: >- pnpm tsx ecosystem-ci.ts run-suites - --shard ${{ matrix.shard }} + ${{ matrix.shard && '--shard ' + matrix.shard || '' }} ${{ matrix.suite }} From 4a9272b099841686e8d5efd78bca4f150382f6f3 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Thu, 22 May 2025 09:28:38 +0800 Subject: [PATCH 07/14] fix --- .github/workflows/ci.yml | 2 +- ecosystem-ci.ts | 2 +- tests/nextjs.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04466791..205e7f45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,5 +98,5 @@ jobs: - run: >- pnpm tsx ecosystem-ci.ts run-suites - ${{ matrix.shard && '--shard ' + matrix.shard || '' }} + ${{ matrix.shard && '--shard ' || '' }}${{ matrix.shard || '' }} ${{ matrix.suite }} diff --git a/ecosystem-ci.ts b/ecosystem-ci.ts index 8a4a0156..0ace07cb 100644 --- a/ecosystem-ci.ts +++ b/ecosystem-ci.ts @@ -90,7 +90,7 @@ cli .option('--suite-tag ', 'suite tag to use') .option('--suite-commit ', 'suite commit sha to use') .option( - '--shard', + '--shard ', 'Shard tests and execute only the selected shard, specify in the form "current/all". 1-based, for example "3/5"', ) .action(async (suites, options: CommandOptions) => { diff --git a/tests/nextjs.ts b/tests/nextjs.ts index 9e71976c..128269f7 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -17,7 +17,7 @@ export async function test(options: RunOptions) { NEXT_TEST_USE_RSPACK: '1', }; if (shardPair) { - await execa(`node run-tests.js --timings -g ${ shardPair } --type production`, { + await execa(`node run-tests.js --timings -g ${ shardPair.shardIndex }/${ shardPair.shardCount } --type production`, { env, shell: true, }) From 9563e0ad0756fb799d108ec768debba02441078c Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Thu, 22 May 2025 10:29:47 +0800 Subject: [PATCH 08/14] u --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 205e7f45..c0591f59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: os: ubuntu-22.04 fail-fast: false runs-on: ${{ matrix.os }} - name: ${{ matrix.suite }} + name: ${{ matrix.suite }} ${{ matrix.shard || '' }} steps: - uses: actions/checkout@v4 - uses: ./.github/actions/build-rspack From 99e7859248dd5f572de4233144318994679943ed Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Mon, 26 May 2025 08:47:27 +0800 Subject: [PATCH 09/14] fix --- tests/nextjs.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index 128269f7..5b806ae1 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -1,14 +1,24 @@ +import path from 'path' +import fs from 'fs'; import { runInRepo, execa } from '../utils' import { RunOptions } from '../types' export async function test(options: RunOptions) { - const { workspace, shardPair } = options; + const { workspace, shardPair, rspackPath } = options; + const rspackCorePath = path.join(rspackPath, 'packages/rspack'); await runInRepo({ ...options, repo: 'vercel/next.js', branch: 'canary', build: ['build'], + beforeTest: async () => { + const nextRspackPath = path.join(workspace, 'next.js/packages/next-rspack'); + const nextRspackPkgPath = path.join(nextRspackPath, 'package.json'); + const pkg = JSON.parse(fs.readFileSync(nextRspackPkgPath, 'utf-8')); + pkg.dependencies['@rspack/core'] = `${rspackCorePath}`; + fs.writeFileSync(nextRspackPkgPath, JSON.stringify(pkg, null, 2)); + }, test: async () => { const env = { ...process.env, @@ -17,12 +27,12 @@ export async function test(options: RunOptions) { NEXT_TEST_USE_RSPACK: '1', }; if (shardPair) { - await execa(`node run-tests.js --timings -g ${ shardPair.shardIndex }/${ shardPair.shardCount } --type production`, { + await execa(`node run-tests.js -g ${ shardPair.shardIndex }/${ shardPair.shardCount } --type production`, { env, shell: true, }) } else { - await execa('node run-tests.js --timings --type production', { + await execa('node run-tests.js --type production', { env, shell: true, }) From cd2ba7bcc5846e601f722d5b5d211b591a4f62ac Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Mon, 26 May 2025 10:34:53 +0800 Subject: [PATCH 10/14] fix --- tests/nextjs.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index 5b806ae1..b2d9c4ad 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -5,7 +5,6 @@ import { RunOptions } from '../types' export async function test(options: RunOptions) { const { workspace, shardPair, rspackPath } = options; - const rspackCorePath = path.join(rspackPath, 'packages/rspack'); await runInRepo({ ...options, @@ -13,11 +12,25 @@ export async function test(options: RunOptions) { branch: 'canary', build: ['build'], beforeTest: async () => { - const nextRspackPath = path.join(workspace, 'next.js/packages/next-rspack'); - const nextRspackPkgPath = path.join(nextRspackPath, 'package.json'); - const pkg = JSON.parse(fs.readFileSync(nextRspackPkgPath, 'utf-8')); - pkg.dependencies['@rspack/core'] = `${rspackCorePath}`; - fs.writeFileSync(nextRspackPkgPath, JSON.stringify(pkg, null, 2)); + const rspackCorePath = path.join(rspackPath, 'packages/rspack'); + + const nextWorkspaceDir = path.join(workspace, 'next.js'); + + const nextRspackDir = path.join(nextWorkspaceDir, 'next.js/packages/next-rspack'); + const nextRspackPkgPath = path.join(nextRspackDir, 'package.json'); + const nextRspackPkg = JSON.parse(fs.readFileSync(nextRspackPkgPath, 'utf-8')); + nextRspackPkg.dependencies['@rspack/core'] = `${rspackCorePath}`; + fs.writeFileSync(nextRspackPkgPath, JSON.stringify(nextRspackPkg, null, 2)); + + const getRspackPath = path.join(nextWorkspaceDir, 'packages/next/src/shared/lib/get-rspack.ts'); + const getRspackContent = fs.readFileSync(getRspackPath, 'utf-8'); + const replacedGetRspackContent = getRspackContent.replace("require.resolve('@rspack/core'", `require.resolve('${rspackCorePath}'`); + fs.writeFileSync(getRspackPath, replacedGetRspackContent); + + const compiledWebpackPath = path.join(nextWorkspaceDir, 'packages/next/src/compiled/webpack/webpack.js'); + const compiledWebpackContent = fs.readFileSync(compiledWebpackPath, 'utf-8'); + const replacedCompiledWebpackContent = compiledWebpackContent.replace("require('@rspack/core')", `require('${rspackCorePath}')`); + fs.writeFileSync(compiledWebpackPath, replacedCompiledWebpackContent); }, test: async () => { const env = { From 9d2ad481f2861c060db15c76cc357c414b203fd2 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Mon, 26 May 2025 11:01:21 +0800 Subject: [PATCH 11/14] fix --- tests/nextjs.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index b2d9c4ad..cfa33e20 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -1,6 +1,6 @@ import path from 'path' import fs from 'fs'; -import { runInRepo, execa } from '../utils' +import { runInRepo, execa, $, cd } from '../utils' import { RunOptions } from '../types' export async function test(options: RunOptions) { @@ -10,18 +10,10 @@ export async function test(options: RunOptions) { ...options, repo: 'vercel/next.js', branch: 'canary', - build: ['build'], - beforeTest: async () => { + build: async () => { const rspackCorePath = path.join(rspackPath, 'packages/rspack'); - const nextWorkspaceDir = path.join(workspace, 'next.js'); - const nextRspackDir = path.join(nextWorkspaceDir, 'next.js/packages/next-rspack'); - const nextRspackPkgPath = path.join(nextRspackDir, 'package.json'); - const nextRspackPkg = JSON.parse(fs.readFileSync(nextRspackPkgPath, 'utf-8')); - nextRspackPkg.dependencies['@rspack/core'] = `${rspackCorePath}`; - fs.writeFileSync(nextRspackPkgPath, JSON.stringify(nextRspackPkg, null, 2)); - const getRspackPath = path.join(nextWorkspaceDir, 'packages/next/src/shared/lib/get-rspack.ts'); const getRspackContent = fs.readFileSync(getRspackPath, 'utf-8'); const replacedGetRspackContent = getRspackContent.replace("require.resolve('@rspack/core'", `require.resolve('${rspackCorePath}'`); @@ -31,6 +23,13 @@ export async function test(options: RunOptions) { const compiledWebpackContent = fs.readFileSync(compiledWebpackPath, 'utf-8'); const replacedCompiledWebpackContent = compiledWebpackContent.replace("require('@rspack/core')", `require('${rspackCorePath}')`); fs.writeFileSync(compiledWebpackPath, replacedCompiledWebpackContent); + + const nodeBindingPath = path.join(rspackPath, 'crates/node_binding'); + cd(nodeBindingPath); + await $`pnpm run move-binding`; + + cd(nextWorkspaceDir); + await $`pnpm run build` }, test: async () => { const env = { From 76fe5ec01339f0ca7f946661b7a0044c1d02a779 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Mon, 26 May 2025 14:38:51 +0800 Subject: [PATCH 12/14] fix --- tests/nextjs.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index cfa33e20..302de514 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -30,6 +30,7 @@ export async function test(options: RunOptions) { cd(nextWorkspaceDir); await $`pnpm run build` + await $`pnpm install` }, test: async () => { const env = { From c55b23244ce119caf32f9256f3d2dd5c2532ad3e Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Tue, 27 May 2025 08:53:01 +0800 Subject: [PATCH 13/14] prettier --- ecosystem-ci.ts | 4 ++-- tests/nextjs.ts | 60 ++++++++++++++++++++++++++++++++----------------- types.d.ts | 6 ++--- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/ecosystem-ci.ts b/ecosystem-ci.ts index 0ace07cb..3c6a7982 100644 --- a/ecosystem-ci.ts +++ b/ecosystem-ci.ts @@ -96,7 +96,7 @@ cli .action(async (suites, options: CommandOptions) => { const { root, rspackPath, workspace } = await setupEnvironment() const suitesToRun = getSuitesToRun(suites, root) - const shardPair = options.shard ? parseShardPair(options.shard) : undefined; + const shardPair = options.shard ? parseShardPair(options.shard) : undefined const runOptions: RunOptions = { ...options, root, @@ -106,7 +106,7 @@ cli suiteBranch: ignorePrecoded(options.suiteBranch), suiteTag: ignorePrecoded(options.suiteTag), suiteCommit: ignorePrecoded(options.suiteCommit), - shardPair + shardPair, } for (const suite of suitesToRun) { await run(suite, runOptions) diff --git a/tests/nextjs.ts b/tests/nextjs.ts index 302de514..1c8b1acf 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -1,34 +1,49 @@ import path from 'path' -import fs from 'fs'; +import fs from 'fs' import { runInRepo, execa, $, cd } from '../utils' import { RunOptions } from '../types' export async function test(options: RunOptions) { - const { workspace, shardPair, rspackPath } = options; + const { workspace, shardPair, rspackPath } = options await runInRepo({ ...options, repo: 'vercel/next.js', branch: 'canary', build: async () => { - const rspackCorePath = path.join(rspackPath, 'packages/rspack'); - const nextWorkspaceDir = path.join(workspace, 'next.js'); + const rspackCorePath = path.join(rspackPath, 'packages/rspack') + const nextWorkspaceDir = path.join(workspace, 'next.js') - const getRspackPath = path.join(nextWorkspaceDir, 'packages/next/src/shared/lib/get-rspack.ts'); - const getRspackContent = fs.readFileSync(getRspackPath, 'utf-8'); - const replacedGetRspackContent = getRspackContent.replace("require.resolve('@rspack/core'", `require.resolve('${rspackCorePath}'`); - fs.writeFileSync(getRspackPath, replacedGetRspackContent); + const getRspackPath = path.join( + nextWorkspaceDir, + 'packages/next/src/shared/lib/get-rspack.ts', + ) + const getRspackContent = fs.readFileSync(getRspackPath, 'utf-8') + const replacedGetRspackContent = getRspackContent.replace( + "require.resolve('@rspack/core'", + `require.resolve('${rspackCorePath}'`, + ) + fs.writeFileSync(getRspackPath, replacedGetRspackContent) - const compiledWebpackPath = path.join(nextWorkspaceDir, 'packages/next/src/compiled/webpack/webpack.js'); - const compiledWebpackContent = fs.readFileSync(compiledWebpackPath, 'utf-8'); - const replacedCompiledWebpackContent = compiledWebpackContent.replace("require('@rspack/core')", `require('${rspackCorePath}')`); - fs.writeFileSync(compiledWebpackPath, replacedCompiledWebpackContent); + const compiledWebpackPath = path.join( + nextWorkspaceDir, + 'packages/next/src/compiled/webpack/webpack.js', + ) + const compiledWebpackContent = fs.readFileSync( + compiledWebpackPath, + 'utf-8', + ) + const replacedCompiledWebpackContent = compiledWebpackContent.replace( + "require('@rspack/core')", + `require('${rspackCorePath}')`, + ) + fs.writeFileSync(compiledWebpackPath, replacedCompiledWebpackContent) - const nodeBindingPath = path.join(rspackPath, 'crates/node_binding'); - cd(nodeBindingPath); - await $`pnpm run move-binding`; + const nodeBindingPath = path.join(rspackPath, 'crates/node_binding') + cd(nodeBindingPath) + await $`pnpm run move-binding` - cd(nextWorkspaceDir); + cd(nextWorkspaceDir) await $`pnpm run build` await $`pnpm install` }, @@ -38,12 +53,15 @@ export async function test(options: RunOptions) { NEXT_EXTERNAL_TESTS_FILTERS: `${workspace}/next.js/test/rspack-build-tests-manifest.json`, NEXT_RSPACK: '1', NEXT_TEST_USE_RSPACK: '1', - }; + } if (shardPair) { - await execa(`node run-tests.js -g ${ shardPair.shardIndex }/${ shardPair.shardCount } --type production`, { - env, - shell: true, - }) + await execa( + `node run-tests.js -g ${shardPair.shardIndex}/${shardPair.shardCount} --type production`, + { + env, + shell: true, + }, + ) } else { await execa('node run-tests.js --type production', { env, diff --git a/types.d.ts b/types.d.ts index be7dcc6a..890dba18 100644 --- a/types.d.ts +++ b/types.d.ts @@ -9,8 +9,8 @@ export interface EnvironmentData { } interface ShardPair { - shardCount: number; - shardIndex: number; + shardCount: number + shardIndex: number } export interface RunOptions { @@ -47,7 +47,7 @@ export interface CommandOptions { suiteBranch?: string suiteTag?: string suiteCommit?: string - shard?: string, + shard?: string } export interface RepoOptions { From 657d5f1dc1c9dca9aff1e017724359a5ab8ee062 Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Tue, 27 May 2025 12:56:40 +0800 Subject: [PATCH 14/14] fix --- .github/workflows/ci.yml | 9 +++++++++ tests/nextjs.ts | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0591f59..5a3ab48e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,6 +69,15 @@ jobs: - suite: nextjs os: ubuntu-22.04 shard: 7/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 7/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 7/7 + - suite: nextjs + os: ubuntu-22.04 + shard: 7/7 - suite: lynx-stack os: ubuntu-22.04 fail-fast: false diff --git a/tests/nextjs.ts b/tests/nextjs.ts index 1c8b1acf..b6fcd006 100644 --- a/tests/nextjs.ts +++ b/tests/nextjs.ts @@ -47,12 +47,17 @@ export async function test(options: RunOptions) { await $`pnpm run build` await $`pnpm install` }, + beforeTest: async () => { + await $`pnpm playwright install --with-deps` + }, test: async () => { const env = { ...process.env, NEXT_EXTERNAL_TESTS_FILTERS: `${workspace}/next.js/test/rspack-build-tests-manifest.json`, NEXT_RSPACK: '1', NEXT_TEST_USE_RSPACK: '1', + TEST_CONCURRENCY: '8', + NEXT_TEST_MODE: 'start', } if (shardPair) { await execa(