Skip to content

Commit 2109c34

Browse files
authored
Merge pull request microsoft#28856 from weswigham/showConfig-exhaustive-test
Fix paths showConfig, exhaustively test showConfig
2 parents 86ec885 + 19de47f commit 2109c34

File tree

93 files changed

+590
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+590
-7
lines changed

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,8 @@ namespace ts {
16931693
listFiles: undefined,
16941694
listEmittedFiles: undefined,
16951695
project: undefined,
1696+
build: undefined,
1697+
version: undefined,
16961698
},
16971699
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath, originalPath: undefined })),
16981700
files: length(files) ? files : undefined,
@@ -1730,7 +1732,7 @@ namespace ts {
17301732
}
17311733

17321734
function getCustomTypeMapOfCommandLineOption(optionDefinition: CommandLineOption): Map<string | number> | undefined {
1733-
if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean") {
1735+
if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean" || optionDefinition.type === "object") {
17341736
// this is of a type CommandLineOptionOfPrimitiveType
17351737
return undefined;
17361738
}

src/testRunner/unittests/showConfig.ts

Lines changed: 123 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
namespace ts {
2-
describe("showTSConfig", () => {
3-
function showTSConfigCorrectly(name: string, commandLinesArgs: string[]) {
2+
describe("showConfig", () => {
3+
function showTSConfigCorrectly(name: string, commandLinesArgs: string[], configJson?: object) {
44
describe(name, () => {
5-
const commandLine = parseCommandLine(commandLinesArgs);
6-
const initResult = convertToTSConfig(commandLine, `/${name}/tsconfig.json`, { getCurrentDirectory() { return `/${name}`; }, useCaseSensitiveFileNames: true });
7-
const outputFileName = `showConfig/${name.replace(/[^a-z0-9\-. ]/ig, "")}/tsconfig.json`;
5+
const outputFileName = `showConfig/${name.replace(/[^a-z0-9\-./ ]/ig, "")}/tsconfig.json`;
86

97
it(`Correct output for ${outputFileName}`, () => {
8+
const cwd = `/${name}`;
9+
const configPath = combinePaths(cwd, "tsconfig.json");
10+
const configContents = configJson ? JSON.stringify(configJson) : undefined;
11+
const configParseHost: ParseConfigFileHost = {
12+
fileExists: path =>
13+
comparePaths(getNormalizedAbsolutePath(path, cwd), configPath) === Comparison.EqualTo ? true : false,
14+
getCurrentDirectory() { return cwd; },
15+
useCaseSensitiveFileNames: true,
16+
onUnRecoverableConfigFileDiagnostic: d => {
17+
throw new Error(flattenDiagnosticMessageText(d.messageText, "\n"));
18+
},
19+
readDirectory() { return []; },
20+
readFile: path =>
21+
comparePaths(getNormalizedAbsolutePath(path, cwd), configPath) === Comparison.EqualTo ? configContents : undefined,
22+
};
23+
let commandLine = parseCommandLine(commandLinesArgs);
24+
if (commandLine.options.project) {
25+
const result = getParsedCommandLineOfConfigFile(commandLine.options.project, commandLine.options, configParseHost);
26+
if (result) {
27+
commandLine = result;
28+
}
29+
}
30+
const initResult = convertToTSConfig(commandLine, configPath, configParseHost);
31+
1032
// tslint:disable-next-line:no-null-keyword
1133
Harness.Baseline.runBaseline(outputFileName, JSON.stringify(initResult, null, 4) + "\n");
1234
});
@@ -30,5 +52,100 @@ namespace ts {
3052
showTSConfigCorrectly("Show TSConfig with incorrect compiler option value", ["--showConfig", "--lib", "nonExistLib,es5,es2015.promise"]);
3153

3254
showTSConfigCorrectly("Show TSConfig with advanced options", ["--showConfig", "--declaration", "--declarationDir", "lib", "--skipLibCheck", "--noErrorTruncation"]);
55+
56+
// Regression test for https://github.com/Microsoft/TypeScript/issues/28836
57+
showTSConfigCorrectly("Show TSConfig with paths and more", ["-p", "tsconfig.json"], {
58+
compilerOptions: {
59+
allowJs: true,
60+
outDir: "./lib",
61+
esModuleInterop: true,
62+
module: "commonjs",
63+
moduleResolution: "node",
64+
target: "ES2017",
65+
sourceMap: true,
66+
baseUrl: ".",
67+
paths: {
68+
"@root/*": ["./*"],
69+
"@configs/*": ["src/configs/*"],
70+
"@common/*": ["src/common/*"],
71+
"*": [
72+
"node_modules/*",
73+
"src/types/*"
74+
]
75+
},
76+
experimentalDecorators: true,
77+
emitDecoratorMetadata: true,
78+
resolveJsonModule: true
79+
},
80+
include: [
81+
"./src/**/*"
82+
]
83+
});
84+
85+
// Bulk validation of all option declarations
86+
for (const option of optionDeclarations) {
87+
if (option.name === "project") continue;
88+
let configObject: object | undefined;
89+
let args: string[];
90+
switch (option.type) {
91+
case "boolean": {
92+
if (option.isTSConfigOnly) {
93+
args = ["-p", "tsconfig.json"];
94+
configObject = { compilerOptions: { [option.name]: true } };
95+
}
96+
else {
97+
args = [`--${option.name}`];
98+
}
99+
break;
100+
}
101+
case "list": {
102+
if (option.isTSConfigOnly) {
103+
args = ["-p", "tsconfig.json"];
104+
configObject = { compilerOptions: { [option.name]: [] } };
105+
}
106+
else {
107+
args = [`--${option.name}`];
108+
}
109+
break;
110+
}
111+
case "string": {
112+
if (option.isTSConfigOnly) {
113+
args = ["-p", "tsconfig.json"];
114+
configObject = { compilerOptions: { [option.name]: "someString" } };
115+
}
116+
else {
117+
args = [`--${option.name}`, "someString"];
118+
}
119+
break;
120+
}
121+
case "number": {
122+
if (option.isTSConfigOnly) {
123+
args = ["-p", "tsconfig.json"];
124+
configObject = { compilerOptions: { [option.name]: 0 } };
125+
}
126+
else {
127+
args = [`--${option.name}`, "0"];
128+
}
129+
break;
130+
}
131+
case "object": {
132+
args = ["-p", "tsconfig.json"];
133+
configObject = { compilerOptions: { [option.name]: {} } };
134+
break;
135+
}
136+
default: {
137+
const val = option.type.keys().next().value;
138+
if (option.isTSConfigOnly) {
139+
args = ["-p", "tsconfig.json"];
140+
configObject = { compilerOptions: { [option.name]: val } };
141+
}
142+
else {
143+
args = [`--${option.name}`, val];
144+
}
145+
break;
146+
}
147+
}
148+
showTSConfigCorrectly(`Shows tsconfig for single option/${option.name}`, args, configObject);
149+
}
33150
});
34-
}
151+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"outDir": "./lib",
5+
"esModuleInterop": true,
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"target": "es2017",
9+
"sourceMap": true,
10+
"baseUrl": "./",
11+
"paths": {
12+
"@root/*": [
13+
"./*"
14+
],
15+
"@configs/*": [
16+
"src/configs/*"
17+
],
18+
"@common/*": [
19+
"src/common/*"
20+
],
21+
"*": [
22+
"node_modules/*",
23+
"src/types/*"
24+
]
25+
},
26+
"experimentalDecorators": true,
27+
"emitDecoratorMetadata": true,
28+
"resolveJsonModule": true
29+
},
30+
"include": [
31+
"./src/**/*"
32+
],
33+
"exclude": [
34+
"./lib"
35+
]
36+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"compilerOptions": {}
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"allowUnreachableCode": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"allowUnusedLabels": true
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"alwaysStrict": true
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "./someString"
4+
}
5+
}

0 commit comments

Comments
 (0)