test(compiler-cli): make typescript_ast_factory_spec tests resilient to line-endings (#38866)
The tests were assuming that newlines were `\n` characters but this is not the case on Windows. This was fixed in #38925, but a better solution is to configure the TS printer to always use `\n` characters for newlines. PR Close #38866
This commit is contained in:
parent
21213e1531
commit
8c16330895
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {leadingComment} from '@angular/compiler';
|
import {leadingComment} from '@angular/compiler';
|
||||||
import {EOL} from 'os';
|
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
import {TypeScriptAstFactory} from '../src/typescript_ast_factory';
|
import {TypeScriptAstFactory} from '../src/typescript_ast_factory';
|
||||||
|
@ -25,7 +24,7 @@ describe('TypeScriptAstFactory', () => {
|
||||||
'/* comment 1 */',
|
'/* comment 1 */',
|
||||||
'//comment 2',
|
'//comment 2',
|
||||||
'x = 10;',
|
'x = 10;',
|
||||||
].join(EOL));
|
].join('\n'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -62,7 +61,7 @@ describe('TypeScriptAstFactory', () => {
|
||||||
' x = 10;',
|
' x = 10;',
|
||||||
' y = 20;',
|
' y = 20;',
|
||||||
'}',
|
'}',
|
||||||
].join(EOL));
|
].join('\n'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -153,7 +152,7 @@ describe('TypeScriptAstFactory', () => {
|
||||||
' x = 10;',
|
' x = 10;',
|
||||||
'else',
|
'else',
|
||||||
' x = 42;',
|
' x = 42;',
|
||||||
].join(EOL));
|
].join('\n'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create an if statement if the else expression is null', () => {
|
it('should create an if statement if the else expression is null', () => {
|
||||||
|
@ -163,7 +162,7 @@ describe('TypeScriptAstFactory', () => {
|
||||||
expect(generate(ifStmt)).toEqual([
|
expect(generate(ifStmt)).toEqual([
|
||||||
'if (!test)',
|
'if (!test)',
|
||||||
' x = 10;',
|
' x = 10;',
|
||||||
].join(EOL));
|
].join('\n'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -363,7 +362,7 @@ describe('TypeScriptAstFactory', () => {
|
||||||
* work via the returned `generate()` function.
|
* work via the returned `generate()` function.
|
||||||
*/
|
*/
|
||||||
function setupStatements(stmts: string = ''): SetupResult<ts.Statement> {
|
function setupStatements(stmts: string = ''): SetupResult<ts.Statement> {
|
||||||
const printer = ts.createPrinter();
|
const printer = ts.createPrinter({newLine: ts.NewLineKind.LineFeed});
|
||||||
const sf = ts.createSourceFile('test.ts', stmts, ts.ScriptTarget.ES2015, true);
|
const sf = ts.createSourceFile('test.ts', stmts, ts.ScriptTarget.ES2015, true);
|
||||||
return {
|
return {
|
||||||
items: Array.from(sf.statements),
|
items: Array.from(sf.statements),
|
||||||
|
|
Loading…
Reference in New Issue