Skip to content

Commit

Permalink
feat(eater): Send eater:finish event when process will be finished
Browse files Browse the repository at this point in the history
  • Loading branch information
yosuke-furukawa committed Sep 8, 2016
1 parent 1d201b1 commit b58f414
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/eater.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Eater extends EventEmitter {
this.reporter.reportFileNumber(this.fileNum);
const currentFiles = this.files.splice(0, this.procs);
this.on('next', this.nextTest);
this.on('finish', (hasAnyError) => process.emit('eater:finish', hasAnyError));
currentFiles.forEach((file) => this.emit('next', file));

}
Expand Down Expand Up @@ -98,6 +99,7 @@ class Eater extends EventEmitter {

}
this.reporter.reportFinish(this.hasAnyError, this.errors);
this.emit('finish', this.hasAnyError);

}

Expand Down
38 changes: 38 additions & 0 deletions test/core/lib/eater/onEaterFinish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const assert = require('power-assert');
const mustCall = require('must-call');
const Eater = require(`${process.cwd()}/lib/eater`);
const mockReporter = {
setChildProc: (child) => {
// do nothing
},
reportFileNumber: () => {
// do nothing
},
reportTestName: (name) => {
// do nothing
},
reportSubTestName: (name, parent) => {
// do nothing
},
reportSubSuccess: (name) => {
// do nothing
},
reportFinish: (name) => {
// do nothing
},
reportSuccess: (name) => {
// do nothing
},
};
const eater = new Eater({
reporter: mockReporter,
dir: 'test/fixture',
ext: 'success.js',
});
eater.eat();

process.on('eater:finish', mustCall((hasAnyError) => {
assert(!hasAnyError);
}));

0 comments on commit b58f414

Please sign in to comment.