@@ -33,7 +33,6 @@ export class MockDefiner {
3333 private _neededImportIdentifierPerFile : { [ key : string ] : Array < ModuleNameIdentifier > } = { } ;
3434 private _internalModuleImportIdentifierPerFile : { [ key : string ] : { [ key in ModuleName ] : ts . Identifier } } = { } ;
3535 private _factoryRegistrationsPerFile : FactoryRegistrationPerFile = { } ;
36- private _registerMockFactoryRegistrationsPerFile : FactoryRegistrationPerFile = { } ;
3736 private _factoryIntersectionsRegistrationsPerFile : FactoryIntersectionRegistrationPerFile = { } ;
3837 private _factoryCache : DeclarationCache ;
3938 private _registerMockFactoryCache : DeclarationCache ;
@@ -93,7 +92,6 @@ export class MockDefiner {
9392 ...this . _getImportsToAddInFile ( sourceFile ) ,
9493 ...this . _getExportsToAddInFile ( sourceFile ) ,
9594 ...this . _getExportsIntersectionToAddInFile ( sourceFile ) ,
96- ...this . _getRegisterMockInFile ( sourceFile ) ,
9795 ] ;
9896 }
9997
@@ -105,7 +103,6 @@ export class MockDefiner {
105103 }
106104 this . _factoryRegistrationsPerFile [ sourceFile . fileName ] = [ ] ;
107105 this . _factoryIntersectionsRegistrationsPerFile [ sourceFile . fileName ] = [ ] ;
108- this . _registerMockFactoryRegistrationsPerFile [ sourceFile . fileName ] = [ ] ;
109106 }
110107
111108 public createMockFactory ( declaration : ts . Declaration ) : void {
@@ -157,16 +154,12 @@ export class MockDefiner {
157154 return this . _declarationCache . get ( declaration ) as string ;
158155 }
159156
160- public storeRegisterMockFor ( declaration : ts . Declaration , factory : ts . FunctionExpression ) : void {
157+ public registerMockFor ( declaration : ts . Declaration , factory : ts . FunctionExpression ) : ts . Node {
161158 const key : string = this . getDeclarationKeyMap ( declaration ) ;
162159
163160 this . _registerMockFactoryCache . set ( declaration , key ) ;
164161
165- this . _registerMockFactoryRegistrationsPerFile [ this . _fileName ] = this . _registerMockFactoryRegistrationsPerFile [ this . _fileName ] || [ ] ;
166- this . _registerMockFactoryRegistrationsPerFile [ this . _fileName ] . push ( {
167- key : declaration ,
168- factory,
169- } ) ;
162+ return this . _getCallRegisterMock ( this . _fileName , key , factory ) ;
170163 }
171164
172165 public hasMockForDeclaration ( declaration : ts . Declaration ) : boolean {
@@ -283,33 +276,20 @@ export class MockDefiner {
283276 return [ ] ;
284277 }
285278
286- private _getRegisterMockInFile ( sourceFile : ts . SourceFile ) : ts . Statement [ ] {
287- if ( this . _registerMockFactoryRegistrationsPerFile [ sourceFile . fileName ] ) {
288- return this . _registerMockFactoryRegistrationsPerFile [ sourceFile . fileName ]
289- . map ( ( reg : { key : ts . Declaration ; factory : ts . Expression } ) => {
290- // NOTE: this._registerMockFactoryCache and
291- // this._registerMockFactoryCache are populated in the same routine
292- // and if the former is defined the latter will be too!
293- // eslint-disable-next-line
294- const key : string = this . _registerMockFactoryCache . get ( reg . key ) ! ;
295-
296- return this . _createRegistration ( sourceFile . fileName , key , reg . factory ) ;
297- } ) ;
298- }
299-
300- return [ ] ;
301- }
302-
303279 private _createRegistration ( fileName : string , key : string , factory : ts . Expression ) : ts . Statement {
304280 return ts . createExpressionStatement (
305- ts . createCall (
306- ts . createPropertyAccess (
307- this . _mockRepositoryAccess ( fileName ) ,
308- ts . createIdentifier ( 'registerFactory' ) ,
309- ) ,
310- [ ] ,
311- [ ts . createStringLiteral ( key ) , factory ] ,
281+ this . _getCallRegisterMock ( fileName , key , factory )
282+ ) ;
283+ }
284+
285+ private _getCallRegisterMock ( fileName : string , key : string , factory : ts . Expression ) : ts . CallExpression {
286+ return ts . createCall (
287+ ts . createPropertyAccess (
288+ this . _mockRepositoryAccess ( fileName ) ,
289+ ts . createIdentifier ( 'registerFactory' ) ,
312290 ) ,
291+ [ ] ,
292+ [ ts . createStringLiteral ( key ) , factory ] ,
313293 ) ;
314294 }
315295
0 commit comments