@@ -8,14 +8,15 @@ import {
88import { constants as fsConstants , promises } from 'node:fs' ;
99import path from 'node:path' ;
1010import { expect , test as base } from '@rstest/playwright' ;
11- import type { PlaywrightOptions } from '@rstest/playwright' ;
11+ import type { PlaywrightFixture , PlaywrightOptions } from '@rstest/playwright' ;
1212import {
1313 copyNodeModules as baseCopyNodeModules ,
1414 editFile as baseEditFile ,
1515 type FileEditor ,
1616 prepareDist as basePrepareDist ,
1717} from '@rstackjs/test-utils' ;
1818import fse from 'fs-extra' ;
19+ import type { TestContext , TestOptions } from 'rstack/test' ;
1920import { RSBUILD_BIN_PATH } from './constants.ts' ;
2021import {
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-
191186type Close = DevResult [ 'close' ] ;
192187
193188const 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
410418export { expect } ;
0 commit comments