Skip to content

Commit

Permalink
Merge pull request #1362 from postmanlabs/feat/event-for-skip-request
Browse files Browse the repository at this point in the history
Expose result object in item callback to identify skipped execution.
  • Loading branch information
vedkribhu authored Jan 8, 2024
2 parents b036d4a + 84f7672 commit 4751c80
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased:
new features:
- >-
Add an argument to item callback to identify if the item execution was skipped
7.36.1:
date: 2023-12-20
chores:
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ runner.run(collection, { /* options */ }, function(err, run) {
},

// Called after completion of an Item
item: function (err, cursor, item, visualizer) {
item: function (err, cursor, item, visualizer, result) {
// err, cursor, item: Same as arguments for "beforeItem"

// visualizer: null or object containing visualizer result that looks like this:
Expand All @@ -266,6 +266,13 @@ runner.run(collection, { /* options */ }, function(err, run) {
// -- Processed template
// processedTemplate: <String>
// }

// result: undefined or object containing following properties
// {
// -- True for items skipped using pm.execution.skipRequest
// isSkipped: <Boolean>
// }

},

// Called before running pre-request script(s) (Yes, Runtime supports multiple pre-request scripts!)
Expand Down
2 changes: 1 addition & 1 deletion lib/runner/extensions/item.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ module.exports = {
}

if (shouldSkipExecution) {
this.triggers.item(prereqExecutionError, coords, item);
this.triggers.item(prereqExecutionError, coords, item, null, { isSkipped: true });

return callback && callback.call(this, prereqExecutionError, {
prerequest: prereqExecutions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@ describe('pm.execution.skipRequest: ', function () {
'exception.calledOnce': false
});
});
});

it('should have isSkipped true in item callback', function () {
expect(testrun).to.be.ok;
expect(testrun).to.nested.include({
'item.calledOnce': true
});

expect(testrun.item.getCall(0).args[4]).to.have.property('isSkipped', true);
});
});

describe('when running multiple requests in a collection run', function () {
var testRun,
Expand Down Expand Up @@ -262,6 +270,19 @@ describe('pm.execution.skipRequest: ', function () {
it('should not invoke sendRequest if called after skipRequest', function () {
expect(testRun.request.callCount).to.equal(1);
});

it('should invoke item callback twice', function () {
expect(testRun.item.callCount).to.equal(2);
});

it('should have isSkipped true in item callback for first item', function () {
expect(testRun.item.getCall(0).args[4]).to.have.property('isSkipped', true);
});

it('should not have isSkipped true in item callback for request not containing skipRequest()',
function () {
expect(testRun.item.getCall(1).args[4]).to.be.undefined;
});
});

describe('when invoked from collection script', function () {
Expand Down Expand Up @@ -338,5 +359,14 @@ describe('pm.execution.skipRequest: ', function () {
it('should not have console events from request\'s prerequest script', function () {
expect(testrun.console.callCount).to.equal(0);
});

it('should have isSkipped true in item callback', function () {
expect(testrun).to.be.ok;
expect(testrun).to.nested.include({
'item.calledOnce': true
});

expect(testrun.item.getCall(0).args[4]).to.have.property('isSkipped', true);
});
});
});

0 comments on commit 4751c80

Please sign in to comment.