@@ -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 => {
@@ -192,6 +192,9 @@ module.exports = function(file, api) {
192192 this . setupType = "setupTest" ;
193193 this . subjectContainerKey = j . literal ( `component:${ node . expression . arguments [ 0 ] . value } ` ) ;
194194 }
195+ } else if ( calleeName === 'setupModelTest' ) {
196+ this . setupType = 'setupTest' ;
197+ this . modelName = node . expression . arguments [ 0 ] . value ;
195198 }
196199
197200 this . setupTypeMethodInvocationNode = node . expression ;
@@ -458,9 +461,16 @@ module.exports = function(file, api) {
458461
459462 thisDotSubjectUsage . forEach ( p => {
460463 let options = p . node . arguments [ 0 ] ;
461- let split = subject . value . split ( ':' ) ;
462- let subjectType = split [ 0 ] ;
463- let subjectName = split [ 1 ] ;
464+ let subjectType ;
465+ let subjectName ;
466+ if ( 'modelName' in moduleInfo ) {
467+ subjectType = 'model' ;
468+ subjectName = moduleInfo . modelName ;
469+ } else {
470+ let split = subject . value . split ( ':' ) ;
471+ subjectType = split [ 0 ] ;
472+ subjectName = split [ 1 ] ;
473+ }
464474 let isSingletonSubject = [ 'model' , 'component' ] . indexOf ( subjectType ) === - 1 ;
465475
466476 // if we don't have `options` and the type is a singleton type
@@ -476,15 +486,7 @@ module.exports = function(file, api) {
476486 )
477487 ) ;
478488 } else if ( subjectType === 'model' ) {
479- ensureImportWithSpecifiers ( {
480- source : '@ember/runloop' ,
481- specifiers : [ 'run' ] ,
482- } ) ;
483-
484489 p . replace (
485- j . callExpression ( j . identifier ( 'run' ) , [
486- j . arrowFunctionExpression (
487- [ ] ,
488490 j . callExpression (
489491 j . memberExpression (
490492 j . callExpression (
@@ -496,11 +498,10 @@ module.exports = function(file, api) {
496498 ) ,
497499 j . identifier ( 'createRecord' )
498500 ) ,
499- [ j . literal ( subjectName ) , options ] . filter ( Boolean )
500- ) ,
501- true
502- ) ,
503- ] )
501+ // creating an empty object expression {} as the 2nd argument here
502+ // because setupModelTests shouldn't need store dependencies
503+ [ j . literal ( subjectName ) , j . objectExpression ( [ ] ) ] . filter ( Boolean )
504+ )
504505 ) ;
505506 } else {
506507 p . replace (
@@ -630,7 +631,8 @@ module.exports = function(file, api) {
630631
631632 function updateToNewEmberMochaImports ( ) {
632633 let mapping = {
633- setupComponentTest : "setupRenderingTest"
634+ setupComponentTest : "setupRenderingTest" ,
635+ setupModelTest : "setupTest"
634636 } ;
635637
636638 let emberMochaImports = root . find ( j . ImportDeclaration , { source : { value : "ember-mocha" } } ) ;
0 commit comments