UNPKG

2.44 kBJavaScriptView Raw
1'use strict';
2
3const { ROLLOUT_KEY, IS_ON_PREM } = require('./config');
4const logger = require('./logger').getLogger('FeatureFlagsService');
5const Promise = require('bluebird');
6const Rox = require('rox-node');
7
8// IS_UNIT_TEST = disable rollout if code run in unit test mode to ignore mocha process stuck on running
9const USE_FEATURE_FLAGS = !IS_ON_PREM && !process.env.IS_UNIT_TEST;
10
11const FORCE_FETCH_TIMEOUT_MS = 20000; // rollout sometimes takes up to 15 seconds to load
12const SEC_IN_DAY = 60 * 60 * 24;
13
14class FeatureFlagsService {
15 constructor() {
16 this.flags = {
17 useNewWebdriverApi: new Rox.Flag(),
18 useNewWSCLI: new Rox.Flag(),
19 disableEdgeVisibilityChecks: new Rox.Flag(),
20 useSafariWebdriverVisibilityChecks: new Rox.Flag(),
21 useClickimVisibilityChecks: new Rox.Flag(),
22 useIEWebdriverVisibilityChecks: new Rox.Flag(),
23 enableTDKRun: new Rox.Flag(true),
24 runGetElementCodeInAut: new Rox.Flag(),
25 enableNpmPackageInstallUsingNpmCli: new Rox.Flag(),
26 enableFrameSwitchOptimization: new Rox.Flag(),
27 maximumJsResultSize: new Rox.Configuration(2000 * 1024),
28 skipFileInputClicks: new Rox.Flag(),
29 enableMockNetwork: new Rox.Flag(),
30 errorMessageOnBadNetwork: new Rox.Flag(true),
31 warnOnBadNetwork: new Rox.Flag(false),
32 };
33 Rox.register('default', this.flags);
34 }
35
36 setProjectId(projectId) {
37 Rox.setCustomStringProperty('projectId', projectId);
38 }
39
40 setCompanyId(companyId) {
41 Rox.setCustomStringProperty('companyId', companyId);
42 }
43
44 setRunnerMode(mode) {
45 Rox.setCustomStringProperty('runnerMode', mode);
46 }
47
48 fetch() {
49 if (!USE_FEATURE_FLAGS) {
50 return Promise.resolve();
51 }
52 const opts = {
53 fetchIntervalInSec: SEC_IN_DAY, // we don't actually want to refresh feature flags in the CLI,
54 disableNetworkFetch: false,
55 };
56
57
58 if (global.ProxyAgent) {
59 const agent = new global.ProxyAgent(global.proxyUri);
60 opts.httpsAgent = agent;
61 opts.httpAgent = agent;
62 }
63
64 return Promise.resolve(Rox.setup(ROLLOUT_KEY, opts))
65 .timeout(FORCE_FETCH_TIMEOUT_MS).catch(err => logger.error('failed to get feature flag status', err));
66 }
67}
68
69module.exports = new FeatureFlagsService();