1+ import { Dgeni , Package } from 'dgeni' ;
12import { TsParser } from '../TsParser' ;
23import { Host } from './host' ;
34
5+ const mockPackage = require ( '../../mocks/mockPackage' ) ;
46const path = require ( 'canonical-path' ) ;
57
68describe ( 'Host' , ( ) => {
9+ const basePath = path . resolve ( __dirname , '../../mocks/tsParser' ) ;
10+
711 let host : Host ;
812 let parser : TsParser ;
9- let basePath : string ;
1013
11- beforeEach ( ( ) => {
12- host = new Host ( ) ;
13- parser = new TsParser ( require ( 'dgeni/lib/mocks/log' ) ( false ) ) ;
14- basePath = path . resolve ( __dirname , '../../mocks/tsParser' ) ;
15- } ) ;
14+ /**
15+ * Creates the Host instance through Dgeni dependency injection. Also allows passing a function
16+ * that will run in Dgeni's configuration lifecycle and allows modifying the host factory.
17+ */
18+ function setupTestDgeniInstance ( configureFn : ( host : Host ) => void ) {
19+ const testPackage = mockPackage ( ) as Package ;
20+
21+ testPackage . config ( ( tsHost : Host ) => configureFn ( tsHost ) ) ;
22+
23+ const dgeni = new Dgeni ( [ testPackage ] ) ;
24+ const injector = dgeni . configureInjector ( ) ;
25+
26+ // Load factories from the Dgeni injector.
27+ host = injector . get ( 'tsHost' ) ;
28+ parser = injector . get ( 'tsParser' ) ;
29+ }
1630
1731 it ( "should read content of a declaration" , ( ) => {
32+ setupTestDgeniInstance ( h => h . concatMultipleLeadingComments = true ) ;
33+
1834 const parseInfo = parser . parse ( [ 'multipleLeadingComments.ts' ] , basePath ) ;
1935 const module = parseInfo . moduleSymbols [ 0 ] ;
2036 const declaration = module . exportArray [ 0 ] . valueDeclaration ! ;
@@ -24,6 +40,8 @@ describe('Host', () => {
2440 } ) ;
2541
2642 it ( 'should be able to disable leading comment concatenation' , ( ) => {
43+ setupTestDgeniInstance ( h => h . concatMultipleLeadingComments = false ) ;
44+
2745 const parseInfo = parser . parse ( [ 'multipleLeadingComments.ts' ] , basePath ) ;
2846 const module = parseInfo . moduleSymbols [ 0 ] ;
2947 const declaration = module . exportArray [ 0 ] . valueDeclaration ! ;
0 commit comments