UNPKG

3.19 kBJavaScriptView Raw
1// src/constants.ts
2var DEFAULT_TIMEOUT = 1e4;
3var DEFAULT_CONFIGS = () => ({
4 specs: [],
5 suites: {},
6 exclude: [],
7 outputDir: void 0,
8 logLevel: "info",
9 logLevels: {},
10 groupLogsByTestSpec: false,
11 excludeDriverLogs: [],
12 bail: 0,
13 waitforInterval: 500,
14 waitforTimeout: 5e3,
15 framework: "mocha",
16 reporters: [],
17 services: [],
18 maxInstances: 100,
19 maxInstancesPerCapability: 100,
20 injectGlobals: true,
21 filesToWatch: [],
22 connectionRetryTimeout: 12e4,
23 connectionRetryCount: 3,
24 execArgv: [],
25 runnerEnv: {},
26 runner: "local",
27 shard: {
28 current: 1,
29 total: 1
30 },
31 specFileRetries: 0,
32 specFileRetriesDelay: 0,
33 specFileRetriesDeferred: false,
34 reporterSyncInterval: 100,
35 reporterSyncTimeout: 5e3,
36 cucumberFeaturesWithLineNumbers: [],
37 /**
38 * framework defaults
39 */
40 mochaOpts: {
41 timeout: DEFAULT_TIMEOUT
42 },
43 jasmineOpts: {
44 defaultTimeoutInterval: DEFAULT_TIMEOUT
45 },
46 cucumberOpts: {
47 timeout: DEFAULT_TIMEOUT
48 },
49 /**
50 * hooks
51 */
52 onPrepare: [],
53 onWorkerStart: [],
54 onWorkerEnd: [],
55 before: [],
56 beforeSession: [],
57 beforeSuite: [],
58 beforeHook: [],
59 beforeTest: [],
60 beforeCommand: [],
61 afterCommand: [],
62 afterTest: [],
63 afterHook: [],
64 afterSuite: [],
65 afterSession: [],
66 after: [],
67 onComplete: [],
68 onReload: [],
69 beforeAssertion: [],
70 afterAssertion: [],
71 /**
72 * cucumber specific hooks
73 */
74 beforeFeature: [],
75 beforeScenario: [],
76 beforeStep: [],
77 afterStep: [],
78 afterScenario: [],
79 afterFeature: []
80});
81
82// src/utils.ts
83import decamelize from "decamelize";
84function isCloudCapability(caps) {
85 return Boolean(caps && (caps["bstack:options"] || caps["sauce:options"] || caps["tb:options"]));
86}
87function validateConfig(defaults, options, keysToKeep = []) {
88 const params = {};
89 for (const [name, expectedOption] of Object.entries(defaults)) {
90 if (typeof options[name] === "undefined" && !expectedOption.default && expectedOption.required) {
91 throw new Error(`Required option "${name.toString()}" is missing`);
92 }
93 if (typeof options[name] === "undefined" && expectedOption.default) {
94 params[name] = expectedOption.default;
95 }
96 if (typeof options[name] !== "undefined") {
97 const optValue = options[name];
98 if (typeof optValue !== expectedOption.type) {
99 throw new Error(`Expected option "${name.toString()}" to be type of ${expectedOption.type} but was ${typeof options[name]}`);
100 }
101 if (typeof expectedOption.validate === "function") {
102 try {
103 expectedOption.validate(optValue);
104 } catch (e) {
105 throw new Error(`Type check for option "${name.toString()}" failed: ${e.message}`);
106 }
107 }
108 if (typeof optValue === "string" && expectedOption.match && !optValue.match(expectedOption.match)) {
109 throw new Error(`Option "${name.toString()}" doesn't match expected values: ${expectedOption.match}`);
110 }
111 params[name] = options[name];
112 }
113 }
114 for (const [name, option] of Object.entries(options)) {
115 if (keysToKeep.includes(name)) {
116 params[name] = option;
117 }
118 }
119 return params;
120}
121export {
122 DEFAULT_CONFIGS,
123 isCloudCapability,
124 validateConfig
125};