From cbff50a7c02fce321a02d32c9c6e5c052179718b Mon Sep 17 00:00:00 2001 From: Jonathan Haviv <53003885+jonathanhaviv@users.noreply.github.com> Date: Wed, 19 Mar 2025 15:21:02 -0700 Subject: [PATCH 1/2] Adding pm.execution.location --- lib/sandbox/pmapi.js | 16 ++++++++++++++++ types/index.d.ts | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/sandbox/pmapi.js b/lib/sandbox/pmapi.js index 06b0f01e..eab71ec9 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} + */ + locationByIds: _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/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; } From c20b1070ff9942e50d6f9385cb65cf8ac16e8d67 Mon Sep 17 00:00:00 2001 From: Jonathan Haviv <53003885+jonathanhaviv@users.noreply.github.com> Date: Wed, 19 Mar 2025 15:24:51 -0700 Subject: [PATCH 2/2] Rename `locationByIds` to `locationIds` in pmapi.js and add unit tests for the new property in pm.test.js. --- lib/sandbox/pmapi.js | 2 +- test/unit/sandbox-libraries/pm.test.js | 36 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/sandbox/pmapi.js b/lib/sandbox/pmapi.js index eab71ec9..6da94dcd 100644 --- a/lib/sandbox/pmapi.js +++ b/lib/sandbox/pmapi.js @@ -359,7 +359,7 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore, * @instance * @type {Array} */ - locationByIds: _assignDefinedReadonly(execution.legacy._itemPathIds || [], /** @lends ExecutionLocation */ { + locationIds: _assignDefinedReadonly(execution.legacy._itemPathIds || [], /** @lends ExecutionLocation */ { /** * The item id whose script is currently being executed. * 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({