|
| 1 | +package execute_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/microsoft/typescript-go/internal/testutil/stringtestutil" |
| 7 | + "github.com/microsoft/typescript-go/internal/vfs/vfstest" |
| 8 | +) |
| 9 | + |
| 10 | +func TestTscExtends(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + testCases := []*tscInput{ |
| 13 | + { |
| 14 | + subScenario: "when building solution with projects extends config with include", |
| 15 | + files: getBuildConfigFileExtendsFileMap(), |
| 16 | + cwd: "/home/src/workspaces/solution", |
| 17 | + commandLineArgs: []string{"--b", "--v", "--listFiles"}, |
| 18 | + }, |
| 19 | + { |
| 20 | + subScenario: "when building project uses reference and both extend config with include", |
| 21 | + files: getBuildConfigFileExtendsFileMap(), |
| 22 | + cwd: "/home/src/workspaces/solution", |
| 23 | + commandLineArgs: []string{"--b", "webpack/tsconfig.json", "--v", "--listFiles"}, |
| 24 | + }, |
| 25 | + getTscExtendsWithSymlinkTestCase("-p"), |
| 26 | + getTscExtendsWithSymlinkTestCase("-b"), |
| 27 | + getTscExtendsConfigDirTestCase("", []string{"--explainFiles"}), |
| 28 | + getTscExtendsConfigDirTestCase(" showConfig", []string{"--showConfig"}), |
| 29 | + getTscExtendsConfigDirTestCase(" with commandline", []string{"--explainFiles", "--outDir", "${configDir}/outDir"}), |
| 30 | + getTscExtendsConfigDirTestCase("", []string{"--b", "--explainFiles", "--v"}), |
| 31 | + } |
| 32 | + |
| 33 | + for _, test := range testCases { |
| 34 | + test.run(t, "extends") |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func getBuildConfigFileExtendsFileMap() FileMap { |
| 39 | + return FileMap{ |
| 40 | + "/home/src/workspaces/solution/tsconfig.json": stringtestutil.Dedent(` |
| 41 | + { |
| 42 | + "references": [ |
| 43 | + { "path": "./shared/tsconfig.json" }, |
| 44 | + { "path": "./webpack/tsconfig.json" }, |
| 45 | + ], |
| 46 | + "files": [], |
| 47 | + }`), |
| 48 | + "/home/src/workspaces/solution/shared/tsconfig-base.json": stringtestutil.Dedent(` |
| 49 | + { |
| 50 | + "include": ["./typings-base/"], |
| 51 | + }`), |
| 52 | + "/home/src/workspaces/solution/shared/typings-base/globals.d.ts": `type Unrestricted = any;`, |
| 53 | + "/home/src/workspaces/solution/shared/tsconfig.json": stringtestutil.Dedent(` |
| 54 | + { |
| 55 | + "extends": "./tsconfig-base.json", |
| 56 | + "compilerOptions": { |
| 57 | + "composite": true, |
| 58 | + "outDir": "../target-tsc-build/", |
| 59 | + "rootDir": "..", |
| 60 | + }, |
| 61 | + "files": ["./index.ts"], |
| 62 | + }`), |
| 63 | + "/home/src/workspaces/solution/shared/index.ts": `export const a: Unrestricted = 1;`, |
| 64 | + "/home/src/workspaces/solution/webpack/tsconfig.json": stringtestutil.Dedent(` |
| 65 | + { |
| 66 | + "extends": "../shared/tsconfig-base.json", |
| 67 | + "compilerOptions": { |
| 68 | + "composite": true, |
| 69 | + "outDir": "../target-tsc-build/", |
| 70 | + "rootDir": "..", |
| 71 | + }, |
| 72 | + "files": ["./index.ts"], |
| 73 | + "references": [{ "path": "../shared/tsconfig.json" }], |
| 74 | + }`), |
| 75 | + "/home/src/workspaces/solution/webpack/index.ts": `export const b: Unrestricted = 1;`, |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +func getTscExtendsWithSymlinkTestCase(builtType string) *tscInput { |
| 80 | + return &tscInput{ |
| 81 | + subScenario: "resolves the symlink path", |
| 82 | + files: FileMap{ |
| 83 | + "/users/user/projects/myconfigs/node_modules/@something/tsconfig-node/tsconfig.json": stringtestutil.Dedent(` |
| 84 | + { |
| 85 | + "extends": "@something/tsconfig-base/tsconfig.json", |
| 86 | + "compilerOptions": { |
| 87 | + "removeComments": true |
| 88 | + } |
| 89 | + } |
| 90 | + `), |
| 91 | + "/users/user/projects/myconfigs/node_modules/@something/tsconfig-base/tsconfig.json": stringtestutil.Dedent(` |
| 92 | + { |
| 93 | + "compilerOptions": { "composite": true } |
| 94 | + } |
| 95 | + `), |
| 96 | + "/users/user/projects/myproject/src/index.ts": stringtestutil.Dedent(` |
| 97 | + // some comment |
| 98 | + export const x = 10; |
| 99 | + `), |
| 100 | + "/users/user/projects/myproject/src/tsconfig.json": stringtestutil.Dedent(` |
| 101 | + { |
| 102 | + "extends": "@something/tsconfig-node/tsconfig.json" |
| 103 | + }`), |
| 104 | + "/users/user/projects/myproject/node_modules/@something/tsconfig-node": vfstest.Symlink("/users/user/projects/myconfigs/node_modules/@something/tsconfig-node"), |
| 105 | + }, |
| 106 | + cwd: "/users/user/projects/myproject", |
| 107 | + commandLineArgs: []string{builtType, "src", "--extendedDiagnostics"}, |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +func getTscExtendsConfigDirTestCase(subScenarioSufix string, commandLineArgs []string) *tscInput { |
| 112 | + return &tscInput{ |
| 113 | + subScenario: "configDir template" + subScenarioSufix, |
| 114 | + files: FileMap{ |
| 115 | + "/home/src/projects/configs/first/tsconfig.json": stringtestutil.Dedent(` |
| 116 | + { |
| 117 | + "extends": "../second/tsconfig.json", |
| 118 | + "include": ["${configDir}/src"], |
| 119 | + "compilerOptions": { |
| 120 | + "typeRoots": ["root1", "${configDir}/root2", "root3"], |
| 121 | + "types": [], |
| 122 | + }, |
| 123 | + }`), |
| 124 | + "/home/src/projects/configs/second/tsconfig.json": stringtestutil.Dedent(` |
| 125 | + { |
| 126 | + "files": ["${configDir}/main.ts"], |
| 127 | + "compilerOptions": { |
| 128 | + "declarationDir": "${configDir}/decls", |
| 129 | + "paths": { |
| 130 | + "@myscope/*": ["${configDir}/types/*"], |
| 131 | + }, |
| 132 | + }, |
| 133 | + "watchOptions": { |
| 134 | + "excludeFiles": ["${configDir}/main.ts"], |
| 135 | + }, |
| 136 | + }`), |
| 137 | + "/home/src/projects/myproject/tsconfig.json": stringtestutil.Dedent(` |
| 138 | + { |
| 139 | + "extends": "../configs/first/tsconfig.json", |
| 140 | + "compilerOptions": { |
| 141 | + "declaration": true, |
| 142 | + "outDir": "outDir", |
| 143 | + "traceResolution": true, |
| 144 | + }, |
| 145 | + }`), |
| 146 | + "/home/src/projects/myproject/main.ts": stringtestutil.Dedent(` |
| 147 | + // some comment |
| 148 | + export const y = 10; |
| 149 | + import { x } from "@myscope/sometype"; |
| 150 | + `), |
| 151 | + "/home/src/projects/myproject/types/sometype.ts": stringtestutil.Dedent(` |
| 152 | + export const x = 10; |
| 153 | + `), |
| 154 | + }, |
| 155 | + cwd: "/home/src/projects/myproject", |
| 156 | + commandLineArgs: commandLineArgs, |
| 157 | + } |
| 158 | +} |
0 commit comments