11import fs from 'node:fs/promises' ;
22import { expect , test } from '@playwright/test' ;
33import { createRsbuild } from '@rsbuild/core' ;
4+ import { join } from 'node:path' ;
5+
6+ const __dirname = new URL ( '.' , import . meta. url ) . pathname ;
47
58const build = async ( ) => {
69 const rsbuild = await createRsbuild ( {
@@ -13,19 +16,19 @@ test('should not work in node environment', async () => {
1316 await build ( ) ;
1417
1518 // dist/server only contains one file
16- expect ( ( await fs . readdir ( 'dist/server' ) ) . length ) . toBe ( 1 ) ;
19+ expect ( ( await fs . readdir ( join ( __dirname , 'dist/server' ) ) ) . length ) . toBe ( 1 ) ;
1720 // only dist/server/index.js exists
1821 expect (
19- await fs . access ( 'dist/server/index.js' ) . then (
22+ await fs . access ( join ( __dirname , 'dist/server/index.js' ) ) . then (
2023 ( ) => true ,
2124 ( ) => false ,
2225 ) ,
2326 ) . toBe ( true ) ;
2427
2528 // dist/static/js contains two files, index.js and assets-retry.js
26- expect ( ( await fs . readdir ( 'dist/static/js' ) ) . length ) . toBe ( 2 ) ;
29+ expect ( ( await fs . readdir ( join ( __dirname , 'dist/static/js' ) ) ) . length ) . toBe ( 2 ) ;
2730 // index.js contains "registerAsyncChunkRetry" function calling
28- expect ( await fs . readFile ( 'dist/static/js/index.js' , 'utf-8' ) ) . toContain (
31+ expect ( await fs . readFile ( join ( __dirname , 'dist/static/js/index.js' ) , 'utf-8' ) ) . toContain (
2932 'registerAsyncChunkRetry' ,
3033 ) ;
3134} ) ;
0 commit comments