Skip to content

Commit

Permalink
Fix bug with reporters remove
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Jul 21, 2018
1 parent 3c559aa commit b4c318c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/reporter/base.js
Expand Up @@ -170,7 +170,7 @@ GlaceReporter.prototype.done = function (failures, fn) {
.catch(e => LOG.error(e));
}
});
prms.then(() => fn(failures));
return prms.then(() => fn(failures));
};
/**
* Registers reporters if they are not.
Expand All @@ -194,5 +194,7 @@ GlaceReporter.register = function () {
* @arg {...object} reporters - Sequence of reporters to remove.
*/
GlaceReporter.remove = function () {
reporters = _.without.apply(_, reporters, arguments);
const args = Array.from(arguments);
args.unshift(reporters);
reporters = _.without.apply(_, args);
};
49 changes: 49 additions & 0 deletions tests/unit/testReporterBase.js
Expand Up @@ -314,4 +314,53 @@ suite("reporter/base", () => {
expect(reporters[0].hookEnd.args[0][0]).to.be.equal("mochaHook");
});
});

test("register()", () => {
let reporters;

beforeChunk(() => {
reporters = [];
GlaceReporter.__set__("reporters", reporters);
});

chunk("registers reporters if they aren't registered", () => {
const reporter1 = new Object();
const reporter2 = new Object();

GlaceReporter.register(reporter1, reporter2);
expect(reporters).to.be.eql([reporter1, reporter2]);
});

chunk("doesn't register reporter if it's already registered", () => {
const reporter1 = new Object();
const reporter2 = new Object();
const reporter3 = new Object();

GlaceReporter.register(reporter1, reporter2);
GlaceReporter.register(reporter3, reporter2);
expect(reporters).to.be.eql([reporter1, reporter2, reporter3]);
});
});

test("remove()", () => {
let reporters;

beforeChunk(() => {
reporters = [new Object(), new Object()];
GlaceReporter.__set__("reporters", reporters);
});

chunk("removes reporter from reporters", () => {
const reporter1 = reporters[0];
GlaceReporter.remove(reporter1);
reporters = GlaceReporter.__get__("reporters");
expect(reporters).to.have.length(1);
expect(reporters).to.not.include(reporter1);
});

chunk("does nothing if reporter isn't registered", () => {
GlaceReporter.remove(new Object());
expect(reporters).to.have.length(2);
});
});
});

0 comments on commit b4c318c

Please sign in to comment.