@appium/driver-test-support 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright OpenJS Foundation and other contributors, https://openjsf.org/
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,80 +1,11 @@
1
+ import type { BaseNSCapabilities, Driver, DriverClass } from '@appium/types';
2
+ import type { SessionHelpers } from './types';
1
3
  /**
2
4
  * Creates some helper functions for E2E tests to manage sessions.
3
- * @template [CommandData=unknown]
4
- * @template [ResponseData=any]
5
- * @param {number} port - Port on which the server is running. Typically this will be retrieved via `get-port` beforehand
6
- * @param {string} [address] - Address/host on which the server is running. Defaults to {@linkcode TEST_HOST}
7
- * @returns {SessionHelpers<CommandData, ResponseData>}
8
5
  */
9
- export function createSessionHelpers<CommandData = unknown, ResponseData = any>(port: number, address?: string): SessionHelpers<CommandData, ResponseData>;
6
+ export declare function createSessionHelpers<CommandData = unknown, ResponseData = any>(port: number, address?: string): SessionHelpers<CommandData, ResponseData>;
10
7
  /**
11
8
  * Creates E2E test suites for a driver.
12
- * @param {DriverClass} DriverClass
13
- * @param {Partial<BaseNSCapabilities>} [defaultCaps]
14
9
  */
15
- export function driverE2ETestSuite(DriverClass: DriverClass, defaultCaps?: Partial<BaseNSCapabilities>): void;
16
- export type DriverClass = import("@appium/types").DriverClass;
17
- export type Driver = import("@appium/types").Driver;
18
- export type Constraints = import("@appium/types").Constraints;
19
- export type StringRecord = import("@appium/types").StringRecord;
20
- export type BaseDriverCapConstraints = import("@appium/types").BaseDriverCapConstraints;
21
- export type BaseNSCapabilities = import("@appium/types").BaseNSCapabilities;
22
- export type RawAxiosRequestConfig = import("axios").RawAxiosRequestConfig;
23
- /**
24
- * `Constraints` is purposefully loose here
25
- */
26
- export type SingularSessionData<C extends Constraints = import("@appium/types").Constraints> = import("@appium/types").SingularSessionData<C>;
27
- export type AxiosResponse<T, D> = import("axios").AxiosResponse<T, D>;
28
- /**
29
- * `Constraints` is purposefully loose here
30
- */
31
- export type NewSessionData<C extends Constraints = import("@appium/types").Constraints> = {
32
- capabilities: import("type-fest").RequireAtLeastOne<import("@appium/types").W3CCapabilities<C>, "firstMatch" | "alwaysMatch">;
33
- };
34
- /**
35
- * `Constraints` is purposefully loose here
36
- */
37
- export type NewSessionResponse<C extends Constraints = import("@appium/types").Constraints> = {
38
- /**
39
- * ,
40
- */
41
- sessionId: string;
42
- capabilities: import("@appium/types").Capabilities<C>;
43
- };
44
- /**
45
- * Some E2E helpers for making requests and managing sessions
46
- * See {@linkcode createSessionHelpers}
47
- */
48
- export type SessionHelpers<CommandData = unknown, ResponseData = any> = {
49
- /**
50
- * - URL to create a new session. Can be used with raw `axios` requests to fully inspect raw response. Mostly, this will not be used.
51
- */
52
- newSessionURL: string;
53
- /**
54
- * - Begin a session
55
- */
56
- startSession: (data: NewSessionData, config?: RawAxiosRequestConfig) => Promise<NewSessionResponse>;
57
- /**
58
- * - End a session. _Note: resolves with raw response object_
59
- */
60
- endSession: (sessionId: string) => Promise<AxiosResponse<{
61
- value: {
62
- error?: string;
63
- } | null;
64
- }, {
65
- validateStatus: null;
66
- }>>;
67
- /**
68
- * - Get info about a session
69
- */
70
- getSession: (sessionId: string) => Promise<SingularSessionData>;
71
- /**
72
- * - Send an arbitrary command via `POST`.
73
- */
74
- postCommand: (sessionId: string, cmdName: string, data?: CommandData, config?: RawAxiosRequestConfig) => Promise<ResponseData>;
75
- /**
76
- * - Send an arbitrary command via `GET`. Optional `sessionId`.
77
- */
78
- getCommand: (sessionIdOrCmdName: string, cmdNameOrConfig: string | RawAxiosRequestConfig, config?: RawAxiosRequestConfig) => Promise<ResponseData>;
79
- };
10
+ export declare function driverE2ETestSuite(DriverClass: DriverClass<Driver>, defaultCaps?: Partial<BaseNSCapabilities>): void;
80
11
  //# sourceMappingURL=e2e-suite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"e2e-suite.d.ts","sourceRoot":"","sources":["../../lib/e2e-suite.js"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,qCANc,WAAW,YACX,YAAY,cACf,MAAM,YACN,MAAM,GACJ,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAiFrD;AAED;;;;GAIG;AACH,gDAHW,WAAW,gBACX,OAAO,CAAC,kBAAkB,CAAC,QAuWrC;0BAGY,OAAO,eAAe,EAAE,WAAW;qBACnC,OAAO,eAAe,EAAE,MAAM;0BAC9B,OAAO,eAAe,EAAE,WAAW;2BACnC,OAAO,eAAe,EAAE,YAAY;uCACpC,OAAO,eAAe,EAAE,wBAAwB;iCAChD,OAAO,eAAe,EAAE,kBAAkB;oCAC1C,OAAO,OAAO,EAAE,qBAAqB;;;;gCAKtB,CAAC,SAAf,WAAY,0CACb,OAAO,eAAe,EAAE,mBAAmB,CAAC,CAAC,CAAC;0BAI9C,CAAC,EAAC,CAAC,IACH,OAAO,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;;;;2BAKpB,CAAC,SAAf,WAAY;kBAEZ,OAAO,WAAW,EAAE,iBAAiB,CAAC,OAAO,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,YAAY,GAAC,aAAa,CAAC;;;;;+BAK/F,CAAC,SAAf,WAAY;;;;eAEZ,MAAM;kBACN,OAAO,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC;;;;;;2BAMvC,WAAW,YACX,YAAY;;;;mBAEZ,MAAM;;;;kBACN,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC,kBAAkB,CAAC;;;;gBACrF,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC;QAAC,KAAK,EAAE;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAC,OAAC,CAAA;KAAC,EAAE;QAAC,cAAc,EAAE,IAAI,CAAA;KAAC,CAAC,CAAC;;;;gBACjG,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC;;;;iBACnD,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC,YAAY,CAAC;;;;gBACjH,CAAC,kBAAkB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAC,qBAAqB,EAAE,MAAM,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC,YAAY,CAAC"}
1
+ {"version":3,"file":"e2e-suite.d.ts","sourceRoot":"","sources":["../../lib/e2e-suite.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,kBAAkB,EAAE,MAAM,EAAE,WAAW,EAAsB,MAAM,eAAe,CAAC;AAChG,OAAO,KAAK,EAAqB,cAAc,EAAC,MAAM,SAAS,CAAC;AAEhE;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,GAAG,OAAO,EAAE,YAAY,GAAG,GAAG,EAC5E,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAkB,GAC1B,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAgD3C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,EAChC,WAAW,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAC5C,IAAI,CAkVN"}
@@ -8,46 +8,25 @@ exports.driverE2ETestSuite = driverE2ETestSuite;
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
9
  const driver_1 = require("appium/driver");
10
10
  const axios_1 = __importDefault(require("axios"));
11
- const bluebird_1 = __importDefault(require("bluebird"));
11
+ const asyncbox_1 = require("asyncbox");
12
12
  const helpers_1 = require("./helpers");
13
13
  const sinon_1 = __importDefault(require("sinon"));
14
14
  const node_http_1 = require("node:http");
15
15
  /**
16
16
  * Creates some helper functions for E2E tests to manage sessions.
17
- * @template [CommandData=unknown]
18
- * @template [ResponseData=any]
19
- * @param {number} port - Port on which the server is running. Typically this will be retrieved via `get-port` beforehand
20
- * @param {string} [address] - Address/host on which the server is running. Defaults to {@linkcode TEST_HOST}
21
- * @returns {SessionHelpers<CommandData, ResponseData>}
22
17
  */
23
18
  function createSessionHelpers(port, address = helpers_1.TEST_HOST) {
24
- const createAppiumTestURL =
25
- /** @type {import('lodash').CurriedFunction2<string,string,string>} */ ((0, helpers_1.createAppiumURL)(address, port));
26
- const createSessionURL = createAppiumTestURL(lodash_1.default, '');
19
+ const createAppiumTestURL = (0, helpers_1.createAppiumURL)(address, port);
20
+ const createSessionURL = (sessionId) => createAppiumTestURL(sessionId, '');
27
21
  const newSessionURL = createAppiumTestURL('', 'session');
28
- return /** @type {SessionHelpers<CommandData, ResponseData>} */ ({
22
+ return {
29
23
  newSessionURL,
30
24
  createAppiumTestURL,
31
- /**
32
- *
33
- * @param {string} sessionId
34
- * @param {string} cmdName
35
- * @param {any} [data]
36
- * @param {RawAxiosRequestConfig} [config]
37
- * @returns {Promise<any>}
38
- */
39
25
  postCommand: async (sessionId, cmdName, data = {}, config = {}) => {
40
26
  const url = createAppiumTestURL(sessionId, cmdName);
41
27
  const response = await axios_1.default.post(url, data, config);
42
28
  return response.data?.value;
43
29
  },
44
- /**
45
- *
46
- * @param {string} sessionIdOrCmdName
47
- * @param {string|RawAxiosRequestConfig} cmdNameOrConfig
48
- * @param {RawAxiosRequestConfig} [config]
49
- * @returns {Promise<any>}
50
- */
51
30
  getCommand: async (sessionIdOrCmdName, cmdNameOrConfig, config = {}) => {
52
31
  if (!lodash_1.default.isString(cmdNameOrConfig)) {
53
32
  config = cmdNameOrConfig;
@@ -61,11 +40,6 @@ function createSessionHelpers(port, address = helpers_1.TEST_HOST) {
61
40
  });
62
41
  return response.data?.value;
63
42
  },
64
- /**
65
- *
66
- * @param {NewSessionData} data
67
- * @param {RawAxiosRequestConfig} [config]
68
- */
69
43
  startSession: async (data, config = {}) => {
70
44
  data = lodash_1.default.defaultsDeep(data, {
71
45
  capabilities: {
@@ -76,17 +50,9 @@ function createSessionHelpers(port, address = helpers_1.TEST_HOST) {
76
50
  const response = await axios_1.default.post(newSessionURL, data, config);
77
51
  return response.data?.value;
78
52
  },
79
- /**
80
- *
81
- * @param {string} sessionId
82
- */
83
53
  endSession: async (sessionId) => await axios_1.default.delete(createSessionURL(sessionId), {
84
54
  validateStatus: null,
85
55
  }),
86
- /**
87
- * @param {string} sessionId
88
- * @returns {Promise<any>}
89
- */
90
56
  getSession: async (sessionId) => {
91
57
  const response = await (0, axios_1.default)({
92
58
  url: createSessionURL(sessionId),
@@ -94,35 +60,23 @@ function createSessionHelpers(port, address = helpers_1.TEST_HOST) {
94
60
  });
95
61
  return response.data?.value;
96
62
  },
97
- });
63
+ };
98
64
  }
99
65
  /**
100
66
  * Creates E2E test suites for a driver.
101
- * @param {DriverClass} DriverClass
102
- * @param {Partial<BaseNSCapabilities>} [defaultCaps]
103
67
  */
104
68
  function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
105
- let address = defaultCaps['appium:address'] ?? helpers_1.TEST_HOST;
69
+ const address = defaultCaps['appium:address'] ?? helpers_1.TEST_HOST;
106
70
  let port = defaultCaps['appium:port'];
107
71
  const className = DriverClass.name || '(unknown driver)';
108
72
  describe(`BaseDriver E2E (as ${className})`, function () {
109
73
  let baseServer;
110
- /** @type {Driver} */
111
74
  let d;
112
- /**
113
- * This URL creates a new session
114
- * @type {string}
115
- **/
116
75
  let newSessionURL;
117
- /** @type {SessionHelpers['startSession']} */
118
76
  let startSession;
119
- /** @type {SessionHelpers['getSession']} */
120
77
  let getSession;
121
- /** @type {SessionHelpers['endSession']} */
122
78
  let endSession;
123
- /** @type {SessionHelpers['getCommand']} */
124
79
  let getCommand;
125
- /** @type {SessionHelpers['postCommand']} */
126
80
  let postCommand;
127
81
  let expect;
128
82
  before(async function () {
@@ -135,13 +89,17 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
135
89
  d = new DriverClass({ port, address });
136
90
  baseServer = await (0, driver_1.server)({
137
91
  routeConfiguringFunction: (0, driver_1.routeConfiguringFunction)(d),
138
- port,
92
+ port: port,
139
93
  hostname: address,
140
- // @ts-expect-error
141
94
  cliArgs: {},
142
95
  });
143
- ({ startSession, getSession, endSession, newSessionURL, getCommand, postCommand } =
144
- createSessionHelpers(port, address));
96
+ const helpers = createSessionHelpers(port, address);
97
+ startSession = helpers.startSession;
98
+ getSession = helpers.getSession;
99
+ endSession = helpers.endSession;
100
+ getCommand = helpers.getCommand;
101
+ postCommand = helpers.postCommand;
102
+ newSessionURL = helpers.newSessionURL;
145
103
  });
146
104
  after(async function () {
147
105
  await baseServer?.close();
@@ -195,7 +153,7 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
195
153
  }));
196
154
  times++;
197
155
  } while (times < 2);
198
- const sessionIds = lodash_1.default.map(await bluebird_1.default.all(reqs), 'sessionId');
156
+ const sessionIds = lodash_1.default.map(await Promise.all(reqs), 'sessionId');
199
157
  expect(lodash_1.default.uniq(sessionIds)).to.have.lengthOf(1);
200
158
  const { status, data } = await endSession(sessionIds[0]);
201
159
  expect(status).to.equal(200);
@@ -211,17 +169,15 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
211
169
  expect(data.value.sessionId).to.exist;
212
170
  expect(data.value.capabilities.platformName).to.equal(defaultCaps.platformName);
213
171
  expect(data.value.capabilities.deviceName).to.equal(defaultCaps['appium:deviceName']);
214
- ({ status, data } = await endSession(/** @type {string} */ (d.sessionId)));
172
+ ({ status, data } = await endSession(d.sessionId));
215
173
  expect(status).to.equal(200);
216
174
  expect(data.value).to.be.null;
217
175
  expect(d.sessionId).to.be.null;
218
176
  });
219
177
  });
220
178
  describe('command timeouts', function () {
221
- let originalFindElement, originalFindElements;
222
- /**
223
- * @param {number} [timeout]
224
- */
179
+ let originalFindElement;
180
+ let originalFindElements;
225
181
  async function startTimeoutSession(timeout) {
226
182
  const caps = lodash_1.default.cloneDeep(defaultCaps);
227
183
  caps['appium:newCommandTimeout'] = timeout;
@@ -234,7 +190,7 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
234
190
  }.bind(d);
235
191
  originalFindElements = d.findElements;
236
192
  d.findElements = async function () {
237
- await bluebird_1.default.delay(200);
193
+ await (0, asyncbox_1.sleep)(200);
238
194
  return ['foo'];
239
195
  }.bind(d);
240
196
  });
@@ -243,18 +199,18 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
243
199
  d.findElements = originalFindElements;
244
200
  });
245
201
  it('should set a default commandTimeout', async function () {
246
- let newSession = await startTimeoutSession();
202
+ const newSession = await startTimeoutSession();
247
203
  expect(d.newCommandTimeoutMs).to.be.above(0);
248
204
  await endSession(newSession.sessionId);
249
205
  });
250
206
  it('should timeout on commands using commandTimeout cap', async function () {
251
- let newSession = await startTimeoutSession(0.25);
252
- const sessionId = /** @type {string} */ (d.sessionId);
207
+ const newSession = await startTimeoutSession(0.25);
208
+ const sessionId = d.sessionId;
253
209
  await postCommand(sessionId, 'element', {
254
210
  using: 'name',
255
211
  value: 'foo',
256
212
  });
257
- await bluebird_1.default.delay(400);
213
+ await (0, asyncbox_1.sleep)(400);
258
214
  const value = await getSession(sessionId);
259
215
  expect(value.error).to.equal('invalid session id');
260
216
  expect(d.sessionId).to.be.null;
@@ -262,9 +218,9 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
262
218
  expect(resp?.error).to.equal('invalid session id');
263
219
  });
264
220
  it('should not timeout with commandTimeout of false', async function () {
265
- let newSession = await startTimeoutSession(0.1);
266
- let start = Date.now();
267
- const value = await postCommand(/** @type {string} */ (d.sessionId), 'elements', {
221
+ const newSession = await startTimeoutSession(0.1);
222
+ const start = Date.now();
223
+ const value = await postCommand(d.sessionId, 'elements', {
268
224
  using: 'name',
269
225
  value: 'foo',
270
226
  });
@@ -274,43 +230,38 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
274
230
  });
275
231
  it('should not timeout with commandTimeout of 0', async function () {
276
232
  d.newCommandTimeoutMs = 2;
277
- let newSession = await startTimeoutSession(0);
278
- await postCommand(/** @type {string} */ (d.sessionId), 'element', {
233
+ const newSession = await startTimeoutSession(0);
234
+ await postCommand(d.sessionId, 'element', {
279
235
  using: 'name',
280
236
  value: 'foo',
281
237
  });
282
- await bluebird_1.default.delay(400);
283
- const value = await getSession(/** @type {string} */ (d.sessionId));
238
+ await (0, asyncbox_1.sleep)(400);
239
+ const value = await getSession(d.sessionId);
284
240
  expect(value.platformName).to.equal(defaultCaps.platformName);
285
241
  const resp = (await endSession(newSession.sessionId)).data.value;
286
242
  expect(resp).to.be.null;
287
243
  d.newCommandTimeoutMs = 60 * 1000;
288
244
  });
289
245
  it('should not timeout if its just the command taking awhile', async function () {
290
- let newSession = await startTimeoutSession(0.25);
291
- // XXX: race condition: we must build this URL before ...something happens...
292
- // which causes `d.sessionId` to be missing
246
+ const newSession = await startTimeoutSession(0.25);
293
247
  const { sessionId } = d;
294
- await postCommand(/** @type {string} */ (d.sessionId), 'element', {
248
+ await postCommand(d.sessionId, 'element', {
295
249
  using: 'name',
296
250
  value: 'foo',
297
251
  });
298
- await bluebird_1.default.delay(400);
299
- const value = await getSession(/** @type {string} */ (sessionId));
300
- expect(/** @type {string} */ (value.error)).to.equal('invalid session id');
252
+ await (0, asyncbox_1.sleep)(400);
253
+ const value = await getSession(sessionId);
254
+ expect(value.error).to.equal('invalid session id');
301
255
  expect(d.sessionId).to.be.null;
302
256
  const resp = (await endSession(newSession.sessionId)).data.value;
303
- expect(/** @type {string} */ ( /** @type { {error: string} } */(resp).error)).to.equal('invalid session id');
257
+ expect(resp?.error).to.equal('invalid session id');
304
258
  });
305
259
  it('should not have a timer running before or after a session', async function () {
306
- // @ts-expect-error
307
260
  expect(d.noCommandTimer).to.be.null;
308
- let newSession = await startTimeoutSession(0.25);
261
+ const newSession = await startTimeoutSession(0.25);
309
262
  expect(newSession.sessionId).to.equal(d.sessionId);
310
- // @ts-expect-error
311
263
  expect(d.noCommandTimer).to.exist;
312
264
  await endSession(newSession.sessionId);
313
- // @ts-expect-error
314
265
  expect(d.noCommandTimer).to.be.null;
315
266
  });
316
267
  });
@@ -325,13 +276,10 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
325
276
  await expect(d.settings.update({ ignoreUnimportantViews: true })).to.not.be.rejected;
326
277
  });
327
278
  it('should reject for invalid update object', async function () {
328
- await expect(
329
- // @ts-expect-error
330
- d.settings.update('invalid json')).to.be.rejectedWith('JSON');
279
+ await expect(d.settings.update('invalid json')).to.be.rejectedWith('JSON');
331
280
  });
332
281
  });
333
282
  describe('unexpected exits', function () {
334
- /** @type {import('sinon').SinonSandbox} */
335
283
  let sandbox;
336
284
  beforeEach(function () {
337
285
  sandbox = sinon_1.default.createSandbox();
@@ -341,12 +289,11 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
341
289
  });
342
290
  it('should reject a current command when the driver crashes', async function () {
343
291
  sandbox.stub(d, 'getStatus').callsFake(async function () {
344
- await bluebird_1.default.delay(5000);
292
+ await (0, asyncbox_1.sleep)(5000);
345
293
  });
346
294
  const reqPromise = getCommand('status', { validateStatus: null });
347
- // make sure that the request gets to the server before our shutdown
348
- await bluebird_1.default.delay(100);
349
- const shutdownEventPromise = new bluebird_1.default((resolve, reject) => {
295
+ await (0, asyncbox_1.sleep)(100);
296
+ const shutdownEventPromise = new Promise((resolve, reject) => {
350
297
  setTimeout(() => reject(new Error('onUnexpectedShutdown event is expected to be fired within 5 seconds timeout')), 5000);
351
298
  d.onUnexpectedShutdown(resolve);
352
299
  });
@@ -357,9 +304,7 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
357
304
  });
358
305
  });
359
306
  describe('event timings', function () {
360
- /** @type {NewSessionResponse} */
361
307
  let session;
362
- /** @type {SingularSessionData} */
363
308
  let res;
364
309
  describe('when not provided the eventTimings cap', function () {
365
310
  before(async function () {
@@ -397,48 +342,4 @@ function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
397
342
  });
398
343
  });
399
344
  }
400
- /**
401
- * @typedef {import('@appium/types').DriverClass} DriverClass
402
- * @typedef {import('@appium/types').Driver} Driver
403
- * @typedef {import('@appium/types').Constraints} Constraints
404
- * @typedef {import('@appium/types').StringRecord} StringRecord
405
- * @typedef {import('@appium/types').BaseDriverCapConstraints} BaseDriverCapConstraints
406
- * @typedef {import('@appium/types').BaseNSCapabilities} BaseNSCapabilities
407
- * @typedef {import('axios').RawAxiosRequestConfig} RawAxiosRequestConfig
408
- */
409
- /**
410
- * `Constraints` is purposefully loose here
411
- * @template {Constraints} [C=Constraints]
412
- * @typedef {import('@appium/types').SingularSessionData<C>} SingularSessionData
413
- */
414
- /**
415
- * @template T,D
416
- * @typedef {import('axios').AxiosResponse<T, D>} AxiosResponse
417
- */
418
- /**
419
- * `Constraints` is purposefully loose here
420
- * @template {Constraints} [C=Constraints]
421
- * @typedef NewSessionData
422
- * @property {import('type-fest').RequireAtLeastOne<import('@appium/types').W3CCapabilities<C>, 'firstMatch'|'alwaysMatch'>} capabilities
423
- */
424
- /**
425
- * `Constraints` is purposefully loose here
426
- * @template {Constraints} [C=Constraints]
427
- * @typedef NewSessionResponse
428
- * @property {string} sessionId,
429
- * @property {import('@appium/types').Capabilities<C>} capabilities
430
- */
431
- /**
432
- * Some E2E helpers for making requests and managing sessions
433
- * See {@linkcode createSessionHelpers}
434
- * @template [CommandData=unknown]
435
- * @template [ResponseData=any]
436
- * @typedef SessionHelpers
437
- * @property {string} newSessionURL - URL to create a new session. Can be used with raw `axios` requests to fully inspect raw response. Mostly, this will not be used.
438
- * @property {(data: NewSessionData, config?: RawAxiosRequestConfig) => Promise<NewSessionResponse>} startSession - Begin a session
439
- * @property {(sessionId: string) => Promise<AxiosResponse<{value: {error?: string}?}, {validateStatus: null}>>} endSession - End a session. _Note: resolves with raw response object_
440
- * @property {(sessionId: string) => Promise<SingularSessionData>} getSession - Get info about a session
441
- * @property {(sessionId: string, cmdName: string, data?: CommandData, config?: RawAxiosRequestConfig) => Promise<ResponseData>} postCommand - Send an arbitrary command via `POST`.
442
- * @property {(sessionIdOrCmdName: string, cmdNameOrConfig: string|RawAxiosRequestConfig, config?: RawAxiosRequestConfig) => Promise<ResponseData>} getCommand - Send an arbitrary command via `GET`. Optional `sessionId`.
443
- */
444
345
  //# sourceMappingURL=e2e-suite.js.map