Skip to content

Commit 872d2ed

Browse files
committed
Various minor tweaks
1 parent 2bdf72a commit 872d2ed

File tree

5 files changed

+61
-63
lines changed

5 files changed

+61
-63
lines changed

cli.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env node
22
'use strict';
3-
43
const path = require('path');
54
const debug = require('debug')('ava');
65

76
// Prefer the local installation of AVA.
87
const resolveCwd = require('resolve-cwd');
98
const localCLI = resolveCwd('ava/cli');
109

11-
// Use path.relative() to detect local AVA installation,
10+
// Use `path.relative()` to detect local AVA installation,
1211
// because __filename's case is inconsistent on Windows
1312
// see https://github.com/nodejs/node/issues/6624
1413
if (localCLI && path.relative(localCLI, __filename) !== '') {

lib/cli.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,21 @@ exports.run = () => {
5454
ava --init foo.js
5555
5656
Default patterns when no arguments:
57-
test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js'
57+
test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js
5858
`, {
5959
string: [
6060
'_',
61-
'timeout',
62-
'source',
6361
'match',
62+
'source',
63+
'timeout',
6464
'concurrency'
6565
],
6666
boolean: [
67+
'init',
6768
'fail-fast',
68-
'verbose',
6969
'serial',
7070
'tap',
71+
'verbose',
7172
'watch',
7273
'update-snapshots'
7374
],
@@ -155,7 +156,7 @@ exports.run = () => {
155156
watcher.observeStdin(process.stdin);
156157
} catch (err) {
157158
if (err.name === 'AvaError') {
158-
// An AvaError may be thrown if chokidar is not installed. Log it nicely.
159+
// An AvaError may be thrown if `chokidar` is not installed. Log it nicely.
159160
console.error(` ${colors.error(figures.cross)} ${err.message}`);
160161
logger.exit(1);
161162
} else {

readme.md

+52-54
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $ ava --init
7474

7575
If you prefer using npm:
7676

77-
```
77+
```console
7878
$ npm install --global ava
7979
$ ava --init
8080
```
@@ -109,8 +109,7 @@ Alternatively using npm:
109109
$ npm install --save-dev ava
110110
```
111111

112-
You'll have to configure the `test` script in your `package.json` to use `ava`
113-
(see above).
112+
You'll have to configure the `test` script in your `package.json` to use `ava` (see above).
114113

115114
### Create your test file
116115

@@ -156,7 +155,7 @@ $ ava --help
156155
--init Add AVA to your project
157156
--fail-fast Stop after first test failure
158157
--serial, -s Run tests serially
159-
--tap, -- [ ] Generate TAP output
158+
--tap, -t Generate TAP output
160159
--verbose, -v Enable verbose output
161160
--no-cache Disable the transpiler cache
162161
--no-power-assert Disable Power Assert
@@ -165,7 +164,7 @@ $ ava --help
165164
--source, -S Pattern to match source files so tests can be re-run (Can be repeated)
166165
--timeout, -T Set global timeout
167166
--concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL)
168-
--update-snapshots, -u Update all snapshots
167+
--update-snapshots, -u Update snapshots
169168

170169
Examples
171170
ava
@@ -274,7 +273,7 @@ Tests are run concurrently. You can specify synchronous and asynchronous tests.
274273

275274
We *highly* recommend the use of [async functions](#async-function-support). They make asynchronous code concise and readable, and they implicitly return a promise so you don't have to.
276275

277-
If you're unable to use promises or observables, you may enable "callback mode" by defining your test with `test.cb([title], fn)`. Tests declared this way **must** be manually ended with `t.end()`. This mode is mainly intended for testing callback-style APIs.
276+
If you're unable to use promises or observables, you may enable "callback mode" by defining your test with `test.cb([title], fn)`. Tests declared this way **must** be manually ended with `t.end()`. This mode is mainly intended for testing callback-style APIs. However, we would strongly recommend [promisifying](https://github.com/sindresorhus/pify) callback-style APIs instead of using "callback mode", as this results in more correct and readable tests.
278277

279278
You must define all tests synchronously. They can't be defined inside `setTimeout`, `setImmediate`, etc.
280279

@@ -350,22 +349,22 @@ test(t => {
350349
for (let i = 0; i < 3; i++) {
351350
t.true(i < 3);
352351
}
353-
}); // fails, 3 assertions are executed which is too many
352+
}); // Fails, 3 assertions are executed which is too many
354353

355354
test(t => {
356355
t.plan(1);
357356

358357
someAsyncFunction(() => {
359358
t.pass();
360359
});
361-
}); // fails, the test ends synchronously before the assertion is executed
360+
}); // Fails, the test ends synchronously before the assertion is executed
362361
```
363362

364363
### Running tests serially
365364

366365
By default tests are run concurrently, which is awesome. Sometimes though you have to write tests that cannot run concurrently.
367366

368-
In these rare cases you can use the `.serial` modifier. It'll force those tests to run serially *before* the concurrent ones.
367+
In these rare cases you can use the `.serial` modifier. It will force those tests to run serially *before* the concurrent ones.
369368

370369
```js
371370
test.serial(t => {
@@ -454,12 +453,12 @@ test.only('boo will run but not exclusively', t => {
454453
t.pass();
455454
});
456455

457-
// won't run, no title
456+
// Won't run, no title
458457
test(function (t) {
459458
t.fail();
460459
});
461460

462-
// won't run, no explicit title
461+
// Won't run, no explicit title
463462
test(function foo(t) {
464463
t.fail();
465464
});
@@ -494,7 +493,7 @@ This allows you to merge `.failing` tests before a fix is implemented without br
494493
```js
495494
// See: github.com/user/repo/issues/1234
496495
test.failing('demonstrate some bug', t => {
497-
t.fail(); // test will count as passed
496+
t.fail(); // Test will count as passed
498497
});
499498
```
500499

@@ -514,35 +513,35 @@ Like `test()` these methods take an optional title and a callback function. The
514513

515514
```js
516515
test.before(t => {
517-
// this runs before all tests
516+
// This runs before all tests
518517
});
519518

520519
test.before(t => {
521-
// this runs after the above, but before tests
520+
// This runs after the above, but before tests
522521
});
523522

524523
test.after('cleanup', t => {
525-
// this runs after all tests
524+
// This runs after all tests
526525
});
527526

528527
test.after.always('guaranteed cleanup', t => {
529-
// this will always run, regardless of earlier failures
528+
// This will always run, regardless of earlier failures
530529
});
531530

532531
test.beforeEach(t => {
533-
// this runs before each test
532+
// This runs before each test
534533
});
535534

536535
test.afterEach(t => {
537-
// this runs after each test
536+
// This runs after each test
538537
});
539538

540539
test.afterEach.always(t => {
541-
// this runs after each test and other test hooks, even if they failed
540+
// This runs after each test and other test hooks, even if they failed
542541
});
543542

544543
test(t => {
545-
// regular test
544+
// Regular test
546545
});
547546
```
548547

@@ -690,32 +689,32 @@ You can customize how AVA transpiles the test files through the `babel` option i
690689

691690
```json
692691
{
693-
"ava": {
694-
"babel": {
695-
"presets": [
696-
"es2015",
697-
"stage-0",
698-
"react"
699-
]
700-
}
701-
},
692+
"ava": {
693+
"babel": {
694+
"presets": [
695+
"es2015",
696+
"stage-0",
697+
"react"
698+
]
699+
}
700+
}
702701
}
703702
```
704703

705704
You can also use the special `"inherit"` keyword. This makes AVA defer to the Babel config in your [`.babelrc` or `package.json` file](https://babeljs.io/docs/usage/babelrc/). This way your test files will be transpiled using the same config as your source files without having to repeat it just for AVA:
706705

707706
```json
708707
{
709-
"babel": {
710-
"presets": [
711-
"es2015",
712-
"stage-0",
713-
"react"
714-
]
715-
},
716-
"ava": {
717-
"babel": "inherit"
718-
},
708+
"babel": {
709+
"presets": [
710+
"es2015",
711+
"stage-0",
712+
"react"
713+
]
714+
},
715+
"ava": {
716+
"babel": "inherit"
717+
}
719718
}
720719
```
721720

@@ -770,7 +769,7 @@ test(async function (t) {
770769
t.true(value);
771770
});
772771

773-
// async arrow function
772+
// Async arrow function
774773
test(async t => {
775774
const value = await promiseFn();
776775
t.true(value);
@@ -788,7 +787,7 @@ test(t => {
788787
t.plan(3);
789788
return Observable.of(1, 2, 3, 4, 5, 6)
790789
.filter(n => {
791-
// only even numbers
790+
// Only even numbers
792791
return n % 2 === 0;
793792
})
794793
.map(() => t.pass());
@@ -801,7 +800,7 @@ AVA supports using `t.end` as the final callback when using node-style error-fir
801800

802801
```js
803802
test.cb(t => {
804-
// t.end automatically checks for error as first argument
803+
// `t.end` automatically checks for error as first argument
805804
fs.readFile('data.txt', t.end);
806805
});
807806
```
@@ -814,7 +813,7 @@ AVA resets a timer after each test, forcing tests to quit if no new test results
814813

815814
You can set timeouts in a human-readable way:
816815

817-
```
816+
```console
818817
$ ava --timeout=10s # 10 seconds
819818
$ ava --timeout=2m # 2 minutes
820819
$ ava --timeout=100 # 100 milliseconds
@@ -866,7 +865,7 @@ Assertions are mixed into the [execution object](#t) provided to each test imple
866865

867866
```js
868867
test(t => {
869-
t.truthy('unicorn'); // assertion
868+
t.truthy('unicorn'); // Assertion
870869
});
871870
```
872871

@@ -972,14 +971,14 @@ Snapshot testing comes as another kind of assertion and uses [jest-snapshot](htt
972971
When used with React, it looks very similar to Jest:
973972

974973
```js
975-
// your component
974+
// Your component
976975
const HelloWorld = () => <h1>Hello World...!</h1>;
977976

978977
export default HelloWorld;
979978
```
980979

981980
```js
982-
// your test
981+
// Your test
983982
import test from 'ava';
984983
import render from 'react-test-renderer';
985984

@@ -1007,7 +1006,9 @@ Every time you run this test afterwards, it will check if the component render h
10071006

10081007
That might look like this:
10091008

1010-
`$ ava --update-snapshots`
1009+
```console
1010+
$ ava --update-snapshots
1011+
```
10111012

10121013
Note that snapshots can be used for much more than just testing components - you can equally well test any other (data) structure that you can stringify.
10131014

@@ -1018,7 +1019,7 @@ Any assertion can be skipped using the `skip` modifier. Skipped assertions are s
10181019
```js
10191020
test(t => {
10201021
t.plan(2);
1021-
t.skip.is(foo(), 5); // no need to change your plan count when skipping
1022+
t.skip.is(foo(), 5); // No need to change your plan count when skipping
10221023
t.is(1, 1);
10231024
});
10241025
```
@@ -1128,23 +1129,20 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
11281129

11291130
## Related
11301131

1132+
- [eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava) - Lint rules for AVA tests
11311133
- [sublime-ava](https://github.com/avajs/sublime-ava) - Snippets for AVA tests
11321134
- [atom-ava](https://github.com/avajs/atom-ava) - Snippets for AVA tests
11331135
- [vscode-ava](https://github.com/samverschueren/vscode-ava) - Snippets for AVA tests
1134-
- [eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava) - Lint rules for AVA tests
11351136
- [gulp-ava](https://github.com/avajs/gulp-ava) - Run tests with gulp
11361137
- [grunt-ava](https://github.com/avajs/grunt-ava) - Run tests with grunt
1137-
- [fly-ava](https://github.com/pine/fly-ava) - Run tests with fly
1138-
- [start-ava](https://github.com/start-runner/ava) - Run tests with start
1139-
1140-
[More...](https://github.com/avajs/awesome-ava#packages)
1138+
- [More…](https://github.com/avajs/awesome-ava#packages)
11411139

11421140
## Links
11431141

11441142
- [Buy AVA stickers](https://www.stickermule.com/user/1070705604/stickers)
11451143
- [Awesome list](https://github.com/avajs/awesome-ava)
1146-
- [JavaScript Air podcast episode](http://jsair.io/ava)
11471144
- [AVA Casts](http://avacasts.com)
1145+
- [More…](https://github.com/avajs/awesome-ava)
11481146

11491147
## Team
11501148

test/run-status.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test('calculate remaining test count', t => {
7171
const runStatus = new RunStatus();
7272
runStatus.testCount = 10;
7373

74-
var results = [{
74+
const results = [{
7575
stats: {
7676
passCount: 1,
7777
failCount: 1,

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ test('waits for t.throws to reject after the promise returned from the test reso
553553
test('multiple resolving and rejecting promises passed to t.throws/t.notThrows', t => {
554554
ava(a => {
555555
a.plan(6);
556-
for (let i = 0; i < 3; ++i) {
556+
for (let i = 0; i < 3; i++) {
557557
a.throws(delay.reject(10, new Error('foo')), 'foo');
558558
a.notThrows(delay(10), 'foo');
559559
}

0 commit comments

Comments
 (0)