ava 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/readme.md CHANGED
@@ -2,20 +2,23 @@
2
2
 
3
3
  > Futuristic test runner
4
4
 
5
- [![Build Status: Linux](https://travis-ci.org/avajs/ava.svg?branch=master)](https://travis-ci.org/avajs/ava) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/igogxrcmhhm085co/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/ava/branch/master) [![Coverage Status](https://coveralls.io/repos/github/avajs/ava/badge.svg?branch=master)](https://coveralls.io/github/avajs/ava?branch=master) [![Gitter](https://badges.gitter.im/join_chat.svg)](https://gitter.im/avajs/ava)
5
+ [![Build Status: Linux](https://travis-ci.org/avajs/ava.svg?branch=master)](https://travis-ci.org/avajs/ava) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/e7v91mu2m5x48ehx/branch/master?svg=true)](https://ci.appveyor.com/project/ava/ava/branch/master) [![Coverage Status](https://coveralls.io/repos/github/avajs/ava/badge.svg?branch=master)](https://coveralls.io/github/avajs/ava?branch=master) [![Dependency Status](https://dependencyci.com/github/avajs/ava/badge)](https://dependencyci.com/github/avajs/ava) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) [![Gitter](https://badges.gitter.im/join_chat.svg)](https://gitter.im/avajs/ava)
6
6
 
7
7
  Even though JavaScript is single-threaded, IO in Node.js can happen in parallel due to its async nature. AVA takes advantage of this and runs your tests concurrently, which is especially beneficial for IO heavy tests. In addition, test files are run in parallel as separate processes, giving you even better performance and an isolated environment for each test file. [Switching](https://github.com/sindresorhus/pageres/commit/663be15acb3dd2eb0f71b1956ef28c2cd3fdeed0) from Mocha to AVA in Pageres brought the test time down from 31 sec to 11 sec. Having tests run concurrently forces you to write atomic tests, meaning tests don't depend on global state or the state of other tests, which is a great thing!
8
8
 
9
+ ![](media/screenshot-mini-reporter.gif)
10
+
9
11
  *Read our [contributing guide](contributing.md) if you're looking to contribute (issues/PRs/etc).*
10
12
 
11
13
  Follow the [AVA Twitter account](https://twitter.com/ava__js) for updates.
12
14
 
13
15
  Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/readme.md), [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/readme.md), [Italiano](https://github.com/avajs/ava-docs/blob/master/it_IT/readme.md), [日本語](https://github.com/avajs/ava-docs/blob/master/ja_JP/readme.md), [한국어](https://github.com/avajs/ava-docs/blob/master/ko_KR/readme.md), [Português](https://github.com/avajs/ava-docs/blob/master/pt_BR/readme.md), [Русский](https://github.com/avajs/ava-docs/blob/master/ru_RU/readme.md), [简体中文](https://github.com/avajs/ava-docs/blob/master/zh_CN/readme.md)
14
16
 
15
- ## Table of Contents
17
+ ## Contents
16
18
 
17
19
  - [Usage](#usage)
18
20
  - [CLI Usage](#cli)
21
+ - [Reporters](#reporters)
19
22
  - [Configuration](#configuration)
20
23
  - [Documentation](#documentation)
21
24
  - [API](#api)
@@ -42,8 +45,9 @@ Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/rea
42
45
  - [Async function support](#async-function-support)
43
46
  - [Observable support](#observable-support)
44
47
  - [Enhanced assertion messages](#enhanced-assertion-messages)
45
- - [Optional TAP output](#optional-tap-output)
48
+ - [TAP reporter](#tap-reporter)
46
49
  - [Clean stack traces](#clean-stack-traces)
50
+ - [Automatic migration from other test runners](https://github.com/avajs/ava-codemods#migrating-to-ava)
47
51
 
48
52
  ## Test syntax
49
53
 
@@ -59,13 +63,15 @@ test(t => {
59
63
 
60
64
  ### Add AVA to your project
61
65
 
62
- Install AVA globally run with `--init` to add AVA to your `package.json`:
66
+ Install AVA globally and run it with `--init` to add AVA to your `package.json`:
63
67
 
64
68
  ```console
65
69
  $ npm install --global ava
66
70
  $ ava --init
67
71
  ```
68
72
 
73
+ Your `package.json` will then look like this:
74
+
69
75
  ```json
70
76
  {
71
77
  "name": "awesome-package",
@@ -73,12 +79,12 @@ $ ava --init
73
79
  "test": "ava"
74
80
  },
75
81
  "devDependencies": {
76
- "ava": "^0.11.0"
82
+ "ava": "^0.15.0"
77
83
  }
78
84
  }
79
85
  ```
80
86
 
81
- Any arguments passed after `--init` are added in the `package.json`.
87
+ Any arguments passed after `--init` are added as config to `package.json`.
82
88
 
83
89
  #### Manual installation
84
90
 
@@ -109,8 +115,6 @@ test('bar', async t => {
109
115
  });
110
116
  ```
111
117
 
112
- <img src="media/screenshot.png" width="150" align="right">
113
-
114
118
  ### Run it
115
119
 
116
120
  ```console
@@ -127,8 +131,6 @@ AVA comes with an intelligent watch mode. [Learn more in its recipe](docs/recipe
127
131
 
128
132
  ## CLI
129
133
 
130
- ![](media/screenshot-mini-reporter.gif)
131
-
132
134
  ```console
133
135
  $ ava --help
134
136
 
@@ -139,10 +141,10 @@ $ ava --help
139
141
  --init Add AVA to your project
140
142
  --fail-fast Stop after first test failure
141
143
  --serial, -s Run tests serially
142
- --require, -r Module to preload (Can be repeated)
143
144
  --tap, -t Generate TAP output
144
145
  --verbose, -v Enable verbose output
145
146
  --no-cache Disable the transpiler cache
147
+ --no-power-assert Disable Power Assert
146
148
  --match, -m Only run tests with matching title (Can be repeated)
147
149
  --watch, -w Re-run tests when tests and source files change
148
150
  --source, -S Pattern to match source files so tests can be re-run (Can be repeated)
@@ -167,6 +169,39 @@ Directories are recursed, with all `*.js` files being treated as test files. Dir
167
169
 
168
170
  When using `npm test`, you can pass positional arguments directly `npm test test2.js`, but flags needs to be passed like `npm test -- --verbose`.
169
171
 
172
+ ## Reporters
173
+
174
+ ### Mini-reporter
175
+
176
+ The mini-reporter is the default reporter.
177
+
178
+ <img src="media/screenshot-mini-reporter.gif" width="460">
179
+
180
+ ### Verbose reporter
181
+
182
+ Use the `--verbose` flag to enable the verbose reporter. This is always used in CI environments unless the [TAP reporter](#tap-reporter) is enabled.
183
+
184
+ <img src="media/screenshot.png" width="150">
185
+
186
+ ### TAP reporter
187
+
188
+ AVA supports the TAP format and thus is compatible with [any TAP reporter](https://github.com/sindresorhus/awesome-tap#reporters). Use the `--tap` flag to enable TAP output.
189
+
190
+ ```console
191
+ $ ava --tap | tap-nyan
192
+ ```
193
+
194
+ <img src="media/tap-output.png" width="398">
195
+
196
+ Please note that the TAP reporter is unavailable when using [watch mode](#watch-it).
197
+
198
+ ### Clean stack traces
199
+
200
+ AVA automatically removes unrelated lines in stack traces, allowing you to find the source of an error much faster.
201
+
202
+ <img src="media/stack-traces.png" width="300">
203
+
204
+
170
205
  ## Configuration
171
206
 
172
207
  All of the CLI options can be configured in the `ava` section of your `package.json`. This allows you to modify the default behavior of the `ava` command, so you don't have to repeatedly type the same options on the command prompt.
@@ -186,8 +221,10 @@ All of the CLI options can be configured in the `ava` section of your `package.j
186
221
  "*oo",
187
222
  "!foo"
188
223
  ],
224
+ "concurrency": 5,
189
225
  "failFast": true,
190
226
  "tap": true,
227
+ "powerAssert": false,
191
228
  "require": [
192
229
  "babel-register"
193
230
  ],
@@ -210,11 +247,13 @@ If you're unable to use promises or observables, you may enable "callback mode"
210
247
 
211
248
  You must define all tests synchronously. They can't be defined inside `setTimeout`, `setImmediate`, etc.
212
249
 
213
- Test files are run from their current directory, so [`process.cwd()`](https://nodejs.org/api/process.html#process_process_cwd) is always the same as [`__dirname`](https://nodejs.org/api/globals.html#globals_dirname). You can just use relative paths instead of doing `path.join(__dirname, 'relative/path')`.
250
+ AVA tries to run test files with their current working directory set to the directory that contains your `package.json` file.
214
251
 
215
252
  ### Creating tests
216
253
 
217
- To create a test you call the `test` function you imported from AVA. Provide the optional title and implementation function. The function will be called when your test is run. It's passed an [execution object](#t) as its first and only argument. By convention this argument is named `t`.
254
+ To create a test you call the `test` function you imported from AVA. Provide the optional title and implementation function. The function will be called when your test is run. It's passed an [execution object](#t) as its first argument.
255
+
256
+ **Note:** In order for the [enhanced assertion messages](#enhanced-assertion-messages) to behave correctly, the first argument **must** be named `t`.
218
257
 
219
258
  ```js
220
259
  import test from 'ava';
@@ -349,7 +388,7 @@ Match titles that are *exactly* `foo` (albeit case insensitively):
349
388
  $ ava --match='foo'
350
389
  ```
351
390
 
352
- Watch titles not containing `foo`:
391
+ Match titles not containing `foo`:
353
392
 
354
393
  ```console
355
394
  $ ava --match='!*foo*'
@@ -432,7 +471,7 @@ test.failing('demonstrate some bug', t => {
432
471
 
433
472
  AVA lets you register hooks that are run before and after your tests. This allows you to run setup and/or teardown code.
434
473
 
435
- `test.before()` registers a hook to be run before the first test in your test file. Similarly `test.after()` registers a hook to be run after the last test. Use `test.after.always()` to register a hook that will **always** run once your tests and other hooks complete. `.always()` hooks run regardless of whether there were earlier failures, so they are ideal for cleanup tasks.
474
+ `test.before()` registers a hook to be run before the first test in your test file. Similarly `test.after()` registers a hook to be run after the last test. Use `test.after.always()` to register a hook that will **always** run once your tests and other hooks complete. `.always()` hooks run regardless of whether there were earlier failures, so they are ideal for cleanup tasks. There are two exceptions to this however. If you use `--fail-fast` AVA will stop testing as soon as a failure occurs, and it won't run any hooks including the `.always()` hooks. Uncaught exceptions will crash your tests, possibly preventing `.always()` hooks from running.
436
475
 
437
476
  `test.beforeEach()` registers a hook to be run before each test in your test file. Similarly `test.afterEach()` a hook to be run after each test. Use `test.afterEach.always()` to register an after hook that is called even if other test hooks, or the test itself, fail. `.always()` hooks are ideal for cleanup tasks.
438
477
 
@@ -512,7 +551,7 @@ test(t => {
512
551
  });
513
552
  ```
514
553
 
515
- By default `t.context` is an object but you can reassign it:
554
+ The context is not shared between tests, allowing you to set up data in a way where it will not risk leaking to other, subsequent tests. By default `t.context` is an object but you can reassign it:
516
555
 
517
556
  ```js
518
557
  test.beforeEach(t => {
@@ -638,7 +677,7 @@ You can customize how AVA transpiles the test files through the `babel` option i
638
677
 
639
678
  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:
640
679
 
641
- ```json
680
+ ```json
642
681
  {
643
682
  "babel": {
644
683
  "presets": [
@@ -661,11 +700,13 @@ Note that AVA will *always* apply [a few internal plugins](docs/recipes/babelrc.
661
700
 
662
701
  AVA includes typings for TypeScript. You have to set up transpilation yourself. When you set `module` to `commonjs` in your `tsconfig.json` file, TypeScript will automatically find the type definitions for AVA. You should set `target` to `es2015` to use promises and async functions.
663
702
 
703
+ See AVA's [TypeScript recipe](docs/recipes/typescript.md) for a more detailed explanation.
704
+
664
705
  ### Transpiling imported modules
665
706
 
666
707
  AVA currently only transpiles the tests you ask it to run. *It will not transpile modules you `import` from outside of the test.* This may be unexpected but there are workarounds.
667
708
 
668
- If you use Babel you can use its [require hook](https://babeljs.io/docs/usage/require/) to transpile imported modules on-the-fly. Run AVA with `--require babel-register` (see [CLI](#cli)) or [configure it in your `package.json`](#configuration).
709
+ If you use Babel you can use its [require hook](https://babeljs.io/docs/usage/require/) to transpile imported modules on-the-fly. To add it, [configure it in your `package.json`](#configuration).
669
710
 
670
711
  You can also transpile your modules in a separate process and refer to the transpiled files rather than the sources from your tests.
671
712
 
@@ -738,24 +779,6 @@ test.cb(t => {
738
779
  });
739
780
  ```
740
781
 
741
- ### Optional TAP output
742
-
743
- AVA can generate TAP output via `--tap` option for use with any [TAP reporter](https://github.com/sindresorhus/awesome-tap#reporters).
744
-
745
- ```console
746
- $ ava --tap | tap-nyan
747
- ```
748
-
749
- <img src="media/tap-output.png" width="398">
750
-
751
- Please note that the TAP reporter is unavailable when using [watch mode](#watch-it).
752
-
753
- ### Clean stack traces
754
-
755
- AVA automatically removes unrelated lines in stack traces, allowing you to find the source of an error much faster.
756
-
757
- <img src="media/stack-traces.png" width="300">
758
-
759
782
  ### Global timeout
760
783
 
761
784
  A global timeout can be set via the `--timeout` option.
@@ -878,6 +901,10 @@ Assert that `function` doesn't throw an `error` or `promise` resolves.
878
901
 
879
902
  Assert that `contents` matches `regex`.
880
903
 
904
+ ### `.notRegex(contents, regex, [message])`
905
+
906
+ Assert that `contents` does not match `regex`.
907
+
881
908
  ### `.ifError(error, [message])`
882
909
 
883
910
  Assert that `error` is falsy.
@@ -959,6 +986,10 @@ You can't use [`istanbul`](https://github.com/gotwarlost/istanbul) for code cove
959
986
 
960
987
  As of version `5.0.0` it uses source maps to report coverage for your actual code, regardless of transpilation. Make sure that the code you're testing includes an inline source map or references a source map file. If you use `babel-register` you can set the `sourceMaps` option in your Babel config to `inline`.
961
988
 
989
+ ### Common pitfalls
990
+
991
+ We have a growing list of [common pitfalls](docs/common-pitfalls.md) you may experience while using AVA. If you encounter any issues you think are common, comment in [this issue](https://github.com/avajs/ava/issues/404).
992
+
962
993
  ## FAQ
963
994
 
964
995
  ### Why not `mocha`, `tape`, `tap`?
@@ -969,10 +1000,6 @@ Tape and tap are pretty good. AVA is highly inspired by their syntax. They too e
969
1000
 
970
1001
  In contrast AVA is highly opinionated and runs tests concurrently, with a separate process for each test file. Its default reporter is easy on the eyes and yet AVA still supports TAP output through a CLI flag.
971
1002
 
972
- ### How can I use custom reporters?
973
-
974
- AVA supports the TAP format and thus is compatible with any [TAP reporter](https://github.com/sindresorhus/awesome-tap#reporters). Use the [`--tap` flag](#optional-tap-output) to enable TAP output.
975
-
976
1003
  ### How is the name written and pronounced?
977
1004
 
978
1005
  AVA, not Ava or ava. Pronounced [`/ˈeɪvə/` ay-və](media/pronunciation.m4a?raw=true).
@@ -995,6 +1022,8 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
995
1022
  - [TypeScript](docs/recipes/typescript.md)
996
1023
  - [Configuring Babel](docs/recipes/babelrc.md)
997
1024
  - [Testing React components](docs/recipes/react.md)
1025
+ - [JSPM and SystemJS](docs/recipes/jspm-systemjs.md)
1026
+ - [Debugging tests with WebStorm](docs/recipes/debugging-with-webstorm.md)
998
1027
 
999
1028
  ## Support
1000
1029
 
@@ -1023,9 +1052,9 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
1023
1052
 
1024
1053
  ## Team
1025
1054
 
1026
- [![Sindre Sorhus](https://avatars.githubusercontent.com/u/170270?s=130)](http://sindresorhus.com) | [![Vadim Demedes](https://avatars.githubusercontent.com/u/697676?s=130)](https://github.com/vdemedes) | [![James Talmage](https://avatars.githubusercontent.com/u/4082216?s=130)](https://github.com/jamestalmage) | [![Mark Wubben](https://avatars.githubusercontent.com/u/33538?s=130)](https://novemberborn.net) | [![Juan Soto](https://avatars.githubusercontent.com/u/8217766?s=130)](https://juansoto.me)
1027
- ---|---|---|---|---|---
1028
- [Sindre Sorhus](http://sindresorhus.com) | [Vadim Demedes](https://github.com/vdemedes) | [James Talmage](https://github.com/jamestalmage) | [Mark Wubben](https://novemberborn.net) | [Juan Soto](https://juansoto.me)
1055
+ [![Sindre Sorhus](https://avatars.githubusercontent.com/u/170270?s=130)](http://sindresorhus.com) | [![Vadim Demedes](https://avatars.githubusercontent.com/u/697676?s=130)](https://github.com/vdemedes) | [![James Talmage](https://avatars.githubusercontent.com/u/4082216?s=130)](https://github.com/jamestalmage) | [![Mark Wubben](https://avatars.githubusercontent.com/u/33538?s=130)](https://novemberborn.net) | [![Juan Soto](https://avatars.githubusercontent.com/u/8217766?s=130)](https://juansoto.me) | [![Jeroen Engels](https://avatars.githubusercontent.com/u/3869412?s=130)](https://github.com/jfmengels)
1056
+ ---|---|---|---|---|---|---
1057
+ [Sindre Sorhus](http://sindresorhus.com) | [Vadim Demedes](https://github.com/vdemedes) | [James Talmage](https://github.com/jamestalmage) | [Mark Wubben](https://novemberborn.net) | [Juan Soto](http://juansoto.me) | [Jeroen Engels](https://github.com/jfmengels)
1029
1058
 
1030
1059
  ### Former
1031
1060