Skip to content

Commit

Permalink
Merge branch 'release/4.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Mar 13, 2024
2 parents 802b31b + 3a99370 commit 28b1648
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 140 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
4.6.0:
date: 2024-03-13
fixed bugs:
- GH-981 Dropped support for legacy sandbox APIs in packages
- GH-985 Fixed the error message shown when there is an error in packages
new features:
- |
GH-984 Added `pm.execution.setNextRequest` API, similar to legacy
`postman.setNextRequest`
chores:
- Updated dependencies

4.5.1:
date: 2024-03-12
chores:
Expand Down
12 changes: 7 additions & 5 deletions lib/sandbox/pm-require.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const MODULE_KEY = '__module_obj', // why not use `module`?
const { LEGACY_GLOBS } = require('./postman-legacy-interface'),

MODULE_KEY = '__module_obj', // why not use `module`?
MODULE_WRAPPER = [
'(function (exports, module) {\n',
`\n})(${MODULE_KEY}.exports, ${MODULE_KEY});`
Expand Down Expand Up @@ -115,11 +117,11 @@ function createPostmanRequire (fileCache, scope) {
if (!path) {
// Error should contain the name exactly as the user specified,
// and not the resolved path.
throw new Error(`Cannot find module '${name}'`);
throw new Error(`Cannot find package '${name}'`);
}

if (store.hasError(path)) {
throw new Error(`Error while loading module '${name}': ${store.getFileError(path)}`);
throw new Error(`Error while loading package '${name}': ${store.getFileError(path)}`);
}

// Any module should not be evaluated twice, so we use it from the
Expand Down Expand Up @@ -158,10 +160,10 @@ function createPostmanRequire (fileCache, scope) {
//
// Why `async` = true?
// - We want to allow execution of async code like setTimeout etc.
scope.exec(wrappedModule, true, (err) => {
scope.exec(wrappedModule, { async: true, block: LEGACY_GLOBS }, (err) => {
// Bubble up the error to be caught as execution error
if (err) {
throw err;
throw new Error(`Error in package '${name}': ${err.message ? err.message : err}`);
}
});

Expand Down
13 changes: 12 additions & 1 deletion lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,18 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore,
* @type {string}
*/
current: execution.legacy._eventItemName
})
}),

/**
* Sets the next request to be run after the current request, when
* running the collection. Passing `null` stops the collection run
* after the current request is executed.
*
* @param {string|null} request - name of the request to run next
*/
setNextRequest: function setNextRequest (request) {
execution.return && (execution.return.nextRequest = request);
}
},

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/sandbox/postman-legacy-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const _ = require('lodash'),
'tests', 'globals', 'environment', 'data', 'request', 'responseCookies', 'responseHeaders', 'responseTime',
'responseCode', 'responseBody', 'iteration', 'postman',
// scope libraries
'JSON', '_', 'CryptoJS', 'atob', 'btoa', 'tv4', 'xml2Json', 'Backbone', 'cheerio'
'_', 'CryptoJS', 'atob', 'btoa', 'tv4', 'xml2Json', 'Backbone', 'cheerio'
// 'JSON', // removing JSON from the list since it is a standard JS object
],

E = '',
Expand Down Expand Up @@ -416,5 +417,7 @@ module.exports = {
}

raiseAssertionEvent(scope, pmapi, onAssertion);
}
},

LEGACY_GLOBS
};

0 comments on commit 28b1648

Please sign in to comment.