Skip to content

Commit f3b3a64

Browse files
committed
Add support for pm.connection and pm.message
1 parent 2759dd3 commit f3b3a64

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lib/sandbox/execute.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ module.exports = function (bridge, glob) {
138138

139139
bridge.dispatch(assertionEventName, options.cursor, assertions);
140140
bridge.dispatch(EXECUTION_ASSERTION_EVENT, options.cursor, assertions);
141+
},
142+
143+
// TODO: Handle timers
144+
dispatchConnectionEvents = {
145+
sendMessage (...args) {
146+
bridge.dispatch('connection.sendMessage.' + id, ...args);
147+
},
148+
close (...args) {
149+
bridge.dispatch('connection.close.' + id, ...args);
150+
}
141151
};
142152

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

216226
bridge.dispatch(executionRequestEventName, options.cursor, id, eventId, request);
217-
}, dispatchAssertions, new PostmanCookieStore(id, bridge, timers), {
227+
}, dispatchAssertions, dispatchConnectionEvents,
228+
new PostmanCookieStore(id, bridge, timers), {
218229
disabledAPIs: initializationOptions.disabledAPIs
219230
})
220231
),

lib/sandbox/execution.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ class Execution {
4242
});
4343

4444
if (options.initializeExecution) {
45-
const { request, response } = options.initializeExecution(this.target, context) || {};
45+
const { request, response, message } = options.initializeExecution(this.target, context) || {};
4646

4747
this.request = request;
4848
this.response = response;
49+
this.message = message;
4950
}
5051
else {
5152
if (TARGETS_WITH_REQUEST[this.target] || _.has(context, PROPERTY.REQUEST)) {

lib/sandbox/pmapi.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ const _ = require('lodash'),
4545
* @param {Execution} execution -
4646
* @param {Function} onRequest -
4747
* @param {Function} onAssertion -
48+
* @param {Object} onConnection -
4849
* @param {Object} cookieStore -
4950
* @param {Object} [options] -
5051
* @param {Array.<String>} [options.disabledAPIs] -
5152
*/
52-
function Postman (execution, onRequest, onAssertion, cookieStore, options = {}) {
53+
function Postman (execution, onRequest, onAssertion, onConnection, cookieStore, options = {}) {
5354
// @todo - ensure runtime passes data in a scope format
5455
let iterationData = new VariableScope();
5556

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

171+
message: execution.message,
172+
170173
/**
171174
* The cookies object contains a list of cookies that are associated with the domain
172175
* to which the request was made.
@@ -250,7 +253,9 @@ function Postman (execution, onRequest, onAssertion, cookieStore, options = {})
250253
});
251254

252255
return self;
253-
}
256+
},
257+
258+
connection: onConnection
254259
}, options.disabledAPIs);
255260

256261
// extend pm api with test runner abilities

0 commit comments

Comments
 (0)