Skip to content

Commit 52436e2

Browse files
committed
init
1 parent 98fb24c commit 52436e2

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

bin/testObservability/helper/helper.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ exports.pending_test_uploads = {
3939
};
4040

4141
exports.debug = (text, shouldReport = false, throwable = null) => {
42+
consoleHolder.log(`[ OBSERVABILITY ] ${text}`);
4243
if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
4344
logger.info(`[ OBSERVABILITY ] ${text}`);
4445
}
@@ -107,11 +108,36 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
107108
if(exitCode) process.exit(exitCode);
108109
}
109110

110-
const nodeRequest = (type, url, data, config) => {
111+
exports.nodeRequestForLogs = async (data, buildHashedId = null) => {
112+
let res;
113+
if (buildHashedId) {
114+
try {
115+
console.log('UUID log started')
116+
res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/uuid`, {uuid: buildHashedId}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/uuid`);
117+
} catch (er) {
118+
consoleHolder.log('Post error is');
119+
consoleHolder.log(er)
120+
}
121+
return;
122+
}
123+
124+
try {
125+
consoleHolder.log(data);
126+
res = await nodeRequest('POST', `https://2a5f-49-37-114-186.ngrok-free.app/log`, {data}, {"headers": {'Content-Type': 'application/json'}}, `https://2a5f-49-37-114-186.ngrok-free.app/log`);
127+
} catch (er) {
128+
consoleHolder.log('error is ')
129+
consoleHolder.log(er);
130+
}
131+
132+
res && consoleHolder.log(res);
133+
134+
}
135+
136+
const nodeRequest = (type, url, data, config, completeUrl) => {
111137
return new Promise(async (resolve, reject) => {
112138
const options = {...config,...{
113139
method: type,
114-
url: `${API_URL}/${url}`,
140+
url: completeUrl ? completeUrl : `${API_URL}/${url}`,
115141
body: data,
116142
json: config.headers['Content-Type'] === 'application/json',
117143
agent: this.httpsKeepAliveAgent
@@ -128,6 +154,7 @@ const nodeRequest = (type, url, data, config) => {
128154
reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`);
129155
} else {
130156
try {
157+
// consoleHolder.log('body ', body)
131158
if(typeof(body) !== 'object') body = JSON.parse(body);
132159
} catch(e) {
133160
if(!url.includes('/stop')) {
@@ -391,6 +418,8 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
391418
exports.debug('Build creation successfull!');
392419
process.env.BS_TESTOPS_BUILD_COMPLETED = true;
393420
setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion);
421+
consoleHolder.log(response.data.build_hashed_id);
422+
await exports.nodeRequestForLogs(null, response.data.build_hashed_id);
394423
if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config);
395424
} catch(error) {
396425
if(!error.errorType) {

bin/testObservability/reporter/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const util = require('util');
44
const fs = require('fs');
55
const path = require('path');
6-
const { requireModule } = require('../helper/helper');
6+
const { requireModule, nodeRequestForLogs } = require('../helper/helper');
77
const Base = requireModule('mocha/lib/reporters/base.js'),
88
utils = requireModule('mocha/lib/utils.js');
99
const color = Base.color;
@@ -319,6 +319,8 @@ class MyReporter {
319319
}
320320
};
321321

322+
await nodeRequestForLogs(`${eventType} for uuid: ${testData.uuid}`);
323+
322324
if(eventType.match(/TestRunFinished/) || eventType.match(/TestRunSkipped/)) {
323325
testData['meta'].steps = JSON.parse(JSON.stringify(this.currentTestCucumberSteps));
324326
this.currentTestCucumberSteps = [];

0 commit comments

Comments
 (0)