Skip to content

Commit efc3b31

Browse files
committed
Code style tweaks
1 parent cb1c3f7 commit efc3b31

40 files changed

+149
-39
lines changed

api.js

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Api extends EventEmitter {
5555
this.options = Object.assign({match: []}, options);
5656
this.options.require = resolveModules(this.options.require);
5757
}
58+
5859
_runFile(file, runStatus, execArgv) {
5960
const hash = this.precompiler.precompileFile(file);
6061
const precompiled = Object.assign({}, this._precompiledHelpers);
@@ -71,17 +72,20 @@ class Api extends EventEmitter {
7172

7273
return emitter;
7374
}
75+
7476
run(files, options) {
7577
return new AvaFiles({cwd: this.options.resolveTestsFrom, files})
7678
.findTestFiles()
7779
.then(files => this._run(files, options));
7880
}
81+
7982
_onTimeout(runStatus) {
8083
const timeout = ms(this.options.timeout);
8184
const err = new AvaError(`Exited because no new tests completed within the last ${timeout}ms of inactivity`);
8285
this._handleError(runStatus, err);
8386
runStatus.emit('timeout');
8487
}
88+
8589
_setupTimeout(runStatus) {
8690
const timeout = ms(this.options.timeout);
8791

@@ -92,9 +96,11 @@ class Api extends EventEmitter {
9296
runStatus._restartTimer();
9397
runStatus.on('test', runStatus._restartTimer);
9498
}
99+
95100
_cancelTimeout(runStatus) {
96101
runStatus._restartTimer.cancel();
97102
}
103+
98104
_setupPrecompiler(files) {
99105
const isCacheEnabled = this.options.cacheEnabled !== false;
100106
let cacheDir = uniqueTempDir();
@@ -121,6 +127,7 @@ class Api extends EventEmitter {
121127
});
122128
});
123129
}
130+
124131
_precompileHelpers() {
125132
this._precompiledHelpers = {};
126133

@@ -136,6 +143,7 @@ class Api extends EventEmitter {
136143
this._precompiledHelpers[file] = hash;
137144
});
138145
}
146+
139147
_run(files, options) {
140148
options = options || {};
141149

@@ -175,6 +183,7 @@ class Api extends EventEmitter {
175183
return this._runWithPool(files, runStatus, concurrency);
176184
});
177185
}
186+
178187
_computeForkExecArgs(files) {
179188
const execArgv = this.options.testOnlyExecArgv || process.execArgv;
180189
let debugArgIndex = -1;
@@ -220,12 +229,14 @@ class Api extends EventEmitter {
220229
return forkExecArgv;
221230
});
222231
}
232+
223233
_handleError(runStatus, err) {
224234
runStatus.handleExceptions({
225235
exception: err,
226236
file: err.file ? path.relative(process.cwd(), err.file) : undefined
227237
});
228238
}
239+
229240
_runWithPool(files, runStatus, concurrency) {
230241
const tests = [];
231242
let execArgvList;

bench/concurrent/alternating-sync-async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
if (i % 2) {

bench/concurrent/async-immediate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test(`test${i}`, () => new Promise(resolve => setImmediate(resolve)));

bench/concurrent/async-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test(`test${i}`, () => new Promise(resolve => setTimeout(resolve, 0)));

bench/concurrent/sync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test(`test${i}`, () => {});

bench/other/failures.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 1000; i++) {
44
test.serial(`test${i}`, t => {

bench/serial/alternating-sync-async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
if (i % 2) {

bench/serial/async-immediate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test.serial(`test${i}`, () => new Promise(resolve => setImmediate(resolve)));

bench/serial/async-timeout.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 3000; i++) {
44
test.serial(`test${i}`, () => new Promise(resolve => setTimeout(resolve, 0)));

bench/serial/sync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test.serial(`test${i}`, () => {});

lib/ava-files.js

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class AvaFiles {
125125

126126
autoBind(this);
127127
}
128+
128129
findTestFiles() {
129130
return handlePaths(this.files, this.excludePatterns, {
130131
cwd: this.cwd,
@@ -134,6 +135,7 @@ class AvaFiles {
134135
symlinks: Object.create(null)
135136
});
136137
}
138+
137139
findTestHelpers() {
138140
return handlePaths(defaultHelperPatterns(), ['!**/node_modules/**'], {
139141
cwd: this.cwd,
@@ -144,6 +146,7 @@ class AvaFiles {
144146
symlinks: Object.create(null)
145147
});
146148
}
149+
147150
isSource(filePath) {
148151
let mixedPatterns = [];
149152
const defaultIgnorePatterns = getDefaultIgnorePatterns();
@@ -195,6 +198,7 @@ class AvaFiles {
195198

196199
return false;
197200
}
201+
198202
isTest(filePath) {
199203
const excludePatterns = this.excludePatterns;
200204
const initialPatterns = this.files.concat(excludePatterns);
@@ -241,6 +245,7 @@ class AvaFiles {
241245
// excludePatterns into account. This mimicks the behavior in api.js
242246
return multimatch(matchable(filePath), recursivePatterns.concat(excludePatterns)).length === 1;
243247
}
248+
244249
getChokidarPatterns() {
245250
let paths = [];
246251
let ignored = [];

lib/beautify-stack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let ignoreStackLines = [];
88

99
const avaInternals = /\/ava\/(?:lib\/)?[\w-]+\.js:\d+:\d+\)?$/;
1010
const avaDependencies = /\/node_modules\/(?:bluebird|empower-core|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//;
11-
const stackFrameLine = /^.+( \(.+:[0-9]+:[0-9]+\)|:[0-9]+:[0-9]+)$/;
11+
const stackFrameLine = /^.+( \(.+:\d+:\d+\)|:\d+:\d+)$/;
1212

1313
if (!debug.enabled) {
1414
ignoreStackLines = StackUtils.nodeInternals();

lib/caching-precompiler.js

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CachingPrecompiler {
3333
this.fileHashes = {};
3434
this.transform = this._createTransform();
3535
}
36+
3637
precompileFile(filePath) {
3738
if (!this.fileHashes[filePath]) {
3839
const source = stripBomBuf(fs.readFileSync(filePath));
@@ -41,11 +42,13 @@ class CachingPrecompiler {
4142

4243
return this.fileHashes[filePath];
4344
}
45+
4446
// Conditionally called by caching-transform when precompiling is required
4547
_init() {
4648
this.babel = require('babel-core');
4749
return this._transform;
4850
}
51+
4952
_transform(code, filePath, hash) {
5053
code = code.toString();
5154

@@ -79,6 +82,7 @@ class CachingPrecompiler {
7982

8083
return `${result.code}\n${comment}`;
8184
}
85+
8286
_createTransform() {
8387
const salt = packageHash.sync([
8488
require.resolve('../package.json'),
@@ -93,6 +97,7 @@ class CachingPrecompiler {
9397
ext: '.js'
9498
});
9599
}
100+
96101
_generateHash(code, filePath, salt) {
97102
const hash = md5Hex([code, filePath, salt]);
98103
this.fileHashes[filePath] = hash;

lib/logger.js

+11
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,51 @@ class Logger {
66
this.reporter = reporter;
77
autoBind(this);
88
}
9+
910
start(runStatus) {
1011
if (!this.reporter.start) {
1112
return;
1213
}
1314

1415
this.write(this.reporter.start(runStatus), runStatus);
1516
}
17+
1618
reset(runStatus) {
1719
if (!this.reporter.reset) {
1820
return;
1921
}
2022

2123
this.write(this.reporter.reset(runStatus), runStatus);
2224
}
25+
2326
test(test, runStatus) {
2427
this.write(this.reporter.test(test, runStatus), runStatus);
2528
}
29+
2630
unhandledError(err, runStatus) {
2731
if (!this.reporter.unhandledError) {
2832
return;
2933
}
3034

3135
this.write(this.reporter.unhandledError(err, runStatus), runStatus);
3236
}
37+
3338
finish(runStatus) {
3439
if (!this.reporter.finish) {
3540
return;
3641
}
3742

3843
this.write(this.reporter.finish(runStatus), runStatus);
3944
}
45+
4046
section() {
4147
if (!this.reporter.section) {
4248
return;
4349
}
4450

4551
this.write(this.reporter.section());
4652
}
53+
4754
clear() {
4855
if (!this.reporter.clear) {
4956
return false;
@@ -52,27 +59,31 @@ class Logger {
5259
this.write(this.reporter.clear());
5360
return true;
5461
}
62+
5563
write(str, runStatus) {
5664
if (typeof str === 'undefined') {
5765
return;
5866
}
5967

6068
this.reporter.write(str, runStatus);
6169
}
70+
6271
stdout(data, runStatus) {
6372
if (!this.reporter.stdout) {
6473
return;
6574
}
6675

6776
this.reporter.stdout(data, runStatus);
6877
}
78+
6979
stderr(data, runStatus) {
7080
if (!this.reporter.stderr) {
7181
return;
7282
}
7383

7484
this.reporter.stderr(data, runStatus);
7585
}
86+
7687
exit(code) {
7788
process.exit(code); // eslint-disable-line unicorn/no-process-exit
7889
}

lib/reporters/improper-usage-messages.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ exports.forError = error => {
1515
Visit the following URL for more details:
1616
1717
${chalk.blue.underline('https://github.com/avajs/ava#throwsfunctionpromise-error-message')}`;
18-
} else if (assertion === 'snapshot') {
18+
}
19+
20+
if (assertion === 'snapshot') {
1921
const name = error.improperUsage.name;
2022
const snapPath = error.improperUsage.snapPath;
2123

0 commit comments

Comments
 (0)