@@ -16,6 +16,8 @@ const mockApi = {
16
16
return '../__tests__/mock_package.json'
17
17
} else if ( path . match ( './node_modules/mockExternal/package.json' ) ) {
18
18
return 'mockExternalPath'
19
+ } else if ( path . match ( 'customNodeModulesPath/mockExternal/package.json' ) ) {
20
+ return 'customExternalPath'
19
21
} else if ( path . match ( './node_modules/mockExternal/index.js' ) ) {
20
22
return 'mockExternalIndex'
21
23
}
@@ -131,7 +133,7 @@ describe.each(['production', 'development'])('getExternals in %s', env => {
131
133
// Mock dep's package.json
132
134
const { readFileSync : realReadFileSync } = fs
133
135
fs . readFileSync = jest . fn ( ( path , ...args ) => {
134
- if ( path === 'mockExternalPath' ) {
136
+ if ( path === 'mockExternalPath' || path === 'customExternalPath' ) {
135
137
return JSON . stringify ( modulePkg )
136
138
}
137
139
// Don't effect other calls
@@ -187,4 +189,13 @@ describe.each(['production', 'development'])('getExternals in %s', env => {
187
189
)
188
190
expect ( externals ) . toBeUndefined ( )
189
191
} )
192
+
193
+ test ( "Dep's package.json is read from nodeModulesPath" , async ( ) => {
194
+ await mockGetExternals ( { } , { nodeModulesPath : 'customNodeModulesPath' } )
195
+
196
+ // App's package.json is read from custom path
197
+ expect ( fs . readFileSync ) . toBeCalledWith ( `customExternalPath` )
198
+ // Not read from default path
199
+ expect ( fs . readFileSync ) . not . toBeCalledWith ( `mockExternalPath` )
200
+ } )
190
201
} )
0 commit comments