From aad1b7614d11cbce6eab2a11fd77cf349529e73c Mon Sep 17 00:00:00 2001 From: Appurva Murawat Date: Sat, 18 Nov 2023 13:43:32 +0530 Subject: [PATCH] Refactor `pm.execution.location` --- CHANGELOG.yaml | 2 +- lib/sandbox/execution-location.js | 17 ----------------- lib/sandbox/pmapi.js | 23 ++++++++++++----------- types/sandbox/prerequest.d.ts | 4 ++-- types/sandbox/test.d.ts | 4 ++-- 5 files changed, 17 insertions(+), 33 deletions(-) delete mode 100644 lib/sandbox/execution-location.js diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 789fbf47..67b60de7 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -1,6 +1,6 @@ unreleased: new features: - - GH-950 Added support for pm.execution.location + - GH-950 Added support for `pm.execution.location` 4.3.0: date: 2023-11-02 diff --git a/lib/sandbox/execution-location.js b/lib/sandbox/execution-location.js deleted file mode 100644 index 195a57e5..00000000 --- a/lib/sandbox/execution-location.js +++ /dev/null @@ -1,17 +0,0 @@ -class ExecutionLocation extends Array { - /** - * - * @param {string} current - Current item name, current item is the item whose script is being executed - * @param {string} rest - Arguments to pass to Array constructor - */ - constructor (current, ...rest) { - super(...rest); - this._current = current; - } - - get current () { - return this._current; - } -} - -module.exports = ExecutionLocation; diff --git a/lib/sandbox/pmapi.js b/lib/sandbox/pmapi.js index 9c297bc7..db514c82 100644 --- a/lib/sandbox/pmapi.js +++ b/lib/sandbox/pmapi.js @@ -6,7 +6,6 @@ const _ = require('lodash'), PostmanResponse = sdk.Response, PostmanCookieList = sdk.CookieList, chai = require('chai'), - ExecutionLocation = require('./execution-location'), /** * Use this function to assign readonly properties to an object @@ -273,23 +272,25 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore, skipRequest: onSkipRequest, /** - * @interface ExecutionLocationInterface + * @interface ExecutionLocation * @extends Array */ - /** - * The element name whose script is currently being executed. - * - * @name ExecutionLocationInterface#current - * @type {string} - */ + /** * The path of the current request. * - * @type {ExecutionLocationInterface} - current execution path + * @type {ExecutionLocation} - current execution path * @instance */ - location: new ExecutionLocation(execution.legacy._eventItemName, - ...(execution.legacy._itemPath || [])) + location: _assignDefinedReadonly(execution.legacy._itemPath || [], /** @lends ExecutionLocation */ { + /** + * The item name whose script is currently being executed. + * + * @instance + * @type {string} + */ + current: execution.legacy._eventItemName + }) } }, options.disabledAPIs); diff --git a/types/sandbox/prerequest.d.ts b/types/sandbox/prerequest.d.ts index 7d207a56..c838d845 100644 --- a/types/sandbox/prerequest.d.ts +++ b/types/sandbox/prerequest.d.ts @@ -115,10 +115,10 @@ declare interface Execution { /** * The path of the current request. */ - location: ExecutionLocationInterface; + location: ExecutionLocation; } -declare interface ExecutionLocationInterface extends Array { +declare interface ExecutionLocation extends Array { /** * The element name whose script is currently being executed. */ diff --git a/types/sandbox/test.d.ts b/types/sandbox/test.d.ts index a260b046..f4d514f0 100644 --- a/types/sandbox/test.d.ts +++ b/types/sandbox/test.d.ts @@ -116,10 +116,10 @@ declare interface Execution { /** * The path of the current request. */ - location: ExecutionLocationInterface; + location: ExecutionLocation; } -declare interface ExecutionLocationInterface extends Array { +declare interface ExecutionLocation extends Array { /** * The element name whose script is currently being executed. */