@@ -4,7 +4,7 @@ module.exports = function(file, api) {
44 const j = api . jscodeshift ;
55 const root = j ( file . source ) ;
66
7- const SETUP_TYPE_METHODS = [ "setupComponentTest" ] ;
7+ const SETUP_TYPE_METHODS = [ "setupComponentTest" , "setupModelTest" ] ;
88
99 function isSetupTypeMethod ( nodePath ) {
1010 return SETUP_TYPE_METHODS . some ( name => {
@@ -193,6 +193,9 @@ module.exports = function(file, api) {
193193 this . setupType = "setupTest" ;
194194 this . subjectContainerKey = j . literal ( `component:${ node . expression . arguments [ 0 ] . value } ` ) ;
195195 }
196+ } else if ( calleeName === 'setupModelTest' ) {
197+ this . setupType = 'setupTest' ;
198+ this . modelName = node . expression . arguments [ 0 ] . value ;
196199 }
197200
198201 this . setupTypeMethodInvocationNode = node . expression ;
@@ -459,9 +462,16 @@ module.exports = function(file, api) {
459462
460463 thisDotSubjectUsage . forEach ( p => {
461464 let options = p . node . arguments [ 0 ] ;
462- let split = subject . value . split ( ':' ) ;
463- let subjectType = split [ 0 ] ;
464- let subjectName = split [ 1 ] ;
465+ let subjectType ;
466+ let subjectName ;
467+ if ( 'modelName' in moduleInfo ) {
468+ subjectType = 'model' ;
469+ subjectName = moduleInfo . modelName ;
470+ } else {
471+ let split = subject . value . split ( ':' ) ;
472+ subjectType = split [ 0 ] ;
473+ subjectName = split [ 1 ] ;
474+ }
465475 let isSingletonSubject = [ 'model' , 'component' ] . indexOf ( subjectType ) === - 1 ;
466476
467477 // if we don't have `options` and the type is a singleton type
@@ -477,15 +487,7 @@ module.exports = function(file, api) {
477487 )
478488 ) ;
479489 } else if ( subjectType === 'model' ) {
480- ensureImportWithSpecifiers ( {
481- source : '@ember/runloop' ,
482- specifiers : [ 'run' ] ,
483- } ) ;
484-
485490 p . replace (
486- j . callExpression ( j . identifier ( 'run' ) , [
487- j . arrowFunctionExpression (
488- [ ] ,
489491 j . callExpression (
490492 j . memberExpression (
491493 j . callExpression (
@@ -497,11 +499,10 @@ module.exports = function(file, api) {
497499 ) ,
498500 j . identifier ( 'createRecord' )
499501 ) ,
500- [ j . literal ( subjectName ) , options ] . filter ( Boolean )
501- ) ,
502- true
503- ) ,
504- ] )
502+ // creating an empty object expression {} as the 2nd argument here
503+ // because setupModelTests shouldn't need store dependencies
504+ [ j . literal ( subjectName ) , j . objectExpression ( [ ] ) ] . filter ( Boolean )
505+ )
505506 ) ;
506507 } else {
507508 p . replace (
@@ -631,7 +632,8 @@ module.exports = function(file, api) {
631632
632633 function updateToNewEmberMochaImports ( ) {
633634 let mapping = {
634- setupComponentTest : "setupRenderingTest"
635+ setupComponentTest : "setupRenderingTest" ,
636+ setupModelTest : "setupTest"
635637 } ;
636638
637639 let emberMochaImports = root . find ( j . ImportDeclaration , { source : { value : "ember-mocha" } } ) ;
0 commit comments