MCPcopy Create free account
hub / github.com/angular/dev-infra / loadTestConfig

Function loadTestConfig

ng-dev/ts-circular-dependencies/config.ts:45–96  ·  view source on GitHub ↗
(configPath: string)

Source from the content-addressed store, hash-verified

43 * loaded, an error will be printed and the process exists with a non-zero exit code.
44 */
45export async function loadTestConfig(configPath: string): Promise<CircularDependenciesTestConfig> {
46 const configBaseDir = dirname(configPath);
47 const resolveRelativePath = (relativePath: string) => resolve(configBaseDir, relativePath);
48
49 try {
50 let config: CircularDependenciesTestConfig;
51 switch (extname(configPath)) {
52 case '.mjs':
53 // Load the ESM configuration file using the TypeScript dynamic import workaround.
54 // Once TypeScript provides support for keeping the dynamic import this workaround can be
55 // changed to a direct dynamic import.
56 config = await loadEsmModule<CircularDependenciesTestConfig>(configPath);
57 break;
58 case '.cjs':
59 config = require(configPath);
60 break;
61 default:
62 // The file could be either CommonJS or ESM.
63 // CommonJS is tried first then ESM if loading fails.
64 try {
65 config = require(configPath);
66 } catch (e) {
67 if ((e as any).code === 'ERR_REQUIRE_ESM') {
68 // Load the ESM configuration file using the TypeScript dynamic import workaround.
69 // Once TypeScript provides support for keeping the dynamic import this workaround can be
70 // changed to a direct dynamic import.
71 config = await loadEsmModule<CircularDependenciesTestConfig>(configPath);
72 }
73
74 throw e;
75 }
76 }
77
78 // Clone to config object. This is needed because in ESM the properties are non writeable
79 config = {...config};
80
81 if (!isAbsolute(config.baseDir)) {
82 config.baseDir = resolveRelativePath(config.baseDir);
83 }
84 if (config.goldenFile && !isAbsolute(config.goldenFile)) {
85 config.goldenFile = resolveRelativePath(config.goldenFile);
86 }
87 if (!isAbsolute(config.glob)) {
88 config.glob = resolveRelativePath(config.glob);
89 }
90 return config;
91 } catch (e) {
92 Log.error('Could not load test configuration file at: ' + configPath);
93 Log.error(`Failed with error:`, e);
94 process.exit(1);
95 }
96}
97
98/**
99 * Lazily compiled dynamic import loader function.

Callers 1

Calls 2

resolveRelativePathFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected