Skip to content
Browse files

Extract system concerns file

  • Loading branch information...
1 parent a9ae566 commit 7ef503cb3d930a436610a1b31ef9d8b5ed7e8fa8 @joelplane joelplane committed Jun 12, 2011
Showing with 27 additions and 18 deletions.
  1. +4 −18 noodleTest.js
  2. +23 −0 system.js
View
22 noodleTest.js
@@ -6,7 +6,8 @@ module.exports = (function(config){
var events = require('./events');
var EventEmitter = events.EventEmitter;
var sys = require('sys');
- var cons = require('./noodleTestConsole');
+ var addConsoleOutputConcerns = require('./noodleTestConsole');
+ var addSystemConcerns = require('./system');
var Assertion = require('./assertion');
var testQueue = require('./testQueue')();
var Test = require('./test')(Assertion, testQueue, config.timeout);
@@ -31,24 +32,9 @@ module.exports = (function(config){
main.emit('popContext', {name: name, context: ctx});
};
- var seen = false;
- var seenFailure = function() {
- seen = true;
- };
- main.on('assertionFailed', seenFailure);
- main.on('testFlunk', seenFailure);
-
- main.onFailureExitNonZero = function() {
- process.on('exit', function(a) {
- if (seen) {
- /* Hack */
- process.kill(process.pid, 'SIGHUP');
- }
- });
- };
-
+ addSystemConcerns(main);
if (!config['quiet']) {
- cons(main);
+ addConsoleOutputConcerns(main);
}
return main;
View
23 system.js
@@ -0,0 +1,23 @@
+module.exports = function(main) {
+
+ /* Ensure script exits non-zero on test failure, to ease use in
+ * Continuous Integration environments.
+ * Client code must call onFailureExitNonZero() to get this feature
+ */
+
+ var seenFailure = false;
+ var seenFailureCallback = function() {
+ seenFailure = true;
+ };
+ main.on('assertionFailed', seenFailureCallback);
+ main.on('testFlunk', seenFailureCallback);
+
+ main.onFailureExitNonZero = function() {
+ process.on('exit', function(a) {
+ if (seenFailure) {
+ /* Hack */
+ process.kill(process.pid, 'SIGHUP');
+ }
+ });
+ };
+};

0 comments on commit 7ef503c

Please sign in to comment.
Something went wrong with that request. Please try again.