-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
custom-config.resolver.ts
30 lines (26 loc) · 1010 Bytes
/
custom-config.resolver.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
import { getSystemPath, join, Path } from '@angular-devkit/core';
import { existsSync } from 'fs';
import { Logger } from '@angular-devkit/core/src/logger';
export class CustomConfigResolver {
constructor(private logger: Logger) {}
resolveGlobal(workspaceRoot: Path): any {
const packageJsonPath = getSystemPath(join(workspaceRoot, 'package.json'));
const packageJson = require(packageJsonPath);
const workspaceJestConfigPath = getSystemPath(join(workspaceRoot, 'jest.config.js'));
return (
packageJson.jest ||
(existsSync(workspaceJestConfigPath) && require(workspaceJestConfigPath)) ||
{}
);
}
resolveForProject(projectRoot: Path, configPath: string) {
const jestConfigPath = getSystemPath(join(projectRoot, configPath));
if (!existsSync(jestConfigPath)) {
this.logger.warn(
`warning: unable to locate custom jest configuration file at path "${jestConfigPath}"`
);
return {};
}
return require(jestConfigPath);
}
}