diff --git a/e2e/helper/fixture.ts b/e2e/helper/fixture.ts index 80d2cca761..44ab6b4dc6 100644 --- a/e2e/helper/fixture.ts +++ b/e2e/helper/fixture.ts @@ -8,7 +8,7 @@ import { import { constants as fsConstants, promises } from 'node:fs'; import path from 'node:path'; import { expect, test as base } from '@rstest/playwright'; -import type { PlaywrightOptions } from '@rstest/playwright'; +import type { PlaywrightFixture, PlaywrightOptions } from '@rstest/playwright'; import { copyNodeModules as baseCopyNodeModules, editFile as baseEditFile, @@ -16,6 +16,7 @@ import { prepareDist as basePrepareDist, } from '@rstackjs/test-utils'; import fse from 'fs-extra'; +import type { TestContext, TestOptions } from 'rstack/test'; import { RSBUILD_BIN_PATH } from './constants.ts'; import { type Build, @@ -182,12 +183,6 @@ type RsbuildFixture = { execCliSync: ExecSync; }; -// Make custom fixtures available to Rstest hook callbacks. -declare module '@rstest/core' { - // rslint-disable-next-line @typescript-eslint/no-empty-object-type - interface TestContext extends RsbuildFixture {} -} - type Close = DevResult['close']; const setupExecOptions = (options: T, cwd: string): T => { @@ -405,6 +400,19 @@ const rsbuildTest = rsbuildBase.extend({ }, }); -export const test = rsbuildTest; +// TODO: Remove these hook type overrides after https://github.com/web-infra-dev/rstest/pull/1604 is released. +type MaybePromise = T | Promise; +type RsbuildTestContext = TestContext & PlaywrightFixture & RsbuildFixture; +type TestCallback = (context: RsbuildTestContext) => MaybePromise; +type AfterEachCallback = (context: RsbuildTestContext) => MaybePromise; +type BeforeEachCallback = (context: RsbuildTestContext) => MaybePromise; +type RsbuildTest = Omit & { + (description: string, callback?: TestCallback, timeout?: number): void; + (description: string, options: TestOptions, callback?: TestCallback): void; + afterEach: (callback: AfterEachCallback, timeout?: number) => void; + beforeEach: (callback: BeforeEachCallback, timeout?: number) => void; +}; + +export const test = rsbuildTest as unknown as RsbuildTest; export { expect }; diff --git a/e2e/package.json b/e2e/package.json index 388b780843..b132668b51 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "setup": "pnpm exec playwright install chromium --with-deps", - "e2e": "rstest" + "e2e": "rs test" }, "dependencies": { "@module-federation/runtime-tools": "catalog:", @@ -38,7 +38,6 @@ "@rsbuild/plugin-type-check": "catalog:", "@rsbuild/plugin-vue": "workspace:*", "@rstackjs/test-utils": "catalog:", - "@rstest/core": "catalog:", "@rstest/playwright": "catalog:", "@scripts/test-helper": "workspace:*", "@tailwindcss/postcss": "catalog:", diff --git a/e2e/rstack.config.ts b/e2e/rstack.config.ts new file mode 100644 index 0000000000..5633010d62 --- /dev/null +++ b/e2e/rstack.config.ts @@ -0,0 +1,26 @@ +import { define } from 'rstack'; + +define.test(() => { + // Disable color in test. + process.env.NO_COLOR = '1'; + + // https://playwright.dev/docs/service-workers-experimental + process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS = '1'; + + const isCI = Boolean(process.env.CI); + + return { + include: ['cases/**/*.test.ts'], + exclude: ['**/node_modules/**', '**/.*/**', '**/test-temp-*/**'], + reporters: ['default', ['github-actions', { annotations: false }]], + isolate: false, + // Existing e2e helpers capture build logs synchronously; interception delays them. + disableConsoleIntercept: true, + retry: isCI ? 3 : 0, + testTimeout: 30_000, + hookTimeout: 30_000, + output: { + externals: ['@rsbuild/core'], + }, + }; +}); diff --git a/e2e/rstest.config.ts b/e2e/rstest.config.ts deleted file mode 100644 index be1394fbdb..0000000000 --- a/e2e/rstest.config.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { defineConfig } from '@rstest/core'; - -// Disable color in test. -process.env.NO_COLOR = '1'; - -// https://playwright.dev/docs/service-workers-experimental -process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS = '1'; - -const isCI = Boolean(process.env.CI); - -export default defineConfig({ - include: ['cases/**/*.test.ts'], - exclude: ['**/node_modules/**', '**/.*/**', '**/test-temp-*/**'], - reporters: ['default', ['github-actions', { annotations: false }]], - isolate: false, - // Existing e2e helpers capture build logs synchronously; interception delays them. - disableConsoleIntercept: true, - retry: isCI ? 3 : 0, - testTimeout: 30_000, - hookTimeout: 30_000, - output: { - externals: ['@rsbuild/core'], - }, -}); diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json index 91ca7e35c1..6d1032449e 100644 --- a/e2e/tsconfig.json +++ b/e2e/tsconfig.json @@ -6,7 +6,7 @@ }, "include": [ "helper", - "rstest.config.ts", + "rstack.config.ts", "cases/**/*.test.ts", "cases/**/*.config.ts", "cases/javascript-api/server-custom-message/src/**/*.ts" diff --git a/package.json b/package.json index 6684781904..72629efdb2 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,11 @@ "prebundle": "pnpm --parallel --filter \"./packages/*\" run prebundle", "prepare": "simple-git-hooks && node --run prebundle", "sort-package-json": "pnpx sort-package-json \"./package.json\" \"packages/*/package.json\"", - "test": "rstest", - "test:watch": "rstest watch" + "test": "rs test", + "test:watch": "rs test watch" }, "devDependencies": { "@rstest/adapter-rslib": "catalog:", - "@rstest/core": "catalog:", "@scripts/config": "workspace:*", "@scripts/test-helper": "workspace:*", "@types/node": "catalog:", diff --git a/packages/core/tests/tsconfig.json b/packages/core/tests/tsconfig.json index 200fba8976..52539c42e0 100644 --- a/packages/core/tests/tsconfig.json +++ b/packages/core/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts", "../src/env.d.ts"] } diff --git a/packages/plugin-babel/tests/tsconfig.json b/packages/plugin-babel/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-babel/tests/tsconfig.json +++ b/packages/plugin-babel/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-less/tests/tsconfig.json b/packages/plugin-less/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-less/tests/tsconfig.json +++ b/packages/plugin-less/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-preact/tests/tsconfig.json b/packages/plugin-preact/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-preact/tests/tsconfig.json +++ b/packages/plugin-preact/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-react/tests/tsconfig.json b/packages/plugin-react/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-react/tests/tsconfig.json +++ b/packages/plugin-react/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-sass/tests/tsconfig.json b/packages/plugin-sass/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-sass/tests/tsconfig.json +++ b/packages/plugin-sass/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-solid/tests/tsconfig.json b/packages/plugin-solid/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-solid/tests/tsconfig.json +++ b/packages/plugin-solid/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-svelte/tests/tsconfig.json b/packages/plugin-svelte/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-svelte/tests/tsconfig.json +++ b/packages/plugin-svelte/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-svgr/tests/tsconfig.json b/packages/plugin-svgr/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-svgr/tests/tsconfig.json +++ b/packages/plugin-svgr/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-tailwindcss/tests/tsconfig.json b/packages/plugin-tailwindcss/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-tailwindcss/tests/tsconfig.json +++ b/packages/plugin-tailwindcss/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/packages/plugin-vue/tests/tsconfig.json b/packages/plugin-vue/tests/tsconfig.json index d4b129ce31..e450cf906e 100644 --- a/packages/plugin-vue/tests/tsconfig.json +++ b/packages/plugin-vue/tests/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@scripts/config/tsconfig", "compilerOptions": { - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "include": ["./**/*.ts"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d497b5d9e8..1c4c62ff33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -94,9 +94,6 @@ catalogs: '@rstest/adapter-rslib': specifier: ^0.11.2 version: 0.11.2 - '@rstest/core': - specifier: ^0.11.2 - version: 0.11.2 '@rstest/playwright': specifier: ^0.11.2 version: 0.11.2 @@ -401,10 +398,7 @@ importers: devDependencies: '@rstest/adapter-rslib': specifier: 'catalog:' - version: 0.11.2(@rslib/core@1.0.0-beta.0)(@rstest/core@0.11.2)(typescript@6.0.3) - '@rstest/core': - specifier: 'catalog:' - version: 0.11.2(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) + version: 0.11.2(@rslib/core@1.0.0-beta.0)(@rstest/core@0.11.3)(typescript@6.0.3) '@scripts/config': specifier: workspace:* version: link:scripts/config @@ -526,12 +520,9 @@ importers: '@rstackjs/test-utils': specifier: 'catalog:' version: 0.2.0 - '@rstest/core': - specifier: 'catalog:' - version: 0.11.2(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) '@rstest/playwright': specifier: 'catalog:' - version: 0.11.2(@rstest/core@0.11.2)(playwright@1.61.1) + version: 0.11.2(@rstest/core@0.11.3)(playwright@1.61.1) '@scripts/test-helper': specifier: workspace:* version: link:../scripts/test-helper @@ -2477,16 +2468,6 @@ packages: engines: {node: '>=18.12.0'} hasBin: true - '@rsbuild/core@2.1.6': - resolution: {integrity: sha512-w2WxblstOgHnDElkqJZVO/jM/EqPaEhg7zqQhON3Xu3Mj9FlVOJx+SgimOtghFzxLt8x7atX4oMUtMTNSZGf0Q==} - engines: {node: ^20.19.0 || >=22.12.0} - hasBin: true - peerDependencies: - core-js: '>= 3.0.0' - peerDependenciesMeta: - core-js: - optional: true - '@rsbuild/core@2.1.7': resolution: {integrity: sha512-Xhs8DkLw2Vk5ydwjNG3GMJe1h03lqlCO4dV9EOG9HSR6vDfh07K48aq3KJ8/ncEL/YuFBaCIJrVc7rMFoR1y7Q==} engines: {node: ^20.19.0 || >=22.12.0} @@ -2831,19 +2812,6 @@ packages: typescript: optional: true - '@rstest/core@0.11.2': - resolution: {integrity: sha512-/CTLkvogDGozY+bCYsc+sKJDDsU/LvDdEZC545+QO1Iv9ds+6vgSWuA+Q2iQF3cReeSkOI9ySARfFemcCoSKpQ==} - engines: {node: ^20.19.0 || >=22.12.0} - hasBin: true - peerDependencies: - happy-dom: ^20.8.3 - jsdom: '*' - peerDependenciesMeta: - happy-dom: - optional: true - jsdom: - optional: true - '@rstest/core@0.11.3': resolution: {integrity: sha512-TXBvW8snHQntxRRYX71a3vTkhQ9SVvbG1PlqmiyxkSwcVxBXdwghJCpYEHu75L6Ay61eQtsc0R8MIq+Qd3aicA==} engines: {node: ^20.19.0 || >=22.12.0} @@ -6508,15 +6476,6 @@ snapshots: core-js: 3.47.0 jiti: 2.7.0 - '@rsbuild/core@2.1.6(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0)': - dependencies: - '@rspack/core': 2.1.5(@module-federation/runtime-tools@2.8.0)(@swc/helpers@0.5.23) - '@swc/helpers': 0.5.23 - optionalDependencies: - core-js: 3.49.0 - transitivePeerDependencies: - - '@module-federation/runtime-tools' - '@rsbuild/core@2.1.7(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0)': dependencies: '@rspack/core': 2.1.5(@module-federation/runtime-tools@2.8.0)(@swc/helpers@0.5.23) @@ -6839,21 +6798,13 @@ snapshots: '@rstackjs/test-utils@0.2.0': {} - '@rstest/adapter-rslib@0.11.2(@rslib/core@1.0.0-beta.0)(@rstest/core@0.11.2)(typescript@6.0.3)': + '@rstest/adapter-rslib@0.11.2(@rslib/core@1.0.0-beta.0)(@rstest/core@0.11.3)(typescript@6.0.3)': dependencies: '@rslib/core': 1.0.0-beta.0(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0)(typescript@6.0.3) - '@rstest/core': 0.11.2(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) + '@rstest/core': 0.11.3(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) optionalDependencies: typescript: 6.0.3 - '@rstest/core@0.11.2(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0)': - dependencies: - '@rsbuild/core': 2.1.6(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) - '@types/chai': 5.2.3 - transitivePeerDependencies: - - '@module-federation/runtime-tools' - - core-js - '@rstest/core@0.11.3(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0)': dependencies: '@rsbuild/core': 2.1.7(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) @@ -6862,9 +6813,9 @@ snapshots: - '@module-federation/runtime-tools' - core-js - '@rstest/playwright@0.11.2(@rstest/core@0.11.2)(playwright@1.61.1)': + '@rstest/playwright@0.11.2(@rstest/core@0.11.3)(playwright@1.61.1)': dependencies: - '@rstest/core': 0.11.2(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) + '@rstest/core': 0.11.3(@module-federation/runtime-tools@2.8.0)(core-js@3.49.0) playwright: 1.61.1 '@shikijs/core@4.3.0': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 9c108881cd..735cd7a3cc 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -45,7 +45,6 @@ catalog: '@rstackjs/load-config': '^0.1.2' '@rstackjs/test-utils': '^0.2.0' '@rstest/adapter-rslib': '^0.11.2' - '@rstest/core': '^0.11.2' '@rstest/playwright': '^0.11.2' '@shikijs/transformers': '^4.3.1' '@svgr/core': '8.1.0' diff --git a/rstack.config.ts b/rstack.config.ts index 969ed06f10..cb8ea2541e 100644 --- a/rstack.config.ts +++ b/rstack.config.ts @@ -1,5 +1,28 @@ import { define } from 'rstack'; +define.test(async () => { + // Disable color in test. + process.env.NO_COLOR = '1'; + + const { withRslibConfig } = await import('@rstest/adapter-rslib'); + + return { + extends: withRslibConfig({ + configPath: './packages/core/rslib.config.ts', + }), + output: { + externals: ['@rsbuild/core'], + }, + name: 'node', + globals: true, + restoreMocks: true, + unstubEnvs: true, + include: ['packages/**/*.test.ts'], + exclude: ['packages/create-rsbuild/template-rstest'], + setupFiles: ['./scripts/test-helper/rstest.setup.ts'], + }; +}); + define.lint(async () => { const { globalIgnores, js, ts } = await import('rstack/lint'); diff --git a/rstest.config.ts b/rstest.config.ts deleted file mode 100644 index c2b2b89405..0000000000 --- a/rstest.config.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { defineConfig } from '@rstest/core'; -import { withRslibConfig } from '@rstest/adapter-rslib'; - -// Disable color in test -process.env.NO_COLOR = '1'; - -// TODO: change to test projects ['packages/*'] -export default defineConfig({ - extends: withRslibConfig({ - configPath: './packages/core/rslib.config.ts', - }), - output: { - externals: ['@rsbuild/core'], - }, - name: 'node', - globals: true, - restoreMocks: true, - unstubEnvs: true, - include: ['packages/**/*.test.ts'], - exclude: ['packages/create-rsbuild/template-rstest'], - setupFiles: ['./scripts/test-helper/rstest.setup.ts'], -}); diff --git a/scripts/test-helper/rstest.setup.ts b/scripts/test-helper/rstest.setup.ts index ea8f88c731..197622641b 100644 --- a/scripts/test-helper/rstest.setup.ts +++ b/scripts/test-helper/rstest.setup.ts @@ -1,5 +1,5 @@ import path from 'node:path'; -import { beforeAll, expect } from '@rstest/core'; +import { beforeAll, expect } from 'rstack/test'; import { createSnapshotSerializer } from 'path-serializer'; beforeAll((suite) => { diff --git a/scripts/test-helper/tsconfig.json b/scripts/test-helper/tsconfig.json index 7690378dd8..a90c0c26e4 100644 --- a/scripts/test-helper/tsconfig.json +++ b/scripts/test-helper/tsconfig.json @@ -4,7 +4,7 @@ "outDir": "dist", "rootDir": "src", "composite": true, - "types": ["@rstest/core/globals"] + "types": ["rstack/test/globals"] }, "references": [ {