/
findUserModulePaths.ts
46 lines (39 loc) · 1.21 KB
/
findUserModulePaths.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
38
39
40
41
42
43
44
45
46
import glob from 'glob';
import micromatch from 'micromatch';
import {
getFixturePatterns,
getDecoratorPatterns,
getIgnorePatterns
} from './shared';
type FindUserModulePathsArgs = {
rootDir: string;
fixturesDir: string;
fixtureFileSuffix: string;
};
type UserModulePaths = {
fixturePaths: string[];
decoratorPaths: string[];
};
export function findUserModulePaths({
rootDir,
fixturesDir,
fixtureFileSuffix
}: FindUserModulePathsArgs): UserModulePaths {
const paths = glob.sync('**/*', {
cwd: rootDir,
absolute: true,
ignore: getIgnorePatterns()
});
const fixturePatterns = getFixturePatterns(fixturesDir, fixtureFileSuffix);
const fixturePaths = getMatchingPaths(paths, fixturePatterns);
const decoratorPaths = getMatchingPaths(paths, getDecoratorPatterns());
// Omit decorators from fixture paths, which happens when decorators are
// placed inside fixture dirs.
const nonDecoratorFixturePaths = fixturePaths.filter(
fixturePath => decoratorPaths.indexOf(fixturePath) === -1
);
return { fixturePaths: nonDecoratorFixturePaths, decoratorPaths };
}
function getMatchingPaths(paths: string[], patterns: string[]): string[] {
return micromatch(paths, patterns, { dot: true });
}