Skip to content

Commit

Permalink
Refactor pm.execution.location
Browse files Browse the repository at this point in the history
  • Loading branch information
appurva21 committed Nov 18, 2023
1 parent f962496 commit 60560f3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 0 additions & 17 deletions lib/sandbox/execution-location.js

This file was deleted.

23 changes: 12 additions & 11 deletions lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -273,23 +272,25 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore,
skipRequest: onSkipRequest,

/**
* @interface ExecutionLocationInterface
* @interface ExecutionLocation
* @extends Array<string>
*/
/**
* 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);

Expand Down
31 changes: 15 additions & 16 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 @@ -68,14 +75,6 @@ declare class PostmanCookieJar {
*/
declare var pm: Postman;

/**
* @param current - Current item name, current item is the item whose script is being executed
* @param rest - Arguments to pass to Array constructor
*/
declare class ExecutionLocation {
constructor(current: string, ...rest: string[]);
}

/**
* @property async - true if the executed script was async, false otherwise
* @property visualizer - visualizer data
Expand All @@ -98,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 @@ -194,12 +193,12 @@ declare interface Execution {
/**
* The path of the current request.
*/
location: ExecutionLocationInterface;
location: ExecutionLocation;
}

declare interface ExecutionLocationInterface extends Array<string> {
declare interface ExecutionLocation extends Array {
/**
* The element name whose script is currently being executed.
* The item name whose script is currently being executed.
*/
current: string;
}
Expand Down Expand Up @@ -247,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
6 changes: 3 additions & 3 deletions types/sandbox/prerequest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ 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.
* The item name whose script is currently being executed.
*/
current: string;
}
Expand Down
6 changes: 3 additions & 3 deletions types/sandbox/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ 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.
* The item name whose script is currently being executed.
*/
current: string;
}
Expand Down

0 comments on commit 60560f3

Please sign in to comment.