@@ -73,6 +73,9 @@ module.exports = function(file, api, options) {
7373 } ;
7474
7575 let emberQUnitImports = root . find ( j . ImportDeclaration , { source : { value : 'ember-qunit' } } ) ;
76+ if ( emberQUnitImports . size ( ) === 0 ) {
77+ return ;
78+ }
7679
7780 // Collect all imports from ember-qunit into local array
7881 let emberQUnitSpecifiers = new Set ( ) ;
@@ -164,7 +167,7 @@ module.exports = function(file, api, options) {
164167 moduleName = calleeArguments [ 1 ] || calleeArguments [ 0 ] ;
165168 subject = calleeArguments [ 0 ] ;
166169
167- let setupIdentifier = 'setupTest' ;
170+ let setupIdentifier = calleeName === 'module' ? null : 'setupTest' ;
168171 if ( options ) {
169172 let hasIntegration = options . properties . some ( p => p . key . name === 'integration' ) ;
170173
@@ -187,6 +190,7 @@ module.exports = function(file, api, options) {
187190
188191 function updateModuleForToNestedModule ( ) {
189192 const POSSIBLE_MODULES = [
193+ { expression : { callee : { name : 'module' } } } ,
190194 { expression : { callee : { name : 'moduleFor' } } } ,
191195 { expression : { callee : { name : 'moduleForComponent' } } } ,
192196 { expression : { callee : { name : 'moduleForModel' } } } ,
@@ -210,13 +214,20 @@ module.exports = function(file, api, options) {
210214 function createModule ( p ) {
211215 let [ moduleName , options , setupType , subject , hasCustomSubject ] = parseModule ( p ) ;
212216
217+ let needsHooks = false ;
218+ let moduleSetupExpression ;
219+ if ( setupType ) {
220+ needsHooks = true ;
221+ moduleSetupExpression = j . expressionStatement (
222+ j . callExpression ( j . identifier ( setupType ) , [ j . identifier ( 'hooks' ) ] )
223+ ) ;
224+ }
225+
213226 // Create the new `module(moduleName, function(hooks) {});` invocation
214227 let callback = j . functionExpression (
215228 null /* no function name */ ,
216229 [ j . identifier ( 'hooks' ) ] ,
217- j . blockStatement ( [
218- j . expressionStatement ( j . callExpression ( j . identifier ( setupType ) , [ j . identifier ( 'hooks' ) ] ) ) ,
219- ] )
230+ j . blockStatement ( [ moduleSetupExpression ] . filter ( Boolean ) )
220231 ) ;
221232 let moduleInvocation = j . expressionStatement (
222233 j . callExpression ( j . identifier ( 'module' ) , [ moduleName , callback ] )
@@ -229,6 +240,7 @@ module.exports = function(file, api, options) {
229240 updateGetOwnerThisUsage ( property . value ) ;
230241
231242 if ( isLifecycleHook ( property ) ) {
243+ needsHooks = true ;
232244 let lifecycleStatement = j . expressionStatement (
233245 j . callExpression ( j . memberExpression ( j . identifier ( 'hooks' ) , property . key ) , [
234246 property . value ,
@@ -246,6 +258,7 @@ module.exports = function(file, api, options) {
246258 }
247259
248260 if ( ! customMethodBeforeEachBody ) {
261+ needsHooks = true ;
249262 customMethodBeforeEachBody = j . blockStatement ( [ ] ) ;
250263 customMethodBeforeEachExpression = j . expressionStatement (
251264 j . callExpression (
@@ -287,6 +300,11 @@ module.exports = function(file, api, options) {
287300 }
288301 }
289302
303+ if ( needsHooks === false ) {
304+ // nothing used the `hooks` argument, remove it
305+ callback . params = [ ] ;
306+ }
307+
290308 return [ moduleInvocation , callback . body . body , setupType , subject , hasCustomSubject ] ;
291309 }
292310
@@ -574,19 +592,13 @@ module.exports = function(file, api, options) {
574592
575593 const printOptions = options . printOptions || { quote : 'single' } ;
576594
577- let emberQUnitImports = root . find ( j . ImportDeclaration , { source : { value : 'ember-qunit' } } ) ;
578- if ( emberQUnitImports . size ( ) > 0 ) {
579- moveQUnitImportsFromEmberQUnit ( ) ;
580- updateToNewEmberQUnitImports ( ) ;
581- updateEmberTestHelperImports ( ) ;
582- updateModuleForToNestedModule ( ) ;
583- updateLookupCalls ( ) ;
584- updateRegisterCalls ( ) ;
585- updateInjectCalls ( ) ;
586- } else {
587- updateEmberTestHelperImports ( ) ;
588- }
589-
595+ moveQUnitImportsFromEmberQUnit ( ) ;
596+ updateToNewEmberQUnitImports ( ) ;
597+ updateEmberTestHelperImports ( ) ;
598+ updateModuleForToNestedModule ( ) ;
599+ updateLookupCalls ( ) ;
600+ updateRegisterCalls ( ) ;
601+ updateInjectCalls ( ) ;
590602 updateWaitUsage ( ) ;
591603
592604 return root . toSource ( printOptions ) ;
0 commit comments