diff --git a/packages/schematics/angular/refactor/jasmine-vitest/test-file-transformer.integration_spec.ts b/packages/schematics/angular/refactor/jasmine-vitest/test-file-transformer.integration_spec.ts index a440eadbbf48..60e2675b7572 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/test-file-transformer.integration_spec.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/test-file-transformer.integration_spec.ts @@ -16,9 +16,7 @@ async function expectTransformation(input: string, expected: string): Promise (line.trim() === '' ? BLANK_LINE_PLACEHOLDER : line)) + .join('\n'); +} + +function restoreBlankLines(content: string): string { + const regex = new RegExp(`^\\s*${BLANK_LINE_PLACEHOLDER.replace(/\//g, '\\/')}\\s*$`, 'gm'); + + return content.replace(regex, ''); +} + /** * Transforms a string of Jasmine test code to Vitest test code. * This is the main entry point for the transformation. @@ -53,9 +68,11 @@ export function transformJasmineToVitest( content: string, reporter: RefactorReporter, ): string { + const contentWithPlaceholders = preserveBlankLines(content); + const sourceFile = ts.createSourceFile( filePath, - content, + contentWithPlaceholders, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS, @@ -151,6 +168,7 @@ export function transformJasmineToVitest( } const printer = ts.createPrinter(); + const transformedContentWithPlaceholders = printer.printFile(result.transformed[0]); - return printer.printFile(result.transformed[0]); + return restoreBlankLines(transformedContentWithPlaceholders); }