Skip to content

Commit 3e62fc9

Browse files
authored
chore: migrate Rstest to Rstack CLI (#8166)
1 parent 12da47d commit 3e62fc9

23 files changed

Lines changed: 88 additions & 129 deletions

File tree

e2e/helper/fixture.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {
88
import { constants as fsConstants, promises } from 'node:fs';
99
import path from 'node:path';
1010
import { expect, test as base } from '@rstest/playwright';
11-
import type { PlaywrightOptions } from '@rstest/playwright';
11+
import type { PlaywrightFixture, PlaywrightOptions } from '@rstest/playwright';
1212
import {
1313
copyNodeModules as baseCopyNodeModules,
1414
editFile as baseEditFile,
1515
type FileEditor,
1616
prepareDist as basePrepareDist,
1717
} from '@rstackjs/test-utils';
1818
import fse from 'fs-extra';
19+
import type { TestContext, TestOptions } from 'rstack/test';
1920
import { RSBUILD_BIN_PATH } from './constants.ts';
2021
import {
2122
type Build,
@@ -182,12 +183,6 @@ type RsbuildFixture = {
182183
execCliSync: ExecSync;
183184
};
184185

185-
// Make custom fixtures available to Rstest hook callbacks.
186-
declare module '@rstest/core' {
187-
// rslint-disable-next-line @typescript-eslint/no-empty-object-type
188-
interface TestContext extends RsbuildFixture {}
189-
}
190-
191186
type Close = DevResult['close'];
192187

193188
const setupExecOptions = <T extends SpawnOptions | ExecSyncOptions>(options: T, cwd: string): T => {
@@ -405,6 +400,19 @@ const rsbuildTest = rsbuildBase.extend<RsbuildFixture>({
405400
},
406401
});
407402

408-
export const test = rsbuildTest;
403+
// TODO: Remove these hook type overrides after https://github.com/web-infra-dev/rstest/pull/1604 is released.
404+
type MaybePromise<T> = T | Promise<T>;
405+
type RsbuildTestContext = TestContext & PlaywrightFixture & RsbuildFixture;
406+
type TestCallback = (context: RsbuildTestContext) => MaybePromise<void>;
407+
type AfterEachCallback = (context: RsbuildTestContext) => MaybePromise<void>;
408+
type BeforeEachCallback = (context: RsbuildTestContext) => MaybePromise<void | AfterEachCallback>;
409+
type RsbuildTest = Omit<typeof rsbuildTest, 'afterEach' | 'beforeEach'> & {
410+
(description: string, callback?: TestCallback, timeout?: number): void;
411+
(description: string, options: TestOptions, callback?: TestCallback): void;
412+
afterEach: (callback: AfterEachCallback, timeout?: number) => void;
413+
beforeEach: (callback: BeforeEachCallback, timeout?: number) => void;
414+
};
415+
416+
export const test = rsbuildTest as unknown as RsbuildTest;
409417

410418
export { expect };

e2e/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"setup": "pnpm exec playwright install chromium --with-deps",
8-
"e2e": "rstest"
8+
"e2e": "rs test"
99
},
1010
"dependencies": {
1111
"@module-federation/runtime-tools": "catalog:",
@@ -38,7 +38,6 @@
3838
"@rsbuild/plugin-type-check": "catalog:",
3939
"@rsbuild/plugin-vue": "workspace:*",
4040
"@rstackjs/test-utils": "catalog:",
41-
"@rstest/core": "catalog:",
4241
"@rstest/playwright": "catalog:",
4342
"@scripts/test-helper": "workspace:*",
4443
"@tailwindcss/postcss": "catalog:",

e2e/rstack.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { define } from 'rstack';
2+
3+
define.test(() => {
4+
// Disable color in test.
5+
process.env.NO_COLOR = '1';
6+
7+
// https://playwright.dev/docs/service-workers-experimental
8+
process.env.PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS = '1';
9+
10+
const isCI = Boolean(process.env.CI);
11+
12+
return {
13+
include: ['cases/**/*.test.ts'],
14+
exclude: ['**/node_modules/**', '**/.*/**', '**/test-temp-*/**'],
15+
reporters: ['default', ['github-actions', { annotations: false }]],
16+
isolate: false,
17+
// Existing e2e helpers capture build logs synchronously; interception delays them.
18+
disableConsoleIntercept: true,
19+
retry: isCI ? 3 : 0,
20+
testTimeout: 30_000,
21+
hookTimeout: 30_000,
22+
output: {
23+
externals: ['@rsbuild/core'],
24+
},
25+
};
26+
});

e2e/rstest.config.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

e2e/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"include": [
88
"helper",
9-
"rstest.config.ts",
9+
"rstack.config.ts",
1010
"cases/**/*.test.ts",
1111
"cases/**/*.config.ts",
1212
"cases/javascript-api/server-custom-message/src/**/*.ts"

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
"prebundle": "pnpm --parallel --filter \"./packages/*\" run prebundle",
1818
"prepare": "simple-git-hooks && node --run prebundle",
1919
"sort-package-json": "pnpx sort-package-json \"./package.json\" \"packages/*/package.json\"",
20-
"test": "rstest",
21-
"test:watch": "rstest watch"
20+
"test": "rs test",
21+
"test:watch": "rs test watch"
2222
},
2323
"devDependencies": {
2424
"@rstest/adapter-rslib": "catalog:",
25-
"@rstest/core": "catalog:",
2625
"@scripts/config": "workspace:*",
2726
"@scripts/test-helper": "workspace:*",
2827
"@types/node": "catalog:",

packages/core/tests/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "@scripts/config/tsconfig",
33
"compilerOptions": {
4-
"types": ["@rstest/core/globals"]
4+
"types": ["rstack/test/globals"]
55
},
66
"include": ["./**/*.ts", "../src/env.d.ts"]
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "@scripts/config/tsconfig",
33
"compilerOptions": {
4-
"types": ["@rstest/core/globals"]
4+
"types": ["rstack/test/globals"]
55
},
66
"include": ["./**/*.ts"]
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "@scripts/config/tsconfig",
33
"compilerOptions": {
4-
"types": ["@rstest/core/globals"]
4+
"types": ["rstack/test/globals"]
55
},
66
"include": ["./**/*.ts"]
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "@scripts/config/tsconfig",
33
"compilerOptions": {
4-
"types": ["@rstest/core/globals"]
4+
"types": ["rstack/test/globals"]
55
},
66
"include": ["./**/*.ts"]
77
}

0 commit comments

Comments
 (0)