1- import { spawn } from 'node:child_process' ;
21import path from 'node:path' ;
32import { stripVTControlCharacters as stripAnsi } from 'node:util' ;
43import { describe , expect , onTestFinished , test } from '@rstest/core' ;
54import fse from 'fs-extra' ;
65import {
6+ expectBuildEnd ,
77 expectFile ,
8- expectFileChanges ,
9- rslibBinPath ,
8+ expectFileWithContent ,
109 runCli ,
1110} from 'test-helper' ;
1211
@@ -91,8 +90,9 @@ export default defineConfig({
9190 },
9291 },
9392 performance: {
93+ buildCache: false,
9494 printFileSize: false,
95- }
95+ },
9696});
9797` ,
9898 ) ;
@@ -104,21 +104,19 @@ export default defineConfig({
104104 const distFooFile = path . join ( __dirname , 'dist/esm/foo.js' ) ;
105105 const distFoo2File = path . join ( __dirname , 'dist/esm/foo2.js' ) ;
106106
107- const child = spawn (
108- 'node' ,
109- [ rslibBinPath , 'build' , '--watch' , '-c' , tempConfigFile ] ,
110- {
111- cwd : __dirname ,
112- stdio : 'pipe' ,
113- shell : true ,
114- } ,
115- ) ;
116- await expectFile ( distIndexFile ) ;
107+ const { child } = runCli ( `build --watch -c ${ tempConfigFile } ` , {
108+ cwd : __dirname ,
109+ } ) ;
110+ await expectFileWithContent ( distIndexFile , 'index' ) ;
117111
118112 fse . outputFileSync ( srcFooFile , `export const foo = 'foo';` ) ;
113+ await expectBuildEnd ( child ) ;
114+ await expectFileWithContent ( distFooFile , `'foo'` ) ;
115+
119116 fse . outputFileSync ( srcFoo2File , `export const foo2 = 'foo2';` ) ;
120- await expectFile ( distFooFile ) ;
121- await expectFile ( distFoo2File ) ;
117+ await expectBuildEnd ( child ) ;
118+ await expectFileWithContent ( distFoo2File , 'foo2' ) ;
119+
122120 const content1 = await fse . readFile ( distFooFile , 'utf-8' ) ;
123121 expect ( content1 ! ) . toMatchInlineSnapshot ( `
124122 "const foo = 'foo';
@@ -137,12 +135,13 @@ export default defineConfig({
137135 fse . removeSync ( srcIndexFile ) ;
138136
139137 // change
140- fse . outputFileSync ( srcFooFile , `export const foo = 'foo1';` ) ;
141- await expectFileChanges ( distFooFile , content1 , 'foo1' ) ;
138+ fse . outputFileSync ( srcFooFile , `export const foo1 = 'foo1';` ) ;
139+ await expectBuildEnd ( child ) ;
140+ await expectFileWithContent ( distFooFile , 'foo1' ) ;
142141 const content3 = await fse . readFile ( distFooFile , 'utf-8' ) ;
143142 expect ( content3 ! ) . toMatchInlineSnapshot ( `
144- "const foo = 'foo1';
145- export { foo };
143+ "const foo1 = 'foo1';
144+ export { foo1 };
146145 "
147146 ` ) ;
148147
0 commit comments