@@ -20,6 +20,8 @@ describe('reflector_host', () => {
2020 var reflectorNestedGenDir : ReflectorHost ;
2121 var reflectorSiblingGenDir : ReflectorHost ;
2222
23+ const DEBUG = false ;
24+
2325 beforeEach ( ( ) => {
2426 context = new MockContext ( '/tmp/src' , clone ( FILES ) ) ;
2527 host = new MockCompilerHost ( context ) ;
@@ -35,86 +37,107 @@ describe('reflector_host', () => {
3537 }
3638 reflectorNestedGenDir = new ReflectorHost (
3739 program , host , {
38- genDir : '/tmp/project/src/gen/' ,
39- basePath : '/tmp/project/src' ,
40+ // Intentional trailing slash, check for regression of #10533
41+ genDir : '/tmp/src/gen/' ,
42+ basePath : '/tmp/src' ,
4043 skipMetadataEmit : false ,
4144 skipTemplateCodegen : false ,
4245 trace : false
4346 } ,
4447 context ) ;
4548 reflectorSiblingGenDir = new ReflectorHost (
4649 program , host , {
47- genDir : '/tmp/project/gen' ,
48- basePath : '/tmp/project/src/' ,
50+ genDir : '/tmp/gen' ,
51+ // Intentional trailing slash, check for regression of #10533
52+ basePath : '/tmp/src/' ,
4953 skipMetadataEmit : false ,
5054 skipTemplateCodegen : false ,
5155 trace : false
5256 } ,
5357 context ) ;
58+
59+ } ) ;
60+
61+ describe ( 'path mapping' , ( ) => {
62+ it ( 'should use rootDirs for calculating relative imports' , ( ) => {
63+ const reflectorHost = new ReflectorHost (
64+ program , host , {
65+ genDir : '/tmp/gen' ,
66+ basePath : '/tmp/src/' ,
67+ skipMetadataEmit : false ,
68+ skipTemplateCodegen : false ,
69+ trace : false ,
70+ traceResolution : DEBUG ,
71+ rootDirs : [ '/tmp/src/' , '/tmp/genfiles/' ] ,
72+ writeImportsForRootDirs : true ,
73+ } ,
74+ context ) ;
75+ expect ( reflectorHost . getImportPath (
76+ '/tmp/src/pathmapping/bootstrap.ts' , '/tmp/genfiles/pathmapping/comp.d.ts' ) )
77+ . toEqual ( './comp' ) ;
78+ } ) ;
5479 } ) ;
5580
56- describe ( 'nestedGenDir ' , ( ) => {
81+ describe ( 'nested genDir ' , ( ) => {
5782 it ( 'should import node_module from factory' , ( ) => {
5883 expect ( reflectorNestedGenDir . getImportPath (
59- '/tmp/project/src/gen/my.ngfactory.ts' ,
60- '/tmp/project/node_modules/@angular/core.d.ts' ) )
84+ '/tmp/src/gen/my.ngfactory.ts' , '/tmp/src/node_modules/@angular/core.d.ts' ) )
6185 . toEqual ( '@angular/core' ) ;
6286 } ) ;
6387
6488 it ( 'should import factory from factory' , ( ) => {
6589 expect ( reflectorNestedGenDir . getImportPath (
66- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/my.other.ngfactory.ts' ) )
90+ '/tmp/src/my.ngfactory.ts' , '/tmp/src/my.other.ngfactory.ts' ) )
6791 . toEqual ( './my.other.ngfactory' ) ;
6892 expect ( reflectorNestedGenDir . getImportPath (
69- '/tmp/project/ src/a/my.ngfactory.ts' , '/tmp/project /src/my.other.css.ts' ) )
93+ '/tmp/src/a/my.ngfactory.ts' , '/tmp/src/my.other.css.ts' ) )
7094 . toEqual ( '../my.other.css' ) ;
7195 expect ( reflectorNestedGenDir . getImportPath (
72- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/a/my.other.css.shim.ts' ) )
96+ '/tmp/src/my.ngfactory.ts' , '/tmp/src/a/my.other.css.shim.ts' ) )
7397 . toEqual ( './a/my.other.css.shim' ) ;
7498 } ) ;
7599
76100 it ( 'should import application from factory' , ( ) => {
77- expect ( reflectorNestedGenDir . getImportPath (
78- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/my.other.ts' ) )
101+ expect (
102+ reflectorNestedGenDir . getImportPath ( '/tmp/src/my.ngfactory.ts' , '/tmp/src/my.other.ts' ) )
79103 . toEqual ( '../my.other' ) ;
80- expect ( reflectorNestedGenDir . getImportPath (
81- '/tmp/project/ src/a/my.ngfactory.ts' , '/tmp/project /src/my.other.ts' ) )
104+ expect (
105+ reflectorNestedGenDir . getImportPath ( '/tmp/src/a/my.ngfactory.ts' , '/tmp/src/my.other.ts' ) )
82106 . toEqual ( '../../my.other' ) ;
83- expect ( reflectorNestedGenDir . getImportPath (
84- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/a/my.other.ts' ) )
107+ expect (
108+ reflectorNestedGenDir . getImportPath ( '/tmp/src/my.ngfactory.ts' , '/tmp/src/a/my.other.ts' ) )
85109 . toEqual ( '../a/my.other' ) ;
86110 } ) ;
87111 } ) ;
88112
89- describe ( 'nestedGenDir ' , ( ) => {
113+ describe ( 'sibling genDir ' , ( ) => {
90114 it ( 'should import node_module from factory' , ( ) => {
91115 expect ( reflectorSiblingGenDir . getImportPath (
92- '/tmp/project/src/gen/my.ngfactory.ts' ,
93- '/tmp/project/node_modules/@angular/core.d.ts' ) )
116+ '/tmp/src/gen/my.ngfactory.ts' , '/tmp/src/node_modules/@angular/core.d.ts' ) )
94117 . toEqual ( '@angular/core' ) ;
95118 } ) ;
96119
97120 it ( 'should import factory from factory' , ( ) => {
98121 expect ( reflectorSiblingGenDir . getImportPath (
99- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/my.other.ngfactory.ts' ) )
122+ '/tmp/src/my.ngfactory.ts' , '/tmp/src/my.other.ngfactory.ts' ) )
100123 . toEqual ( './my.other.ngfactory' ) ;
101124 expect ( reflectorSiblingGenDir . getImportPath (
102- '/tmp/project/ src/a/my.ngfactory.ts' , '/tmp/project /src/my.other.css.ts' ) )
125+ '/tmp/src/a/my.ngfactory.ts' , '/tmp/src/my.other.css.ts' ) )
103126 . toEqual ( '../my.other.css' ) ;
104127 expect ( reflectorSiblingGenDir . getImportPath (
105- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/a/my.other.css.shim.ts' ) )
128+ '/tmp/src/my.ngfactory.ts' , '/tmp/src/a/my.other.css.shim.ts' ) )
106129 . toEqual ( './a/my.other.css.shim' ) ;
107130 } ) ;
108131
109132 it ( 'should import application from factory' , ( ) => {
110- expect ( reflectorSiblingGenDir . getImportPath (
111- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/my.other.ts' ) )
133+ expect (
134+ reflectorSiblingGenDir . getImportPath ( '/tmp/src/my.ngfactory.ts' , '/tmp/src/my.other.ts' ) )
112135 . toEqual ( './my.other' ) ;
113136 expect ( reflectorSiblingGenDir . getImportPath (
114- '/tmp/project/ src/a/my.ngfactory.ts' , '/tmp/project /src/my.other.ts' ) )
137+ '/tmp/src/a/my.ngfactory.ts' , '/tmp/src/my.other.ts' ) )
115138 . toEqual ( '../my.other' ) ;
116139 expect ( reflectorSiblingGenDir . getImportPath (
117- '/tmp/project/ src/my.ngfactory.ts' , '/tmp/project /src/a/my.other.ts' ) )
140+ '/tmp/src/my.ngfactory.ts' , '/tmp/src/a/my.other.ts' ) )
118141 . toEqual ( './a/my.other' ) ;
119142 } ) ;
120143 } ) ;
@@ -131,7 +154,7 @@ describe('reflector_host', () => {
131154
132155 it ( 'should be able to produce an import from main @angular/core' , ( ) => {
133156 expect ( reflectorNestedGenDir . getImportPath (
134- '/tmp/project/ src/main.ts' , '/tmp/project /node_modules/@angular/core.d.ts' ) )
157+ '/tmp/src/main.ts' , '/tmp/src /node_modules/@angular/core.d.ts' ) )
135158 . toEqual ( '@angular/core' ) ;
136159 } ) ;
137160
@@ -295,6 +318,11 @@ const FILES: Entry = {
295318 } )
296319 }
297320 } ,
321+ 'pathmapping' : { 'bootstrap.ts' : `import {a} from './comp.d.ts';` } ,
322+ 'a' : {
323+ 'my.other.css.shim.ts' : dummyModule ,
324+ } ,
325+ 'my.other.ts' : dummyModule ,
298326 'node_modules' : {
299327 '@angular' : {
300328 'core.d.ts' : dummyModule ,
@@ -304,6 +332,13 @@ const FILES: Entry = {
304332 'unused.d.ts' : dummyModule
305333 }
306334 }
335+ } ,
336+ 'genfiles' : {
337+ 'pathmapping' : {
338+ 'comp.d.ts' : `
339+ export declare let a: string;
340+ `
341+ }
307342 }
308343 }
309344} ;
0 commit comments