-
Notifications
You must be signed in to change notification settings - Fork 304
/
ng-jest-config.ts
62 lines (57 loc) · 2.35 KB
/
ng-jest-config.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { formatDiagnostics, ParsedConfiguration, readConfiguration } from '@angular/compiler-cli';
import { ConfigSet } from 'ts-jest/dist/config/config-set';
import type { CompilerOptions } from 'typescript';
import type { ProjectConfigTsJest } from 'ts-jest/dist/types';
export class NgJestConfig extends ConfigSet {
/**
* Override `ts-jest` property
*/
parsedTsConfig!: ParsedConfiguration;
constructor(readonly jestCfg: ProjectConfigTsJest) {
super(jestCfg);
}
/**
* Override `ts-jest` behavior because we use `readConfiguration` which will read and resolve tsconfig.
*/
protected _resolveTsConfig(compilerOptions?: CompilerOptions, resolvedConfigFile?: string): ParsedConfiguration {
this.logger.debug(
'_resolveTsConfig: read and resolve config from tsconfig using @angular/compiler-cli readConfiguration',
);
let result: ParsedConfiguration;
if (resolvedConfigFile) {
result = readConfiguration(resolvedConfigFile);
} else {
result = readConfiguration(this.cwd);
if (compilerOptions) {
result = {
...result,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
options: {
...result.options,
...compilerOptions,
} as Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any
};
}
}
if (result.errors?.length) {
throw new Error(formatDiagnostics(result.errors));
}
return {
...result,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
options: {
...result.options,
// Overwrite outDir so we can find generated files next to their .ts origin in compilerHost.
outDir: '',
suppressOutputPathCheck: true,
skipLibCheck: result.options.skipLibCheck ?? true,
// For performance, disable AOT decorator downleveling transformer for applications in the CLI.
// The transformer is not needed for VE or Ivy in this plugin since Angular decorators are removed.
// While the transformer would make no changes, it would still need to walk each source file AST.
annotationsAs: 'decorators' as const,
module: result.options.module ?? this.compilerModule.ModuleKind.CommonJS,
target: result.options.target ?? this.compilerModule.ScriptTarget.ES2015,
},
};
}
}