-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.js
236 lines (212 loc) · 7 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
var os = require('os');
var fs = require('fs');
var argv = require('optimist').argv;
var mkdirp = require('mkdirp');
var child_process = require('child_process');
var _ = require('lodash');
var log = require('loglevel');
function pathExists(path) {
try {
fs.statSync(path);
}
catch (err) {
if (err.code == 'ENOENT') {
return false;
}
}
return true;
}
function findEgisUi() {
return './node_modules/@egis/egis-ui/build';
}
var EGISUI = findEgisUi();
// Level of logging verbosity: trace | debug | info | warn | error | silent
var logLevel = argv.egisLogLevel || 'warn';
log.setLevel(logLevel);
console.log('build tools: log level', log.getLevel());
module.exports = {
EGISUI: EGISUI,
unzip: function (path, to)
{
mkdirp(to);
this.sh("unzip -o " + path + " -d " + to);
},
sh: function (cmd)
{
return child_process.execSync(cmd).toString('utf8').trim()
},
exists: function (path)
{
return pathExists(path);
},
filterExistingFiles(pathes) {
return pathes.filter((path) => this.exists(path));
},
dateFormat: function(date, fstr, utc) {
utc = utc ? 'getUTC' : 'get';
return fstr.replace (/%[YmdHMS]/g, function (m) {
switch (m) {
case '%Y': return date[utc + 'FullYear'] (); // no leading zeros required
case '%m': m = 1 + date[utc + 'Month'] (); break;
case '%d': m = date[utc + 'Date'] (); break;
case '%H': m = date[utc + 'Hours'] (); break;
case '%M': m = date[utc + 'Minutes'] (); break;
case '%S': m = date[utc + 'Seconds'] (); break;
default: return m.slice (1); // unknown code, remove %
}
// add leading zero if required
return ('0' + m).slice (-2);
});
},
defaultKarma: function (config)
{
var outputDir = argv.outDir || 'test-output';
var hostname = argv.host || process.env['IP'] || this.ip() || 'localhost';
var launchersBase = 'TestingBot';
var seleniumVersion = '3.11.0';
var customLaunchers = {
'REMOTE-IE11': {
base: launchersBase,
browserName: 'internet explorer',
platform: 'WIN10',
version: '11'
},
'REMOTE-MSEdge': {
base: launchersBase,
browserName: 'microsoftedge',
version: '17',
platform: 'WIN10'
},
'REMOTE-FF': {
base: launchersBase,
browserName: 'firefox',
platform: 'WIN10'
},
'REMOTE-Safari': {
base: launchersBase,
browserName: 'safari',
version: '12'
},
'REMOTE-SafariLegacy': {
base: launchersBase,
browserName: 'safari',
version: '11'
},
'REMOTE-Chrome': {
base: launchersBase,
browserName: 'chrome',
platform: 'CAPITAN'
}
};
var browsers = Object.keys(customLaunchers);
var projectName = argv.projectName;
var testingBotBuildName = process.env.CIRCLE_BUILD_NUM;
if (testingBotBuildName) {
testingBotBuildName = '' + projectName + '/' + testingBotBuildName;
projectName = testingBotBuildName;
}
var group_filename = function(base_fn, ext) {
return _.compact([base_fn, argv.group]).join('-') + '.' + ext;
};
if ((argv.reporters || []).indexOf('testingbot') >= 0) {
var tbConfig = {
testName: (projectName || '') + ' Karma',
recordVideo: true,
recordScreenshots: true,
connectOptions: {
verbose: false,
'se-port': 4445,
logfile: 'test-output/' + group_filename('testingbot_tunnel', 'log')
},
build: testingBotBuildName
};
Object.keys(customLaunchers).forEach(function (key) {
customLaunchers[key]['selenium-version'] = seleniumVersion;
});
config.set({
testingbot: tbConfig
})
}
config.set({
junitReporter: {
outputDir: outputDir + '/junit/' // results will be saved as $outputDir/$browserName.xml
//outputFile: undefined // if included, results will be saved as $outputDir/$browserName/$outputFile
//suite: ''
},
hostname: config.hostname || hostname.split(' ').join(''),
basePath: '',
frameworks: ['jasmine-jquery', 'jasmine', 'fixture'],
exclude: [],
preprocessors: {
'**/*.js': ['sourcemap'],
'**/*.json' : ['json_fixtures']
},
customLaunchers: customLaunchers,
jsonFixturesPreprocessor: {
variableName: '__json__'
},
reporters: ['progress', 'html', 'junit', 'verbose'],
browsers: browsers,
browserDisconnectTimeout: 10*1000, // default is 2000
browserDisconnectTolerance: 1, // default is 0
browserNoActivityTimeout: 4*60*1000, // default is 10*1000
captureTimeout: 2*60*1000, // default is 60*1000
htmlReporter: {
outputFile: outputDir + '/' + group_filename('unit', 'html')
},
coverageReporter: {
reporters: [
{
type : 'html'
}, {
type : 'lcov',
subdir : 'lcov'
}
]
},
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
singleRun: false,
});
if (argv.grep) {
config.set({
client: {
args: ['--grep', argv.grep]
}
});
}
},
ip: function ()
{
var ifaces = os.networkInterfaces();
var ip;
Object.keys(ifaces).forEach(function (ifname)
{
ifaces[ifname].forEach(function (iface)
{
if ('IPv4' !== iface.family || iface.internal !== false || iface.address.startsWith('172'))
{
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return;
}
ip = iface.address;
});
});
return ip;
},
extend: function(a, b) {
for (var key in b)
{
if (b.hasOwnProperty(key))
{
a[key] = b[key];
}
}
return a;
},
defaultWdioConfig: function() {
return require('./wdio.conf');
},
log: log
};