@@ -46,7 +46,8 @@ module.exports = function(file, api, options) {
4646 let emberQUnitImports = root . find ( j . ImportDeclaration , { source : { value : 'ember-qunit' } } ) ;
4747
4848 // Collect all imports from ember-qunit into local array
49- let specifiers = new Set ( ) ;
49+ let emberQUnitSpecifiers = new Set ( ) ;
50+
5051 emberQUnitImports
5152 . find ( j . ImportSpecifier )
5253 . forEach ( p => {
@@ -65,25 +66,57 @@ module.exports = function(file, api, options) {
6566 } )
6667 . forEach ( p => {
6768 let [ , , setupType ] = parseModule ( p ) ;
68- specifiers . add ( setupType ) ;
69+ emberQUnitSpecifiers . add ( setupType ) ;
6970 } ) ;
7071 } else {
71- specifiers . add ( mappedName ) ;
72+ emberQUnitSpecifiers . add ( mappedName ) ;
7273 }
7374 } )
7475 // Remove all existing import specifiers
7576 . remove ( ) ;
7677
78+ emberQUnitImports
79+ . get ( 'specifiers' )
80+ . replace ( Array . from ( emberQUnitSpecifiers ) . map ( s => j . importSpecifier ( j . identifier ( s ) ) ) ) ;
81+ }
82+
83+ function updateEmberTestHelperImports ( ) {
84+ let specifiers = new Set ( ) ;
85+ let emberTestHelpersImport = root . find ( j . ImportDeclaration , {
86+ source : { value : 'ember-test-helpers' } ,
87+ } ) ;
88+
7789 [ 'render' , 'clearRender' ] . forEach ( type => {
7890 let usages = findTestHelperUsageOf ( root , type ) ;
7991 if ( usages . size ( ) > 0 ) {
8092 specifiers . add ( type ) ;
8193 }
8294 } ) ;
8395
84- emberQUnitImports
85- . get ( 'specifiers' )
86- . replace ( Array . from ( specifiers ) . map ( s => j . importSpecifier ( j . identifier ( s ) ) ) ) ;
96+ if ( specifiers . size > 0 ) {
97+ if ( emberTestHelpersImport . size ( ) > 0 ) {
98+ // collect existing imports
99+ emberTestHelpersImport
100+ . find ( j . ImportSpecifier )
101+ . forEach ( p => specifiers . add ( p . node . imported . name ) )
102+ . remove ( ) ;
103+ } else {
104+ // Add new `import from 'ember-test-helpers'` node
105+ root
106+ . find ( j . ImportDeclaration , { source : { value : 'ember-qunit' } } )
107+ . insertAfter ( j . importDeclaration ( [ ] , j . literal ( 'ember-test-helpers' ) ) ) ;
108+
109+ emberTestHelpersImport = root . find ( j . ImportDeclaration , {
110+ source : { value : 'ember-test-helpers' } ,
111+ } ) ;
112+ }
113+
114+ emberTestHelpersImport . get ( 'specifiers' ) . replace (
115+ Array . from ( specifiers )
116+ . sort ( )
117+ . map ( s => j . importSpecifier ( j . identifier ( s ) ) )
118+ ) ;
119+ }
87120 }
88121
89122 function findTestHelperUsageOf ( collection , property ) {
@@ -500,6 +533,7 @@ module.exports = function(file, api, options) {
500533
501534 moveQUnitImportsFromEmberQUnit ( ) ;
502535 updateToNewEmberQUnitImports ( ) ;
536+ updateEmberTestHelperImports ( ) ;
503537 updateModuleForToNestedModule ( ) ;
504538 updateLookupCalls ( ) ;
505539 updateRegisterCalls ( ) ;
0 commit comments