@@ -10,7 +10,9 @@ import { HeaderButtonsProviderDropdownMenu } from '../HeaderButtonsProviderDropd
10
10
import { HeaderButtonsProviderPlain } from '../HeaderButtonsProviderPlain' ;
11
11
import * as fs from 'node:fs' ;
12
12
import * as path from 'node:path' ;
13
- import * as child_process from 'node:child_process' ;
13
+ import { exec } from 'child_process' ;
14
+ import { promisify } from 'util' ;
15
+ const execAsync = promisify ( exec ) ;
14
16
15
17
describe ( 'HeaderButtonsProvider renders' , ( ) => {
16
18
it ( 'only the child when menu is not shown' , ( ) => {
@@ -129,15 +131,15 @@ describe('HeaderButtonsProvider renders', () => {
129
131
console . warn = originalWarn ;
130
132
} ) ;
131
133
132
- it ( 'should match the expected modules snapshot' , ( ) => {
133
- // TODO improve detection of the example path
134
+ it ( 'should match the expected modules snapshot' , async ( ) => {
134
135
const cwd = process . cwd ( ) ;
135
136
const examplePath = `${ cwd } /example/` ;
136
- child_process . execSync (
137
- `cd ${ examplePath } && yarn requires-ios && yarn requires-android`
137
+ const iosPromise = execAsync ( `cd ${ examplePath } && yarn requires-ios` ) ;
138
+ const androidPromise = execAsync (
139
+ `cd ${ examplePath } && yarn requires-android`
138
140
) ;
141
+ await Promise . all ( [ iosPromise , androidPromise ] ) ;
139
142
140
- // Read the output from the file
141
143
const outputIos = fs . readFileSync (
142
144
path . join ( examplePath , `requires-ios.txt` ) ,
143
145
'utf8'
@@ -147,20 +149,14 @@ describe('HeaderButtonsProvider renders', () => {
147
149
'utf8'
148
150
) ;
149
151
150
- const filteredIos = outputIos
151
- . split ( '\n' )
152
- . filter ( ( line ) => line . includes ( 'header-buttons/src' ) )
153
- . map ( ( path ) => {
154
- // return file name only
155
- return path . split ( '/' ) . pop ( ) ;
156
- } ) ;
157
- const filteredAndroid = outputAndroid
158
- . split ( '\n' )
159
- . filter ( ( line ) => line . includes ( 'header-buttons/src' ) )
160
- . map ( ( path ) => {
161
- // return file name only
162
- return path . split ( '/' ) . pop ( ) ;
163
- } ) ;
152
+ const filterAndExtractFileNames = ( output : string ) =>
153
+ output
154
+ . split ( '\n' )
155
+ . filter ( ( line ) => line . includes ( 'header-buttons/src' ) )
156
+ . map ( ( path ) => path . split ( '/' ) . pop ( ) ) ;
157
+
158
+ const filteredIos = filterAndExtractFileNames ( outputIos ) ;
159
+ const filteredAndroid = filterAndExtractFileNames ( outputAndroid ) ;
164
160
165
161
expect ( filteredIos ) . not . toContain ( 'Menu.tsx' ) ;
166
162
expect ( filteredIos ) . not . toContain ( 'HeaderButtonsProviderDropdownMenu.tsx' ) ;
0 commit comments