Skip to content

Commit 8c16330

Browse files
petebacondarwinjosephperrott
authored andcommitted
test(compiler-cli): make typescript_ast_factory_spec tests resilient to line-endings (angular#38866)
The tests were assuming that newlines were `\n` characters but this is not the case on Windows. This was fixed in angular#38925, but a better solution is to configure the TS printer to always use `\n` characters for newlines. PR Close angular#38866
1 parent 21213e1 commit 8c16330

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

packages/compiler-cli/src/ngtsc/translator/test/typescript_ast_factory_spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {leadingComment} from '@angular/compiler';
9-
import {EOL} from 'os';
109
import * as ts from 'typescript';
1110

1211
import {TypeScriptAstFactory} from '../src/typescript_ast_factory';
@@ -25,7 +24,7 @@ describe('TypeScriptAstFactory', () => {
2524
'/* comment 1 */',
2625
'//comment 2',
2726
'x = 10;',
28-
].join(EOL));
27+
].join('\n'));
2928
});
3029
});
3130

@@ -62,7 +61,7 @@ describe('TypeScriptAstFactory', () => {
6261
' x = 10;',
6362
' y = 20;',
6463
'}',
65-
].join(EOL));
64+
].join('\n'));
6665
});
6766
});
6867

@@ -153,7 +152,7 @@ describe('TypeScriptAstFactory', () => {
153152
' x = 10;',
154153
'else',
155154
' x = 42;',
156-
].join(EOL));
155+
].join('\n'));
157156
});
158157

159158
it('should create an if statement if the else expression is null', () => {
@@ -163,7 +162,7 @@ describe('TypeScriptAstFactory', () => {
163162
expect(generate(ifStmt)).toEqual([
164163
'if (!test)',
165164
' x = 10;',
166-
].join(EOL));
165+
].join('\n'));
167166
});
168167
});
169168

@@ -363,7 +362,7 @@ describe('TypeScriptAstFactory', () => {
363362
* work via the returned `generate()` function.
364363
*/
365364
function setupStatements(stmts: string = ''): SetupResult<ts.Statement> {
366-
const printer = ts.createPrinter();
365+
const printer = ts.createPrinter({newLine: ts.NewLineKind.LineFeed});
367366
const sf = ts.createSourceFile('test.ts', stmts, ts.ScriptTarget.ES2015, true);
368367
return {
369368
items: Array.from(sf.statements),

0 commit comments

Comments
 (0)