@@ -17,7 +17,8 @@ describe('reflector_host', () => {
17
17
var context : MockContext ;
18
18
var host : ts . CompilerHost ;
19
19
var program : ts . Program ;
20
- var reflectorHost : ReflectorHost ;
20
+ var reflectorNestedGenDir : ReflectorHost ;
21
+ var reflectorSiblingGenDir : ReflectorHost ;
21
22
22
23
beforeEach ( ( ) => {
23
24
context = new MockContext ( '/tmp/src' , clone ( FILES ) ) ;
@@ -32,20 +33,95 @@ describe('reflector_host', () => {
32
33
if ( errors && errors . length ) {
33
34
throw new Error ( 'Expected no errors' ) ;
34
35
}
35
- reflectorHost = new ReflectorHost (
36
+ reflectorNestedGenDir = new ReflectorHost (
36
37
program , host , {
37
- genDir : '/tmp/dist ' ,
38
- basePath : '/tmp/src' ,
38
+ genDir : '/tmp/project/src/gen ' ,
39
+ basePath : '/tmp/project/ src' ,
39
40
skipMetadataEmit : false ,
40
41
skipTemplateCodegen : false ,
41
42
trace : false
42
43
} ,
43
44
context ) ;
45
+ reflectorSiblingGenDir = new ReflectorHost (
46
+ program , host , {
47
+ genDir : '/tmp/project/gen' ,
48
+ basePath : '/tmp/project/src' ,
49
+ skipMetadataEmit : false ,
50
+ skipTemplateCodegen : false ,
51
+ trace : false
52
+ } ,
53
+ context ) ;
54
+ } ) ;
55
+
56
+ describe ( 'nestedGenDir' , ( ) => {
57
+ it ( 'should import node_module from factory' , ( ) => {
58
+ expect ( reflectorNestedGenDir . getImportPath (
59
+ '/tmp/project/src/gen/my.ngfactory.ts' ,
60
+ '/tmp/project/node_modules/@angular/core.d.ts' ) )
61
+ . toEqual ( '@angular/core' ) ;
62
+ } ) ;
63
+
64
+ it ( 'should import factory from factory' , ( ) => {
65
+ expect ( reflectorNestedGenDir . getImportPath (
66
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/my.other.ngfactory.ts' ) )
67
+ . toEqual ( './my.other.ngfactory' ) ;
68
+ expect ( reflectorNestedGenDir . getImportPath (
69
+ '/tmp/project/src/a/my.ngfactory.ts' , '/tmp/project/src/my.other.css.ts' ) )
70
+ . toEqual ( '../my.other.css' ) ;
71
+ expect ( reflectorNestedGenDir . getImportPath (
72
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/a/my.other.css.shim.ts' ) )
73
+ . toEqual ( './a/my.other.css.shim' ) ;
74
+ } ) ;
75
+
76
+ it ( 'should import application from factory' , ( ) => {
77
+ expect ( reflectorNestedGenDir . getImportPath (
78
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/my.other.ts' ) )
79
+ . toEqual ( '../my.other' ) ;
80
+ expect ( reflectorNestedGenDir . getImportPath (
81
+ '/tmp/project/src/a/my.ngfactory.ts' , '/tmp/project/src/my.other.ts' ) )
82
+ . toEqual ( '../../my.other' ) ;
83
+ expect ( reflectorNestedGenDir . getImportPath (
84
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/a/my.other.ts' ) )
85
+ . toEqual ( '../a/my.other' ) ;
86
+ } ) ;
87
+ } ) ;
88
+
89
+ describe ( 'nestedGenDir' , ( ) => {
90
+ it ( 'should import node_module from factory' , ( ) => {
91
+ expect ( reflectorSiblingGenDir . getImportPath (
92
+ '/tmp/project/src/gen/my.ngfactory.ts' ,
93
+ '/tmp/project/node_modules/@angular/core.d.ts' ) )
94
+ . toEqual ( '@angular/core' ) ;
95
+ } ) ;
96
+
97
+ it ( 'should import factory from factory' , ( ) => {
98
+ expect ( reflectorSiblingGenDir . getImportPath (
99
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/my.other.ngfactory.ts' ) )
100
+ . toEqual ( './my.other.ngfactory' ) ;
101
+ expect ( reflectorSiblingGenDir . getImportPath (
102
+ '/tmp/project/src/a/my.ngfactory.ts' , '/tmp/project/src/my.other.css.ts' ) )
103
+ . toEqual ( '../my.other.css' ) ;
104
+ expect ( reflectorSiblingGenDir . getImportPath (
105
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/a/my.other.css.shim.ts' ) )
106
+ . toEqual ( './a/my.other.css.shim' ) ;
107
+ } ) ;
108
+
109
+ it ( 'should import application from factory' , ( ) => {
110
+ expect ( reflectorSiblingGenDir . getImportPath (
111
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/my.other.ts' ) )
112
+ . toEqual ( './my.other' ) ;
113
+ expect ( reflectorSiblingGenDir . getImportPath (
114
+ '/tmp/project/src/a/my.ngfactory.ts' , '/tmp/project/src/my.other.ts' ) )
115
+ . toEqual ( '../my.other' ) ;
116
+ expect ( reflectorSiblingGenDir . getImportPath (
117
+ '/tmp/project/src/my.ngfactory.ts' , '/tmp/project/src/a/my.other.ts' ) )
118
+ . toEqual ( './a/my.other' ) ;
119
+ } ) ;
44
120
} ) ;
45
121
46
122
it ( 'should provide the import locations for angular' , ( ) => {
47
123
let { coreDecorators, diDecorators, diMetadata, animationMetadata, provider} =
48
- reflectorHost . angularImportLocations ( ) ;
124
+ reflectorNestedGenDir . angularImportLocations ( ) ;
49
125
expect ( coreDecorators ) . toEqual ( '@angular/core/src/metadata' ) ;
50
126
expect ( diDecorators ) . toEqual ( '@angular/core/src/di/decorators' ) ;
51
127
expect ( diMetadata ) . toEqual ( '@angular/core/src/di/metadata' ) ;
@@ -54,82 +130,86 @@ describe('reflector_host', () => {
54
130
} ) ;
55
131
56
132
it ( 'should be able to produce an import from main @angular/core' , ( ) => {
57
- expect ( reflectorHost . getImportPath ( 'main.ts' , 'node_modules/@angular/core.d.ts' ) )
133
+ expect ( reflectorNestedGenDir . getImportPath (
134
+ '/tmp/project/src/main.ts' , '/tmp/project/node_modules/@angular/core.d.ts' ) )
58
135
. toEqual ( '@angular/core' ) ;
59
136
} ) ;
60
137
61
- it ( 'should be ble to produce an import from main to a sub-directory' , ( ) => {
62
- expect ( reflectorHost . getImportPath ( 'main.ts' , 'lib/utils.ts' ) ) . toEqual ( './lib/utils' ) ;
138
+ it ( 'should be able to produce an import from main to a sub-directory' , ( ) => {
139
+ expect ( reflectorNestedGenDir . getImportPath ( 'main.ts' , 'lib/utils.ts' ) ) . toEqual ( './lib/utils' ) ;
63
140
} ) ;
64
141
65
142
it ( 'should be able to produce an import from to a peer file' , ( ) => {
66
- expect ( reflectorHost . getImportPath ( 'lib/utils.ts' , 'lib/collections.ts' ) )
143
+ expect ( reflectorNestedGenDir . getImportPath ( 'lib/utils.ts' , 'lib/collections.ts' ) )
67
144
. toEqual ( './collections' ) ;
68
145
} ) ;
69
146
70
147
it ( 'should be able to produce an import from to a sibling directory' , ( ) => {
71
- expect ( reflectorHost . getImportPath ( 'lib2/utils2.ts' , 'lib/utils.ts' ) ) . toEqual ( '../lib/utils' ) ;
148
+ expect ( reflectorNestedGenDir . getImportPath ( 'lib2/utils2.ts' , 'lib/utils.ts' ) )
149
+ . toEqual ( '../lib/utils' ) ;
72
150
} ) ;
73
151
74
152
it ( 'should be able to produce a symbol for an exported symbol' , ( ) => {
75
- expect ( reflectorHost . findDeclaration ( '@angular/router-deprecated' , 'foo' , 'main.ts' ) )
153
+ expect ( reflectorNestedGenDir . findDeclaration ( '@angular/router-deprecated' , 'foo' , 'main.ts' ) )
76
154
. toBeDefined ( ) ;
77
155
} ) ;
78
156
79
157
it ( 'should be able to produce a symbol for values space only reference' , ( ) => {
80
- expect (
81
- reflectorHost . findDeclaration ( '@angular/router-deprecated/src/providers' , 'foo' , 'main.ts' ) )
158
+ expect ( reflectorNestedGenDir . findDeclaration (
159
+ '@angular/router-deprecated/src/providers' , 'foo' , 'main.ts' ) )
82
160
. toBeDefined ( ) ;
83
161
} ) ;
84
162
85
163
86
164
it ( 'should be produce the same symbol if asked twice' , ( ) => {
87
- let foo1 = reflectorHost . getStaticSymbol ( 'main.ts' , 'foo' ) ;
88
- let foo2 = reflectorHost . getStaticSymbol ( 'main.ts' , 'foo' ) ;
165
+ let foo1 = reflectorNestedGenDir . getStaticSymbol ( 'main.ts' , 'foo' ) ;
166
+ let foo2 = reflectorNestedGenDir . getStaticSymbol ( 'main.ts' , 'foo' ) ;
89
167
expect ( foo1 ) . toBe ( foo2 ) ;
90
168
} ) ;
91
169
92
170
it ( 'should be able to produce a symbol for a module with no file' , ( ) => {
93
- expect ( reflectorHost . getStaticSymbol ( 'angularjs' , 'SomeAngularSymbol' ) ) . toBeDefined ( ) ;
171
+ expect ( reflectorNestedGenDir . getStaticSymbol ( 'angularjs' , 'SomeAngularSymbol' ) ) . toBeDefined ( ) ;
94
172
} ) ;
95
173
96
174
it ( 'should be able to read a metadata file' , ( ) => {
97
- expect ( reflectorHost . getMetadataFor ( 'node_modules/@angular/core.d.ts' ) )
175
+ expect ( reflectorNestedGenDir . getMetadataFor ( 'node_modules/@angular/core.d.ts' ) )
98
176
. toEqual ( { __symbolic : 'module' , version : 1 , metadata : { foo : { __symbolic : 'class' } } } ) ;
99
177
} ) ;
100
178
101
179
it ( 'should be able to read metadata from an otherwise unused .d.ts file ' , ( ) => {
102
- expect ( reflectorHost . getMetadataFor ( 'node_modules/@angular/unused.d.ts' ) ) . toBeUndefined ( ) ;
180
+ expect ( reflectorNestedGenDir . getMetadataFor ( 'node_modules/@angular/unused.d.ts' ) )
181
+ . toBeUndefined ( ) ;
103
182
} ) ;
104
183
105
184
it ( 'should return undefined for missing modules' , ( ) => {
106
- expect ( reflectorHost . getMetadataFor ( 'node_modules/@angular/missing.d.ts' ) ) . toBeUndefined ( ) ;
185
+ expect ( reflectorNestedGenDir . getMetadataFor ( 'node_modules/@angular/missing.d.ts' ) )
186
+ . toBeUndefined ( ) ;
107
187
} ) ;
108
188
109
189
it ( 'should be able to trace a named export' , ( ) => {
110
- const symbol =
111
- reflectorHost . findDeclaration ( './reexport/reexport.d.ts' , 'One' , '/tmp/src/main.ts' ) ;
190
+ const symbol = reflectorNestedGenDir . findDeclaration (
191
+ './reexport/reexport.d.ts' , 'One' , '/tmp/src/main.ts' ) ;
112
192
expect ( symbol . name ) . toEqual ( 'One' ) ;
113
193
expect ( symbol . filePath ) . toEqual ( '/tmp/src/reexport/src/origin1.d.ts' ) ;
114
194
} ) ;
115
195
116
196
it ( 'should be able to trace a renamed export' , ( ) => {
117
- const symbol =
118
- reflectorHost . findDeclaration ( './reexport/reexport.d.ts' , 'Four' , '/tmp/src/main.ts' ) ;
197
+ const symbol = reflectorNestedGenDir . findDeclaration (
198
+ './reexport/reexport.d.ts' , 'Four' , '/tmp/src/main.ts' ) ;
119
199
expect ( symbol . name ) . toEqual ( 'Three' ) ;
120
200
expect ( symbol . filePath ) . toEqual ( '/tmp/src/reexport/src/origin1.d.ts' ) ;
121
201
} ) ;
122
202
123
203
it ( 'should be able to trace an export * export' , ( ) => {
124
- const symbol =
125
- reflectorHost . findDeclaration ( './reexport/reexport.d.ts' , 'Five' , '/tmp/src/main.ts' ) ;
204
+ const symbol = reflectorNestedGenDir . findDeclaration (
205
+ './reexport/reexport.d.ts' , 'Five' , '/tmp/src/main.ts' ) ;
126
206
expect ( symbol . name ) . toEqual ( 'Five' ) ;
127
207
expect ( symbol . filePath ) . toEqual ( '/tmp/src/reexport/src/origin5.d.ts' ) ;
128
208
} ) ;
129
209
130
210
it ( 'should be able to trace a multi-level re-export' , ( ) => {
131
- const symbol =
132
- reflectorHost . findDeclaration ( './reexport/reexport.d.ts' , 'Thirty' , '/tmp/src/main.ts' ) ;
211
+ const symbol = reflectorNestedGenDir . findDeclaration (
212
+ './reexport/reexport.d.ts' , 'Thirty' , '/tmp/src/main.ts' ) ;
133
213
expect ( symbol . name ) . toEqual ( 'Thirty' ) ;
134
214
expect ( symbol . filePath ) . toEqual ( '/tmp/src/reexport/src/origin30.d.ts' ) ;
135
215
} ) ;
0 commit comments