MCPcopy Create free account
hub / github.com/angular/angular / compareOutputs

Function compareOutputs

packages/compiler-cli/preprocessor/test/utils.ts:615–646  ·  view source on GitHub ↗
(actual: TestFile[], expected: TestFile[])

Source from the content-addressed store, hash-verified

613 * Compare actual outputs with expected outputs
614 */
615export function compareOutputs(actual: TestFile[], expected: TestFile[]): void {
616 const actualMap = new Map(actual.map((f) => [f.path, f.content]));
617 const expectedMap = new Map(expected.map((f) => [f.path, f.content]));
618
619 for (const [filePath, expectedContent] of expectedMap) {
620 const actualContent = actualMap.get(filePath);
621 if (actualContent === undefined) {
622 throw new Error(`Missing file: ${filePath}`);
623 }
624 const normalizedActual = normalizeWhitespace(actualContent);
625 const normalizedExpected = normalizeWhitespace(expectedContent);
626
627 if (!checkMatch(actualContent, expectedContent)) {
628 const diff = createTwoFilesPatch(
629 `${filePath} (expected)`,
630 `${filePath} (actual)`,
631 normalizedExpected,
632 normalizedActual,
633 '',
634 '',
635 {context: 3},
636 );
637 throw new Error(`Content mismatch for ${filePath}:\n\n${diff}`);
638 }
639 }
640
641 for (const filePath of actualMap.keys()) {
642 if (!expectedMap.has(filePath)) {
643 throw new Error(`Unexpected file: ${filePath}`);
644 }
645 }
646}
647
648function normalizeWhitespace(s: string): string {
649 let normalized = s

Callers 1

golden_spec.tsFile · 0.85

Calls 6

normalizeWhitespaceFunction · 0.85
checkMatchFunction · 0.85
mapMethod · 0.80
getMethod · 0.65
keysMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected