forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.ts
More file actions
73 lines (65 loc) · 2.75 KB
/
options.ts
File metadata and controls
73 lines (65 loc) · 2.75 KB
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
63
64
65
66
67
68
69
70
71
72
73
/**
* @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.dev/license
*/
import { type BuilderContext, targetFromTargetString } from '@angular-devkit/architect';
import path from 'node:path';
import { normalizeCacheOptions } from '../../utils/normalize-cache';
import { getProjectRootPaths } from '../../utils/project-metadata';
import { isTTY } from '../../utils/tty';
import type { Schema as UnitTestBuilderOptions } from './schema';
export type NormalizedUnitTestBuilderOptions = Awaited<ReturnType<typeof normalizeOptions>>;
export async function normalizeOptions(
context: BuilderContext,
projectName: string,
options: UnitTestBuilderOptions,
) {
// Setup base paths based on workspace root and project information
const workspaceRoot = context.workspaceRoot;
const projectMetadata = await context.getProjectMetadata(projectName);
const { projectRoot, projectSourceRoot } = getProjectRootPaths(workspaceRoot, projectMetadata);
// Gather persistent caching option and provide a project specific cache location
const cacheOptions = normalizeCacheOptions(projectMetadata, workspaceRoot);
cacheOptions.path = path.join(cacheOptions.path, projectName);
// Target specifier defaults to the current project's build target using a development configuration
const buildTargetSpecifier = options.buildTarget ?? `::development`;
const buildTarget = targetFromTargetString(buildTargetSpecifier, projectName, 'build');
const { tsConfig, runner, reporters, browsers } = options;
return {
// Project/workspace information
workspaceRoot,
projectRoot,
projectSourceRoot,
cacheOptions,
// Target/configuration specified options
buildTarget,
include: options.include ?? ['**/*.spec.ts'],
exclude: options.exclude ?? [],
runnerName: runner,
codeCoverage: options.codeCoverage
? {
exclude: options.codeCoverageExclude,
reporters: options.codeCoverageReporters?.map((entry) =>
typeof entry === 'string'
? ([entry, {}] as [string, Record<string, unknown>])
: (entry as [string, Record<string, unknown>]),
),
}
: undefined,
tsConfig,
reporters,
browsers,
watch: options.watch ?? isTTY(),
debug: options.debug ?? false,
providersFile: options.providersFile && path.join(workspaceRoot, options.providersFile),
setupFiles: options.setupFiles
? options.setupFiles.map((setupFile) => path.join(workspaceRoot, setupFile))
: [],
};
}
export function injectTestingPolyfills(polyfills: string[] = []): string[] {
return polyfills.includes('zone.js') ? [...polyfills, 'zone.js/testing'] : polyfills;
}