UNPKG

5.79 kBJavaScriptView Raw
1var os = require('os');
2var fs = require('fs');
3var path = require('path');
4var argv = require('optimist').argv;
5var mkdirp = require('mkdirp');
6var child_process = require('child_process');
7var _ = require('lodash');
8
9function pathExists(path) {
10 try {
11 fs.statSync(path);
12 }
13 catch (err) {
14 if (err.code == 'ENOENT') {
15 return false;
16 }
17 }
18 return true;
19}
20
21function findEgisUi() {
22 var egisUiPath = path.normalize('../EgisUI/build/');
23
24 if (!pathExists(egisUiPath)) {
25 egisUiPath = './node_modules/@egis/egis-ui/build'
26 }
27 return egisUiPath;
28}
29
30var EGISUI = findEgisUi();
31
32module.exports = {
33
34 EGISUI: EGISUI,
35
36 unzip: function (path, to)
37 {
38
39 mkdirp(to);
40 this.sh("unzip -o " + path + " -d " + to);
41 },
42
43 sh: function (cmd)
44 {
45 return child_process.execSync(cmd).toString('utf8').trim()
46 },
47
48 exists: function (path)
49 {
50 return pathExists(path);
51 },
52 dateFormat: function(date, fstr, utc) {
53 utc = utc ? 'getUTC' : 'get';
54 return fstr.replace (/%[YmdHMS]/g, function (m) {
55 switch (m) {
56 case '%Y': return date[utc + 'FullYear'] (); // no leading zeros required
57 case '%m': m = 1 + date[utc + 'Month'] (); break;
58 case '%d': m = date[utc + 'Date'] (); break;
59 case '%H': m = date[utc + 'Hours'] (); break;
60 case '%M': m = date[utc + 'Minutes'] (); break;
61 case '%S': m = date[utc + 'Seconds'] (); break;
62 default: return m.slice (1); // unknown code, remove %
63 }
64 // add leading zero if required
65 return ('0' + m).slice (-2);
66 });
67 },
68 defaultKarma: function (config)
69 {
70 var hostname = argv.host || process.env['IP'] || this.ip();
71
72 var launchersBase = 'TestingBot';
73 var customLaunchers = {
74 'REMOTE-IE10': {
75 base: launchersBase,
76 browserName: 'internet explorer',
77 platform: 'WIN8',
78 version: '10'
79 },
80 'REMOTE-IE11': {
81 base: launchersBase,
82 browserName: 'internet explorer',
83 platform: 'WIN10',
84 version: '11'
85 },
86 'REMOTE-MSEdge': {
87 base: launchersBase,
88 browserName: 'microsoftedge',
89 platform: 'WIN10'
90 },
91 'REMOTE-FF': {
92 base: launchersBase,
93 browserName: 'firefox',
94 platform: 'WIN10'
95 },
96 'REMOTE-Safari': {
97 base: launchersBase,
98 browserName: 'safari',
99 platform: 'CAPITAN'
100 },
101 'REMOTE-Chrome': {
102 base: launchersBase,
103 browserName: 'chrome',
104 platform: 'CAPITAN'
105 }
106 };
107
108 var browsers = Object.keys(customLaunchers);
109
110 var projectName = argv.projectName;
111 var testingBotBuildName = process.env.CIRCLE_BUILD_NUM;
112 if (testingBotBuildName) testingBotBuildName = '' + projectName + '/' + testingBotBuildName;
113
114 var group_filename = function(base_fn, ext) {
115 return _.compact([base_fn, argv.group]).join('-') + '.' + ext;
116 };
117 config.set({
118 junitReporter: {
119 outputDir: 'test-output/junit/' // results will be saved as $outputDir/$browserName.xml
120 //outputFile: undefined // if included, results will be saved as $outputDir/$browserName/$outputFile
121 //suite: ''
122 },
123 hostname: hostname.split(' ').join(''),
124 basePath: '',
125 frameworks: ['jasmine-jquery', 'jasmine', 'fixture'],
126 exclude: [],
127 preprocessors: {
128 '**/*.js': ['sourcemap'],
129 '**/*.json' : ['json_fixtures']
130 },
131 customLaunchers: customLaunchers,
132 jsonFixturesPreprocessor: {
133 variableName: '__json__'
134 },
135 reporters: ['progress', 'html', 'junit', 'verbose'],
136 testingbot: {
137 testName: (projectName || '') + ' Karma',
138 recordVideo: true,
139 recordScreenshots: true,
140 connectOptions: {
141 verbose: false,
142 'se-port': 4445,
143 logfile: 'test-output/' + group_filename('testingbot_tunnel', 'log')
144 },
145 build: testingBotBuildName
146 },
147 browsers: browsers,
148 browserDisconnectTimeout: 10*1000, // default is 2000
149 browserDisconnectTolerance: 1, // default is 0
150 browserNoActivityTimeout: 4*60*1000, // default is 10*1000
151 captureTimeout: 2*60*1000, // default is 60*1000
152 htmlReporter: {
153 outputFile: 'test-output/' + group_filename('unit', 'html')
154 },
155 colors: true,
156 logLevel: config.LOG_INFO,
157 autoWatch: true,
158 singleRun: false,
159 hostname: config.hostname.split(' ').join('')
160 });
161 },
162
163 ip: function ()
164 {
165 var ifaces = os.networkInterfaces();
166 var ip;
167 Object.keys(ifaces).forEach(function (ifname)
168 {
169 ifaces[ifname].forEach(function (iface)
170 {
171
172 if ('IPv4' !== iface.family || iface.internal !== false || iface.address.startsWith('172'))
173 {
174 // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
175 return;
176 }
177 ip = iface.address;
178 });
179
180 });
181 return ip;
182 }
183};
\No newline at end of file