Permalink
Browse files

Add experimental start/before/after/exit events.

All events are asynchronous and they must have a valid signature.
Once an event/message is processed, the continuation block must be called
for Lotte to resume.

- 'start'  function(options,    resume) { resume(); }
- 'before' function(file,       resume) { reusme(); }
- 'after'  function(file, code, resume) { resume(); }
- 'exit'   function(code,       resume) { resume(); }

where:

- 'options' is an array derived from the command-line or a Lottefile
- 'file' is a test file (absolute path)
- 'code' is the exit code either of the test file or the entire suite
  • Loading branch information...
1 parent 1efbf22 commit 00033bec943dc3ddb5563b2b4172d54a0a476192 @StanAngeloff committed Dec 10, 2011
Showing with 27 additions and 17 deletions.
  1. +8 −3 bin/cli.js
  2. +19 −14 lib/lotte.js
View
@@ -165,9 +165,14 @@ function main(options) {
if (options['server']) {
server.listen(options.port, options.address);
}
- require('../lib/lotte').process(options, function(e, code) {
- server.close();
- process.exit(e ? 1 << 8 : code);
+ events.message('start', [options], function() {
+ require('../lib/lotte').process(options, function(e, code) {
+ code = (e ? 1 << 8 : code);
+ events.message('exit', [code], function() {
+ server.close();
+ process.exit(code);
+ });
+ });
});
});
});
View
@@ -5,7 +5,8 @@ const STATUS_KILLED = 'killed';
var childProcess = require('child_process'),
fs = require('fs'),
path = require('path'),
- console = require('./console');
+ console = require('./console'),
+ events = require('./events');
var __basename = path.basename(__filename, '.js');
@@ -112,19 +113,23 @@ function queue(take, template, options, resume) {
if (files.length && take > 0) {
take = take - 1;
(function(top) {
- processOne(top, template, options, function(e, code, buffers) {
- if (buffers) {
- process.stdout.write(buffers.stdout);
- process.stderr.write(buffers.stderr);
- }
- highestCode = Math.max(code || 0, highestCode);
- if (e) {
- console.warn.exception(e);
- } else {
- options.processed.push(top);
- }
- take = take + 1;
- remaining = remaining - 1;
+ events.message('before', [top], function() {
+ processOne(top, template, options, function(e, code, buffers) {
+ if (buffers) {
+ process.stdout.write(buffers.stdout);
+ process.stderr.write(buffers.stderr);
+ }
+ highestCode = Math.max(code || 0, highestCode);
+ if (e) {
+ console.warn.exception(e);
+ } else {
+ options.processed.push(top);
+ }
+ events.message('after', [top, code], function() {
+ take = take + 1;
+ remaining = remaining - 1;
+ });
+ });
});
})(files.shift());
}

0 comments on commit 00033be

Please sign in to comment.