forked from macacajs/uitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uitest-mocha-shim.js
72 lines (59 loc) · 1.52 KB
/
uitest-mocha-shim.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
;(function() {
'use strict';
var isElectron = /Electron/i.test(navigator.userAgent);
if (!isElectron) {
console.info('Macaca Electron Environment not support.');
} else {
var { remote } = require('electron');
var remoteConsole = remote.require('console');
var ipcRenderer = require('electron').ipcRenderer;
// we have to do this so that mocha output doesn't look like shit
console.log = function () {
if (/stdout:/.test(arguments[0])) {
return;
}
remoteConsole.log.apply(remoteConsole, arguments);
};
}
window._macaca_uitest = {
screenshot: function(name, cb) {
if (!isElectron) {
return cb();
}
if (typeof process === 'undefined') {
return cb();
}
setTimeout(function() {
ipcRenderer.send('ipc', {
action: 'screenshot',
data: {
dir: './test/screenshot/' + name
}
});
setTimeout(function() {
cb();
}, 100);
}, 100);
},
setup: function(options) {
var mochaOptions = options;
if (isElectron) {
mochaOptions = Object.assign({}, options, {
reporter: 'spec',
useColors: true
});
}
return mocha.setup(mochaOptions);
},
run: function() {
return mocha.run(function(failedCount) {
isElectron && ipcRenderer.send('ipc', {
action: 'exit',
data: {
failedCount: failedCount
}
});
});
}
};
})();