Skip to content

Commit 024e002

Browse files
committed
refactor: use async
1 parent 228c4e1 commit 024e002

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/overflowMenu/__tests__/OverflowMenuProvider.test.tsx

+16-20
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { HeaderButtonsProviderDropdownMenu } from '../HeaderButtonsProviderDropd
1010
import { HeaderButtonsProviderPlain } from '../HeaderButtonsProviderPlain';
1111
import * as fs from 'node:fs';
1212
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);
1416

1517
describe('HeaderButtonsProvider renders', () => {
1618
it('only the child when menu is not shown', () => {
@@ -129,15 +131,15 @@ describe('HeaderButtonsProvider renders', () => {
129131
console.warn = originalWarn;
130132
});
131133

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 () => {
134135
const cwd = process.cwd();
135136
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`
138140
);
141+
await Promise.all([iosPromise, androidPromise]);
139142

140-
// Read the output from the file
141143
const outputIos = fs.readFileSync(
142144
path.join(examplePath, `requires-ios.txt`),
143145
'utf8'
@@ -147,20 +149,14 @@ describe('HeaderButtonsProvider renders', () => {
147149
'utf8'
148150
);
149151

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);
164160

165161
expect(filteredIos).not.toContain('Menu.tsx');
166162
expect(filteredIos).not.toContain('HeaderButtonsProviderDropdownMenu.tsx');

0 commit comments

Comments
 (0)