Skip to content

Add pm.execution.locationIds #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>}
*/
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
Expand Down
36 changes: 36 additions & 0 deletions test/unit/sandbox-libraries/pm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 5 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
Loading