1namespace ts { 2 describe("unittests:: tsbuild:: javascriptProjectEmit:: loads js-based projects and emits them correctly", () => { 3 verifyTsc({ 4 scenario: "javascriptProjectEmit", 5 subScenario: `loads js-based projects and emits them correctly`, 6 fs: () => loadProjectFromFiles({ 7 "/src/common/nominal.js": Utils.dedent` 8 /** 9 * @template T, Name 10 * @typedef {T & {[Symbol.species]: Name}} Nominal 11 */ 12 module.exports = {}; 13 `, 14 "/src/common/tsconfig.json": Utils.dedent` 15 { 16 "extends": "../tsconfig.base.json", 17 "compilerOptions": { 18 "composite": true 19 }, 20 "include": ["nominal.js"] 21 }`, 22 "/src/sub-project/index.js": Utils.dedent` 23 import { Nominal } from '../common/nominal'; 24 25 /** 26 * @typedef {Nominal<string, 'MyNominal'>} MyNominal 27 */ 28 `, 29 "/src/sub-project/tsconfig.json": Utils.dedent` 30 { 31 "extends": "../tsconfig.base.json", 32 "compilerOptions": { 33 "composite": true 34 }, 35 "references": [ 36 { "path": "../common" } 37 ], 38 "include": ["./index.js"] 39 }`, 40 "/src/sub-project-2/index.js": Utils.dedent` 41 import { MyNominal } from '../sub-project/index'; 42 43 const variable = { 44 key: /** @type {MyNominal} */('value'), 45 }; 46 47 /** 48 * @return {keyof typeof variable} 49 */ 50 export function getVar() { 51 return 'key'; 52 } 53 `, 54 "/src/sub-project-2/tsconfig.json": Utils.dedent` 55 { 56 "extends": "../tsconfig.base.json", 57 "compilerOptions": { 58 "composite": true 59 }, 60 "references": [ 61 { "path": "../sub-project" } 62 ], 63 "include": ["./index.js"] 64 }`, 65 "/src/tsconfig.json": Utils.dedent` 66 { 67 "compilerOptions": { 68 "composite": true 69 }, 70 "references": [ 71 { "path": "./sub-project" }, 72 { "path": "./sub-project-2" } 73 ], 74 "include": [] 75 }`, 76 "/src/tsconfig.base.json": Utils.dedent` 77 { 78 "compilerOptions": { 79 "skipLibCheck": true, 80 "rootDir": "./", 81 "outDir": "../lib", 82 "allowJs": true, 83 "checkJs": true, 84 "declaration": true 85 } 86 }`, 87 }, symbolLibContent), 88 commandLineArgs: ["-b", "/src"] 89 }); 90 }); 91 92 describe("unittests:: tsbuild:: javascriptProjectEmit:: loads outfile js projects and concatenates them correctly", () => { 93 let projFs: vfs.FileSystem; 94 before(() => { 95 projFs = loadProjectFromFiles({ 96 "/src/common/nominal.js": Utils.dedent` 97 /** 98 * @template T, Name 99 * @typedef {T & {[Symbol.species]: Name}} Nominal 100 */ 101 `, 102 "/src/common/tsconfig.json": Utils.dedent` 103 { 104 "extends": "../tsconfig.base.json", 105 "compilerOptions": { 106 "composite": true, 107 "outFile": "common.js", 108 109 }, 110 "include": ["nominal.js"] 111 }`, 112 "/src/sub-project/index.js": Utils.dedent` 113 /** 114 * @typedef {Nominal<string, 'MyNominal'>} MyNominal 115 */ 116 const c = /** @type {*} */(null); 117 `, 118 "/src/sub-project/tsconfig.json": Utils.dedent` 119 { 120 "extends": "../tsconfig.base.json", 121 "compilerOptions": { 122 "composite": true, 123 "outFile": "sub-project.js", 124 125 }, 126 "references": [ 127 { "path": "../common", "prepend": true } 128 ], 129 "include": ["./index.js"] 130 }`, 131 "/src/sub-project-2/index.js": Utils.dedent` 132 const variable = { 133 key: /** @type {MyNominal} */('value'), 134 }; 135 136 /** 137 * @return {keyof typeof variable} 138 */ 139 function getVar() { 140 return 'key'; 141 } 142 `, 143 "/src/sub-project-2/tsconfig.json": Utils.dedent` 144 { 145 "extends": "../tsconfig.base.json", 146 "compilerOptions": { 147 "composite": true, 148 "outFile": "sub-project-2.js", 149 150 }, 151 "references": [ 152 { "path": "../sub-project", "prepend": true } 153 ], 154 "include": ["./index.js"] 155 }`, 156 "/src/tsconfig.json": Utils.dedent` 157 { 158 "compilerOptions": { 159 "composite": true, 160 "outFile": "src.js" 161 }, 162 "references": [ 163 { "path": "./sub-project", "prepend": true }, 164 { "path": "./sub-project-2", "prepend": true } 165 ], 166 "include": [] 167 }`, 168 "/src/tsconfig.base.json": Utils.dedent` 169 { 170 "compilerOptions": { 171 "skipLibCheck": true, 172 "rootDir": "./", 173 "allowJs": true, 174 "checkJs": true, 175 "declaration": true 176 } 177 }`, 178 }, symbolLibContent); 179 }); 180 after(() => { 181 projFs = undefined!; 182 }); 183 verifyTsc({ 184 scenario: "javascriptProjectEmit", 185 subScenario: `loads outfile js projects and concatenates them correctly`, 186 fs: () => projFs, 187 commandLineArgs: ["-b", "/src"] 188 }); 189 verifyTscSerializedIncrementalEdits({ 190 scenario: "javascriptProjectEmit", 191 subScenario: `modifies outfile js projects and concatenates them correctly`, 192 fs: () => projFs, 193 commandLineArgs: ["-b", "/src"], 194 incrementalScenarios: [{ 195 buildKind: BuildKind.IncrementalDtsUnchanged, 196 modifyFs: fs => replaceText(fs, "/src/sub-project/index.js", "null", "undefined") 197 }] 198 }); 199 }); 200 201 describe("unittests:: tsbuild:: javascriptProjectEmit:: loads js-based projects with non-moved json files and emits them correctly", () => { 202 verifyTsc({ 203 scenario: "javascriptProjectEmit", 204 subScenario: `loads js-based projects with non-moved json files and emits them correctly`, 205 fs: () => loadProjectFromFiles({ 206 "/src/common/obj.json": Utils.dedent` 207 { 208 "val": 42 209 }`, 210 "/src/common/index.ts": Utils.dedent` 211 import x = require("./obj.json"); 212 export = x; 213 `, 214 "/src/common/tsconfig.json": Utils.dedent` 215 { 216 "extends": "../tsconfig.base.json", 217 "compilerOptions": { 218 "outDir": null, 219 "composite": true 220 }, 221 "include": ["index.ts", "obj.json"] 222 }`, 223 "/src/sub-project/index.js": Utils.dedent` 224 import mod from '../common'; 225 226 export const m = mod; 227 `, 228 "/src/sub-project/tsconfig.json": Utils.dedent` 229 { 230 "extends": "../tsconfig.base.json", 231 "compilerOptions": { 232 "composite": true 233 }, 234 "references": [ 235 { "path": "../common" } 236 ], 237 "include": ["./index.js"] 238 }`, 239 "/src/sub-project-2/index.js": Utils.dedent` 240 import { m } from '../sub-project/index'; 241 242 const variable = { 243 key: m, 244 }; 245 246 export function getVar() { 247 return variable; 248 } 249 `, 250 "/src/sub-project-2/tsconfig.json": Utils.dedent` 251 { 252 "extends": "../tsconfig.base.json", 253 "compilerOptions": { 254 "composite": true 255 }, 256 "references": [ 257 { "path": "../sub-project" } 258 ], 259 "include": ["./index.js"] 260 }`, 261 "/src/tsconfig.json": Utils.dedent` 262 { 263 "compilerOptions": { 264 "composite": true 265 }, 266 "references": [ 267 { "path": "./sub-project" }, 268 { "path": "./sub-project-2" } 269 ], 270 "include": [] 271 }`, 272 "/src/tsconfig.base.json": Utils.dedent` 273 { 274 "compilerOptions": { 275 "skipLibCheck": true, 276 "rootDir": "./", 277 "outDir": "../out", 278 "allowJs": true, 279 "checkJs": true, 280 "resolveJsonModule": true, 281 "esModuleInterop": true, 282 "declaration": true 283 } 284 }`, 285 }, symbolLibContent), 286 commandLineArgs: ["-b", "/src"] 287 }); 288 }); 289} 290