@@ -7,12 +7,6 @@ const _ = require('lodash'),
77 PostmanCookieList = sdk . CookieList ,
88 chai = require ( 'chai' ) ,
99
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-
1610 /**
1711 * Use this function to assign readonly properties to an object
1812 *
@@ -53,12 +47,11 @@ const _ = require('lodash'),
5347 * @param {Function } onSkipRequest - callback to execute when pm.execution.skipRequest() called
5448 * @param {Function } onAssertion - callback to execute when pm.expect() called
5549 * @param {Object } cookieStore - cookie store
56- * @param {Object } requireStore - require store
57- * @param {Object } scope - scope
50+ * @param {Function } require - require
5851 * @param {Object } [options] - options
5952 * @param {Array.<String> } [options.disabledAPIs] - list of disabled APIs
6053 */
61- function Postman ( execution , onRequest , onSkipRequest , onAssertion , cookieStore , requireStore , scope , options = { } ) {
54+ function Postman ( execution , onRequest , onSkipRequest , onAssertion , cookieStore , require , options = { } ) {
6255 // @todo - ensure runtime passes data in a scope format
6356 let iterationData = new VariableScope ( ) ;
6457
@@ -301,59 +294,7 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore,
301294 } )
302295 } ,
303296
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
357298 } , options . disabledAPIs ) ;
358299
359300 // extend pm api with test runner abilities
0 commit comments