Skip to content

Commit

Permalink
refactor: use arrow functions to capture this
Browse files Browse the repository at this point in the history
PR-URL: nodejs#351
  • Loading branch information
targos authored Feb 21, 2017
1 parent 6f5a0de commit 5ab6b08
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions lib/citgm.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ function Tester(mod, options) {
util.inherits(Tester, EventEmitter);

Tester.prototype.run = function() {
const self = this;
this.emit('start', this.module.raw, this.options);

async.waterfall([
init.bind(null, self),
init.bind(null, this),
find.bind(null, 'node'),
find.bind(null, 'npm'),
tempDirectory.create,
Expand All @@ -114,45 +113,44 @@ Tester.prototype.run = function() {
unpack,
npm.install,
npm.test
], function(err) {
if (!self.cleanexit) {
], (err) => {
if (!this.cleanexit) {
const payload = {
name: self.module.name || self.module.raw,
version: self.module.version,
flaky: self.module.flaky,
expectFail: self.module.expectFail
name: this.module.name || this.module.raw,
version: this.module.version,
flaky: this.module.flaky,
expectFail: this.module.expectFail
};
if (err && !payload.expectFail) {
self.emit('fail', err);
this.emit('fail', err);
payload.error = err;
} else if (!err && payload.expectFail) {
self.emit('fail', 'this module should have failed');
this.emit('fail', 'this module should have failed');
payload.error = 'this module should have failed';
}
if (self.testOutput !== '') {
payload.testOutput += self.testOutput + '\n';
if (this.testOutput !== '') {
payload.testOutput += this.testOutput + '\n';
}
if (self.testError !== '') {
payload.testOutput += self.testError + '\n';
if (this.testError !== '') {
payload.testOutput += this.testError + '\n';
}
tempDirectory.remove(self, function() {
self.emit('end', payload);
self.cleanexit = true;
tempDirectory.remove(this, () => {
this.emit('end', payload);
this.cleanexit = true;
});
}
});
};

Tester.prototype.cleanup = function () {
const self = this;
self.cleanexit = true;
this.cleanexit = true;
const payload = {
name: self.module.name || self.module.raw,
name: this.module.name || this.module.raw,
error: Error('Process Interrupted')
};
self.emit('fail', payload.error);
tempDirectory.remove(self, function() {
self.emit('end', payload);
this.emit('fail', payload.error);
tempDirectory.remove(this, () => {
this.emit('end', payload);
});
};

Expand Down

0 comments on commit 5ab6b08

Please sign in to comment.