@@ -7,12 +7,6 @@ const _ = require('lodash'),
7
7
PostmanCookieList = sdk . CookieList ,
8
8
chai = require ( 'chai' ) ,
9
9
10
- MODULE_KEY = '__module_obj' , // why not use `module`?
11
- MODULE_WRAPPER = [
12
- '(function (exports, module) {\n' ,
13
- `\n})(${ MODULE_KEY } .exports, ${ MODULE_KEY } );`
14
- ] ,
15
-
16
10
/**
17
11
* Use this function to assign readonly properties to an object
18
12
*
@@ -53,12 +47,11 @@ const _ = require('lodash'),
53
47
* @param {Function } onSkipRequest - callback to execute when pm.execution.skipRequest() called
54
48
* @param {Function } onAssertion - callback to execute when pm.expect() called
55
49
* @param {Object } cookieStore - cookie store
56
- * @param {Object } requireStore - require store
57
- * @param {Object } scope - scope
50
+ * @param {Function } require - require
58
51
* @param {Object } [options] - options
59
52
* @param {Array.<String> } [options.disabledAPIs] - list of disabled APIs
60
53
*/
61
- function Postman ( execution , onRequest , onSkipRequest , onAssertion , cookieStore , requireStore , scope , options = { } ) {
54
+ function Postman ( execution , onRequest , onSkipRequest , onAssertion , cookieStore , require , options = { } ) {
62
55
// @todo - ensure runtime passes data in a scope format
63
56
let iterationData = new VariableScope ( ) ;
64
57
@@ -301,59 +294,7 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore,
301
294
} )
302
295
} ,
303
296
304
- require : function require ( name ) {
305
- const path = requireStore . getResolvedPath ( name ) ;
306
-
307
- this . cache = this . cache || { } ;
308
-
309
- // Always use the resolved path as the ID of the module. This
310
- // ensures that relative paths are handled correctly.
311
- if ( this . cache [ path ] ) {
312
- return this . cache [ path ] . exports ;
313
- }
314
-
315
- const file = path && requireStore . getFileData ( path ) ;
316
-
317
- if ( ! file ) {
318
- // Error should contain the name exactly as the user specified.
319
- throw new Error ( `Cannot find module '${ name } '` ) ;
320
- }
321
-
322
- const moduleObj = {
323
- id : path ,
324
- exports : { }
325
- } ;
326
-
327
- // Add to cache before executing. This ensures that any dependency
328
- // that tries to import it's parent/ancestor gets the cached
329
- // version and not end up in infinite loop.
330
- this . cache [ moduleObj . id ] = moduleObj ;
331
-
332
- const wrappedModule = MODULE_WRAPPER [ 0 ] + file + MODULE_WRAPPER [ 1 ] ;
333
-
334
- scope . import ( {
335
- [ MODULE_KEY ] : moduleObj
336
- } ) ;
337
-
338
- // Note: We're executing the code in the same scope as the one
339
- // which called the `pm.require` function. This is because we want
340
- // to share the global scope across all the required modules. Any
341
- // locals are available inside the required modules and any locals
342
- // created inside the required modules are available to the parent.
343
- //
344
- // Why `async` = true?
345
- // - We want to allow execution of async code like setTimeout etc.
346
- scope . exec ( wrappedModule , true , ( err ) => {
347
- // Bubble up the error to be caught as execution error
348
- if ( err ) {
349
- throw err ;
350
- }
351
- } ) ;
352
-
353
- scope . unset ( MODULE_KEY ) ;
354
-
355
- return moduleObj . exports ;
356
- }
297
+ require : require
357
298
} , options . disabledAPIs ) ;
358
299
359
300
// extend pm api with test runner abilities
0 commit comments