Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pm.connection and pm.message #923

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/sandbox/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ module.exports = function (bridge, glob) {

bridge.dispatch(assertionEventName, options.cursor, assertions);
bridge.dispatch(EXECUTION_ASSERTION_EVENT, options.cursor, assertions);
},

// TODO: Handle timers
dispatchConnectionEvents = {
sendMessage (...args) {
bridge.dispatch('connection.sendMessage.' + id, ...args);
},
close (...args) {
bridge.dispatch('connection.close.' + id, ...args);
}
};

let waiting,
Expand Down Expand Up @@ -214,7 +224,8 @@ module.exports = function (bridge, glob) {
var eventId = timers.setEvent(callback);

bridge.dispatch(executionRequestEventName, options.cursor, id, eventId, request);
}, dispatchAssertions, new PostmanCookieStore(id, bridge, timers), {
}, dispatchAssertions, dispatchConnectionEvents,
new PostmanCookieStore(id, bridge, timers), {
disabledAPIs: initializationOptions.disabledAPIs
})
),
Expand Down
3 changes: 2 additions & 1 deletion lib/sandbox/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class Execution {
});

if (options.initializeExecution) {
const { request, response } = options.initializeExecution(this.target, context) || {};
const { request, response, message } = options.initializeExecution(this.target, context) || {};

this.request = request;
this.response = response;
this.message = message;
}
else {
if (TARGETS_WITH_REQUEST[this.target] || _.has(context, PROPERTY.REQUEST)) {
Expand Down
19 changes: 17 additions & 2 deletions lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ const _ = require('lodash'),
* @param {Execution} execution -
* @param {Function} onRequest -
* @param {Function} onAssertion -
* @param {Object} onConnection -
* @param {Object} cookieStore -
* @param {Object} [options] -
* @param {Array.<String>} [options.disabledAPIs] -
*/
function Postman (execution, onRequest, onAssertion, cookieStore, options = {}) {
function Postman (execution, onRequest, onAssertion, onConnection, cookieStore, options = {}) {
// @todo - ensure runtime passes data in a scope format
let iterationData = new VariableScope();

Expand Down Expand Up @@ -167,6 +168,8 @@ function Postman (execution, onRequest, onAssertion, cookieStore, options = {})
*/
response: execution.response,

message: execution.message,

/**
* The cookies object contains a list of cookies that are associated with the domain
* to which the request was made.
Expand Down Expand Up @@ -250,7 +253,9 @@ function Postman (execution, onRequest, onAssertion, cookieStore, options = {})
});

return self;
}
},

connection: onConnection
}, options.disabledAPIs);

// extend pm api with test runner abilities
Expand All @@ -265,6 +270,16 @@ function Postman (execution, onRequest, onAssertion, cookieStore, options = {})
}
});
}

if (this.message) {
// these are removed before serializing see `purse.js`
Object.defineProperty(this.message, 'to', {
get () {
return chai.expect(this).to;
}
});
}

// add request assertions
if (this.request) {
// these are removed before serializing see `purse.js`
Expand Down