diff --git a/lib/sandbox/pmapi.js b/lib/sandbox/pmapi.js index 06b0f01e..6da94dcd 100644 --- a/lib/sandbox/pmapi.js +++ b/lib/sandbox/pmapi.js @@ -353,6 +353,22 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore, current: execution.legacy._eventItemName }), + /** + * The path of the current request by Ids + * + * @instance + * @type {Array} + */ + locationIds: _assignDefinedReadonly(execution.legacy._itemPathIds || [], /** @lends ExecutionLocation */ { + /** + * The item id whose script is currently being executed. + * + * @instance + * @type {string} + */ + current: execution.legacy._itemId + }), + /** * Sets the next request to be run after the current request, when * running the collection. Passing `null` stops the collection run diff --git a/test/unit/sandbox-libraries/pm.test.js b/test/unit/sandbox-libraries/pm.test.js index 453dd11a..84093157 100644 --- a/test/unit/sandbox-libraries/pm.test.js +++ b/test/unit/sandbox-libraries/pm.test.js @@ -1280,6 +1280,42 @@ describe('sandbox library - pm api', function () { }); }); + describe('.locationIds', function () { + it('should return the correct path of the request', function (done) { + context.execute({ + script: ` + var assert = require('assert'); + assert.deepEqual(Array.from(pm.execution.locationIds), ['collection-id', 'request-id']); + ` }, { + legacy: { + _itemName: 'request-name', + _itemId: 'request-id', + _itemPath: ['C1', 'R1'], + _itemPathIds: ['collection-id', 'request-id'], + _eventItemName: 'R1' + } + }, done); + }); + + describe('.current ', function () { + it('should return the correct current item', function (done) { + context.execute({ + script: ` + var assert = require('assert'); + assert.deepEqual(pm.execution.locationIds.current, 'request-id'); + ` }, { + legacy: { + _itemName: 'request-name', + _itemId: 'request-id', + _itemPath: ['C1', 'R1'], + _itemPathIds: ['collection-id', 'request-id'], + _eventItemName: 'R1' + } + }, done); + }); + }); + }); + describe('.setNextRequest', function () { it('should have the next request in result.nextRequest', function (done) { context.execute({ diff --git a/types/index.d.ts b/types/index.d.ts index 69e94f45..37085f84 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -292,6 +292,10 @@ declare interface Execution { * The path of the current request. */ location: ExecutionLocation; + /** + * The path of the current request by Ids + */ + locationIds: ExecutionLocation; /** * Sets the next request to be run after the current request, when * running the collection. Passing `null` stops the collection run @@ -303,7 +307,7 @@ declare interface Execution { declare interface ExecutionLocation extends Array { /** - * The item name whose script is currently being executed. + * The item name or id whose script is currently being executed. */ current: string; }