Skip to content

Commit 12df032

Browse files
author
Andy
authored
Merge pull request #15142 from Microsoft/newLine
Don't access `sys.newLine` inside unit tests
2 parents 11ac006 + 893e324 commit 12df032

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ namespace ts {
895895
* @param fileNames array of filenames to be generated into tsconfig.json
896896
*/
897897
/* @internal */
898-
export function generateTSConfig(options: CompilerOptions, fileNames: string[]): string {
898+
export function generateTSConfig(options: CompilerOptions, fileNames: string[], newLine: string): string {
899899
const compilerOptions = extend(options, defaultInitCompilerOptions);
900900
const configurations: { compilerOptions: MapLike<CompilerOptionsValue>; files?: string[] } = {
901901
compilerOptions: serializeCompilerOptions(compilerOptions)
@@ -1053,7 +1053,7 @@ namespace ts {
10531053
}
10541054
result.push(`}`);
10551055

1056-
return result.join(sys.newLine);
1056+
return result.join(newLine);
10571057
}
10581058
}
10591059

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ namespace ts {
739739
reportDiagnostic(createCompilerDiagnostic(Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file), /* host */ undefined);
740740
}
741741
else {
742-
sys.writeFile(file, generateTSConfig(options, fileNames));
742+
sys.writeFile(file, generateTSConfig(options, fileNames, sys.newLine));
743743
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* host */ undefined);
744744
}
745745

src/harness/unittests/initializeTSConfig.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,11 @@ namespace ts {
66
function initTSConfigCorrectly(name: string, commandLinesArgs: string[]) {
77
describe(name, () => {
88
const commandLine = parseCommandLine(commandLinesArgs);
9-
const initResult = generateTSConfig(commandLine.options, commandLine.fileNames);
9+
const initResult = generateTSConfig(commandLine.options, commandLine.fileNames, "\n");
1010
const outputFileName = `tsConfig/${name.replace(/[^a-z0-9\-. ]/ig, "")}/tsconfig.json`;
1111

1212
it(`Correct output for ${outputFileName}`, () => {
13-
Harness.Baseline.runBaseline(outputFileName, () => {
14-
if (initResult) {
15-
// normalize line endings
16-
return initResult.replace(new RegExp(sys.newLine, "g"), "\n");
17-
}
18-
else {
19-
// This can happen if compiler recieve invalid compiler-options
20-
/* tslint:disable:no-null-keyword */
21-
return null;
22-
/* tslint:enable:no-null-keyword */
23-
}
24-
});
13+
Harness.Baseline.runBaseline(outputFileName, () => initResult);
2514
});
2615
});
2716
}

0 commit comments

Comments
 (0)