Skip to content

Commit d160da7

Browse files
committed
Add script to run specs in CI, fixes adamlaska#61.
1 parent 0cd3f3c commit d160da7

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

script/cibuild

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import subprocess
5+
6+
7+
test = os.path.join(os.path.dirname(__file__), 'test.py')
8+
subprocess.check_call([test, '--ci'])

script/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main():
1717
else:
1818
atom_shell = os.path.join(SOURCE_ROOT, 'out', 'Debug', 'atom.exe')
1919

20-
subprocess.check_call([atom_shell, 'spec'])
20+
subprocess.check_call([atom_shell, 'spec'] + sys.argv[1:])
2121

2222

2323
if __name__ == '__main__':

spec/index.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@
1515

1616
require('coffee-script'); // Supports .coffee tests.
1717

18+
// Rediret all output to browser.
19+
var ipc = require('ipc');
20+
global.__defineGetter__('console', function() {
21+
return {
22+
log: function() {
23+
args = Array.prototype.slice.call(arguments);
24+
ipc.sendChannel('console.log', args);
25+
},
26+
error: function() {
27+
args = Array.prototype.slice.call(arguments);
28+
ipc.sendChannel('console.error', args);
29+
},
30+
}
31+
});
32+
1833
var Mocha = require('mocha');
1934

2035
var mocha = new Mocha();
@@ -24,6 +39,14 @@
2439
if (query.grep) mocha.grep(query.grep);
2540
if (query.invert) mocha.invert();
2641

42+
// Check if we are running in CI.
43+
var argv = require('remote').process.argv;
44+
var isCi = false;
45+
if (argv[1] == '--ci') {
46+
isCi = true;
47+
mocha.reporter('tap');
48+
}
49+
2750
// Read all test files.
2851
var walker = require('walkdir').walk(__dirname);
2952

@@ -33,8 +56,10 @@
3356
});
3457

3558
walker.on('end', function() {
36-
mocha.run(function() {
59+
var runner = mocha.run(function() {
3760
Mocha.utils.highlightTags('code');
61+
if (isCi)
62+
ipc.sendChannel('process.exit', runner.failures);
3863
});
3964
});
4065
})();

spec/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ ipc.on('message', function() {
1010
ipc.send.apply(this, arguments);
1111
});
1212

13+
ipc.on('console.log', function(pid, rid, args) {
14+
console.log.apply(console, args);
15+
});
16+
17+
ipc.on('console.error', function(pid, rid, args) {
18+
console.log.apply(console, args);
19+
});
20+
21+
ipc.on('process.exit', function(pid, rid, code) {
22+
process.exit(code);
23+
});
24+
1325
process.on('uncaughtException', function() {
1426
window.openDevTools();
1527
});

0 commit comments

Comments
 (0)