@e2e-dev/browserstack 0.0.0-stage → 0.0.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 +202 -0
- package/NOTICE +5 -0
- package/README.md +39 -2
- package/dist/.build.json +1 -0
- package/dist/credentials.d.ts +6 -0
- package/dist/credentials.js +17 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/provider.d.ts +62 -0
- package/dist/provider.js +179 -0
- package/dist/sessions.d.ts +38 -0
- package/dist/sessions.js +181 -0
- package/package.json +61 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @e2e-dev/browserstack
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run `@e2e-dev/mobile` tests on [BrowserStack App Automate](https://www.browserstack.com/app-automate)
|
|
4
|
+
real Android and iOS devices. Each worker slot leases one device, with your app installed,
|
|
5
|
+
and releases it when the run ends.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @e2e-dev/browserstack
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts title="e2e.config.ts"
|
|
12
|
+
import type { E2EConfig } from 'e2e';
|
|
13
|
+
import { mobile } from '@e2e-dev/mobile';
|
|
14
|
+
import { browserstack } from '@e2e-dev/browserstack';
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
targets: [
|
|
18
|
+
{
|
|
19
|
+
engine: mobile({
|
|
20
|
+
platform: 'android',
|
|
21
|
+
device: browserstack({ device: 'Google Pixel 9', osVersion: '16.0', app: 'bs://<app-id>', appiumVersion: '3.2.0' }),
|
|
22
|
+
}),
|
|
23
|
+
app: { bundleId: 'com.example.app' },
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
workers: 2,
|
|
27
|
+
} satisfies E2EConfig;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Set `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` in the run environment, from
|
|
31
|
+
**Account & Profile → My profile → Authentication & Security**. The username is the one
|
|
32
|
+
shown there, not your email address. `device` and `osVersion` must match BrowserStack's
|
|
33
|
+
App Automate catalog exactly, and `app` is a `bs://` app id, an `https` URL, or a local path.
|
|
34
|
+
|
|
35
|
+
See the [integration guide](https://e2e.tester.army/docs/integrations/browserstack) for every
|
|
36
|
+
option and the limits.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
Apache-2.0
|
package/dist/.build.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"0.0.0"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface BrowserStackCredentials {
|
|
2
|
+
readonly username: string;
|
|
3
|
+
readonly accessKey: string;
|
|
4
|
+
}
|
|
5
|
+
/** `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` from the run's environment; throws naming each one that is unset or blank. */
|
|
6
|
+
export declare function browserstackCredentials(env: Readonly<Record<string, string | undefined>>): BrowserStackCredentials;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const BROWSERSTACK_USERNAME = 'BROWSERSTACK_USERNAME';
|
|
2
|
+
const BROWSERSTACK_ACCESS_KEY = 'BROWSERSTACK_ACCESS_KEY';
|
|
3
|
+
/** `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` from the run's environment; throws naming each one that is unset or blank. */
|
|
4
|
+
export function browserstackCredentials(env) {
|
|
5
|
+
const username = envValue(env, BROWSERSTACK_USERNAME);
|
|
6
|
+
const accessKey = envValue(env, BROWSERSTACK_ACCESS_KEY);
|
|
7
|
+
if (username === undefined || accessKey === undefined) {
|
|
8
|
+
const missing = [username === undefined ? BROWSERSTACK_USERNAME : undefined, accessKey === undefined ? BROWSERSTACK_ACCESS_KEY : undefined].filter((name) => name !== undefined);
|
|
9
|
+
throw new Error(`${missing.join(' and ')} ${missing.length === 1 ? 'is' : 'are'} not set; set ${BROWSERSTACK_USERNAME} and ${BROWSERSTACK_ACCESS_KEY} to your BrowserStack username and access key in the environment \`e2e run\` starts in`);
|
|
10
|
+
}
|
|
11
|
+
return { username, accessKey };
|
|
12
|
+
}
|
|
13
|
+
/** A non-empty variable from the run's environment, trimmed, or `undefined`. */
|
|
14
|
+
function envValue(env, name) {
|
|
15
|
+
const value = env[name]?.trim();
|
|
16
|
+
return value === undefined || value === '' ? undefined : value;
|
|
17
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@e2e-dev/browserstack` public surface: `browserstack()`, a device provider
|
|
3
|
+
* that leases BrowserStack App Automate real Android and iOS devices for
|
|
4
|
+
* `@e2e-dev/mobile` through agent-device's built-in BrowserStack provider.
|
|
5
|
+
*/
|
|
6
|
+
export { browserstack } from './provider.ts';
|
|
7
|
+
export type { BrowserStackOptions } from './provider.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@e2e-dev/browserstack` public surface: `browserstack()`, a device provider
|
|
3
|
+
* that leases BrowserStack App Automate real Android and iOS devices for
|
|
4
|
+
* `@e2e-dev/mobile` through agent-device's built-in BrowserStack provider.
|
|
5
|
+
*/
|
|
6
|
+
export { browserstack } from './provider.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrowserStack App Automate's real Android and iOS devices as a
|
|
3
|
+
* `DeviceProvider` for the mobile engine, through agent-device's built-in
|
|
4
|
+
* `browserstack` provider: each lease comes from its own agent-device daemon,
|
|
5
|
+
* which runs the session over BrowserStack's Appium hub.
|
|
6
|
+
*/
|
|
7
|
+
import type { DeviceProvider } from '@e2e-dev/mobile';
|
|
8
|
+
/** What `browserstack()` takes: the device, its OS version, and the app BrowserStack installs on it. */
|
|
9
|
+
export interface BrowserStackOptions {
|
|
10
|
+
/** Device name exactly as BrowserStack's App Automate catalog lists it: `Google Pixel 9`, `iPhone 16`. */
|
|
11
|
+
readonly device: string;
|
|
12
|
+
/** OS version exactly as the catalog lists it for that device: `16.0` on Android, `18` on iOS. */
|
|
13
|
+
readonly osVersion: string;
|
|
14
|
+
/**
|
|
15
|
+
* The build BrowserStack installs on every session: a `bs://` app id; an
|
|
16
|
+
* `https` URL, which BrowserStack fetches once per run; or a local path,
|
|
17
|
+
* resolved against the project root and uploaded when the session starts.
|
|
18
|
+
*/
|
|
19
|
+
readonly app: string;
|
|
20
|
+
/** Dashboard project the sessions are grouped under. Defaults to `e2e`. */
|
|
21
|
+
readonly project?: string | undefined;
|
|
22
|
+
/** Dashboard build the sessions are grouped under. Defaults to the run id. */
|
|
23
|
+
readonly build?: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Name of every session on the dashboard, with `-<slot>` appended when the
|
|
26
|
+
* target leases more than one device, so each slot's session has its own.
|
|
27
|
+
* Defaults to `e2e-<run id>-<target>-<slot>`. Slots count from 1.
|
|
28
|
+
*/
|
|
29
|
+
readonly sessionName?: string | undefined;
|
|
30
|
+
/** Orientation the device starts in; absent, the device's default. */
|
|
31
|
+
readonly orientation?: 'portrait' | 'landscape' | undefined;
|
|
32
|
+
/** Country the device's IP geolocates to, as a code BrowserStack takes: `US`, `FR`. */
|
|
33
|
+
readonly geoLocation?: string | undefined;
|
|
34
|
+
/** The device's time zone, as BrowserStack takes it: `New_York`. */
|
|
35
|
+
readonly timezone?: string | undefined;
|
|
36
|
+
/** The app's language, as BrowserStack takes it: `fr`. */
|
|
37
|
+
readonly language?: string | undefined;
|
|
38
|
+
/** The device's locale, as BrowserStack takes it: `fr_FR`. */
|
|
39
|
+
readonly locale?: string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Appium version BrowserStack starts for the session, such as `3.2.0`.
|
|
42
|
+
* Absent, BrowserStack's default Appium 1.x, which lacks the `mobile:`
|
|
43
|
+
* commands deep links and hardware buttons use.
|
|
44
|
+
*/
|
|
45
|
+
readonly appiumVersion?: string | undefined;
|
|
46
|
+
/** A named network condition profile, such as `4g-lte-advanced-good`. Not with `customNetwork`. */
|
|
47
|
+
readonly networkProfile?: string | undefined;
|
|
48
|
+
/** A custom network shape, as BrowserStack takes it. Not with `networkProfile`. */
|
|
49
|
+
readonly customNetwork?: string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* iOS only: keep the uploaded app's signature instead of letting BrowserStack
|
|
52
|
+
* re-sign it, which strips entitlements such as push notifications.
|
|
53
|
+
*/
|
|
54
|
+
readonly noResignApp?: boolean | undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* BrowserStack devices for `mobile({ device: browserstack({ device, osVersion, app }) })`:
|
|
58
|
+
* one real device and isolated agent-device daemon per worker slot. The
|
|
59
|
+
* session starts, and installs `app`, when the daemon allocates the lease;
|
|
60
|
+
* releasing the lease stops the daemon, which ends the session.
|
|
61
|
+
*/
|
|
62
|
+
export declare function browserstack(options: BrowserStackOptions): DeviceProvider;
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrowserStack App Automate's real Android and iOS devices as a
|
|
3
|
+
* `DeviceProvider` for the mobile engine, through agent-device's built-in
|
|
4
|
+
* `browserstack` provider: each lease comes from its own agent-device daemon,
|
|
5
|
+
* which runs the session over BrowserStack's Appium hub.
|
|
6
|
+
*/
|
|
7
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
8
|
+
import { agentDeviceLeases } from '@e2e-dev/mobile/lease';
|
|
9
|
+
import { ConfigurationError, rejectUnknownKeys } from 'e2e/engine';
|
|
10
|
+
import { browserstackCredentials } from './credentials.js';
|
|
11
|
+
import { browserstackApiEndpoint, findSession, uploadAppFromUrl } from './sessions.js';
|
|
12
|
+
/** agent-device's name for BrowserStack, as the lease provider and the tenant. */
|
|
13
|
+
const PROVIDER = 'browserstack';
|
|
14
|
+
/** The dashboard project sessions are grouped under when `project` is absent. */
|
|
15
|
+
const DEFAULT_PROJECT = 'e2e';
|
|
16
|
+
const ORIENTATIONS = new Set(['portrait', 'landscape']);
|
|
17
|
+
/** Every option `browserstack()` takes, kept equal to `BrowserStackOptions` by the compiler. */
|
|
18
|
+
const OPTIONS = {
|
|
19
|
+
device: { kind: 'required' },
|
|
20
|
+
osVersion: { kind: 'required' },
|
|
21
|
+
app: { kind: 'required' },
|
|
22
|
+
project: { kind: 'string' },
|
|
23
|
+
build: { kind: 'string' },
|
|
24
|
+
sessionName: { kind: 'string' },
|
|
25
|
+
orientation: { kind: 'string', leaseKey: 'providerDeviceOrientation' },
|
|
26
|
+
geoLocation: { kind: 'string', leaseKey: 'providerGeoLocation' },
|
|
27
|
+
timezone: { kind: 'string', leaseKey: 'providerTimezone' },
|
|
28
|
+
language: { kind: 'string', leaseKey: 'providerLanguage' },
|
|
29
|
+
locale: { kind: 'string', leaseKey: 'providerLocale' },
|
|
30
|
+
appiumVersion: { kind: 'string', leaseKey: 'providerAppiumVersion' },
|
|
31
|
+
networkProfile: { kind: 'string', leaseKey: 'providerNetworkProfile' },
|
|
32
|
+
customNetwork: { kind: 'string', leaseKey: 'providerCustomNetwork' },
|
|
33
|
+
noResignApp: { kind: 'boolean', leaseKey: 'providerNoResignApp' },
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* BrowserStack devices for `mobile({ device: browserstack({ device, osVersion, app }) })`:
|
|
37
|
+
* one real device and isolated agent-device daemon per worker slot. The
|
|
38
|
+
* session starts, and installs `app`, when the daemon allocates the lease;
|
|
39
|
+
* releasing the lease stops the daemon, which ends the session.
|
|
40
|
+
*/
|
|
41
|
+
export function browserstack(options) {
|
|
42
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
43
|
+
throw new ConfigurationError('INVALID_CONFIG', 'browserstack: options must be an object with `device`, `osVersion`, and `app`');
|
|
44
|
+
}
|
|
45
|
+
rejectUnknownKeys('browserstack()', options, Object.keys(OPTIONS));
|
|
46
|
+
const deviceFeatures = {};
|
|
47
|
+
for (const [key, { kind, leaseKey }] of Object.entries(OPTIONS)) {
|
|
48
|
+
const value = options[key];
|
|
49
|
+
checkOption(key, kind, value);
|
|
50
|
+
// A flag is allocated only when set.
|
|
51
|
+
if (leaseKey !== undefined && value !== undefined && value !== false)
|
|
52
|
+
deviceFeatures[leaseKey] = value;
|
|
53
|
+
}
|
|
54
|
+
if (options.orientation !== undefined && !ORIENTATIONS.has(options.orientation)) {
|
|
55
|
+
throw new ConfigurationError('INVALID_CONFIG', `browserstack: \`orientation\` must be 'portrait' or 'landscape', not ${JSON.stringify(options.orientation)}`);
|
|
56
|
+
}
|
|
57
|
+
if (/^http:\/\//i.test(options.app)) {
|
|
58
|
+
throw new ConfigurationError('INVALID_CONFIG', 'browserstack: `app` must be an https URL, a `bs://` id, or a local path, not a plain http URL');
|
|
59
|
+
}
|
|
60
|
+
if (options.networkProfile !== undefined && options.customNetwork !== undefined) {
|
|
61
|
+
throw new ConfigurationError('INVALID_CONFIG', 'browserstack: set `networkProfile` or `customNetwork`, not both');
|
|
62
|
+
}
|
|
63
|
+
const noResignApp = options.noResignApp === true;
|
|
64
|
+
const { device, osVersion, app, project, build, sessionName } = options;
|
|
65
|
+
const leases = agentDeviceLeases({ provider: PROVIDER, label: 'BrowserStack' });
|
|
66
|
+
/**
|
|
67
|
+
* The `https` build's upload for one run, API endpoint, and account, whose
|
|
68
|
+
* `bs://` id every slot of that run shares. Anything else uploads again,
|
|
69
|
+
* so a later run never installs an earlier run's build, and a failed upload
|
|
70
|
+
* may be tried again.
|
|
71
|
+
*/
|
|
72
|
+
let uploaded;
|
|
73
|
+
function providerApp(request, credentials) {
|
|
74
|
+
if (!/^https:\/\//i.test(app))
|
|
75
|
+
return Promise.resolve(appSource(app, request.projectRoot));
|
|
76
|
+
const endpoint = browserstackApiEndpoint(request.env);
|
|
77
|
+
const key = JSON.stringify([request.runId, endpoint, credentials.username]);
|
|
78
|
+
if (uploaded?.key === key)
|
|
79
|
+
return uploaded.id;
|
|
80
|
+
const upload = { key, id: uploadAppFromUrl(endpoint, credentials, app, request.signal) };
|
|
81
|
+
uploaded = upload;
|
|
82
|
+
// The URL may carry a signed token, so the log names the upload by its id only.
|
|
83
|
+
upload.id.then((id) => {
|
|
84
|
+
try {
|
|
85
|
+
request.log(`uploaded the app URL as ${id}`);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// The run's log may be closed by now.
|
|
89
|
+
}
|
|
90
|
+
}, () => { if (uploaded === upload)
|
|
91
|
+
uploaded = undefined; });
|
|
92
|
+
return upload.id;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
name: PROVIDER,
|
|
96
|
+
async acquire(request) {
|
|
97
|
+
if (request.appPath !== undefined)
|
|
98
|
+
throw new Error("BrowserStack installs the app from `app`; leave the target's `app.appPath` out");
|
|
99
|
+
if (noResignApp && request.platform !== 'ios')
|
|
100
|
+
throw new ConfigurationError('INVALID_CONFIG', 'browserstack: `noResignApp` applies to iOS only');
|
|
101
|
+
const credentials = browserstackCredentials(request.env);
|
|
102
|
+
request.signal.throwIfAborted();
|
|
103
|
+
const appId = await providerApp(request, credentials);
|
|
104
|
+
request.signal.throwIfAborted();
|
|
105
|
+
const selectors = {
|
|
106
|
+
device,
|
|
107
|
+
providerOsVersion: osVersion,
|
|
108
|
+
providerApp: appId,
|
|
109
|
+
providerProject: project ?? DEFAULT_PROJECT,
|
|
110
|
+
providerBuild: build ?? request.runId,
|
|
111
|
+
providerSessionName: slotSessionName(sessionName, request),
|
|
112
|
+
...deviceFeatures,
|
|
113
|
+
};
|
|
114
|
+
return leases.acquire(request, {
|
|
115
|
+
env: { BROWSERSTACK_USERNAME: credentials.username, BROWSERSTACK_ACCESS_KEY: credentials.accessKey },
|
|
116
|
+
selectors,
|
|
117
|
+
summary: `${device}, ${request.platform} ${osVersion}; session ${selectors.providerSessionName} reserved`,
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
release: (lease, context) => leases.release(lease, context),
|
|
121
|
+
// Runs in the worker, from the lease alone. BrowserStack records the whole session, so its video starts when the session did.
|
|
122
|
+
async record(lease, context) {
|
|
123
|
+
const calledAt = new Date().toISOString();
|
|
124
|
+
const session = sessionRef(lease);
|
|
125
|
+
if (session === undefined)
|
|
126
|
+
throw new Error(`lease ${lease.id} carries no BrowserStack build and session name to find its recording by`);
|
|
127
|
+
const credentials = browserstackCredentials(context.env);
|
|
128
|
+
const endpoint = browserstackApiEndpoint(context.env);
|
|
129
|
+
const found = await findSession(endpoint, credentials, session, context.signal);
|
|
130
|
+
return {
|
|
131
|
+
// Without a usable start time from BrowserStack, the moment recording was asked for is the closest known bound.
|
|
132
|
+
startedAt: found.startedAt ?? calledAt,
|
|
133
|
+
stop: async ({ signal }) => {
|
|
134
|
+
const ended = await findSession(endpoint, credentials, session, signal);
|
|
135
|
+
if (ended.videoUrl === undefined)
|
|
136
|
+
throw new Error(`BrowserStack session ${ended.id} (${JSON.stringify(session.sessionName)}, build ${JSON.stringify(session.build)}) reports no video URL`);
|
|
137
|
+
return { url: ended.videoUrl, mediaType: 'video/mp4' };
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/** Throws `INVALID_CONFIG` unless `value` is what an option of `kind` takes. */
|
|
144
|
+
function checkOption(key, kind, value) {
|
|
145
|
+
if (kind === 'required' && (typeof value !== 'string' || value.trim() === '')) {
|
|
146
|
+
throw new ConfigurationError('INVALID_CONFIG', `browserstack: \`${key}\` is required, as a non-empty string`);
|
|
147
|
+
}
|
|
148
|
+
if (value === undefined)
|
|
149
|
+
return;
|
|
150
|
+
if (kind === 'string' && (typeof value !== 'string' || value.trim() === '')) {
|
|
151
|
+
throw new ConfigurationError('INVALID_CONFIG', `browserstack: \`${key}\` must be a non-empty string`);
|
|
152
|
+
}
|
|
153
|
+
if (kind === 'boolean' && typeof value !== 'boolean') {
|
|
154
|
+
throw new ConfigurationError('INVALID_CONFIG', `browserstack: \`${key}\` must be a boolean, not ${JSON.stringify(value)}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The dashboard name of a slot's session, unique among the run's slots of the
|
|
159
|
+
* target so `record` can find the session by it within its build.
|
|
160
|
+
*/
|
|
161
|
+
function slotSessionName(sessionName, { runId, targetName, slot, slots }) {
|
|
162
|
+
if (sessionName === undefined)
|
|
163
|
+
return `e2e-${runId}-${targetName}-${slot + 1}`;
|
|
164
|
+
return slots > 1 ? `${sessionName}-${slot + 1}` : sessionName;
|
|
165
|
+
}
|
|
166
|
+
/** `app` as the daemon reads it: a `bs://` id as written, a local path resolved against the project root, never the daemon's working directory. */
|
|
167
|
+
function appSource(app, projectRoot) {
|
|
168
|
+
if (isAbsolute(app) || /^[a-z][a-z0-9+.-]*:\/\//i.test(app))
|
|
169
|
+
return app;
|
|
170
|
+
return resolve(projectRoot, app);
|
|
171
|
+
}
|
|
172
|
+
/** The build and session name `acquire` put on a lease's `client`, when they are there. */
|
|
173
|
+
function sessionRef({ client }) {
|
|
174
|
+
const build = client?.providerBuild;
|
|
175
|
+
const sessionName = client?.providerSessionName;
|
|
176
|
+
if (typeof build !== 'string' || build === '' || typeof sessionName !== 'string' || sessionName === '')
|
|
177
|
+
return undefined;
|
|
178
|
+
return { build, sessionName };
|
|
179
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrowserStack's App Automate REST API over `fetch`: uploads a build from a
|
|
3
|
+
* URL, and finds a session by its build and name, with its start time and the
|
|
4
|
+
* URL of its video.
|
|
5
|
+
*/
|
|
6
|
+
import type { BrowserStackCredentials } from './credentials.ts';
|
|
7
|
+
/** A session the recording covers, as the lease named it. */
|
|
8
|
+
export interface SessionRef {
|
|
9
|
+
readonly build: string;
|
|
10
|
+
readonly sessionName: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The API at `BROWSERSTACK_API_ENDPOINT` from the run's environment, else
|
|
14
|
+
* BrowserStack's own. Throws, without repeating the value, when the override
|
|
15
|
+
* is not an http(s) URL or carries a username or password, which a failed
|
|
16
|
+
* request would otherwise put in its error message.
|
|
17
|
+
*/
|
|
18
|
+
export declare function browserstackApiEndpoint(env: Readonly<Record<string, string | undefined>>): string;
|
|
19
|
+
/** A session the lookup found: its `hashed_id`, when it started, and its video, if the API says. */
|
|
20
|
+
export interface FoundSession {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
/** ISO timestamp in UTC; `undefined` when the session has no start time or one that does not parse. */
|
|
23
|
+
readonly startedAt: string | undefined;
|
|
24
|
+
/** `undefined` until BrowserStack has a video for the session. */
|
|
25
|
+
readonly videoUrl: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The newest session named `sessionName` in the newest build named `build`,
|
|
29
|
+
* reading each list a page at a time. Every request is bounded by
|
|
30
|
+
* `REQUEST_TIMEOUT_MS` and `signal`, and errors name the build and the
|
|
31
|
+
* session, never the credentials or a URL.
|
|
32
|
+
*/
|
|
33
|
+
export declare function findSession(endpoint: string, credentials: BrowserStackCredentials, { build, sessionName }: SessionRef, signal: AbortSignal): Promise<FoundSession>;
|
|
34
|
+
/**
|
|
35
|
+
* Has BrowserStack fetch the build at `url` and returns its `bs://` app id:
|
|
36
|
+
* the session's `app` capability takes only an uploaded app, never a URL.
|
|
37
|
+
*/
|
|
38
|
+
export declare function uploadAppFromUrl(endpoint: string, credentials: BrowserStackCredentials, url: string, signal: AbortSignal): Promise<string>;
|
package/dist/sessions.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrowserStack's App Automate REST API over `fetch`: uploads a build from a
|
|
3
|
+
* URL, and finds a session by its build and name, with its start time and the
|
|
4
|
+
* URL of its video.
|
|
5
|
+
*/
|
|
6
|
+
import { ConfigurationError } from 'e2e/engine';
|
|
7
|
+
/** The App Automate API's base. */
|
|
8
|
+
const DEFAULT_API_ENDPOINT = 'https://api-cloud.browserstack.com/app-automate';
|
|
9
|
+
const REQUEST_TIMEOUT_MS = 15_000;
|
|
10
|
+
/** BrowserStack downloads the build before it answers an upload from a URL. */
|
|
11
|
+
const UPLOAD_TIMEOUT_MS = 300_000;
|
|
12
|
+
/** Builds or sessions the list asks for at once. */
|
|
13
|
+
const PAGE_SIZE = 50;
|
|
14
|
+
/** Pages a lookup reads before it gives up: both lists are newest first, so the run is near the top. */
|
|
15
|
+
const MAX_PAGES = 10;
|
|
16
|
+
/**
|
|
17
|
+
* The API at `BROWSERSTACK_API_ENDPOINT` from the run's environment, else
|
|
18
|
+
* BrowserStack's own. Throws, without repeating the value, when the override
|
|
19
|
+
* is not an http(s) URL or carries a username or password, which a failed
|
|
20
|
+
* request would otherwise put in its error message.
|
|
21
|
+
*/
|
|
22
|
+
export function browserstackApiEndpoint(env) {
|
|
23
|
+
const override = env['BROWSERSTACK_API_ENDPOINT']?.trim();
|
|
24
|
+
if (override === undefined || override === '')
|
|
25
|
+
return DEFAULT_API_ENDPOINT;
|
|
26
|
+
if (!URL.canParse(override) || !/^https?:$/.test(new URL(override).protocol))
|
|
27
|
+
throw new ConfigurationError('INVALID_CONFIG', 'BROWSERSTACK_API_ENDPOINT is not an http(s) URL');
|
|
28
|
+
const url = new URL(override);
|
|
29
|
+
if (url.search !== '' || url.hash !== '')
|
|
30
|
+
throw new ConfigurationError('INVALID_CONFIG', 'BROWSERSTACK_API_ENDPOINT must not carry a query or fragment');
|
|
31
|
+
if (url.username !== '' || url.password !== '') {
|
|
32
|
+
throw new ConfigurationError('INVALID_CONFIG', 'BROWSERSTACK_API_ENDPOINT must not carry a username or password; set BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY instead');
|
|
33
|
+
}
|
|
34
|
+
return override.replace(/\/+$/, '');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The newest session named `sessionName` in the newest build named `build`,
|
|
38
|
+
* reading each list a page at a time. Every request is bounded by
|
|
39
|
+
* `REQUEST_TIMEOUT_MS` and `signal`, and errors name the build and the
|
|
40
|
+
* session, never the credentials or a URL.
|
|
41
|
+
*/
|
|
42
|
+
export async function findSession(endpoint, credentials, { build, sessionName }, signal) {
|
|
43
|
+
const auth = basicAuth(credentials);
|
|
44
|
+
const what = `BrowserStack session lookup in build ${JSON.stringify(build)}`;
|
|
45
|
+
// Builds of different projects may share a name, as targets of one run do by default.
|
|
46
|
+
for (const buildId of await findBuilds(endpoint, auth, build, signal)) {
|
|
47
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
48
|
+
const rows = await getRows(listUrl(`${endpoint}/builds/${encodeURIComponent(buildId)}/sessions.json`, page), auth, signal, what);
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
const session = asRecord(asRecord(row)?.['automation_session']);
|
|
51
|
+
const id = session?.['hashed_id'];
|
|
52
|
+
if (session?.['name'] === sessionName && typeof id === 'string' && id !== '') {
|
|
53
|
+
const video = session['video_url'];
|
|
54
|
+
return { id, startedAt: utcTimestamp(session['created_at']), videoUrl: typeof video === 'string' && isHttpUrl(video) ? video : undefined };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (rows.length < PAGE_SIZE)
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`BrowserStack has no session named ${JSON.stringify(sessionName)} in build ${JSON.stringify(build)}`);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Has BrowserStack fetch the build at `url` and returns its `bs://` app id:
|
|
65
|
+
* the session's `app` capability takes only an uploaded app, never a URL.
|
|
66
|
+
*/
|
|
67
|
+
export async function uploadAppFromUrl(endpoint, credentials, url, signal) {
|
|
68
|
+
const form = new FormData();
|
|
69
|
+
form.set('url', url);
|
|
70
|
+
// The API may echo the URL, which can carry a signed token: `request` hides it in every error.
|
|
71
|
+
const body = asRecord(await request(new URL(`${endpoint}/upload`), basicAuth(credentials), signal, 'BrowserStack app upload from a URL', { timeoutMs: UPLOAD_TIMEOUT_MS, form, hide: url }));
|
|
72
|
+
const appUrl = body?.['app_url'];
|
|
73
|
+
if (typeof appUrl !== 'string' || !appUrl.startsWith('bs://'))
|
|
74
|
+
throw new Error('BrowserStack app upload from a URL failed: no bs:// app id in the response');
|
|
75
|
+
return appUrl;
|
|
76
|
+
}
|
|
77
|
+
/** `message` with `url`, raw or encoded, and its query string replaced, so a signed token never reaches a log. */
|
|
78
|
+
function redact(message, url) {
|
|
79
|
+
const query = URL.canParse(url) ? new URL(url).search.slice(1) : '';
|
|
80
|
+
return [url, encodeURIComponent(url), query, encodeURIComponent(query)]
|
|
81
|
+
.filter((secret) => secret !== '')
|
|
82
|
+
.reduce((text, secret) => text.split(secret).join('<app URL>'), message);
|
|
83
|
+
}
|
|
84
|
+
/** A transport error's message with `url` redacted, in place of the error itself. */
|
|
85
|
+
function redactedError(cause, url) {
|
|
86
|
+
return new Error(redact(cause instanceof Error ? cause.message : String(cause), url));
|
|
87
|
+
}
|
|
88
|
+
/** An error saying `message`, caused by `cause`. */
|
|
89
|
+
function withCause(message, cause) {
|
|
90
|
+
return new Error(message, { cause });
|
|
91
|
+
}
|
|
92
|
+
/** The `hashed_id` of every build named `build`, newest first. */
|
|
93
|
+
async function findBuilds(endpoint, auth, build, signal) {
|
|
94
|
+
const what = `BrowserStack build lookup for ${JSON.stringify(build)}`;
|
|
95
|
+
const ids = [];
|
|
96
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
97
|
+
const rows = await getRows(listUrl(`${endpoint}/builds.json`, page), auth, signal, what);
|
|
98
|
+
for (const row of rows) {
|
|
99
|
+
const found = asRecord(asRecord(row)?.['automation_build']);
|
|
100
|
+
const id = found?.['hashed_id'];
|
|
101
|
+
if (found?.['name'] === build && typeof id === 'string' && id !== '')
|
|
102
|
+
ids.push(id);
|
|
103
|
+
}
|
|
104
|
+
if (rows.length < PAGE_SIZE)
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
if (ids.length > 0)
|
|
108
|
+
return ids;
|
|
109
|
+
throw new Error(`BrowserStack has no build named ${JSON.stringify(build)}`);
|
|
110
|
+
}
|
|
111
|
+
function listUrl(base, page) {
|
|
112
|
+
const url = new URL(base);
|
|
113
|
+
url.searchParams.set('limit', String(PAGE_SIZE));
|
|
114
|
+
url.searchParams.set('offset', String(page * PAGE_SIZE));
|
|
115
|
+
return url;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A `created_at` as an ISO timestamp in UTC. The API sends one with a zone;
|
|
119
|
+
* a time without one is read as UTC.
|
|
120
|
+
*/
|
|
121
|
+
function utcTimestamp(value) {
|
|
122
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
123
|
+
return undefined;
|
|
124
|
+
const text = value.trim();
|
|
125
|
+
const ms = Date.parse(/(Z|[+-]\d{2}:?\d{2})$/.test(text) ? text : `${text}Z`);
|
|
126
|
+
return Number.isNaN(ms) ? undefined : new Date(ms).toISOString();
|
|
127
|
+
}
|
|
128
|
+
function basicAuth({ username, accessKey }) {
|
|
129
|
+
return `Basic ${Buffer.from(`${username}:${accessKey}`).toString('base64')}`;
|
|
130
|
+
}
|
|
131
|
+
/** One authenticated GET answered with a JSON array; anything else throws, as `what`, with the HTTP status and the API's message. */
|
|
132
|
+
async function getRows(url, auth, signal, what) {
|
|
133
|
+
const body = await request(url, auth, signal, what, { timeoutMs: REQUEST_TIMEOUT_MS });
|
|
134
|
+
if (!Array.isArray(body))
|
|
135
|
+
throw new Error(`${what} failed: no list in the response`);
|
|
136
|
+
return body;
|
|
137
|
+
}
|
|
138
|
+
/** One authenticated request, a POST when it carries a form, answered with JSON; anything else throws, as `what`, with the HTTP status and the API's message, `hide` replaced in both. */
|
|
139
|
+
async function request(url, auth, signal, what, { timeoutMs, form, hide }) {
|
|
140
|
+
const clean = (text) => (hide === undefined ? text : redact(text, hide));
|
|
141
|
+
const timeout = new AbortController();
|
|
142
|
+
const timer = setTimeout(() => timeout.abort(), timeoutMs);
|
|
143
|
+
let response;
|
|
144
|
+
let text;
|
|
145
|
+
try {
|
|
146
|
+
response = await fetch(url, {
|
|
147
|
+
...(form === undefined ? {} : { method: 'POST', body: form }),
|
|
148
|
+
headers: { Authorization: auth, Accept: 'application/json' },
|
|
149
|
+
signal: AbortSignal.any([signal, timeout.signal]),
|
|
150
|
+
});
|
|
151
|
+
text = await response.text();
|
|
152
|
+
}
|
|
153
|
+
catch (cause) {
|
|
154
|
+
const failure = signal.aborted ? 'cancelled' : timeout.signal.aborted ? `got no answer within ${timeoutMs / 1000} s` : `failed: ${clean(cause instanceof Error ? cause.message : String(cause))}`;
|
|
155
|
+
if (hide === undefined)
|
|
156
|
+
throw new Error(`${what} ${failure}`, { cause });
|
|
157
|
+
// The error may carry the hidden URL in its own cause or properties, so only its redacted message is kept.
|
|
158
|
+
throw withCause(`${what} ${failure}`, redactedError(cause, hide));
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
}
|
|
163
|
+
let body;
|
|
164
|
+
try {
|
|
165
|
+
body = JSON.parse(text);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
throw new Error(`${what} failed: HTTP ${response.status}, not JSON`);
|
|
169
|
+
}
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
const message = asRecord(body)?.['message'] ?? asRecord(body)?.['error'];
|
|
172
|
+
throw new Error(`${what} failed: HTTP ${response.status}${typeof message === 'string' && message !== '' ? ` (${clean(message).slice(0, 200)})` : ''}`);
|
|
173
|
+
}
|
|
174
|
+
return body;
|
|
175
|
+
}
|
|
176
|
+
function asRecord(value) {
|
|
177
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
|
|
178
|
+
}
|
|
179
|
+
function isHttpUrl(value) {
|
|
180
|
+
return URL.canParse(value) && /^https?:$/.test(new URL(value).protocol);
|
|
181
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e2e-dev/browserstack",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "BrowserStack App Automate real Android and iOS devices for e2e mobile tests",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"e2e",
|
|
7
|
+
"end-to-end",
|
|
8
|
+
"testing",
|
|
9
|
+
"mobile-testing",
|
|
10
|
+
"browserstack",
|
|
11
|
+
"app-automate",
|
|
12
|
+
"device-cloud",
|
|
13
|
+
"real-devices",
|
|
14
|
+
"agent-device",
|
|
15
|
+
"ci"
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/tester-army/e2e.git",
|
|
21
|
+
"directory": "packages/browserstack"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/tester-army/e2e/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/tester-army/e2e/tree/main/packages/browserstack#readme",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"registry": "https://registry.npmjs.org/",
|
|
29
|
+
"access": "public",
|
|
30
|
+
"tag": "latest"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"NOTICE"
|
|
42
|
+
],
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@e2e-dev/mobile": ">=0.12.5 <1",
|
|
45
|
+
"e2e": ">=0.15.0 <1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@e2e-dev/mobile": "0.12.4",
|
|
49
|
+
"@types/node": "26.6.5",
|
|
50
|
+
"e2e": "0.21.3",
|
|
51
|
+
"typescript": "7.0.2",
|
|
52
|
+
"vitest": "5.0.5"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": "^22.22.3 || >=24.8.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc --project tsconfig.build.json && node ../../scripts/stamp-dist.ts",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"test:watch": "vitest",
|
|
62
|
+
"test:unit": "vitest run tests/unit"
|
|
63
|
+
}
|
|
6
64
|
}
|