Skip to content

Commit d7d0396

Browse files
committed
MochaAdapter: Fix TypeErorr due to arrow-function reporter
Follows-up 3708273, which revealed that the only reason this code previously worked is that we compiled it to ES5 where the arrow function became a normal function. The CI build did not catch this because the integration test for QUnit/Jasmine/Mocha is passing for QUnit and Jasmine and then aborts silently without exit code due to a different bug, so it has not actually been testing this code for a while, unfortunately. I will address that in a separate commit soon.
1 parent 7ec72e3 commit d7d0396

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/adapters/MochaAdapter.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ module.exports = class MochaAdapter extends EventEmitter {
66
super();
77

88
this.mocha = mocha;
9-
this.origReporter = mocha._reporter;
10-
11-
mocha.reporter((runner) => {
12-
this.runner = runner;
13-
14-
// eslint-disable-next-line no-unused-vars
15-
const origReporterInstance = new (this.origReporter.bind(this.mocha,
16-
this.runner))();
17-
18-
runner.on('start', this.onStart.bind(this));
19-
runner.on('suite', this.onSuite.bind(this));
20-
runner.on('test', this.onTest.bind(this));
21-
runner.on('pending', this.onPending.bind(this));
22-
runner.on('fail', this.onFail.bind(this));
23-
runner.on('test end', this.onTestEnd.bind(this));
24-
runner.on('suite end', this.onSuiteEnd.bind(this));
25-
runner.on('end', this.onEnd.bind(this));
9+
10+
// Mocha will instantiate the given function as a constructor
11+
// even if you only need a callback.
12+
// As such, it can't be an arrow function as those throw TypeError
13+
// if instantiated.
14+
const self = this;
15+
mocha.reporter(function (runner) {
16+
self.runner = runner;
17+
18+
runner.on('start', self.onStart.bind(self));
19+
runner.on('suite', self.onSuite.bind(self));
20+
runner.on('test', self.onTest.bind(self));
21+
runner.on('pending', self.onPending.bind(self));
22+
runner.on('fail', self.onFail.bind(self));
23+
runner.on('test end', self.onTestEnd.bind(self));
24+
runner.on('suite end', self.onSuiteEnd.bind(self));
25+
runner.on('end', self.onEnd.bind(self));
2626
});
2727
}
2828

0 commit comments

Comments
 (0)