test(compiler-cli): ensure that golden partial files are parsed accurately (#39939)

Previously files were serialized with an extra newline seperator that
was not removed when parsing. This caused the parsed file to start with
an extra newline that invalidated its source-map.

Also, the splitting was producing an empty entry at the start of the extracted
golden files which is now ignored.

PR Close #39939
This commit is contained in:
Pete Bacon Darwin 2020-11-30 14:25:21 +00:00 committed by Misko Hevery
parent 2afa3801bc
commit c5ea3d5b0e
1 changed files with 5 additions and 3 deletions

View File

@ -11,7 +11,7 @@ const headerStart =
' * PARTIAL FILE: ';
const headerEnd =
'\n ****************************************************************************************************/';
'\n ****************************************************************************************************/\n';
/**
* Render the partially compiled files into a single golden partial output string.
@ -19,7 +19,7 @@ const headerEnd =
* @param files The partially compiled files to be rendered.
*/
export function renderGoldenPartial(files: PartiallyCompiledFile[]): string {
return files.map(file => `${headerStart + file.path + headerEnd}\n${file.content}`).join('\n');
return files.map(file => `${headerStart + file.path + headerEnd}${file.content}`).join('\n');
}
/**
@ -35,8 +35,10 @@ export function parseGoldenPartial(partialContent: string): PartiallyCompiledFil
const partials = partialContent.split(headerStart);
for (const partial of partials) {
const [path, content] = partial.split(headerEnd);
if (path) {
files.push({path, content});
}
}
return files;
}