@@ -198,6 +198,73 @@ describe('dependencies', () => {
198198 . to . have . been . calledOnceWith ( config , application , host , 'app-dependencies-loaded' , expectedDependencies )
199199 } )
200200
201+ it ( 'should include two dependencies when they are in different paths' , ( ) => {
202+ const moduleName = 'custom-module'
203+ const packageVersion = '1.0.0'
204+ const nestedPackageVersion = '0.5.0'
205+ const firstLevelDependency = [ fileURIWithoutNodeModules , 'node_modules' , moduleName , 'index1.js' ] . join ( '/' )
206+ const nestedDependency =
207+ [ fileURIWithoutNodeModules , 'node_modules' , 'dependency' , 'node_modules' , moduleName , 'index1.js' ] . join ( '/' )
208+
209+ requirePackageJson . callsFake ( function ( dependencyPath ) {
210+ if ( dependencyPath . includes ( path . join ( 'node_modules' , 'dependency' , 'node_modules' ) ) ) {
211+ return { version : nestedPackageVersion }
212+ } else {
213+ return { version : packageVersion }
214+ }
215+ } )
216+
217+ dependencies . start ( config , application , host )
218+ moduleLoadStartChannel . publish ( { request : moduleName , filename : firstLevelDependency } )
219+ moduleLoadStartChannel . publish ( { request : moduleName , filename : nestedDependency } )
220+
221+ const expectedDependencies1 = {
222+ dependencies : [
223+ { name : moduleName , version : packageVersion }
224+ ]
225+ }
226+ const expectedDependencies2 = {
227+ dependencies : [
228+ { name : moduleName , version : nestedPackageVersion }
229+ ]
230+ }
231+ expect ( sendData ) . to . have . been . calledTwice
232+
233+ expect ( sendData . firstCall )
234+ . to . have . been . calledWith ( config , application , host , 'app-dependencies-loaded' , expectedDependencies1 )
235+
236+ expect ( sendData . secondCall )
237+ . to . have . been . calledWith ( config , application , host , 'app-dependencies-loaded' , expectedDependencies2 )
238+ } )
239+
240+ it ( 'should include only one dependency when they are in different paths but the version number is the same' , ( ) => {
241+ const moduleName = 'custom-module'
242+ const packageVersion = '1.0.0'
243+ const firstLevelDependency = [ fileURIWithoutNodeModules , 'node_modules' , moduleName , 'index1.js' ] . join ( '/' )
244+ const nestedDependency =
245+ [ fileURIWithoutNodeModules , 'node_modules' , 'dependency' , 'node_modules' , moduleName , 'index1.js' ] . join ( '/' )
246+
247+ requirePackageJson . callsFake ( function ( dependencyPath ) {
248+ if ( dependencyPath . includes ( path . join ( 'node_modules' , 'dependency' , 'node_modules' ) ) ) {
249+ return { version : packageVersion }
250+ } else {
251+ return { version : packageVersion }
252+ }
253+ } )
254+
255+ dependencies . start ( config , application , host )
256+ moduleLoadStartChannel . publish ( { request : moduleName , filename : firstLevelDependency } )
257+ moduleLoadStartChannel . publish ( { request : moduleName , filename : nestedDependency } )
258+
259+ const expectedDependencies = {
260+ dependencies : [
261+ { name : moduleName , version : packageVersion }
262+ ]
263+ }
264+ expect ( sendData ) . to . have . been
265+ . calledOnceWith ( config , application , host , 'app-dependencies-loaded' , expectedDependencies )
266+ } )
267+
201268 it ( 'should call sendData only once with duplicated dependency' , ( ) => {
202269 const request = 'custom-module'
203270 requirePackageJson . returns ( { version : '1.0.0' } )
0 commit comments