1
1
import path from 'path' ;
2
2
import { testSuite , expect } from 'manten' ;
3
+ import { createFixture } from 'fs-fixture' ;
3
4
import { tsx } from '../utils/tsx' ;
4
5
5
6
export default testSuite ( async ( { describe } , fixturePath : string ) => {
@@ -12,6 +13,35 @@ export default testSuite(async ({ describe }, fixturePath: string) => {
12
13
expect ( tsxProcess . stderr ) . toMatch ( 'Error: Missing required parameter "script path"' ) ;
13
14
} ) ;
14
15
16
+ test ( 'watch files for changes' , async ( ) => {
17
+ const fixture = await createFixture ( {
18
+ 'index.js' : 'console.log(1)' ,
19
+ } ) ;
20
+
21
+ const tsxProcess = tsx ( {
22
+ args : [
23
+ 'watch' ,
24
+ path . join ( fixture . path , 'index.js' ) ,
25
+ ] ,
26
+ } ) ;
27
+
28
+ await new Promise < void > ( ( resolve ) => {
29
+ async function onStdOut ( data : Buffer ) {
30
+ const chunkString = data . toString ( ) ;
31
+
32
+ if ( chunkString . match ( '1\n' ) ) {
33
+ await fixture . writeFile ( 'index.js' , 'console.log(2)' ) ;
34
+ } else if ( chunkString . match ( '2\n' ) ) {
35
+ tsxProcess . kill ( ) ;
36
+ resolve ( ) ;
37
+ }
38
+ }
39
+
40
+ tsxProcess . stdout ! . on ( 'data' , onStdOut ) ;
41
+ tsxProcess . stderr ! . on ( 'data' , onStdOut ) ;
42
+ } ) ;
43
+ } , 5000 ) ;
44
+
15
45
test ( 'suppresses warnings & clear screen' , async ( ) => {
16
46
const tsxProcess = tsx ( {
17
47
args : [
0 commit comments