browserstack-cypress-cli 1.37.4 → 1.37.5
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/bin/commands/runs.js
CHANGED
|
@@ -133,6 +133,8 @@ module.exports = function run(args, rawArgs) {
|
|
|
133
133
|
const port = await findAvailablePort(preferredPort);
|
|
134
134
|
process.env.REPORTER_API_PORT_NO = port
|
|
135
135
|
|
|
136
|
+
utils.validateCollectorUrls();
|
|
137
|
+
|
|
136
138
|
// Send build start to TEST REPORTING AND ANALYTICS
|
|
137
139
|
if(shouldProcessEventForTesthub()) {
|
|
138
140
|
await TestHubHandler.launchBuild(bsConfig, bsConfigPath);
|
package/bin/helpers/utils.js
CHANGED
|
@@ -31,7 +31,7 @@ const usageReporting = require("./usageReporting"),
|
|
|
31
31
|
pkg = require('../../package.json'),
|
|
32
32
|
transports = require('./logger').transports,
|
|
33
33
|
o11yHelpers = require('../testObservability/helper/helper'),
|
|
34
|
-
{ OBSERVABILITY_ENV_VARS, TEST_OBSERVABILITY_REPORTER } = require('../testObservability/helper/constants');
|
|
34
|
+
{ OBSERVABILITY_ENV_VARS, TEST_OBSERVABILITY_REPORTER, API_URL_ENV, REMOTE_API_URL_ENV, apiUrl, remoteReporterApiUrl } = require('../testObservability/helper/constants');
|
|
35
35
|
|
|
36
36
|
const { default: axios } = require("axios");
|
|
37
37
|
const { shouldProcessEventForTesthub } = require("../testhub/utils");
|
|
@@ -572,6 +572,22 @@ exports.setBuildTags = (bsConfig, args) => {
|
|
|
572
572
|
logger.debug(`Setting the build tag = ${bsConfig.run_settings.build_tag}`);
|
|
573
573
|
};
|
|
574
574
|
|
|
575
|
+
// Called before anything is created server-side: setSystemEnvs runs after the TestHub build
|
|
576
|
+
// exists, so a malformed collector override would otherwise fail with a build already open.
|
|
577
|
+
exports.validateCollectorUrls = () => {
|
|
578
|
+
// Both, because remoteReporterApiUrl() short-circuits past apiUrl() when the remote override
|
|
579
|
+
// is set, which would leave a malformed general override unchecked until the first request.
|
|
580
|
+
apiUrl();
|
|
581
|
+
remoteReporterApiUrl();
|
|
582
|
+
// Remote-only means this process keeps its built-in collector while the machine reports to
|
|
583
|
+
// another one. That is correct when the built-in default has been pointed at the same
|
|
584
|
+
// environment, and a silently split build when it has not. Only the host is named: the
|
|
585
|
+
// path survives normalization and can carry a token.
|
|
586
|
+
if (process.env[REMOTE_API_URL_ENV] && !process.env[API_URL_ENV]) {
|
|
587
|
+
logger.warn(`${REMOTE_API_URL_ENV} is set without ${API_URL_ENV}: this run will create its build on the built-in collector and the remote reporter will post test results to ${new URL(remoteReporterApiUrl()).host}. Both must be the same environment.`);
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
|
|
575
591
|
exports.setSystemEnvs = (bsConfig) => {
|
|
576
592
|
let envKeys = {};
|
|
577
593
|
|
|
@@ -610,6 +626,10 @@ exports.setSystemEnvs = (bsConfig) => {
|
|
|
610
626
|
logger.error(`Error in adding accessibility configs ${error}`)
|
|
611
627
|
}
|
|
612
628
|
|
|
629
|
+
// Remote reporter must post to this build's collector, not its package default. Kept out of the
|
|
630
|
+
// try below, which swallows errors: a rejected override must fail rather than fall back silently.
|
|
631
|
+
envKeys[API_URL_ENV] = remoteReporterApiUrl();
|
|
632
|
+
|
|
613
633
|
try {
|
|
614
634
|
OBSERVABILITY_ENV_VARS.forEach(key => {
|
|
615
635
|
envKeys[key] = process.env[key];
|
|
@@ -7,7 +7,7 @@ const { HttpsProxyAgent = require('https-proxy-agent') } = require('https-proxy-
|
|
|
7
7
|
const logger = require("../../helpers/logger").winstonLogger;
|
|
8
8
|
const utils = require('../../helpers/utils');
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const { apiUrl, consoleHolder, TEST_REPORTING_ANALYTICS } = require('../helper/constants');
|
|
11
11
|
|
|
12
12
|
/* Below global methods are added here to remove cyclic dependency with helper.js, refactor later */
|
|
13
13
|
const httpsKeepAliveAgent = new https.Agent({
|
|
@@ -148,7 +148,7 @@ class CrashReporter {
|
|
|
148
148
|
'X-BSTACK-TESTOPS': 'true'
|
|
149
149
|
},
|
|
150
150
|
method: 'POST',
|
|
151
|
-
url: `${
|
|
151
|
+
url: `${apiUrl()}/api/v1/analytics`,
|
|
152
152
|
data: data,
|
|
153
153
|
json: true,
|
|
154
154
|
agent: httpsKeepAliveAgent
|
|
@@ -3,7 +3,42 @@ const path = require('path');
|
|
|
3
3
|
exports.consoleHolder = Object.assign({},console);
|
|
4
4
|
exports.BATCH_SIZE = 1000;
|
|
5
5
|
exports.BATCH_INTERVAL = 2000;
|
|
6
|
-
|
|
6
|
+
const DEFAULT_API_URL = 'https://collector-observability.browserstack.com';
|
|
7
|
+
|
|
8
|
+
// Overridable so the reporter on the remote machine posts to the collector the build was created
|
|
9
|
+
// on. Errors never echo the value: it can carry credentials and callers log them.
|
|
10
|
+
const httpsOverride = (name) => {
|
|
11
|
+
const value = process.env[name];
|
|
12
|
+
if (!value) return undefined;
|
|
13
|
+
let parsed;
|
|
14
|
+
try {
|
|
15
|
+
parsed = new URL(value);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
throw new Error(`${name} must be a valid https:// URL`);
|
|
18
|
+
}
|
|
19
|
+
if (parsed.protocol !== 'https:' || !parsed.hostname) {
|
|
20
|
+
throw new Error(`${name} must be an https:// URL`);
|
|
21
|
+
}
|
|
22
|
+
if (parsed.search || parsed.hash) {
|
|
23
|
+
throw new Error(`${name} must not contain a query or fragment`);
|
|
24
|
+
}
|
|
25
|
+
// URL.origin drops userinfo, so accepting it would silently discard a credential the
|
|
26
|
+
// caller believes it is sending.
|
|
27
|
+
if (parsed.username || parsed.password) {
|
|
28
|
+
throw new Error(`${name} must not contain a username or password`);
|
|
29
|
+
}
|
|
30
|
+
// Endpoints are appended as `${base}/${path}`.
|
|
31
|
+
return `${parsed.origin}${parsed.pathname}`.replace(/\/+$/, '');
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const API_URL_ENV = 'BROWSERSTACK_TEST_OBSERVABILITY_API_URL';
|
|
35
|
+
// Separate override for when the remote machine cannot reach the cli's own collector.
|
|
36
|
+
const REMOTE_API_URL_ENV = 'BROWSERSTACK_TEST_OBSERVABILITY_REMOTE_API_URL';
|
|
37
|
+
exports.API_URL_ENV = API_URL_ENV;
|
|
38
|
+
exports.REMOTE_API_URL_ENV = REMOTE_API_URL_ENV;
|
|
39
|
+
|
|
40
|
+
exports.apiUrl = () => httpsOverride(API_URL_ENV) || DEFAULT_API_URL;
|
|
41
|
+
exports.remoteReporterApiUrl = () => httpsOverride(REMOTE_API_URL_ENV) || exports.apiUrl();
|
|
7
42
|
|
|
8
43
|
exports.IPC_EVENTS = {
|
|
9
44
|
LOG: 'testObservability:cypressLog',
|
|
@@ -27,7 +27,7 @@ const GLOBAL_MODULE_PATH = execSync('npm root -g').toString().trim();
|
|
|
27
27
|
const { name, version } = require('../../../package.json');
|
|
28
28
|
|
|
29
29
|
const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require('../../helpers/constants');
|
|
30
|
-
const { consoleHolder,
|
|
30
|
+
const { consoleHolder, apiUrl, TEST_OBSERVABILITY_REPORTER, TEST_OBSERVABILITY_REPORTER_LOCAL, TEST_REPORTING_ANALYTICS } = require('./constants');
|
|
31
31
|
|
|
32
32
|
const ALLOWED_MODULES = [
|
|
33
33
|
'cypress/package.json',
|
|
@@ -128,10 +128,18 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
|
|
|
128
128
|
exports.nodeRequest = (type, url, data, config) => {
|
|
129
129
|
const requestQueueHandler = require('./requestQueueHandler');
|
|
130
130
|
return new Promise(async (resolve, reject) => {
|
|
131
|
+
// Rejected rather than thrown: this executor is async, so a throw here would never reach
|
|
132
|
+
// the returned promise and the caller would hang.
|
|
133
|
+
let collectorUrl;
|
|
134
|
+
try {
|
|
135
|
+
collectorUrl = apiUrl();
|
|
136
|
+
} catch (err) {
|
|
137
|
+
return reject(err);
|
|
138
|
+
}
|
|
131
139
|
const options = {
|
|
132
140
|
...config,
|
|
133
141
|
method: type,
|
|
134
|
-
url: `${
|
|
142
|
+
url: `${collectorUrl}/${url}`,
|
|
135
143
|
data: data,
|
|
136
144
|
httpsAgent: this.httpsKeepAliveAgent,
|
|
137
145
|
maxAttempts: 2,
|