Skip to content

Commit

Permalink
fix(actions): before & after test execution
Browse files Browse the repository at this point in the history
  • Loading branch information
asciidisco committed Nov 28, 2014
1 parent ed50a6f commit d0ce489
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
38 changes: 20 additions & 18 deletions lib/dalek/suite.js
Expand Up @@ -133,39 +133,42 @@ Suite.prototype = {
*/

testFinished: function (callback, tests) {
var self = this;
var complete = function() {
// check if there are still tests that should be executed in this suite,
// if so, run them
if (self.decrementTestsToBeExecuted() > 1) {
self.executeNextTest(tests);
return self;
if (this.decrementTestsToBeExecuted() > 1) {
this.executeNextTest(tests);
return this;
}

// run a function after the testsuite, if given
if (self.options.teardown) {
self.options.teardown();
if (this.options.teardown) {
this.options.teardown();
}

// emit the suite finished event
self.reporterEmitter.emit('report:testsuite:finished', self.name);
this.reporterEmitter.emit('report:testsuite:finished', this.name);

// move on to the next suite
callback();
return self;
};
return this;
}.bind(this);

// run a function after the test, if given
if (typeof self.options.afterEach === 'function') {

if (typeof this.options.afterEach === 'function') {
// If there is an argument, assume async.
if (self.options.afterEach.length === 1) {
self.options.afterEach(function() {
if (this.options.afterEach.length === 1) {
this.options.afterEach(function() {
return complete();
});
}.bind(this));
} else {
// no argument, assume sync.
self.options.afterEach();
this.options.afterEach();
return complete();
}
} else {
return complete();
}

},
Expand Down Expand Up @@ -364,15 +367,14 @@ Suite.prototype = {
}

// kickstart the test execution
var self = this;
this.executeNextTest(tests, function() {
// emit the suite started event
self.reporterEmitter.emit('report:testsuite:started', self.name);
this.reporterEmitter.emit('report:testsuite:started', this.name);
// listen to the test:finished event & then start the next test
// if there are no tests in this suite left,
// run the async callback & mark this suite as finished
self.emitter.onAny(self.testFinished.bind(self, callback, tests));
});
this.emitter.onAny(this.testFinished.bind(this, callback, tests));
}.bind(this));

return this;
}
Expand Down
8 changes: 5 additions & 3 deletions test/lib_dalek_actions_screenshots_TEST.js
@@ -1,14 +1,16 @@
'use strict';

var expect = require('chai').expect;
var Actions = require('../lib/dalek/actions.js')({reporter: null});
var EventEmitter2 = require('eventemitter2').EventEmitter2;
var Actions = require('../lib/dalek/actions.js')({reporter: reporter});

describe('dalek-internal-screenshot-action', function() {

var actions;

beforeEach(function () {
actions = new Actions();
actions.reporter = new EventEmitter2();
actions.actionPromiseQueue = [];
});

Expand Down Expand Up @@ -38,4 +40,4 @@ describe('dalek-internal-screenshot-action', function() {
expect(actions.actionPromiseQueue[1]).to.be.an('function');
});

});
});

0 comments on commit d0ce489

Please sign in to comment.