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 . deepEqual ( missing , [ ] ) ;
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 . deepEqual ( missing , [ "d:/pretend/nonexistent.ts" ] ) ; // Absolute path
52+ } ) ;
53+
54+ it ( "handles multiple missing root files" , ( ) => {
55+ const program = createProgram ( [ "./nonexistent0.ts" , "./nonexistent1.ts" ] , options , testCompilerHost ) ;
56+ const missing = program . getMissingFilePaths ( ) . sort ( ) ;
57+ assert . deepEqual ( missing , [ "d:/pretend/nonexistent0.ts" , "d:/pretend/nonexistent1.ts" ] ) ;
58+ } ) ;
59+
60+ it ( "handles a mix of present and missing root files" , ( ) => {
61+ const program = createProgram ( [ "./nonexistent0.ts" , emptyFileRelativePath , "./nonexistent1.ts" ] , options , testCompilerHost ) ;
62+ const missing = program . getMissingFilePaths ( ) . sort ( ) ;
63+ assert . deepEqual ( missing , [ "d:/pretend/nonexistent0.ts" , "d:/pretend/nonexistent1.ts" ] ) ;
64+ } ) ;
65+
66+ it ( "handles repeatedly specified root files" , ( ) => {
67+ const program = createProgram ( [ "./nonexistent.ts" , "./nonexistent.ts" ] , options , testCompilerHost ) ;
68+ const missing = program . getMissingFilePaths ( ) ;
69+ assert . isDefined ( missing ) ;
70+ assert . deepEqual ( missing , [ "d:/pretend/nonexistent.ts" ] ) ;
71+ } ) ;
72+
73+ it ( "normalizes file paths" , ( ) => {
74+ const program0 = createProgram ( [ "./nonexistent.ts" , "./NONEXISTENT.ts" ] , options , testCompilerHost ) ;
75+ const program1 = createProgram ( [ "./NONEXISTENT.ts" , "./nonexistent.ts" ] , options , testCompilerHost ) ;
76+ const missing0 = program0 . getMissingFilePaths ( ) ;
77+ const missing1 = program1 . getMissingFilePaths ( ) ;
78+ assert . equal ( missing0 . length , 1 ) ;
79+ assert . deepEqual ( missing0 , missing1 ) ;
80+ } ) ;
81+
82+ it ( "handles missing triple slash references" , ( ) => {
83+ const program = createProgram ( [ referenceFileRelativePath ] , options , testCompilerHost ) ;
84+ const missing = program . getMissingFilePaths ( ) . sort ( ) ;
85+ assert . isDefined ( missing ) ;
86+ assert . deepEqual ( missing , [
87+ // From absolute reference
88+ "d:/imaginary/nonexistent1.ts" ,
89+
90+ // From relative reference
91+ "d:/pretend/nonexistent2.ts" ,
92+
93+ // From unqualified reference
94+ "d:/pretend/nonexistent3.ts" ,
95+
96+ // From no-extension reference
97+ "d:/pretend/nonexistent4.d.ts" ,
98+ "d:/pretend/nonexistent4.ts" ,
99+ "d:/pretend/nonexistent4.tsx"
100+ ] ) ;
101+ } ) ;
102+ } ) ;
103+ }
0 commit comments