|
4 | 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
5 | 5 | // TypeScript Version: 2.4 |
6 | 6 | /// <reference types="node" /> |
7 | | -declare var postman: PostmanLegacy; |
| 7 | +import {CookieList, Request, VariableScope} from "postman-collection"; |
| 8 | + |
| 9 | +declare global { |
| 10 | + var postman: PostmanLegacy; |
| 11 | + |
| 12 | + interface PostmanLegacy { |
| 13 | + /*** |
| 14 | + * Sets the next request to be executed. |
| 15 | + * @param requestName Name of the next request to be executed. |
| 16 | + */ |
| 17 | + setNextRequest(requestName: string): void; |
| 18 | + } |
| 19 | + |
| 20 | + class Postman { |
| 21 | + constructor(bridge: EventEmitter, execution: Execution, onRequest: (...params: any[]) => any, cookieStore: any); |
| 22 | + |
| 23 | + /** |
| 24 | + * The pm.info object contains information pertaining to the script being executed. |
| 25 | + * Useful information such as the request name, request Id, and iteration count are |
| 26 | + * stored inside of this object. |
| 27 | + */ |
| 28 | + info: Info; |
| 29 | + globals: VariableScope; |
| 30 | + environment: VariableScope; |
| 31 | + collectionVariables: VariableScope; |
| 32 | + variables: VariableScope; |
| 33 | + /** |
| 34 | + * The iterationData object contains data from the data file provided during a collection run. |
| 35 | + */ |
| 36 | + iterationData: VariableScope; |
| 37 | + /** |
| 38 | + * The request object inside pm is a representation of the request for which this script is being run. |
| 39 | + * For a pre-request script, this is the request that is about to be sent and when in a test script, |
| 40 | + * this is the representation of the request that was sent. |
| 41 | + */ |
| 42 | + request: Request; |
| 43 | + /** |
| 44 | + * The cookies object contains a list of cookies that are associated with the domain |
| 45 | + * to which the request was made. |
| 46 | + */ |
| 47 | + cookies: CookieList; |
| 48 | + visualizer: Visualizer; |
| 49 | + |
| 50 | + /** |
| 51 | + * Allows one to send request from script asynchronously. |
| 52 | + */ |
| 53 | + // TODO: figure out what the correct type is here, both Request from the built in types and from postman-collection |
| 54 | + // seem to be incorrect |
| 55 | + sendRequest(req: unknown | string, callback: (...params: any[]) => any): void; |
| 56 | + |
| 57 | + // TODO: import this type instead of relying on ambient module augmentation. this would require a tsconfig.json |
| 58 | + // to explicitly specify global modules in the "types" property, however it doesn't seem to work since there |
| 59 | + // seems to be types for postman-collection defined in both postman-collection and @types/postman-collection |
| 60 | + expect: Chai.ExpectStatic; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Contains information pertaining to the script execution |
| 65 | + */ |
| 66 | + interface Info { |
| 67 | + /** |
| 68 | + * Contains information whether the script being executed is a "prerequest" or a "test" script. |
| 69 | + */ |
| 70 | + eventName: string; |
| 71 | + /** |
| 72 | + * Is the value of the current iteration being run. |
| 73 | + */ |
| 74 | + iteration: number; |
| 75 | + /** |
| 76 | + * Is the total number of iterations that are scheduled to run. |
| 77 | + */ |
| 78 | + iterationCount: number; |
| 79 | + /** |
| 80 | + * The saved name of the individual request being run. |
| 81 | + */ |
| 82 | + requestName: string; |
| 83 | + /** |
| 84 | + * The unique guid that identifies the request being run. |
| 85 | + */ |
| 86 | + requestId: string; |
| 87 | + } |
| 88 | + |
| 89 | + interface Visualizer { |
| 90 | + /** |
| 91 | + * Set visualizer template and its options |
| 92 | + * @param template - visualisation layout in form of template |
| 93 | + * @param [data] - data object to be used in template |
| 94 | + * @param [options] - options to use while processing the template |
| 95 | + */ |
| 96 | + set(template: string, data?: any, options?: any): void; |
| 97 | + |
| 98 | + /** |
| 99 | + * Clear all visualizer data |
| 100 | + */ |
| 101 | + clear(): void; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * The pm object encloses all information pertaining to the script being executed and |
| 106 | + * allows one to access a copy of the request being sent or the response received. |
| 107 | + * It also allows one to get and set environment and global variables. |
| 108 | + */ |
| 109 | + var pm: Postman; |
| 110 | + |
| 111 | + interface PostmanCookieJar { |
| 112 | + /** |
| 113 | + * Get the cookie value with the given name. |
| 114 | + */ |
| 115 | + get(url: string, name: string, callback: (...params: any[]) => any): void; |
| 116 | + |
| 117 | + /** |
| 118 | + * Get all the cookies for the given URL. |
| 119 | + */ |
| 120 | + getAll(url: string, options: any, callback: (...params: any[]) => any): void; |
| 121 | + |
| 122 | + /** |
| 123 | + * Set or update a cookie. |
| 124 | + */ |
| 125 | + set(url: string, name: string | any, value?: string | ((...params: any[]) => any), callback?: (...params: any[]) => any): void; |
| 126 | + |
| 127 | + /** |
| 128 | + * Remove single cookie with the given name. |
| 129 | + */ |
| 130 | + unset(url: string, name: string, callback?: (...params: any[]) => any): void; |
| 131 | + |
| 132 | + /** |
| 133 | + * Remove all the cookies for the given URL. |
| 134 | + */ |
| 135 | + clear(url: string, callback?: (...params: any[]) => any): void; |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + interface Postman { |
| 140 | + test: Test; |
| 141 | + } |
| 142 | + |
| 143 | + interface Test { |
| 144 | + |
| 145 | + /** |
| 146 | + * You can use this function to write test specifications inside either the Pre-request Script or Tests sandbox. |
| 147 | + * Writing tests inside this function allows you to name the test accurately and this function also ensures the |
| 148 | + * rest of the script is not blocked even if there are errors inside the function. |
| 149 | + * @param testName |
| 150 | + * @param specFunction |
| 151 | + */ |
| 152 | + (testName: string, specFunction: Function): void |
| 153 | + |
| 154 | + /** |
| 155 | + * Get the total number tests from a specific location. |
| 156 | + */ |
| 157 | + index(): number, |
| 158 | + |
| 159 | + /** |
| 160 | + * By appending .skip(), you may tell test runner to ignore test case. |
| 161 | + * @param testName |
| 162 | + */ |
| 163 | + skip(testName: string): void |
| 164 | + } |
8 | 165 |
|
9 | | -declare interface PostmanLegacy { |
10 | | - /*** |
11 | | - * Sets the next request to be executed. |
12 | | - * @param requestName Name of the next request to be executed. |
13 | | - */ |
14 | | - setNextRequest(requestName: string): void; |
15 | | -} |
16 | | - |
17 | | -declare class Postman { |
18 | | - constructor(bridge: EventEmitter, execution: Execution, onRequest: (...params: any[]) => any, cookieStore: any); |
19 | | - /** |
20 | | - * The pm.info object contains information pertaining to the script being executed. |
21 | | - * Useful information such as the request name, request Id, and iteration count are |
22 | | - * stored inside of this object. |
23 | | - */ |
24 | | - info: Info; |
25 | | - globals: import("postman-collection").VariableScope; |
26 | | - environment: import("postman-collection").VariableScope; |
27 | | - collectionVariables: import("postman-collection").VariableScope; |
28 | | - variables: import("postman-collection").VariableScope; |
29 | | - /** |
30 | | - * The iterationData object contains data from the data file provided during a collection run. |
31 | | - */ |
32 | | - iterationData: import("postman-collection").VariableScope; |
33 | | - /** |
34 | | - * The request object inside pm is a representation of the request for which this script is being run. |
35 | | - * For a pre-request script, this is the request that is about to be sent and when in a test script, |
36 | | - * this is the representation of the request that was sent. |
37 | | - */ |
38 | | - request: import("postman-collection").Request; |
39 | | - /** |
40 | | - * The cookies object contains a list of cookies that are associated with the domain |
41 | | - * to which the request was made. |
42 | | - */ |
43 | | - cookies: import("postman-collection").CookieList; |
44 | | - visualizer: Visualizer; |
45 | | - /** |
46 | | - * Allows one to send request from script asynchronously. |
47 | | - */ |
48 | | - sendRequest(req: import("postman-collection").Request | string, callback: (...params: any[]) => any): void; |
49 | | - expect: Chai.ExpectStatic; |
50 | | -} |
51 | | - |
52 | | -/** |
53 | | - * Contains information pertaining to the script execution |
54 | | - */ |
55 | | -declare interface Info { |
56 | | - /** |
57 | | - * Contains information whether the script being executed is a "prerequest" or a "test" script. |
58 | | - */ |
59 | | - eventName: string; |
60 | | - /** |
61 | | - * Is the value of the current iteration being run. |
62 | | - */ |
63 | | - iteration: number; |
64 | | - /** |
65 | | - * Is the total number of iterations that are scheduled to run. |
66 | | - */ |
67 | | - iterationCount: number; |
68 | | - /** |
69 | | - * The saved name of the individual request being run. |
70 | | - */ |
71 | | - requestName: string; |
72 | | - /** |
73 | | - * The unique guid that identifies the request being run. |
74 | | - */ |
75 | | - requestId: string; |
76 | | -} |
77 | | - |
78 | | -declare interface Visualizer { |
79 | | - /** |
80 | | - * Set visualizer template and its options |
81 | | - * @param template - visualisation layout in form of template |
82 | | - * @param [data] - data object to be used in template |
83 | | - * @param [options] - options to use while processing the template |
84 | | - */ |
85 | | - set(template: string, data?: any, options?: any): void; |
86 | | - /** |
87 | | - * Clear all visualizer data |
88 | | - */ |
89 | | - clear(): void; |
90 | | -} |
91 | | - |
92 | | -/** |
93 | | - * The pm object encloses all information pertaining to the script being executed and |
94 | | - * allows one to access a copy of the request being sent or the response received. |
95 | | - * It also allows one to get and set environment and global variables. |
96 | | - */ |
97 | | -declare var pm: Postman; |
98 | | - |
99 | | -declare interface PostmanCookieJar { |
100 | | - /** |
101 | | - * Get the cookie value with the given name. |
102 | | - */ |
103 | | - get(url: string, name: string, callback: (...params: any[]) => any): void; |
104 | | - /** |
105 | | - * Get all the cookies for the given URL. |
106 | | - */ |
107 | | - getAll(url: string, options?: any, callback: (...params: any[]) => any): void; |
108 | | - /** |
109 | | - * Set or update a cookie. |
110 | | - */ |
111 | | - set(url: string, name: string | any, value?: string | ((...params: any[]) => any), callback?: (...params: any[]) => any): void; |
112 | | - /** |
113 | | - * Remove single cookie with the given name. |
114 | | - */ |
115 | | - unset(url: string, name: string, callback?: (...params: any[]) => any): void; |
116 | | - /** |
117 | | - * Remove all the cookies for the given URL. |
118 | | - */ |
119 | | - clear(url: string, callback?: (...params: any[]) => any): void; |
120 | | -} |
121 | | - |
122 | | - |
123 | | - |
124 | | -interface Postman { |
125 | | - test: Test; |
126 | | -} |
127 | | - |
128 | | -interface Test { |
129 | | - |
130 | | - /** |
131 | | - * You can use this function to write test specifications inside either the Pre-request Script or Tests sandbox. |
132 | | - * Writing tests inside this function allows you to name the test accurately and this function also ensures the |
133 | | - * rest of the script is not blocked even if there are errors inside the function. |
134 | | - * @param testName |
135 | | - * @param specFunction |
136 | | - */ |
137 | | - (testName: string, specFunction: Function): void |
138 | | - |
139 | | - /** |
140 | | - * Get the total number tests from a specific location. |
141 | | - */ |
142 | | - index(): number, |
143 | | - |
144 | | - /** |
145 | | - * By appending .skip(), you may tell test runner to ignore test case. |
146 | | - * @param testName |
147 | | - */ |
148 | | - skip(testName: string): void |
149 | 166 | } |
150 | 167 |
|
151 | 168 | declare module "postman-collection" { |
152 | 169 |
|
153 | | -interface CookieList { |
154 | | - jar() : PostmanCookieJar |
155 | | -} |
| 170 | + interface CookieList { |
| 171 | + jar(): PostmanCookieJar |
| 172 | + } |
156 | 173 |
|
157 | 174 | } |
0 commit comments