1namespace ts { 2 describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => { 3 let outFileFs: vfs.FileSystem; 4 before(() => { 5 outFileFs = loadProjectFromDisk("tests/projects/amdModulesWithOut"); 6 }); 7 after(() => { 8 outFileFs = undefined!; 9 }); 10 11 interface VerifyOutFileScenarioInput { 12 subScenario: string; 13 modifyFs?: (fs: vfs.FileSystem) => void; 14 modifyAgainFs?: (fs: vfs.FileSystem) => void; 15 } 16 17 function verifyOutFileScenario({ 18 subScenario, 19 modifyFs, 20 modifyAgainFs 21 }: VerifyOutFileScenarioInput) { 22 verifyTscWithEdits({ 23 scenario: "amdModulesWithOut", 24 subScenario, 25 fs: () => outFileFs, 26 commandLineArgs: ["--b", "/src/app", "--verbose"], 27 baselineSourceMap: true, 28 modifyFs, 29 edits: [ 30 { 31 subScenario: "incremental-declaration-doesnt-change", 32 modifyFs: fs => appendText(fs, "/src/lib/file1.ts", "console.log(x);") 33 }, 34 ...(modifyAgainFs ? [{ 35 subScenario: "incremental-headers-change-without-dts-changes", 36 modifyFs: modifyAgainFs 37 }] : emptyArray), 38 ] 39 }); 40 } 41 42 describe("Prepend output with .tsbuildinfo", () => { 43 verifyOutFileScenario({ 44 subScenario: "modules and globals mixed in amd", 45 }); 46 47 // Prologues 48 describe("Prologues", () => { 49 verifyOutFileScenario({ 50 subScenario: "multiple prologues in all projects", 51 modifyFs: fs => { 52 enableStrict(fs, "/src/lib/tsconfig.json"); 53 addTestPrologue(fs, "/src/lib/file0.ts", `"myPrologue"`); 54 addTestPrologue(fs, "/src/lib/file2.ts", `"myPrologueFile"`); 55 addTestPrologue(fs, "/src/lib/global.ts", `"myPrologue3"`); 56 enableStrict(fs, "/src/app/tsconfig.json"); 57 addTestPrologue(fs, "/src/app/file3.ts", `"myPrologue"`); 58 addTestPrologue(fs, "/src/app/file4.ts", `"myPrologue2";`); 59 }, 60 modifyAgainFs: fs => addTestPrologue(fs, "/src/lib/file1.ts", `"myPrologue5"`) 61 }); 62 }); 63 64 // Shebang 65 describe("Shebang", () => { 66 // changes declaration because its emitted in .d.ts file 67 verifyOutFileScenario({ 68 subScenario: "shebang in all projects", 69 modifyFs: fs => { 70 addShebang(fs, "lib", "file0"); 71 addShebang(fs, "lib", "file1"); 72 addShebang(fs, "app", "file3"); 73 }, 74 }); 75 }); 76 77 // emitHelpers 78 describe("emitHelpers", () => { 79 verifyOutFileScenario({ 80 subScenario: "multiple emitHelpers in all projects", 81 modifyFs: fs => { 82 addSpread(fs, "lib", "file0"); 83 addRest(fs, "lib", "file1"); 84 addRest(fs, "app", "file3"); 85 addSpread(fs, "app", "file4"); 86 }, 87 modifyAgainFs: fs => removeRest(fs, "lib", "file1") 88 }); 89 }); 90 91 // triple slash refs 92 describe("triple slash refs", () => { 93 // changes declaration because its emitted in .d.ts file 94 verifyOutFileScenario({ 95 subScenario: "triple slash refs in all projects", 96 modifyFs: fs => { 97 addTripleSlashRef(fs, "lib", "file0"); 98 addTripleSlashRef(fs, "app", "file4"); 99 } 100 }); 101 }); 102 103 describe("stripInternal", () => { 104 function stripInternalScenario(fs: vfs.FileSystem) { 105 const internal = "/*@internal*/"; 106 replaceText(fs, "/src/app/tsconfig.json", `"composite": true,`, `"composite": true, 107"stripInternal": true,`); 108 replaceText(fs, "/src/lib/file0.ts", "const", `${internal} const`); 109 appendText(fs, "/src/lib/file1.ts", ` 110export class normalC { 111 ${internal} constructor() { } 112 ${internal} prop: string; 113 ${internal} method() { } 114 ${internal} get c() { return 10; } 115 ${internal} set c(val: number) { } 116} 117export namespace normalN { 118 ${internal} export class C { } 119 ${internal} export function foo() {} 120 ${internal} export namespace someNamespace { export class C {} } 121 ${internal} export namespace someOther.something { export class someClass {} } 122 ${internal} export import someImport = someNamespace.C; 123 ${internal} export type internalType = internalC; 124 ${internal} export const internalConst = 10; 125 ${internal} export enum internalEnum { a, b, c } 126} 127${internal} export class internalC {} 128${internal} export function internalfoo() {} 129${internal} export namespace internalNamespace { export class someClass {} } 130${internal} export namespace internalOther.something { export class someClass {} } 131${internal} export import internalImport = internalNamespace.someClass; 132${internal} export type internalType = internalC; 133${internal} export const internalConst = 10; 134${internal} export enum internalEnum { a, b, c }`); 135 } 136 137 // Verify initial + incremental edits 138 verifyOutFileScenario({ 139 subScenario: "stripInternal", 140 modifyFs: stripInternalScenario, 141 modifyAgainFs: fs => replaceText(fs, "/src/lib/file1.ts", `export const`, `/*@internal*/ export const`), 142 }); 143 }); 144 145 describe("when the module resolution finds original source file", () => { 146 function modifyFs(fs: vfs.FileSystem) { 147 // Make lib to output to parent dir 148 replaceText(fs, "/src/lib/tsconfig.json", `"outFile": "module.js"`, `"outFile": "../module.js", "rootDir": "../"`); 149 // Change reference to file1 module to resolve to lib/file1 150 replaceText(fs, "/src/app/file3.ts", "file1", "lib/file1"); 151 } 152 153 verifyTsc({ 154 scenario: "amdModulesWithOut", 155 subScenario: "when the module resolution finds original source file", 156 fs: () => outFileFs, 157 commandLineArgs: ["-b", "/src/app", "--verbose"], 158 modifyFs, 159 baselineSourceMap: true, 160 }); 161 }); 162 }); 163 }); 164} 165