Skip to content

Commit

Permalink
Add require to disabledAPIs if no resolvedPackages
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Feb 21, 2024
1 parent acb1ca5 commit fa4eec8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 9 additions & 3 deletions lib/sandbox/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ module.exports = function (bridge, glob) {
// create the execution object
execution = new Execution(id, event, context, { ...options, initializeExecution }),

disabledAPIs = [
...(initializationOptions.disabledAPIs || [])
],

/**
* Dispatch assertions from `pm.test` or legacy `test` API.
*
Expand Down Expand Up @@ -206,6 +210,10 @@ module.exports = function (bridge, glob) {
timers.clearEvent(id, err, res);
});

if (!options.resolvedPackages) {
disabledAPIs.push('require');
}

// send control to the function that executes the context and prepares the scope
executeContext(scope, code, execution,
// if a console is sent, we use it. otherwise this also prevents erroneous referencing to any console
Expand All @@ -230,9 +238,7 @@ module.exports = function (bridge, glob) {
dispatchAssertions,
new PostmanCookieStore(id, bridge, timers),
createPostmanRequire(options.resolvedPackages, scope),
{
disabledAPIs: initializationOptions.disabledAPIs
})
{ disabledAPIs })
),
dispatchAssertions,
{ disableLegacyAPIs: initializationOptions.disableLegacyAPIs });
Expand Down
6 changes: 1 addition & 5 deletions lib/sandbox/pm-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ class PostmanRequireStore {
* console.log(module.foo); // bar
*/
function createPostmanRequire (fileCache, scope) {
if (!fileCache) {
return;
}

const store = new PostmanRequireStore(fileCache),
const store = new PostmanRequireStore(fileCache || {}),
cache = {};

/**
Expand Down
10 changes: 7 additions & 3 deletions lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,14 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore,
},

/**
* @param {String} name - name
* @returns {any} - module
* Imports a package in the script.
*
* @param {String} name - name of the module
* @returns {any} - exports from the module
*/
require: requireFn
require: function (name) {
return requireFn(name);
}
}, options.disabledAPIs);

// extend pm api with test runner abilities
Expand Down

0 comments on commit fa4eec8

Please sign in to comment.