-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathtest-files.ts
37 lines (33 loc) · 1.2 KB
/
test-files.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import fastGlob, { Options as GlobOptions } from 'fast-glob';
/**
* Finds all test files in the project.
*
* @param options The builder options describing where to find tests.
* @param workspaceRoot The path to the root directory of the workspace.
* @param glob A promisified implementation of the `glob` module. Only intended for
* testing purposes.
* @returns A set of all test files in the project.
*/
export async function findTestFiles(
include: string[],
exclude: string[],
workspaceRoot: string,
glob: typeof fastGlob = fastGlob,
): Promise<Set<string>> {
const globOptions: GlobOptions = {
cwd: workspaceRoot,
ignore: ['node_modules/**'].concat(exclude),
braceExpansion: false, // Do not expand `a{b,c}` to `ab,ac`.
extglob: false, // Disable "extglob" patterns.
};
const included = await Promise.all(include.map((pattern) => glob(pattern, globOptions)));
// Flatten and deduplicate any files found in multiple include patterns.
return new Set(included.flat());
}