1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const glob = require("glob");
|
4 | const path = require("path");
|
5 | const exitCodes_1 = require("./exitCodes");
|
6 | const logger_1 = require("./logger");
|
7 | let logger = new logger_1.Logger('configParser');
|
8 |
|
9 | try {
|
10 | require('coffee-script').register();
|
11 | }
|
12 | catch (e) {
|
13 |
|
14 | }
|
15 |
|
16 | try {
|
17 | require('coffeescript').register();
|
18 | }
|
19 | catch (e) {
|
20 |
|
21 | }
|
22 |
|
23 | try {
|
24 | require('LiveScript');
|
25 | }
|
26 | catch (e) {
|
27 |
|
28 | }
|
29 | class ConfigParser {
|
30 | constructor() {
|
31 |
|
32 | this.config_ = {
|
33 | specs: [],
|
34 | multiCapabilities: [],
|
35 | verboseMultiSessions: false,
|
36 | rootElement: '',
|
37 | allScriptsTimeout: 11000,
|
38 | getPageTimeout: 10000,
|
39 | params: {},
|
40 | framework: 'jasmine',
|
41 | jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: (30 * 1000) },
|
42 | seleniumArgs: [],
|
43 | mochaOpts: { ui: 'bdd', reporter: 'list' },
|
44 | configDir: './',
|
45 | noGlobals: false,
|
46 | plugins: [],
|
47 | skipSourceMapSupport: false,
|
48 | ng12Hybrid: false
|
49 | };
|
50 | }
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | static resolveFilePatterns(patterns, opt_omitWarnings, opt_relativeTo) {
|
61 | let resolvedFiles = [];
|
62 | let cwd = opt_relativeTo || process.cwd();
|
63 | patterns = (typeof patterns === 'string') ? [patterns] : patterns;
|
64 | if (patterns) {
|
65 | for (let fileName of patterns) {
|
66 | let matches = glob.hasMagic(fileName) ? glob.sync(fileName, { cwd }) : [fileName];
|
67 | if (!matches.length && !opt_omitWarnings) {
|
68 | logger.warn('pattern ' + fileName + ' did not match any files.');
|
69 | }
|
70 | for (let match of matches) {
|
71 | let resolvedPath = path.resolve(cwd, match);
|
72 | resolvedFiles.push(resolvedPath);
|
73 | }
|
74 | }
|
75 | }
|
76 | return resolvedFiles;
|
77 | }
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 | static getSpecs(config) {
|
84 | let specs = [];
|
85 | if (config.suite) {
|
86 | config.suite.split(',').forEach((suite) => {
|
87 | let suiteList = config.suites ? config.suites[suite] : null;
|
88 | if (suiteList == null) {
|
89 | throw new exitCodes_1.ConfigError(logger, 'Unknown test suite: ' + suite);
|
90 | }
|
91 | union(specs, makeArray(suiteList));
|
92 | });
|
93 | return specs;
|
94 | }
|
95 | if (config.specs.length > 0) {
|
96 | return config.specs;
|
97 | }
|
98 | Object.keys(config.suites || {}).forEach((suite) => {
|
99 | union(specs, makeArray(config.suites[suite]));
|
100 | });
|
101 | return specs;
|
102 | }
|
103 | |
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | addConfig_(additionalConfig, relativeTo) {
|
111 |
|
112 |
|
113 | ['seleniumServerJar', 'chromeDriver', 'firefoxPath', 'frameworkPath', 'geckoDriver',
|
114 | 'onPrepare']
|
115 | .forEach((name) => {
|
116 | if (additionalConfig[name] && typeof additionalConfig[name] === 'string') {
|
117 | additionalConfig[name] = path.resolve(relativeTo, additionalConfig[name]);
|
118 | }
|
119 | });
|
120 | merge_(this.config_, additionalConfig);
|
121 | }
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | addFileConfig(filename) {
|
129 | if (!filename) {
|
130 | return this;
|
131 | }
|
132 | let filePath = path.resolve(process.cwd(), filename);
|
133 | let fileConfig;
|
134 | try {
|
135 | fileConfig = require(filePath).config;
|
136 | }
|
137 | catch (e) {
|
138 | throw new exitCodes_1.ConfigError(logger, 'failed loading configuration file ' + filename, e);
|
139 | }
|
140 | if (!fileConfig) {
|
141 | throw new exitCodes_1.ConfigError(logger, 'configuration file ' + filename + ' did not export a config object');
|
142 | }
|
143 | fileConfig.configDir = path.dirname(filePath);
|
144 | this.addConfig_(fileConfig, fileConfig.configDir);
|
145 | return this;
|
146 | }
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | addConfig(argv) {
|
154 | this.addConfig_(argv, process.cwd());
|
155 | return this;
|
156 | }
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | getConfig() {
|
164 | return this.config_;
|
165 | }
|
166 | }
|
167 | exports.ConfigParser = ConfigParser;
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | let merge_ = function (into, from) {
|
178 | for (let key in from) {
|
179 | if (into[key] instanceof Object && !(into[key] instanceof Array) &&
|
180 | !(into[key] instanceof Function)) {
|
181 | merge_(into[key], from[key]);
|
182 | }
|
183 | else {
|
184 | into[key] = from[key];
|
185 | }
|
186 | }
|
187 | return into;
|
188 | };
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | let makeArray = function (item) {
|
194 | return Array.isArray(item) ? item : [item];
|
195 | };
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | let union = function (dest, src) {
|
204 | let elems = {};
|
205 | for (let key in dest) {
|
206 | elems[dest[key]] = true;
|
207 | }
|
208 | for (let key in src) {
|
209 | if (!elems[src[key]]) {
|
210 | dest.push(src[key]);
|
211 | elems[src[key]] = true;
|
212 | }
|
213 | }
|
214 | };
|
215 |
|
\ | No newline at end of file |