@@ -6,7 +6,7 @@ import cssEscape from 'shared/utils/css-escape'
6
6
import waitForDataMatch from 'shared/utils/wait-for-data-match'
7
7
import dedent from 'ts-dedent'
8
8
import { it , beforeAll , afterAll , expect } from 'vitest'
9
- import { spawnd , SpawndChildProcess } from 'spawnd '
9
+ import { execa , ExecaChildProcess } from 'execa '
10
10
11
11
const HTMLFilepath = path . join ( __dirname , 'test.html' )
12
12
const originHTMLText = dedent `
@@ -51,19 +51,19 @@ export default config
51
51
52
52
const virtualCSSFilepath = path . join ( __dirname , '.virtual/master.css' )
53
53
54
- let child : SpawndChildProcess
54
+ let subprocess : ExecaChildProcess
55
55
56
56
beforeAll ( ( ) => {
57
57
fs . writeFileSync ( HTMLFilepath , originHTMLText , { flag : 'w+' } )
58
58
fs . writeFileSync ( optionsFilepath , originOptionsText , { flag : 'w+' } )
59
59
fs . writeFileSync ( configFilepath , originConfigText , { flag : 'w+' } )
60
- child = spawnd ( 'tsx ../../../src/bin extract -w' , { shell : true , cwd : __dirname } )
60
+ subprocess = execa ( 'tsx ../../../src/bin extract -w' , { shell : true , cwd : __dirname } )
61
61
} , 120000 )
62
62
63
63
it ( 'start watch process' , async ( ) => {
64
64
await Promise . all ( [
65
- waitForDataMatch ( child , ( data ) => data . includes ( 'Start watching source changes' ) ) ,
66
- waitForDataMatch ( child , ( data ) => data . includes ( 'exported' ) )
65
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'Start watching source changes' ) ) ,
66
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'exported' ) )
67
67
] )
68
68
const fileCSSText = fs . readFileSync ( virtualCSSFilepath , { encoding : 'utf8' } )
69
69
expect ( fileCSSText ) . toContain ( cssEscape ( 'font:heavy' ) )
@@ -74,39 +74,39 @@ it('start watch process', async () => {
74
74
75
75
it ( 'change options file `fixed` and reset process' , async ( ) => {
76
76
await Promise . all ( [
77
- waitForDataMatch ( child , ( data ) => data . includes ( 'watching source changes' ) , async ( ) => {
77
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'watching source changes' ) , async ( ) => {
78
78
fs . writeFileSync ( optionsFilepath , originOptionsText . replace ( 'fixed: []' , 'fixed: [\'fg:red\']' ) )
79
79
} ) ,
80
- waitForDataMatch ( child , ( data ) => data . includes ( `inserted 'fg:red'` ) ) ,
81
- waitForDataMatch ( child , ( data ) => data . includes ( 'exported' ) ) ,
80
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( `inserted 'fg:red'` ) ) ,
81
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'exported' ) ) ,
82
82
] )
83
83
const fileCSSText = fs . readFileSync ( virtualCSSFilepath , { encoding : 'utf8' } )
84
84
expect ( fileCSSText ) . toContain ( cssEscape ( 'fg:red' ) )
85
85
} , 120000 )
86
86
87
87
it ( 'change config file `styles` and reset process' , async ( ) => {
88
88
await Promise . all ( [
89
- waitForDataMatch ( child , ( data ) => data . includes ( 'watching source changes' ) , async ( ) => {
89
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'watching source changes' ) , async ( ) => {
90
90
fs . writeFileSync ( configFilepath , originConfigText . replace ( 'bg:red' , 'bg:blue' ) )
91
91
} ) ,
92
- waitForDataMatch ( child , ( data ) => data . includes ( 'exported' ) )
92
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'exported' ) )
93
93
] )
94
94
const fileCSSText = fs . readFileSync ( virtualCSSFilepath , { encoding : 'utf8' } )
95
95
expect ( fileCSSText ) . toContain ( '.btn{background-color:rgb(var(--blue))' )
96
96
} , 120000 )
97
97
98
98
it ( 'change html file class attr and update' , async ( ) => {
99
99
await Promise . all ( [
100
- waitForDataMatch ( child , ( data ) => data . includes ( 'watching source changes' ) , ( ) => {
100
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'watching source changes' ) , ( ) => {
101
101
fs . writeFileSync ( HTMLFilepath , originHTMLText . replace ( 'hmr-test' , 'text:underline' ) )
102
102
} ) ,
103
- waitForDataMatch ( child , ( data ) => data . includes ( `classes inserted` ) ) ,
104
- waitForDataMatch ( child , ( data ) => data . includes ( 'exported' ) )
103
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( `classes inserted` ) ) ,
104
+ waitForDataMatch ( subprocess , ( data ) => data . includes ( 'exported' ) )
105
105
] )
106
106
const fileCSSText = fs . readFileSync ( virtualCSSFilepath , { encoding : 'utf8' } )
107
107
expect ( fileCSSText ) . toContain ( cssEscape ( 'text:underline' ) )
108
108
} , 120000 )
109
109
110
110
afterAll ( async ( ) => {
111
- await child . destroy ( )
111
+ subprocess . kill ( )
112
112
} , 120000 )
0 commit comments