Skip to content

Commit ffef6d6

Browse files
committed
minor style tweaks
1 parent e010816 commit ffef6d6

12 files changed

+69
-16
lines changed

api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Api.prototype._runFile = function (file) {
5151
var options = objectAssign({}, this.options, {
5252
precompiled: this.precompiler.generateHashForFile(file)
5353
});
54+
5455
return fork(file, options)
5556
.on('stats', this._handleStats)
5657
.on('test', this._handleTest)

lib/beautify-stack.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
32
var StackUtils = require('stack-utils');
43
var debug = require('debug')('ava');
54

@@ -10,10 +9,8 @@ var stackUtils = new StackUtils({
109
])
1110
});
1211

13-
function beautifyStack(stack) {
12+
module.exports = function (stack) {
1413
return stack.split('\n')[0] + '\n' + stackUtils.clean(stack).split('\n').map(function (s) {
1514
return ' ' + s;
1615
}).join('\n');
17-
}
18-
19-
module.exports = beautifyStack;
16+
};

lib/caching-precompiler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
var cachingTransform = require('caching-transform');
21
var fs = require('fs');
32
var path = require('path');
3+
var cachingTransform = require('caching-transform');
44
var md5Hex = require('md5-hex');
55
var stripBom = require('strip-bom');
66

77
module.exports = CachingPrecompiler;
88

99
function CachingPrecompiler(cacheDir) {
1010
if (!(this instanceof CachingPrecompiler)) {
11-
throw new Error('CachingPrecompiler must be called with new');
11+
throw new TypeError('Class constructor CachingPrecompiler cannot be invoked without \'new\'');
1212
}
13+
1314
this.cacheDir = cacheDir;
1415
this.filenameToHash = {};
1516
this.transform = this._createTransform();
@@ -84,6 +85,7 @@ CachingPrecompiler.prototype.precompileFile = function (filename) {
8485
if (!this.filenameToHash[filename]) {
8586
this.transform(stripBom(fs.readFileSync(filename)), filename);
8687
}
88+
8789
return this.filenameToHash[filename];
8890
};
8991

lib/colors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
32
var chalk = require('chalk');
43

54
module.exports = {

lib/concurrent.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function Concurrent(tests, bail) {
99
if (!this instanceof Concurrent) {
1010
throw new TypeError('Class constructor Concurrent cannot be invoked without \'new\'');
1111
}
12+
1213
this.tests = tests;
1314
this.bail = bail;
1415
}
@@ -27,21 +28,25 @@ Concurrent.prototype.run = function () {
2728
if (passed) {
2829
passed = false;
2930
reason = result.reason;
31+
3032
if (bail) {
3133
throw BAIL_ERROR;
3234
}
3335
}
3436
}
37+
3538
return result;
3639
}
3740

3841
for (var i = 0; i < tests.length; i++) {
3942
var result = tests[i].run();
43+
4044
if (isPromise(result)) {
4145
sync = false;
4246
results.push(result.then(addAsync));
4347
} else {
4448
results.push(result);
49+
4550
if (!result.passed) {
4651
if (bail) {
4752
return {
@@ -78,6 +83,7 @@ Concurrent.prototype.run = function () {
7883
if (err !== BAIL_ERROR) {
7984
throw err;
8085
}
86+
8187
return {
8288
passed: false,
8389
reason: reason

lib/reporters/mini.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ MiniReporter.prototype._update = function (data) {
179179
}
180180

181181
var currentStatus = this.currentStatus;
182+
182183
if (currentStatus.length) {
183184
lastLine = this.lastLineTracker.lastLine();
184185
// We need a newline at the end of the last log line, before the status message.
@@ -205,6 +206,7 @@ function eraseLines(count) {
205206
for (var i = 0; i < count; i++) {
206207
clear += ERASE_LINE + (i < count - 1 ? CURSOR_UP : '');
207208
}
209+
208210
if (count) {
209211
clear += CURSOR_TO_COLUMN_0;
210212
}

lib/runner.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ optionChain(chainableMethods, function (opts, title, fn) {
4747
fn = title;
4848
title = null;
4949
}
50+
5051
this.tests.add({
5152
metadata: opts,
5253
fn: fn,
@@ -57,6 +58,7 @@ optionChain(chainableMethods, function (opts, title, fn) {
5758
Runner.prototype._addTestResult = function (result) {
5859
if (result.result.metadata.type === 'test') {
5960
this.stats.testCount++;
61+
6062
if (result.result.metadata.skipped) {
6163
this.stats.skipCount++;
6264
}

lib/send.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
// utility to send messages to processes
4-
function send(ps, name, data) {
4+
module.exports = function (ps, name, data) {
55
if (typeof ps === 'string') {
66
data = name || {};
77
name = ps;
@@ -13,6 +13,4 @@ function send(ps, name, data) {
1313
data: data,
1414
ava: true
1515
});
16-
}
17-
18-
module.exports = send;
16+
};

lib/sequence.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function Sequence(tests, bail) {
88
if (!this instanceof Sequence) {
99
throw new TypeError('Class constructor Sequence cannot be invoked without \'new\'');
1010
}
11+
1112
this.tests = tests;
1213
this.bail = bail;
1314
}
@@ -24,10 +25,13 @@ Sequence.prototype.run = function () {
2425
for (var i = 0; i < len; i++) {
2526
var test = tests[i];
2627
var result = test.run();
28+
2729
if (isPromise(result)) {
2830
return this._runAsync(results, result, tests.slice(i + 1));
2931
}
32+
3033
results.push(result);
34+
3135
if (!result.passed) {
3236
if (bail) {
3337
return {
@@ -41,6 +45,7 @@ Sequence.prototype.run = function () {
4145
}
4246
}
4347
}
48+
4449
return {
4550
passed: passed,
4651
reason: reason,
@@ -57,11 +62,13 @@ Sequence.prototype._runAsync = function (results, firstAsyncResult, remaining) {
5762

5863
function processResult(result) {
5964
results.push(result);
65+
6066
if (!result.passed) {
6167
if (passed) {
6268
passed = false;
6369
reason = result.reason;
6470
}
71+
6572
if (bail) {
6673
throw BAIL_ERROR;
6774
}
@@ -70,19 +77,22 @@ Sequence.prototype._runAsync = function (results, firstAsyncResult, remaining) {
7077

7178
var result = firstAsyncResult.then(function (firstResult) {
7279
processResult(firstResult);
80+
7381
return Promise.each(remaining, function (test) {
7482
var result = test.run();
83+
7584
if (isPromise(result)) {
7685
return result.then(processResult);
7786
}
87+
7888
processResult(result);
7989
});
8090
});
8191

8292
if (bail) {
83-
result = result.catch(function (e) {
84-
if (e !== BAIL_ERROR) {
85-
throw e;
93+
result = result.catch(function (err) {
94+
if (err !== BAIL_ERROR) {
95+
throw err;
8696
}
8797
});
8898
}

lib/test-collection.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ module.exports = TestCollection;
33

44
function TestCollection() {
55
if (!(this instanceof TestCollection)) {
6-
throw new Error('must use `new TestCollection()`');
6+
throw new TypeError('Class constructor TestCollection cannot be invoked without \'new\'');
77
}
8+
89
this.serial = [];
910
this.concurrent = [];
1011
this.tests = {
@@ -19,24 +20,31 @@ function TestCollection() {
1920
TestCollection.prototype.add = function (test) {
2021
var metadata = test.metadata;
2122
var type = metadata.type;
23+
2224
if (!type) {
2325
throw new Error('test type must be specified');
2426
}
27+
2528
if (type === 'test') {
2629
if (this.hasExclusive && !metadata.exclusive) {
2730
return;
2831
}
32+
2933
if (metadata.exclusive && !this.hasExclusive) {
3034
this.hasExclusive = true;
3135
this.serial = [];
3236
this.concurrent = [];
3337
}
38+
3439
(metadata.serial ? this.serial : this.concurrent).push(test);
40+
3541
return;
3642
}
43+
3744
if (metadata.exclusive) {
3845
throw new Error('you can\'t use "only" with a ' + type + ' test');
3946
}
47+
4048
this.tests[type].push(test);
4149
};
4250

@@ -65,9 +73,11 @@ function computeTitle(entry) {
6573
function buildHooks(hookArray, title, contextRef, report) {
6674
return hookArray.map(function (hook) {
6775
var test = buildHook(hook, title, contextRef, report);
76+
6877
if (hook.metadata.skipped) {
6978
return skipRunner(test, report);
7079
}
80+
7181
return test;
7282
});
7383
}
@@ -103,9 +113,11 @@ function buildTestWithHooks(entry, beforeEach, afterEach, report) {
103113
if (entry.metadata.skipped) {
104114
return [skipRunner(buildTest(entry), report)];
105115
}
116+
106117
var contextRef = {context: {}};
107118
var arr = buildHooks(beforeEach, entry.title, contextRef, report);
108119
arr.push(buildTest(entry, contextRef, report));
120+
109121
return arr.concat(buildHooks(afterEach, entry.title, contextRef, report));
110122
}
111123

@@ -127,6 +139,7 @@ TestCollection.prototype.buildPhases = function (report) {
127139
if (entry.metadata.skipped) {
128140
return skipRunner(entry, report);
129141
}
142+
130143
return buildTest(entry, null, report);
131144
})),
132145
new Sequence([
@@ -141,6 +154,7 @@ TestCollection.prototype.buildPhases = function (report) {
141154
if (entry.metadata.skipped) {
142155
return skipRunner(entry, report);
143156
}
157+
144158
return buildTest(entry, null, report);
145159
}))
146160
],

lib/test-worker.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ if (opts.tty) {
77
process.stdout.isTTY = true;
88
process.stdout.columns = opts.tty.columns || 80;
99
process.stdout.rows = opts.tty.rows;
10+
1011
var tty = require('tty');
1112
var isatty = tty.isatty;
13+
1214
tty.isatty = function (fd) {
1315
if (fd === 1 || fd === process.stdout) {
1416
return true;
1517
}
18+
1619
return isatty(fd);
1720
};
1821
}
@@ -66,10 +69,12 @@ exports.avaRequired = false;
6669

6770
installPrecompiler(function (filename) {
6871
var precompiled = opts.precompiled[filename];
72+
6973
if (precompiled) {
7074
sourceMapCache[filename] = path.join(cacheDir, precompiled + '.map');
7175
return fs.readFileSync(path.join(cacheDir, precompiled + '.js'), 'utf8');
7276
}
77+
7378
return null;
7479
});
7580

0 commit comments

Comments
 (0)