@@ -164,7 +164,8 @@ describe("ExternalModule", function() {
164164 // set up
165165 const variableToCheck = "foo" ;
166166 const request = "bar" ;
167- const expected = "if(typeof foo === 'undefined') {var e = new Error(\"Cannot find module \\\"bar\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e;}" ;
167+ const expected = `if(typeof foo === 'undefined') {var e = new Error(\"Cannot find module \\\"bar\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e;}
168+ ` ;
168169
169170 // invoke
170171 const result = externalModule . checkExternalVariable ( variableToCheck , request ) ;
@@ -173,4 +174,62 @@ describe("ExternalModule", function() {
173174 result . should . eql ( expected ) ;
174175 } ) ;
175176 } ) ;
177+
178+ describe ( "#getSourceForAmdOrUmdExternal" , function ( ) {
179+ it ( "looks up a global variable as specified by the id" , function ( ) {
180+ // set up
181+ const id = "someId" ;
182+ const optional = false ;
183+ const expected = "module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;" ;
184+
185+ // invoke
186+ const result = externalModule . getSourceForAmdOrUmdExternal ( id , optional , request ) ;
187+
188+ // check
189+ result . should . eql ( expected ) ;
190+ } ) ;
191+ describe ( "given an optinal check is set" , function ( ) {
192+ it ( "ads a check for the existance of the variable before looking it up" , function ( ) {
193+ // set up
194+ const id = "someId" ;
195+ const optional = true ;
196+ const expected = `if(typeof __WEBPACK_EXTERNAL_MODULE_someId__ === 'undefined') {var e = new Error("Cannot find module \\"some/request\\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
197+ module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;` ;
198+
199+ // invoke
200+ const result = externalModule . getSourceForAmdOrUmdExternal ( id , optional , request ) ;
201+
202+ // check
203+ result . should . eql ( expected ) ;
204+ } ) ;
205+ } ) ;
206+ } ) ;
207+
208+ describe ( "#getSourceForDefaultCase" , function ( ) {
209+ it ( "returns the given request as lookup" , function ( ) {
210+ // set up
211+ const optional = false ;
212+ const expected = "module.exports = some/request;" ;
213+
214+ // invoke
215+ const result = externalModule . getSourceForDefaultCase ( optional , request ) ;
216+
217+ // check
218+ result . should . eql ( expected ) ;
219+ } ) ;
220+ describe ( "given an optinal check is requested" , function ( ) {
221+ it ( "checks for the existance of the request setting it" , function ( ) {
222+ // set up
223+ const optional = true ;
224+ const expected = `if(typeof some/request === 'undefined') {var e = new Error("Cannot find module \\"some/request\\""); e.code = 'MODULE_NOT_FOUND'; throw e;}
225+ module.exports = some/request;` ;
226+
227+ // invoke
228+ const result = externalModule . getSourceForDefaultCase ( optional , request ) ;
229+
230+ // check
231+ result . should . eql ( expected ) ;
232+ } ) ;
233+ } ) ;
234+ } ) ;
176235} ) ;
0 commit comments