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

Function testApiGolden

bazel/api-golden/test_api_report.ts:51–152  ·  view source on GitHub ↗
(
  indexFilePath: string,
  stripExportPattern: RegExp,
  typeNamesAndLocations: string[],
  packageJsonPath: string,
  customPackageName: string,
)

Source from the content-addressed store, hash-verified

49 * is scoped to a specific subpath/entry-point.
50 */
51export async function testApiGolden(
52 indexFilePath: string,
53 stripExportPattern: RegExp,
54 typeNamesAndLocations: string[],
55 packageJsonPath: string,
56 customPackageName: string,
57): Promise<string | null> {
58 const tempDir =
59 process.env.TEST_TMPDIR ??
60 (await fs.promises.mkdtemp(path.join(os.tmpdir(), 'api-golden-rule')));
61 const typeNames: string[] = [];
62 const typeLocations: string[] = [];
63
64 typeNamesAndLocations.forEach((nameAndLocation) => {
65 const [name, location] = nameAndLocation.split('|');
66 typeNames.push(name);
67 typeLocations.push(`./${location}`);
68 });
69
70 const configObject: IConfigFile = {
71 compiler: {
72 overrideTsconfig: {
73 files: [indexFilePath, ...typeLocations],
74 compilerOptions: {
75 paths: {},
76 types: typeNames,
77 lib: ['esnext', 'dom'],
78 },
79 },
80 },
81 projectFolder: path.dirname(packageJsonPath),
82 mainEntryPointFilePath: indexFilePath,
83 dtsRollup: {enabled: false},
84 docModel: {enabled: false},
85 apiReport: {
86 enabled: true,
87 reportFolder: tempDir,
88 reportTempFolder: tempDir,
89 reportFileName: customPackageName.replace(/\//g, '_'),
90 },
91 tsdocMetadata: {enabled: false},
92 newlineKind: 'lf',
93 messages: {
94 extractorMessageReporting: {
95 // If an export does not have a release tag (like `@public`), API extractor maps
96 // considers it still as `Public`. We hide the message for now given the Angular
97 // repositories do not follow the TSDoc standard. https://tsdoc.org/.
98 // TODO: Make this an error once TSDoc standard is followed in all projects.
99 [ExtractorMessageId.MissingReleaseTag]: {logLevel: ExtractorLogLevel.None},
100 },
101 },
102 };
103
104 const packageNameSegments = customPackageName.split('/');
105 const isScopedPackage = packageNameSegments[0][0] === '@' && packageNameSegments.length > 1;
106 // API extractor allows one-slash when the package uses the scoped-package convention.
107 const slashConversionStartIndex = isScopedPackage ? 1 : 0;
108 const normalizedRest = packageNameSegments.slice(slashConversionStartIndex).join('_');

Callers 1

test_api_report.tsFile · 0.85

Calls 5

processExtractorMessageFunction · 0.85
pushMethod · 0.45
sliceMethod · 0.45
applyMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected