Skip to content

Commit

Permalink
Merge branch 'release/4.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Nov 18, 2023
2 parents 2f85c31 + 0b22f3f commit d8d4062
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 37 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
4.4.0:
date: 2023-11-18
new features:
- GH-950 Added support for `pm.execution.location`
chores:
- Updated dependencies

4.3.0:
date: 2023-11-02
new features:
Expand Down
23 changes: 22 additions & 1 deletion lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,28 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore,
* @excludeFromTestScript
* @instance
*/
skipRequest: onSkipRequest
skipRequest: onSkipRequest,

/**
* @interface ExecutionLocation
* @extends Array<string>
*/

/**
* The path of the current request.
*
* @type {ExecutionLocation} - current execution path
* @instance
*/
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);

Expand Down
56 changes: 31 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postman-sandbox",
"version": "4.3.0",
"version": "4.4.0",
"description": "Sandbox for Postman Scripts to run in Node.js or browser",
"author": "Postman Inc.",
"license": "Apache-2.0",
Expand Down Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"lodash": "4.17.21",
"postman-collection": "4.2.1",
"postman-collection": "4.3.0",
"teleport-javascript": "1.0.0",
"uvm": "2.1.1"
},
Expand All @@ -52,7 +52,7 @@
"@postman/tough-cookie": "4.1.3-postman.1",
"ajv": "6.12.5",
"assert": "2.0.0",
"async": "^3.2.4",
"async": "^3.2.5",
"atob": "2.1.2",
"backbone": "1.5.0",
"browserify": "^16.5.2",
Expand Down Expand Up @@ -89,7 +89,7 @@
"shelljs": "^0.8.5",
"sinon": "^12.0.1",
"sinon-chai": "^3.7.0",
"terser": "^5.22.0",
"terser": "^5.24.0",
"tsd-jsdoc": "^2.5.0",
"tv4": "1.3.0",
"uniscope": "2.0.1",
Expand Down
34 changes: 34 additions & 0 deletions test/unit/sandbox-libraries/pm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,5 +1087,39 @@ describe('sandbox library - pm api', function () {
});
});
});

describe('.location', 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.location), ['C1', 'R1']);
` }, {
legacy: {
_itemName: 'request-name',
_itemId: 'request-id',
_itemPath: ['C1', 'R1'],
_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.location.current, 'R1');
` }, {
legacy: {
_itemName: 'request-name',
_itemId: 'request-id',
_itemPath: ['C1', 'R1'],
_eventItemName: 'R1'
}
}, done);
});
});
});
});
});
28 changes: 23 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// Type definitions for postman-sandbox 4.3.0
// Project: https://github.com/postmanlabs/postman-sandbox
// Definitions by: PostmanLabs
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="node" />

declare const CONSOLE_EVENT = "execution.console";

/**
* List of functions that we expect and create for console
*/
declare const logLevels: String[];
declare const logLevels: string[];

/**
* Replacer to be used with teleport-javascript to handle cases which are not
Expand Down Expand Up @@ -90,7 +97,7 @@ declare type Return = {
*/
declare class Postman {
constructor(execution: Execution, onRequest: (...params: any[]) => any, onSkipRequest: (...params: any[]) => any, onAssertion: (...params: any[]) => any, cookieStore: any, options?: {
disabledAPIs?: String[];
disabledAPIs?: string[];
});
/**
* The pm.info object contains information pertaining to the script being executed.
Expand Down Expand Up @@ -183,6 +190,17 @@ declare interface Execution {
* Stops the current request and its scripts from executing.
*/
skipRequest(): void;
/**
* The path of the current request.
*/
location: ExecutionLocation;
}

declare interface ExecutionLocation extends Array {
/**
* The item name whose script is currently being executed.
*/
current: string;
}

/**
Expand Down Expand Up @@ -228,19 +246,19 @@ declare var SandboxGlobals: any;
* The set of timer function names. We use this array to define common behaviour of all setters and clearer timer
* functions
*/
declare const timerFunctionNames: String[];
declare const timerFunctionNames: string[];

/**
* This object defines a set of timer function names that are trigerred a number of times instead of a single time.
* Such timers, when placed in generic rules, needs special attention.
*/
declare const multiFireTimerFunctions: Boolean[];
declare const multiFireTimerFunctions: boolean[];

/**
* This object defines a set of function timer names that do not fire based on any pre-set duration or interval.
* Such timers, when placed in generic rules, needs special attention.
*/
declare const staticTimerFunctions: Boolean[];
declare const staticTimerFunctions: boolean[];

/**
* A local copy of Slice function of Array
Expand Down
13 changes: 12 additions & 1 deletion types/sandbox/prerequest.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for postman-sandbox 4.2.8
// Type definitions for postman-sandbox 4.3.0
// Project: https://github.com/postmanlabs/postman-sandbox
// Definitions by: PostmanLabs
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down Expand Up @@ -112,6 +112,17 @@ declare interface Execution {
* @excludeFromTestScript
*/
skipRequest(): void;
/**
* The path of the current request.
*/
location: ExecutionLocation;
}

declare interface ExecutionLocation extends Array {
/**
* The item name whose script is currently being executed.
*/
current: string;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion types/sandbox/test.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for postman-sandbox 4.2.8
// Type definitions for postman-sandbox 4.3.0
// Project: https://github.com/postmanlabs/postman-sandbox
// Definitions by: PostmanLabs
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down Expand Up @@ -113,6 +113,17 @@ declare interface Visualizer {
}

declare interface Execution {
/**
* The path of the current request.
*/
location: ExecutionLocation;
}

declare interface ExecutionLocation extends Array {
/**
* The item name whose script is currently being executed.
*/
current: string;
}

/**
Expand Down

0 comments on commit d8d4062

Please sign in to comment.