Fix paths showConfig, exhaustively test showConfig

This commit is contained in:
Wesley Wigham
2018-12-04 16:24:25 -08:00
parent ee987a25e2
commit 19de47f2db
93 changed files with 590 additions and 7 deletions
+3 -1
View File
@@ -1693,6 +1693,8 @@ namespace ts {
listFiles: undefined,
listEmittedFiles: undefined,
project: undefined,
build: undefined,
version: undefined,
},
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath, originalPath: undefined })),
files: length(files) ? files : undefined,
@@ -1730,7 +1732,7 @@ namespace ts {
}
function getCustomTypeMapOfCommandLineOption(optionDefinition: CommandLineOption): Map<string | number> | undefined {
if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean") {
if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean" || optionDefinition.type === "object") {
// this is of a type CommandLineOptionOfPrimitiveType
return undefined;
}
+123 -6
View File
@@ -1,12 +1,34 @@
namespace ts {
describe("showTSConfig", () => {
function showTSConfigCorrectly(name: string, commandLinesArgs: string[]) {
describe("showConfig", () => {
function showTSConfigCorrectly(name: string, commandLinesArgs: string[], configJson?: object) {
describe(name, () => {
const commandLine = parseCommandLine(commandLinesArgs);
const initResult = convertToTSConfig(commandLine, `/${name}/tsconfig.json`, { getCurrentDirectory() { return `/${name}`; }, useCaseSensitiveFileNames: true });
const outputFileName = `showConfig/${name.replace(/[^a-z0-9\-. ]/ig, "")}/tsconfig.json`;
const outputFileName = `showConfig/${name.replace(/[^a-z0-9\-./ ]/ig, "")}/tsconfig.json`;
it(`Correct output for ${outputFileName}`, () => {
const cwd = `/${name}`;
const configPath = combinePaths(cwd, "tsconfig.json");
const configContents = configJson ? JSON.stringify(configJson) : undefined;
const configParseHost: ParseConfigFileHost = {
fileExists: path =>
comparePaths(getNormalizedAbsolutePath(path, cwd), configPath) === Comparison.EqualTo ? true : false,
getCurrentDirectory() { return cwd; },
useCaseSensitiveFileNames: true,
onUnRecoverableConfigFileDiagnostic: d => {
throw new Error(flattenDiagnosticMessageText(d.messageText, "\n"));
},
readDirectory() { return []; },
readFile: path =>
comparePaths(getNormalizedAbsolutePath(path, cwd), configPath) === Comparison.EqualTo ? configContents : undefined,
};
let commandLine = parseCommandLine(commandLinesArgs);
if (commandLine.options.project) {
const result = getParsedCommandLineOfConfigFile(commandLine.options.project, commandLine.options, configParseHost);
if (result) {
commandLine = result;
}
}
const initResult = convertToTSConfig(commandLine, configPath, configParseHost);
// tslint:disable-next-line:no-null-keyword
Harness.Baseline.runBaseline(outputFileName, JSON.stringify(initResult, null, 4) + "\n");
});
@@ -30,5 +52,100 @@ namespace ts {
showTSConfigCorrectly("Show TSConfig with incorrect compiler option value", ["--showConfig", "--lib", "nonExistLib,es5,es2015.promise"]);
showTSConfigCorrectly("Show TSConfig with advanced options", ["--showConfig", "--declaration", "--declarationDir", "lib", "--skipLibCheck", "--noErrorTruncation"]);
// Regression test for https://github.com/Microsoft/TypeScript/issues/28836
showTSConfigCorrectly("Show TSConfig with paths and more", ["-p", "tsconfig.json"], {
compilerOptions: {
allowJs: true,
outDir: "./lib",
esModuleInterop: true,
module: "commonjs",
moduleResolution: "node",
target: "ES2017",
sourceMap: true,
baseUrl: ".",
paths: {
"@root/*": ["./*"],
"@configs/*": ["src/configs/*"],
"@common/*": ["src/common/*"],
"*": [
"node_modules/*",
"src/types/*"
]
},
experimentalDecorators: true,
emitDecoratorMetadata: true,
resolveJsonModule: true
},
include: [
"./src/**/*"
]
});
// Bulk validation of all option declarations
for (const option of optionDeclarations) {
if (option.name === "project") continue;
let configObject: object | undefined;
let args: string[];
switch (option.type) {
case "boolean": {
if (option.isTSConfigOnly) {
args = ["-p", "tsconfig.json"];
configObject = { compilerOptions: { [option.name]: true } };
}
else {
args = [`--${option.name}`];
}
break;
}
case "list": {
if (option.isTSConfigOnly) {
args = ["-p", "tsconfig.json"];
configObject = { compilerOptions: { [option.name]: [] } };
}
else {
args = [`--${option.name}`];
}
break;
}
case "string": {
if (option.isTSConfigOnly) {
args = ["-p", "tsconfig.json"];
configObject = { compilerOptions: { [option.name]: "someString" } };
}
else {
args = [`--${option.name}`, "someString"];
}
break;
}
case "number": {
if (option.isTSConfigOnly) {
args = ["-p", "tsconfig.json"];
configObject = { compilerOptions: { [option.name]: 0 } };
}
else {
args = [`--${option.name}`, "0"];
}
break;
}
case "object": {
args = ["-p", "tsconfig.json"];
configObject = { compilerOptions: { [option.name]: {} } };
break;
}
default: {
const val = option.type.keys().next().value;
if (option.isTSConfigOnly) {
args = ["-p", "tsconfig.json"];
configObject = { compilerOptions: { [option.name]: val } };
}
else {
args = [`--${option.name}`, val];
}
break;
}
}
showTSConfigCorrectly(`Shows tsconfig for single option/${option.name}`, args, configObject);
}
});
}
}
@@ -0,0 +1,36 @@
{
"compilerOptions": {
"allowJs": true,
"outDir": "./lib",
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es2017",
"sourceMap": true,
"baseUrl": "./",
"paths": {
"@root/*": [
"./*"
],
"@configs/*": [
"src/configs/*"
],
"@common/*": [
"src/common/*"
],
"*": [
"node_modules/*",
"src/types/*"
]
},
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true
},
"include": [
"./src/**/*"
],
"exclude": [
"./lib"
]
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowJs": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowUnreachableCode": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowUnusedLabels": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"alwaysStrict": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"baseUrl": "./someString"
}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"charset": "someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"checkJs": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"composite": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"declaration": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"declarationDir": "./someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"declarationMap": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"diagnostics": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"disableSizeLimit": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"downlevelIteration": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"emitBOM": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"emitDeclarationOnly": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"emitDecoratorMetadata": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"esModuleInterop": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"extendedDiagnostics": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true
}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"importHelpers": true
}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"inlineSourceMap": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"inlineSources": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"isolatedModules": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsx": "preserve"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsxFactory": "someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"keyofStringsOnly": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"lib": []
}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"locale": "someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"mapRoot": "someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"maxNodeModuleJsDepth": 0
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "none"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"moduleResolution": "node"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"newLine": "crlf"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noEmit": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noEmitHelpers": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noEmitOnError": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noErrorTruncation": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noFallthroughCasesInSwitch": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noImplicitAny": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noImplicitReturns": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noImplicitThis": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noImplicitUseStrict": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noLib": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noResolve": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noStrictGenericChecks": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noUnusedLocals": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noUnusedParameters": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"out": "someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"outDir": "./someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"outFile": "./someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"paths": {}
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"plugins": []
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"preserveConstEnums": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"preserveSymlinks": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"preserveWatchOutput": true
}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"reactNamespace": "someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"removeComments": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"resolveJsonModule": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"rootDir": "./someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"rootDirs": []
}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"skipDefaultLibCheck": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"skipLibCheck": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"sourceMap": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"sourceRoot": "someString"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strict": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strictBindCallApply": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strictFunctionTypes": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strictNullChecks": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strictPropertyInitialization": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"stripInternal": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"suppressExcessPropertyErrors": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"suppressImplicitAnyIndexErrors": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "es3"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"traceResolution": true
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"typeRoots": []
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"types": []
}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}
@@ -0,0 +1,3 @@
{
"compilerOptions": {}
}