1
1
import * as Harness from "../../_namespaces/Harness" ;
2
2
import * as ts from "../../_namespaces/ts" ;
3
- import { commandLineCallbacks } from "../tsc/helpers" ;
3
+ import { dedent } from "../../_namespaces/Utils" ;
4
+ import { commandLineCallbacks , libContent } from "../tsc/helpers" ;
4
5
import {
5
6
createWatchedSystem ,
6
7
File ,
@@ -11,6 +12,7 @@ import {
11
12
applyEdit ,
12
13
createBaseline ,
13
14
createWatchCompilerHostOfConfigFileForBaseline ,
15
+ createWatchCompilerHostOfFilesAndCompilerOptionsForBaseline ,
14
16
runWatchBaseline ,
15
17
watchBaseline ,
16
18
} from "./helpers" ;
@@ -718,3 +720,103 @@ describe("unittests:: tsc-watch:: watchAPI:: when builder emit occurs with emitO
718
720
verify ( "when emitting with emitOnlyDtsFiles" ) ;
719
721
verify ( "when emitting with emitOnlyDtsFiles with outFile" , "outFile.js" ) ;
720
722
} ) ;
723
+
724
+ describe ( "unittests:: tsc-watch:: watchAPI:: when creating program with project references but not config file" , ( ) => {
725
+ function setup ( libExtends : boolean ) {
726
+ const system = createWatchedSystem ( {
727
+ "/user/username/projects/project/tsconfig.json" : JSON . stringify ( {
728
+ compilerOptions : { types : [ ] } ,
729
+ files : [ "app.ts" ] ,
730
+ references : [ { path : "./lib" } ]
731
+ } ) ,
732
+ "/user/username/projects/project/app.ts" : dedent `
733
+ import { one } from './lib';
734
+ console.log(one);
735
+ ` ,
736
+ "/user/username/projects/project/lib/tsconfig.json" : JSON . stringify ( {
737
+ extends : libExtends ? "./tsconfig.base.json" : undefined ,
738
+ compilerOptions : libExtends ? undefined : { composite : true , types : [ ] } ,
739
+ files : [ "index.ts" ] ,
740
+ } ) ,
741
+ "/user/username/projects/project/lib/tsconfig.base.json" : JSON . stringify ( {
742
+ compilerOptions : { composite : true , types : [ ] } ,
743
+ } ) ,
744
+ "/user/username/projects/project/lib/index.ts" : "export const one = 1;" ,
745
+ "/user/username/projects/project/lib/index.d.ts" : "export const one = 1;" ,
746
+ [ libFile . path ] : libContent ,
747
+ } ) ;
748
+ const baseline = createBaseline ( system ) ;
749
+ const commandLine = ts . getParsedCommandLineOfConfigFile (
750
+ "/user/username/projects/project/tsconfig.json" ,
751
+ { extendedDiagnostics : true } ,
752
+ {
753
+ useCaseSensitiveFileNames : true ,
754
+ fileExists : path => system . fileExists ( path ) ,
755
+ readFile : path => system . readFile ( path ) ,
756
+ getCurrentDirectory : ( ) => system . getCurrentDirectory ( ) ,
757
+ readDirectory : ( path , extensions , excludes , includes , depth ) => system . readDirectory ( path , extensions , excludes , includes , depth ) ,
758
+ onUnRecoverableConfigFileDiagnostic : ts . noop ,
759
+ }
760
+ ) ! ;
761
+ const compilerHost = createWatchCompilerHostOfFilesAndCompilerOptionsForBaseline ( {
762
+ cb : baseline . cb ,
763
+ system,
764
+ rootFiles : commandLine . fileNames ,
765
+ options : commandLine . options ,
766
+ projectReferences : commandLine . projectReferences ,
767
+ watchOptions : commandLine . watchOptions ,
768
+ } ) ;
769
+ const watch = ts . createWatchProgram ( compilerHost ) ;
770
+ return { watch, baseline } ;
771
+ }
772
+
773
+ it ( "when watching referenced project when there is no config file name" , ( ) => {
774
+ const { watch, baseline } = setup ( /*libExtends*/ false ) ;
775
+ runWatchBaseline ( {
776
+ scenario : "watchApi" ,
777
+ subScenario : "when watching referenced project when there is no config file name" ,
778
+ commandLineArgs : [ "--w" , "-p" , "." , "--extendedDiagnostics" ] ,
779
+ ...baseline ,
780
+ edits : [
781
+ {
782
+ caption : "Modify lib tsconfig" ,
783
+ edit : sys => sys . writeFile ( `/user/username/projects/project/lib/tsconfig.json` , JSON . stringify ( {
784
+ compilerOptions : { composite : true } ,
785
+ files : [ "index.ts" ] ,
786
+ } ) ) ,
787
+ timeouts : sys => sys . runQueuedTimeoutCallbacks ( ) ,
788
+ } ,
789
+ ] ,
790
+ watchOrSolution : watch
791
+ } ) ;
792
+ } ) ;
793
+
794
+ it ( "when watching referenced project with extends when there is no config file name" , ( ) => {
795
+ const { watch, baseline } = setup ( /*libExtends*/ true ) ;
796
+ runWatchBaseline ( {
797
+ scenario : "watchApi" ,
798
+ subScenario : "when watching referenced project with extends when there is no config file name" ,
799
+ commandLineArgs : [ "--w" , "-p" , "." , "--extendedDiagnostics" ] ,
800
+ ...baseline ,
801
+ edits : [
802
+ {
803
+ caption : "Modify lib tsconfig" ,
804
+ edit : sys => sys . writeFile ( `/user/username/projects/project/lib/tsconfig.json` , JSON . stringify ( {
805
+ extends : "./tsconfig.base.json" ,
806
+ compilerOptions : { typeRoots : [ ] } ,
807
+ files : [ "index.ts" ] ,
808
+ } ) ) ,
809
+ timeouts : sys => sys . runQueuedTimeoutCallbacks ( ) ,
810
+ } ,
811
+ {
812
+ caption : "Modify lib extends" ,
813
+ edit : sys => sys . writeFile ( `/user/username/projects/project/lib/tsconfig.base.json` , JSON . stringify ( {
814
+ compilerOptions : { composite : true } ,
815
+ } ) ) ,
816
+ timeouts : sys => sys . runQueuedTimeoutCallbacks ( ) ,
817
+ } ,
818
+ ] ,
819
+ watchOrSolution : watch
820
+ } ) ;
821
+ } ) ;
822
+ } ) ;
0 commit comments