]> khamidou — GitHub mirrors - electron.git/commitdiff
Add script to run specs in CI, fixes #61.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 21 Aug 2013 03:15:22 +0000 (11:15 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 21 Aug 2013 03:41:08 +0000 (11:41 +0800)
script/cibuild [new file with mode: 0755]
script/test.py
spec/index.html
spec/main.js

diff --git a/script/cibuild b/script/cibuild
new file mode 100755 (executable)
index 0000000..6394615
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+
+import os
+import subprocess
+
+
+test = os.path.join(os.path.dirname(__file__), 'test.py')
+subprocess.check_call([test, '--ci'])
index dd9842fdecf3b9029485f054b7c04c90a50e3880..54601a6e7216d010c717d6a37e61f5ce8b84d255 100755 (executable)
@@ -17,7 +17,7 @@ def main():
   else:
     atom_shell = os.path.join(SOURCE_ROOT, 'out', 'Debug', 'atom.exe')
 
-  subprocess.check_call([atom_shell, 'spec'])
+  subprocess.check_call([atom_shell, 'spec'] + sys.argv[1:])
 
 
 if __name__ == '__main__':
index 16d8389edaf31fdf094502ea60997d8fb0232970..eb40fc7e3740864d85abc5a18ba92c4911ff0349 100644 (file)
 
   require('coffee-script'); // Supports .coffee tests.
 
+  // Rediret all output to browser.
+  var ipc = require('ipc');
+  global.__defineGetter__('console', function() {
+    return {
+      log: function() {
+        args = Array.prototype.slice.call(arguments);
+        ipc.sendChannel('console.log', args);
+      },
+      error: function() {
+        args = Array.prototype.slice.call(arguments);
+        ipc.sendChannel('console.error', args);
+      },
+    }
+  });
+
   var Mocha = require('mocha');
 
   var mocha = new Mocha();
   if (query.grep) mocha.grep(query.grep);
   if (query.invert) mocha.invert();
 
+  // Check if we are running in CI.
+  var argv = require('remote').process.argv;
+  var isCi = false;
+  if (argv[1] == '--ci') {
+    isCi = true;
+    mocha.reporter('tap');
+  }
+
   // Read all test files.
   var walker = require('walkdir').walk(__dirname);
 
   });
 
   walker.on('end', function() {
-    mocha.run(function() {
+    var runner = mocha.run(function() {
       Mocha.utils.highlightTags('code');
+      if (isCi)
+        ipc.sendChannel('process.exit', runner.failures);
     });
   });
 })();
index dbe8cca608a74e0e469617be06c66c94d8d7025c..7947bc063be1c3b6046831fe86891b6a77720590 100644 (file)
@@ -10,6 +10,18 @@ ipc.on('message', function() {
   ipc.send.apply(this, arguments);
 });
 
+ipc.on('console.log', function(pid, rid, args) {
+  console.log.apply(console, args);
+});
+
+ipc.on('console.error', function(pid, rid, args) {
+  console.log.apply(console, args);
+});
+
+ipc.on('process.exit', function(pid, rid, code) {
+  process.exit(code);
+});
+
 process.on('uncaughtException', function() {
   window.openDevTools();
 });