Skip to content

Commit

Permalink
chore: add channel-beta postman collection dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
vedkribhu committed Sep 1, 2023
1 parent 5e890c2 commit 38e4243
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/sandbox/execute-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ module.exports = function (scope, code, execution, console, timers, pmapi, onAss
});

scope.exec(code, function (err) {
if (err && err.message === 'Execution Skipped') {
// If execution was skipped, we don't want to throw an error to user.
// The error was thrown by the sandbox itself to abort execution. We simply
// terminate the execution here by ignoring the error.
err = null;
}

// we check if the execution went async by determining the timer queue length at this time
execution.return.async = (timers.queueLength() > 0);

Expand Down
8 changes: 7 additions & 1 deletion lib/sandbox/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ module.exports = function (bridge, glob) {
var eventId = timers.setEvent(callback);

bridge.dispatch(executionRequestEventName, options.cursor, id, eventId, request);
}, dispatchAssertions, new PostmanCookieStore(id, bridge, timers), {
}, function () {
execution.shouldSkipExecution = true;

timers.terminate(null, true);
throw new Error('Execution Skipped');
},
dispatchAssertions, new PostmanCookieStore(id, bridge, timers), {
disabledAPIs: initializationOptions.disabledAPIs
})
),
Expand Down
1 change: 1 addition & 0 deletions lib/sandbox/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Execution {
this.id = id;
this.target = event.listen || PROPERTY.SCRIPT;
this.legacy = options.legacy || {};
this.shouldSkipExecution = false;
this.cursor = _.isObject(options.cursor) ? options.cursor : {};

this.data = _.get(context, PROPERTY.DATA, {});
Expand Down
8 changes: 7 additions & 1 deletion lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ const _ = require('lodash'),
*
* @param {Execution} execution -
* @param {Function} onRequest -
* @param {Function} onSkipRequest - callback to execute when pm.skipRequest called
* @param {Function} onAssertion -
* @param {Object} cookieStore -
* @param {Object} [options] -
* @param {Array.<String>} [options.disabledAPIs] -
*/
function Postman (execution, onRequest, onAssertion, cookieStore, options = {}) {
function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore, options = {}) {
// @todo - ensure runtime passes data in a scope format
let iterationData = new VariableScope();

Expand Down Expand Up @@ -250,7 +251,12 @@ function Postman (execution, onRequest, onAssertion, cookieStore, options = {})
});

return self;
},

skipRequest: function () {
onSkipRequest();
}

}, options.disabledAPIs);

// extend pm api with test runner abilities
Expand Down

0 comments on commit 38e4243

Please sign in to comment.