1+ /// <reference path="..\harness.ts" />
2+
3+ namespace ts {
4+ describe ( "Program.getMissingFilePaths" , ( ) => {
5+
6+ const options : CompilerOptions = {
7+ noLib : true ,
8+ } ;
9+
10+ const emptyFileName = "empty.ts" ;
11+ const emptyFileRelativePath = "./" + emptyFileName ;
12+
13+ const emptyFile : Harness . Compiler . TestFile = {
14+ unitName : emptyFileName ,
15+ content : ""
16+ } ;
17+
18+ const referenceFileName = "reference.ts" ;
19+ const referenceFileRelativePath = "./" + referenceFileName ;
20+
21+ const referenceFile : Harness . Compiler . TestFile = {
22+ unitName : referenceFileName ,
23+ content :
24+ "/// <reference path=\"d:/imaginary/nonexistent1.ts\"/>\n" + // Absolute
25+ "/// <reference path=\"./nonexistent2.ts\"/>\n" + // Relative
26+ "/// <reference path=\"nonexistent3.ts\"/>\n" + // Unqualified
27+ "/// <reference path=\"nonexistent4\"/>\n" // No extension
28+ } ;
29+
30+ const testCompilerHost = Harness . Compiler . createCompilerHost (
31+ /*inputFiles*/ [ emptyFile , referenceFile ] ,
32+ /*writeFile*/ undefined ,
33+ /*scriptTarget*/ undefined ,
34+ /*useCaseSensitiveFileNames*/ false ,
35+ /*currentDirectory*/ "d:\\pretend\\" ,
36+ /*newLineKind*/ NewLineKind . LineFeed ,
37+ /*libFiles*/ undefined
38+ ) ;
39+
40+ it ( "handles no missing root files" , ( ) => {
41+ const program = createProgram ( [ emptyFileRelativePath ] , options , testCompilerHost ) ;
42+ const missing = program . getMissingFilePaths ( ) ;
43+ assert . isDefined ( missing ) ;
44+ assert . equal ( missing . length , 0 ) ;
45+ } ) ;
46+
47+ it ( "handles missing root file" , ( ) => {
48+ const program = createProgram ( [ "./nonexistent.ts" ] , options , testCompilerHost ) ;
49+ const missing = program . getMissingFilePaths ( ) ;
50+ assert . isDefined ( missing ) ;
51+ assert . equal ( missing . length , 1 ) ;
52+ assert . equal ( missing [ 0 ] . toString ( ) , "d:/pretend/nonexistent.ts" ) ; // Absolute path
53+ } ) ;
54+
55+ it ( "handles multiple missing root files" , ( ) => {
56+ const program = createProgram ( [ "./nonexistent0.ts" , "./nonexistent1.ts" ] , options , testCompilerHost ) ;
57+ const missing = program . getMissingFilePaths ( ) . sort ( ) ;
58+ assert . equal ( missing . length , 2 ) ;
59+ assert . equal ( missing [ 0 ] . toString ( ) , "d:/pretend/nonexistent0.ts" ) ;
60+ assert . equal ( missing [ 1 ] . toString ( ) , "d:/pretend/nonexistent1.ts" ) ;
61+ } ) ;
62+
63+ it ( "handles a mix of present and missing root files" , ( ) => {
64+ const program = createProgram ( [ "./nonexistent0.ts" , emptyFileRelativePath , "./nonexistent1.ts" ] , options , testCompilerHost ) ;
65+ const missing = program . getMissingFilePaths ( ) . sort ( ) ;
66+ assert . equal ( missing . length , 2 ) ;
67+ assert . equal ( missing [ 0 ] . toString ( ) , "d:/pretend/nonexistent0.ts" ) ;
68+ assert . equal ( missing [ 1 ] . toString ( ) , "d:/pretend/nonexistent1.ts" ) ;
69+ } ) ;
70+
71+ it ( "handles repeatedly specified root files" , ( ) => {
72+ const program = createProgram ( [ "./nonexistent.ts" , "./nonexistent.ts" ] , options , testCompilerHost ) ;
73+ const missing = program . getMissingFilePaths ( ) ;
74+ assert . isDefined ( missing ) ;
75+ assert . equal ( missing . length , 1 ) ;
76+ assert . equal ( missing [ 0 ] . toString ( ) , "d:/pretend/nonexistent.ts" ) ;
77+ } ) ;
78+
79+ it ( "normalizes file paths" , ( ) => {
80+ const program0 = createProgram ( [ "./nonexistent.ts" , "./NONEXISTENT.ts" ] , options , testCompilerHost ) ;
81+ const program1 = createProgram ( [ "./NONEXISTENT.ts" , "./nonexistent.ts" ] , options , testCompilerHost ) ;
82+ const missing0 = program0 . getMissingFilePaths ( ) ;
83+ const missing1 = program1 . getMissingFilePaths ( ) ;
84+ assert . equal ( missing0 . length , 1 ) ;
85+ assert . deepEqual ( missing0 , missing1 ) ;
86+ } ) ;
87+
88+ it ( "handles missing triple slash references" , ( ) => {
89+ const program = createProgram ( [ referenceFileRelativePath ] , options , testCompilerHost ) ;
90+ const missing = program . getMissingFilePaths ( ) . sort ( ) ;
91+ assert . isDefined ( missing ) ;
92+ assert . equal ( missing . length , 6 ) ;
93+
94+ // From absolute reference
95+ assert . equal ( missing [ 0 ] . toString ( ) , "d:/imaginary/nonexistent1.ts" ) ;
96+
97+ // From relative reference
98+ assert . equal ( missing [ 1 ] . toString ( ) , "d:/pretend/nonexistent2.ts" ) ;
99+
100+ // From unqualified reference
101+ assert . equal ( missing [ 2 ] . toString ( ) , "d:/pretend/nonexistent3.ts" ) ;
102+
103+ // From no-extension reference
104+ assert . equal ( missing [ 3 ] . toString ( ) , "d:/pretend/nonexistent4.d.ts" ) ;
105+ assert . equal ( missing [ 4 ] . toString ( ) , "d:/pretend/nonexistent4.ts" ) ;
106+ assert . equal ( missing [ 5 ] . toString ( ) , "d:/pretend/nonexistent4.tsx" ) ;
107+ } ) ;
108+ } ) ;
109+ }
0 commit comments