diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index bab15a130..38318c0c1 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -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: diff --git a/README.md b/README.md index b73d7c54b..ed21e83b9 100644 --- a/README.md +++ b/README.md @@ -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: @@ -266,6 +266,13 @@ runner.run(collection, { /* options */ }, function(err, run) { // -- Processed template // processedTemplate: // } + + // result: undefined or object containing following properties + // { + // -- True for items skipped using pm.execution.skipRequest + // isSkipped: + // } + }, // Called before running pre-request script(s) (Yes, Runtime supports multiple pre-request scripts!) diff --git a/lib/runner/extensions/item.command.js b/lib/runner/extensions/item.command.js index dee675ece..0fe36cf91 100644 --- a/lib/runner/extensions/item.command.js +++ b/lib/runner/extensions/item.command.js @@ -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 diff --git a/test/integration/request-flow/skip-execution-from-sandbox.test.js b/test/integration/request-flow/skip-execution-from-sandbox.test.js index 4a499c07b..0b316c595 100644 --- a/test/integration/request-flow/skip-execution-from-sandbox.test.js +++ b/test/integration/request-flow/skip-execution-from-sandbox.test.js @@ -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, @@ -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 () { @@ -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); + }); }); });