electron/spec/get-files.ts
Milan Burda ee87438d28
test: use async helpers to simplify tests (#37314)
test: use async helpers to simplify the tests

Co-authored-by: Milan Burda <miburda@microsoft.com>
2023-02-17 12:32:39 -06:00

14 lines
463 B
TypeScript

import * as walkdir from 'walkdir';
import { emittedOnce } from './lib/events-helpers';
export async function getFiles (directoryPath: string, { filter = null }: {filter?: ((file: string) => boolean) | null} = {}) {
const files: string[] = [];
const walker = walkdir(directoryPath, {
no_recurse: true
});
walker.on('file', (file) => {
if (!filter || filter(file)) { files.push(file); }
});
await emittedOnce(walker, 'end');
return files;
}