@wdio/browserstack-service 7.28.0 → 7.29.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/build/constants.d.ts +9 -0
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +12 -2
- package/build/cucumber-types.d.ts +177 -0
- package/build/cucumber-types.d.ts.map +1 -0
- package/build/cucumber-types.js +3 -0
- package/build/insights-handler.d.ts +40 -0
- package/build/insights-handler.d.ts.map +1 -0
- package/build/insights-handler.js +398 -0
- package/build/launcher.d.ts +5 -3
- package/build/launcher.d.ts.map +1 -1
- package/build/launcher.js +35 -4
- package/build/reporter.d.ts +13 -0
- package/build/reporter.d.ts.map +1 -0
- package/build/reporter.js +74 -0
- package/build/request-handler.d.ts +26 -0
- package/build/request-handler.d.ts.map +1 -0
- package/build/request-handler.js +93 -0
- package/build/service.d.ts +16 -16
- package/build/service.d.ts.map +1 -1
- package/build/service.js +84 -33
- package/build/types.d.ts +116 -0
- package/build/types.d.ts.map +1 -1
- package/build/util.d.ts +85 -1
- package/build/util.d.ts.map +1 -1
- package/build/util.js +486 -1
- package/package.json +8 -4
package/build/util.js
CHANGED
|
@@ -1,7 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getParentSuiteName = exports.isBrowserstackCapability = exports.getBrowserCapabilities = exports.getBrowserDescription = void 0;
|
|
29
|
+
exports.sleep = exports.getObservabilityBuildTags = exports.getObservabilityBuild = exports.getObservabilityProject = exports.getObservabilityKey = exports.getObservabilityUser = exports.batchAndPostEvents = exports.shouldAddServiceVersion = exports.isScreenshotCommand = exports.getHookType = exports.getHierarchy = exports.uploadEventData = exports.getLogTag = exports.removeAnsiColors = exports.getScenarioExamples = exports.isBrowserstackSession = exports.getCloudProvider = exports.getUniqueIdentifierForCucumber = exports.getUniqueIdentifier = exports.getGitMetaData = exports.getCiInfo = exports.stopBuildUpstream = exports.launchTestSession = exports.getParentSuiteName = exports.isBrowserstackCapability = exports.getBrowserCapabilities = exports.getBrowserDescription = void 0;
|
|
30
|
+
const os_1 = require("os");
|
|
31
|
+
const util_1 = require("util");
|
|
32
|
+
const http_1 = __importDefault(require("http"));
|
|
33
|
+
const https_1 = __importDefault(require("https"));
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const logger_1 = __importDefault(require("@wdio/logger"));
|
|
36
|
+
const got_1 = __importStar(require("got"));
|
|
37
|
+
const git_repo_info_1 = __importDefault(require("git-repo-info"));
|
|
38
|
+
const gitconfiglocal_1 = __importDefault(require("gitconfiglocal"));
|
|
4
39
|
const constants_1 = require("./constants");
|
|
40
|
+
const request_handler_1 = __importDefault(require("./request-handler"));
|
|
41
|
+
const pGitconfig = (0, util_1.promisify)(gitconfiglocal_1.default);
|
|
42
|
+
const log = (0, logger_1.default)('@wdio/browserstack-service');
|
|
43
|
+
const DEFAULT_REQUEST_CONFIG = {
|
|
44
|
+
agent: {
|
|
45
|
+
http: new http_1.default.Agent({ keepAlive: true }),
|
|
46
|
+
https: new https_1.default.Agent({ keepAlive: true }),
|
|
47
|
+
},
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
'X-BSTACK-OBS': 'true'
|
|
51
|
+
},
|
|
52
|
+
};
|
|
5
53
|
/**
|
|
6
54
|
* get browser description for Browserstack service
|
|
7
55
|
* @param cap browser capablities
|
|
@@ -61,3 +109,440 @@ function getParentSuiteName(fullTitle, testSuiteTitle) {
|
|
|
61
109
|
return parentSuiteName.trim();
|
|
62
110
|
}
|
|
63
111
|
exports.getParentSuiteName = getParentSuiteName;
|
|
112
|
+
async function launchTestSession(options, config, bsConfig) {
|
|
113
|
+
const data = {
|
|
114
|
+
format: 'json',
|
|
115
|
+
project_name: getObservabilityProject(options, bsConfig.projectName),
|
|
116
|
+
name: getObservabilityBuild(options, bsConfig.buildName),
|
|
117
|
+
start_time: (new Date()).toISOString(),
|
|
118
|
+
tags: getObservabilityBuildTags(options, bsConfig.buildTag),
|
|
119
|
+
host_info: {
|
|
120
|
+
hostname: (0, os_1.hostname)(),
|
|
121
|
+
platform: (0, os_1.platform)(),
|
|
122
|
+
type: (0, os_1.type)(),
|
|
123
|
+
version: (0, os_1.version)(),
|
|
124
|
+
arch: (0, os_1.arch)()
|
|
125
|
+
},
|
|
126
|
+
ci_info: getCiInfo(),
|
|
127
|
+
build_run_identifier: process.env.BROWSERSTACK_BUILD_RUN_IDENTIFIER,
|
|
128
|
+
failed_tests_rerun: process.env.BROWSERSTACK_RERUN || false,
|
|
129
|
+
version_control: await getGitMetaData(),
|
|
130
|
+
observability_version: {
|
|
131
|
+
frameworkName: config.framework,
|
|
132
|
+
sdkVersion: bsConfig.bstackServiceVersion
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
const url = `${constants_1.DATA_ENDPOINT}/api/v1/builds`;
|
|
137
|
+
const response = await got_1.default.post(url, {
|
|
138
|
+
...DEFAULT_REQUEST_CONFIG,
|
|
139
|
+
username: getObservabilityUser(options, config),
|
|
140
|
+
password: getObservabilityKey(options, config),
|
|
141
|
+
json: data
|
|
142
|
+
}).json();
|
|
143
|
+
log.debug(`[Start_Build] Success response: ${JSON.stringify(response)}`);
|
|
144
|
+
process.env.BS_TESTOPS_BUILD_COMPLETED = 'true';
|
|
145
|
+
if (response.jwt)
|
|
146
|
+
process.env.BS_TESTOPS_JWT = response.jwt;
|
|
147
|
+
if (response.build_hashed_id)
|
|
148
|
+
process.env.BS_TESTOPS_BUILD_HASHED_ID = response.build_hashed_id;
|
|
149
|
+
if (response.allow_screenshots)
|
|
150
|
+
process.env.BS_TESTOPS_ALLOW_SCREENSHOTS = response.allow_screenshots.toString();
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (error instanceof got_1.HTTPError && error.response && error.response.statusCode == 401) {
|
|
154
|
+
log.debug('Data upload to BrowserStack Test Observability failed either due to incorrect credentials or an unsupported SDK version or because you do not have access to the product.');
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
log.debug(`[Start_Build] Failed. Error: ${error}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.launchTestSession = launchTestSession;
|
|
162
|
+
async function stopBuildUpstream() {
|
|
163
|
+
if (!process.env.BS_TESTOPS_BUILD_COMPLETED) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!process.env.BS_TESTOPS_JWT) {
|
|
167
|
+
log.debug('[STOP_BUILD] Missing Authentication Token/ Build ID');
|
|
168
|
+
return {
|
|
169
|
+
status: 'error',
|
|
170
|
+
message: 'Token/buildID is undefined, build creation might have failed'
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const data = {
|
|
174
|
+
'stop_time': (new Date()).toISOString()
|
|
175
|
+
};
|
|
176
|
+
try {
|
|
177
|
+
const url = `${constants_1.DATA_ENDPOINT}/api/v1/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID}/stop`;
|
|
178
|
+
const response = await got_1.default.put(url, {
|
|
179
|
+
agent: DEFAULT_REQUEST_CONFIG.agent,
|
|
180
|
+
headers: {
|
|
181
|
+
...DEFAULT_REQUEST_CONFIG.headers,
|
|
182
|
+
'Authorization': `Bearer ${process.env.BS_TESTOPS_JWT}`
|
|
183
|
+
},
|
|
184
|
+
json: data
|
|
185
|
+
}).json();
|
|
186
|
+
log.debug(`[STOP_BUILD] Success response: ${JSON.stringify(response)}`);
|
|
187
|
+
return {
|
|
188
|
+
status: 'success',
|
|
189
|
+
message: ''
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
log.debug(`[STOP_BUILD] Failed. Error: ${error}`);
|
|
194
|
+
return {
|
|
195
|
+
status: 'error',
|
|
196
|
+
message: error.message
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.stopBuildUpstream = stopBuildUpstream;
|
|
201
|
+
function getCiInfo() {
|
|
202
|
+
var env = process.env;
|
|
203
|
+
// Jenkins
|
|
204
|
+
if ((typeof env.JENKINS_URL === 'string' && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === 'string' && env.JENKINS_HOME.length > 0)) {
|
|
205
|
+
return {
|
|
206
|
+
name: 'Jenkins',
|
|
207
|
+
build_url: env.BUILD_URL,
|
|
208
|
+
job_name: env.JOB_NAME,
|
|
209
|
+
build_number: env.BUILD_NUMBER
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
// CircleCI
|
|
213
|
+
if (env.CI === 'true' && env.CIRCLECI === 'true') {
|
|
214
|
+
return {
|
|
215
|
+
name: 'CircleCI',
|
|
216
|
+
build_url: env.CIRCLE_BUILD_URL,
|
|
217
|
+
job_name: env.CIRCLE_JOB,
|
|
218
|
+
build_number: env.CIRCLE_BUILD_NUM
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// Travis CI
|
|
222
|
+
if (env.CI === 'true' && env.TRAVIS === 'true') {
|
|
223
|
+
return {
|
|
224
|
+
name: 'Travis CI',
|
|
225
|
+
build_url: env.TRAVIS_BUILD_WEB_URL,
|
|
226
|
+
job_name: env.TRAVIS_JOB_NAME,
|
|
227
|
+
build_number: env.TRAVIS_BUILD_NUMBER
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
// Codeship
|
|
231
|
+
if (env.CI === 'true' && env.CI_NAME === 'codeship') {
|
|
232
|
+
return {
|
|
233
|
+
name: 'Codeship',
|
|
234
|
+
build_url: null,
|
|
235
|
+
job_name: null,
|
|
236
|
+
build_number: null
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
// Bitbucket
|
|
240
|
+
if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
|
|
241
|
+
return {
|
|
242
|
+
name: 'Bitbucket',
|
|
243
|
+
build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
|
|
244
|
+
job_name: null,
|
|
245
|
+
build_number: env.BITBUCKET_BUILD_NUMBER
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
// Drone
|
|
249
|
+
if (env.CI === 'true' && env.DRONE === 'true') {
|
|
250
|
+
return {
|
|
251
|
+
name: 'Drone',
|
|
252
|
+
build_url: env.DRONE_BUILD_LINK,
|
|
253
|
+
job_name: null,
|
|
254
|
+
build_number: env.DRONE_BUILD_NUMBER
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
// Semaphore
|
|
258
|
+
if (env.CI === 'true' && env.SEMAPHORE === 'true') {
|
|
259
|
+
return {
|
|
260
|
+
name: 'Semaphore',
|
|
261
|
+
build_url: env.SEMAPHORE_ORGANIZATION_URL,
|
|
262
|
+
job_name: env.SEMAPHORE_JOB_NAME,
|
|
263
|
+
build_number: env.SEMAPHORE_JOB_ID
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
// GitLab
|
|
267
|
+
if (env.CI === 'true' && env.GITLAB_CI === 'true') {
|
|
268
|
+
return {
|
|
269
|
+
name: 'GitLab',
|
|
270
|
+
build_url: env.CI_JOB_URL,
|
|
271
|
+
job_name: env.CI_JOB_NAME,
|
|
272
|
+
build_number: env.CI_JOB_ID
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// Buildkite
|
|
276
|
+
if (env.CI === 'true' && env.BUILDKITE === 'true') {
|
|
277
|
+
return {
|
|
278
|
+
name: 'Buildkite',
|
|
279
|
+
build_url: env.BUILDKITE_BUILD_URL,
|
|
280
|
+
job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
|
|
281
|
+
build_number: env.BUILDKITE_BUILD_NUMBER
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
// Visual Studio Team Services
|
|
285
|
+
if (env.TF_BUILD === 'True') {
|
|
286
|
+
return {
|
|
287
|
+
name: 'Visual Studio Team Services',
|
|
288
|
+
build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
|
|
289
|
+
job_name: env.SYSTEM_DEFINITIONID,
|
|
290
|
+
build_number: env.BUILD_BUILDID
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
// if no matches, return null
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
exports.getCiInfo = getCiInfo;
|
|
297
|
+
async function getGitMetaData() {
|
|
298
|
+
var info = (0, git_repo_info_1.default)();
|
|
299
|
+
if (!info.commonGitDir)
|
|
300
|
+
return {};
|
|
301
|
+
const { remote } = await pGitconfig(info.commonGitDir);
|
|
302
|
+
const remotes = Object.keys(remote).map(remoteName => ({ name: remoteName, url: remote[remoteName]['url'] }));
|
|
303
|
+
return {
|
|
304
|
+
name: 'git',
|
|
305
|
+
sha: info.sha,
|
|
306
|
+
short_sha: info.abbreviatedSha,
|
|
307
|
+
branch: info.branch,
|
|
308
|
+
tag: info.tag,
|
|
309
|
+
committer: info.committer,
|
|
310
|
+
committer_date: info.committerDate,
|
|
311
|
+
author: info.author,
|
|
312
|
+
author_date: info.authorDate,
|
|
313
|
+
commit_message: info.commitMessage,
|
|
314
|
+
root: info.root,
|
|
315
|
+
common_git_dir: info.commonGitDir,
|
|
316
|
+
worktree_git_dir: info.worktreeGitDir,
|
|
317
|
+
last_tag: info.lastTag,
|
|
318
|
+
commits_since_last_tag: info.commitsSinceLastTag,
|
|
319
|
+
remotes: remotes
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
exports.getGitMetaData = getGitMetaData;
|
|
323
|
+
function getUniqueIdentifier(test) {
|
|
324
|
+
return `${test.parent} - ${test.title}`;
|
|
325
|
+
}
|
|
326
|
+
exports.getUniqueIdentifier = getUniqueIdentifier;
|
|
327
|
+
function getUniqueIdentifierForCucumber(world) {
|
|
328
|
+
return world.pickle.uri + '_' + world.pickle.astNodeIds.join(',');
|
|
329
|
+
}
|
|
330
|
+
exports.getUniqueIdentifierForCucumber = getUniqueIdentifierForCucumber;
|
|
331
|
+
function getCloudProvider(browser) {
|
|
332
|
+
if (browser.options && browser.options.hostname && browser.options.hostname.includes('browserstack')) {
|
|
333
|
+
return 'browserstack';
|
|
334
|
+
}
|
|
335
|
+
return 'unknown_grid';
|
|
336
|
+
}
|
|
337
|
+
exports.getCloudProvider = getCloudProvider;
|
|
338
|
+
function isBrowserstackSession(browser) {
|
|
339
|
+
if (!browser) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
return getCloudProvider(browser).toLowerCase() == 'browserstack';
|
|
343
|
+
}
|
|
344
|
+
exports.isBrowserstackSession = isBrowserstackSession;
|
|
345
|
+
function getScenarioExamples(world) {
|
|
346
|
+
var _a;
|
|
347
|
+
const scenario = world.pickle;
|
|
348
|
+
// no examples present
|
|
349
|
+
if ((scenario.astNodeIds && scenario.astNodeIds.length <= 1) || scenario.astNodeIds == undefined)
|
|
350
|
+
return;
|
|
351
|
+
const pickleId = scenario.astNodeIds[0];
|
|
352
|
+
const examplesId = scenario.astNodeIds[1];
|
|
353
|
+
const gherkinDocumentChildren = (_a = world.gherkinDocument.feature) === null || _a === void 0 ? void 0 : _a.children;
|
|
354
|
+
let examples = [];
|
|
355
|
+
gherkinDocumentChildren === null || gherkinDocumentChildren === void 0 ? void 0 : gherkinDocumentChildren.forEach(child => {
|
|
356
|
+
var _a;
|
|
357
|
+
if (child.rule) {
|
|
358
|
+
// handle if rule is present
|
|
359
|
+
child.rule.children.forEach(childLevel2 => {
|
|
360
|
+
var _a;
|
|
361
|
+
if (childLevel2.scenario && childLevel2.scenario.id == pickleId && childLevel2.scenario.examples) {
|
|
362
|
+
const passedExamples = (_a = childLevel2.scenario.examples.flatMap((val) => (val.tableBody)).find((item) => item.id == examplesId)) === null || _a === void 0 ? void 0 : _a.cells.map((val) => (val.value));
|
|
363
|
+
if (passedExamples)
|
|
364
|
+
examples = passedExamples;
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
else if (child.scenario && child.scenario.id == pickleId && child.scenario.examples) {
|
|
369
|
+
// handle if scenario outside rule
|
|
370
|
+
const passedExamples = (_a = child.scenario.examples.flatMap((val) => (val.tableBody)).find((item) => item.id == examplesId)) === null || _a === void 0 ? void 0 : _a.cells.map((val) => (val.value));
|
|
371
|
+
if (passedExamples)
|
|
372
|
+
examples = passedExamples;
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
if (examples.length)
|
|
376
|
+
return examples;
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
exports.getScenarioExamples = getScenarioExamples;
|
|
380
|
+
function removeAnsiColors(message) {
|
|
381
|
+
// https://stackoverflow.com/a/29497680
|
|
382
|
+
// eslint-disable-next-line no-control-regex
|
|
383
|
+
return message.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
|
|
384
|
+
}
|
|
385
|
+
exports.removeAnsiColors = removeAnsiColors;
|
|
386
|
+
function getLogTag(eventType) {
|
|
387
|
+
if (eventType == 'TestRunStarted' || eventType == 'TestRunFinished') {
|
|
388
|
+
return 'Test_Upload';
|
|
389
|
+
}
|
|
390
|
+
else if (eventType == 'HookRunStarted' || eventType == 'HookRunFinished') {
|
|
391
|
+
return 'Hook_Upload';
|
|
392
|
+
}
|
|
393
|
+
else if (eventType == 'ScreenshotCreated') {
|
|
394
|
+
return 'Screenshot_Upload';
|
|
395
|
+
}
|
|
396
|
+
else if (eventType == 'LogCreated') {
|
|
397
|
+
return 'Log_Upload';
|
|
398
|
+
}
|
|
399
|
+
return 'undefined';
|
|
400
|
+
}
|
|
401
|
+
exports.getLogTag = getLogTag;
|
|
402
|
+
async function uploadEventData(eventData, eventUrl = constants_1.DATA_EVENT_ENDPOINT) {
|
|
403
|
+
let logTag = 'BATCH_UPLOAD';
|
|
404
|
+
if (!Array.isArray(eventData)) {
|
|
405
|
+
logTag = getLogTag(eventData.event_type);
|
|
406
|
+
}
|
|
407
|
+
if (eventUrl == constants_1.DATA_SCREENSHOT_ENDPOINT)
|
|
408
|
+
logTag = 'screenshot_upload';
|
|
409
|
+
if (!process.env.BS_TESTOPS_BUILD_COMPLETED) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (!process.env.BS_TESTOPS_JWT) {
|
|
413
|
+
log.debug(`[${logTag}] Missing Authentication Token/ Build ID`);
|
|
414
|
+
return {
|
|
415
|
+
status: 'error',
|
|
416
|
+
message: 'Token/buildID is undefined, build creation might have failed'
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
const url = `${constants_1.DATA_ENDPOINT}/${eventUrl}`;
|
|
421
|
+
request_handler_1.default.getInstance().pendingUploads += 1;
|
|
422
|
+
const data = await got_1.default.post(url, {
|
|
423
|
+
agent: DEFAULT_REQUEST_CONFIG.agent,
|
|
424
|
+
headers: {
|
|
425
|
+
...DEFAULT_REQUEST_CONFIG.headers,
|
|
426
|
+
'Authorization': `Bearer ${process.env.BS_TESTOPS_JWT}`
|
|
427
|
+
},
|
|
428
|
+
json: eventData
|
|
429
|
+
}).json();
|
|
430
|
+
log.debug(`[${logTag}] Success response: ${JSON.stringify(data)}`);
|
|
431
|
+
request_handler_1.default.getInstance().pendingUploads -= 1;
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
log.debug(`[${logTag}] Failed. Error: ${error}`);
|
|
435
|
+
request_handler_1.default.getInstance().pendingUploads -= 1;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
exports.uploadEventData = uploadEventData;
|
|
439
|
+
// get hierarchy for a particular test (called by reporter for skipped tests)
|
|
440
|
+
function getHierarchy(fullTitle) {
|
|
441
|
+
if (!fullTitle)
|
|
442
|
+
return [];
|
|
443
|
+
return fullTitle.split('.').slice(0, -1);
|
|
444
|
+
}
|
|
445
|
+
exports.getHierarchy = getHierarchy;
|
|
446
|
+
function getHookType(hookName) {
|
|
447
|
+
if (hookName.includes('before each')) {
|
|
448
|
+
return 'BEFORE_EACH';
|
|
449
|
+
}
|
|
450
|
+
else if (hookName.includes('before all')) {
|
|
451
|
+
return 'BEFORE_ALL';
|
|
452
|
+
}
|
|
453
|
+
else if (hookName.includes('after each')) {
|
|
454
|
+
return 'AFTER_EACH';
|
|
455
|
+
}
|
|
456
|
+
else if (hookName.includes('after all')) {
|
|
457
|
+
return 'AFTER_ALL';
|
|
458
|
+
}
|
|
459
|
+
return 'unknown';
|
|
460
|
+
}
|
|
461
|
+
exports.getHookType = getHookType;
|
|
462
|
+
function isScreenshotCommand(args) {
|
|
463
|
+
return args.endpoint && args.endpoint.includes('/screenshot');
|
|
464
|
+
}
|
|
465
|
+
exports.isScreenshotCommand = isScreenshotCommand;
|
|
466
|
+
function shouldAddServiceVersion(config, testObservability) {
|
|
467
|
+
if (config.services && config.services.toString().includes('chromedriver') && testObservability != false) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
exports.shouldAddServiceVersion = shouldAddServiceVersion;
|
|
473
|
+
async function batchAndPostEvents(eventUrl, kind, data) {
|
|
474
|
+
if (!process.env.BS_TESTOPS_BUILD_COMPLETED || !process.env.BS_TESTOPS_JWT) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
try {
|
|
478
|
+
const url = `${constants_1.DATA_ENDPOINT}/${eventUrl}`;
|
|
479
|
+
const response = await got_1.default.post(url, {
|
|
480
|
+
agent: DEFAULT_REQUEST_CONFIG.agent,
|
|
481
|
+
headers: {
|
|
482
|
+
...DEFAULT_REQUEST_CONFIG.headers,
|
|
483
|
+
'Authorization': `Bearer ${process.env.BS_TESTOPS_JWT}`
|
|
484
|
+
},
|
|
485
|
+
json: data
|
|
486
|
+
}).json();
|
|
487
|
+
log.debug(`[${kind}] Success response: ${JSON.stringify(response)}`);
|
|
488
|
+
}
|
|
489
|
+
catch (error) {
|
|
490
|
+
log.debug(`[${kind}] EXCEPTION IN ${kind} REQUEST TO TEST OBSERVABILITY : ${error}`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
exports.batchAndPostEvents = batchAndPostEvents;
|
|
494
|
+
function getObservabilityUser(options, config) {
|
|
495
|
+
if (process.env.BROWSERSTACK_USERNAME) {
|
|
496
|
+
return process.env.BROWSERSTACK_USERNAME;
|
|
497
|
+
}
|
|
498
|
+
if (options.testObservabilityOptions && options.testObservabilityOptions.user) {
|
|
499
|
+
return options.testObservabilityOptions.user;
|
|
500
|
+
}
|
|
501
|
+
return config.user;
|
|
502
|
+
}
|
|
503
|
+
exports.getObservabilityUser = getObservabilityUser;
|
|
504
|
+
function getObservabilityKey(options, config) {
|
|
505
|
+
if (process.env.BROWSERSTACK_ACCESS_KEY) {
|
|
506
|
+
return process.env.BROWSERSTACK_ACCESS_KEY;
|
|
507
|
+
}
|
|
508
|
+
if (options.testObservabilityOptions && options.testObservabilityOptions.key) {
|
|
509
|
+
return options.testObservabilityOptions.key;
|
|
510
|
+
}
|
|
511
|
+
return config.key;
|
|
512
|
+
}
|
|
513
|
+
exports.getObservabilityKey = getObservabilityKey;
|
|
514
|
+
function getObservabilityProject(options, bstackProjectName) {
|
|
515
|
+
if (process.env.TEST_OBSERVABILITY_PROJECT_NAME) {
|
|
516
|
+
return process.env.TEST_OBSERVABILITY_PROJECT_NAME;
|
|
517
|
+
}
|
|
518
|
+
if (options.testObservabilityOptions && options.testObservabilityOptions.projectName) {
|
|
519
|
+
return options.testObservabilityOptions.projectName;
|
|
520
|
+
}
|
|
521
|
+
return bstackProjectName;
|
|
522
|
+
}
|
|
523
|
+
exports.getObservabilityProject = getObservabilityProject;
|
|
524
|
+
function getObservabilityBuild(options, bstackBuildName) {
|
|
525
|
+
if (process.env.TEST_OBSERVABILITY_BUILD_NAME) {
|
|
526
|
+
return process.env.TEST_OBSERVABILITY_BUILD_NAME;
|
|
527
|
+
}
|
|
528
|
+
if (options.testObservabilityOptions && options.testObservabilityOptions.buildName) {
|
|
529
|
+
return options.testObservabilityOptions.buildName;
|
|
530
|
+
}
|
|
531
|
+
return bstackBuildName || path_1.default.basename(path_1.default.resolve(process.cwd()));
|
|
532
|
+
}
|
|
533
|
+
exports.getObservabilityBuild = getObservabilityBuild;
|
|
534
|
+
function getObservabilityBuildTags(options, bstackBuildTag) {
|
|
535
|
+
if (process.env.TEST_OBSERVABILITY_BUILD_TAG) {
|
|
536
|
+
return process.env.TEST_OBSERVABILITY_BUILD_TAG.split(',');
|
|
537
|
+
}
|
|
538
|
+
if (options.testObservabilityOptions && options.testObservabilityOptions.buildTag) {
|
|
539
|
+
return options.testObservabilityOptions.buildTag;
|
|
540
|
+
}
|
|
541
|
+
if (bstackBuildTag) {
|
|
542
|
+
return [bstackBuildTag];
|
|
543
|
+
}
|
|
544
|
+
return [];
|
|
545
|
+
}
|
|
546
|
+
exports.getObservabilityBuildTags = getObservabilityBuildTags;
|
|
547
|
+
const sleep = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
548
|
+
exports.sleep = sleep;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/browserstack-service",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.29.0",
|
|
4
4
|
"description": "WebdriverIO service for better Browserstack integration",
|
|
5
5
|
"author": "Adam Bjerstedt <abjerstedt@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-browserstack-service",
|
|
@@ -23,13 +23,17 @@
|
|
|
23
23
|
"url": "https://github.com/webdriverio/webdriverio/issues"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@types/
|
|
26
|
+
"@types/gitconfiglocal": "^2.0.1",
|
|
27
27
|
"@wdio/logger": "7.26.0",
|
|
28
|
+
"@wdio/reporter": "7.25.4",
|
|
28
29
|
"@wdio/types": "7.26.0",
|
|
29
30
|
"browserstack-local": "^1.4.5",
|
|
30
31
|
"form-data": "^4.0.0",
|
|
32
|
+
"git-repo-info": "^2.1.1",
|
|
33
|
+
"gitconfiglocal": "^2.1.0",
|
|
31
34
|
"got": "^11.0.2",
|
|
32
|
-
"
|
|
35
|
+
"uuid": "^8.3.2",
|
|
36
|
+
"webdriverio": "7.29.0"
|
|
33
37
|
},
|
|
34
38
|
"peerDependencies": {
|
|
35
39
|
"@wdio/cli": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
@@ -38,5 +42,5 @@
|
|
|
38
42
|
"access": "public"
|
|
39
43
|
},
|
|
40
44
|
"types": "./build/index.d.ts",
|
|
41
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "9a9d22b1b9c3e0f2347a8965072c91d311d71120"
|
|
42
46
|
}
|