@@ -268,6 +268,43 @@ func TestBuildConfigFileErrors(t *testing.T) {
268268 }
269269}
270270
271+ func TestBuildEmitDeclarationOnly (t * testing.T ) {
272+ t .Parallel ()
273+ testCases := []* tscInput {
274+ getBuildEmitDeclarationOnlyTestCase (false ),
275+ getBuildEmitDeclarationOnlyTestCase (true ),
276+ {
277+ subScenario : `only dts output in non circular imports project with emitDeclarationOnly` ,
278+ files : getBuildEmitDeclarationOnlyImportFileMap (true , false ),
279+ commandLineArgs : []string {"--b" , "--verbose" },
280+ edits : []* tscEdit {
281+ {
282+ caption : "incremental-declaration-doesnt-change" ,
283+ edit : func (sys * testSys ) {
284+ sys .replaceFileText (
285+ "/home/src/workspaces/project/src/a.ts" ,
286+ "export interface A {" ,
287+ stringtestutil .Dedent (`
288+ class C { }
289+ export interface A {` ),
290+ )
291+ },
292+ },
293+ {
294+ caption : "incremental-declaration-changes" ,
295+ edit : func (sys * testSys ) {
296+ sys .replaceFileText ("/home/src/workspaces/project/src/a.ts" , "b: B;" , "b: B; foo: any;" )
297+ },
298+ },
299+ },
300+ },
301+ }
302+
303+ for _ , test := range testCases {
304+ test .run (t , "emitDeclarationOnly" )
305+ }
306+ }
307+
271308func TestBuildSolutionProject (t * testing.T ) {
272309 t .Parallel ()
273310 testCases := []* tscInput {
@@ -558,3 +595,79 @@ func getBuildCommandLineEmitDeclarationOnlyTestCases(options []string, suffix st
558595 },
559596 }
560597}
598+
599+ func getBuildEmitDeclarationOnlyImportFileMap (declarationMap bool , circularRef bool ) FileMap {
600+ files := FileMap {
601+ "/home/src/workspaces/project/src/a.ts" : stringtestutil .Dedent (`
602+ import { B } from "./b";
603+
604+ export interface A {
605+ b: B;
606+ }
607+ ` ),
608+ "/home/src/workspaces/project/src/b.ts" : stringtestutil .Dedent (`
609+ import { C } from "./c";
610+
611+ export interface B {
612+ b: C;
613+ }
614+ ` ),
615+ "/home/src/workspaces/project/src/c.ts" : stringtestutil .Dedent (`
616+ import { A } from "./a";
617+
618+ export interface C {
619+ a: A;
620+ }
621+ ` ),
622+ "/home/src/workspaces/project/src/index.ts" : stringtestutil .Dedent (`
623+ export { A } from "./a";
624+ export { B } from "./b";
625+ export { C } from "./c";
626+ ` ),
627+ "/home/src/workspaces/project/tsconfig.json" : stringtestutil .Dedent (fmt .Sprintf (`
628+ {
629+ "compilerOptions": {
630+ "incremental": true,
631+ "target": "es5",
632+ "module": "commonjs",
633+ "declaration": true,
634+ "declarationMap": %t,
635+ "sourceMap": true,
636+ "outDir": "./lib",
637+ "composite": true,
638+ "strict": true,
639+ "esModuleInterop": true,
640+ "alwaysStrict": true,
641+ "rootDir": "src",
642+ "emitDeclarationOnly": true,
643+ },
644+ }` , declarationMap )),
645+ }
646+ if ! circularRef {
647+ delete (files , "/home/src/workspaces/project/src/index.ts" )
648+ files ["/home/src/workspaces/project/src/a.ts" ] = stringtestutil .Dedent (`
649+ export class B { prop = "hello"; }
650+
651+ export interface A {
652+ b: B;
653+ }
654+ ` )
655+ }
656+ return files
657+ }
658+
659+ func getBuildEmitDeclarationOnlyTestCase (declarationMap bool ) * tscInput {
660+ return & tscInput {
661+ subScenario : `only dts output in circular import project with emitDeclarationOnly` + core .IfElse (declarationMap , " and declarationMap" , "" ),
662+ files : getBuildEmitDeclarationOnlyImportFileMap (declarationMap , true ),
663+ commandLineArgs : []string {"--b" , "--verbose" },
664+ edits : []* tscEdit {
665+ {
666+ caption : "incremental-declaration-changes" ,
667+ edit : func (sys * testSys ) {
668+ sys .replaceFileText ("/home/src/workspaces/project/src/a.ts" , "b: B;" , "b: B; foo: any;" )
669+ },
670+ },
671+ },
672+ }
673+ }
0 commit comments