You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/05-command-line.md
+63-1
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,8 @@ Commands:
15
15
16
16
Positionals:
17
17
pattern Glob patterns to select what test files to run. Leave empty if you
18
-
want AVA to run all test files instead [string]
18
+
want AVA to run all test files instead. Add a colon and specify line
19
+
numbers of specific tests to run [string]
19
20
20
21
Options:
21
22
--version Show version number [boolean]
@@ -42,6 +43,7 @@ Options:
42
43
Examples:
43
44
ava
44
45
ava test.js
46
+
ava test.js:4,7-9
45
47
```
46
48
47
49
*Note that the CLI will use your local install of AVA when available, even when run globally.*
@@ -149,6 +151,66 @@ test(function foo(t) {
149
151
});
150
152
```
151
153
154
+
## Running tests at specific line numbers
155
+
156
+
AVA lets you run tests exclusively by referring to their line numbers. Target a single line, a range of lines or both. You can select any line number of a test.
157
+
158
+
The format is a comma-separated list of `[X|Y-Z]` where `X`, `Y` and `Z` are integers between `1` and the last line number of the file.
159
+
160
+
This feature is only available from the command line. It won't work if you use tools like `ts-node/register` or `@babel/register`, and it does not currently work with `@ava/babel` and `@ava/typescript`.
161
+
162
+
### Running a single test
163
+
164
+
To only run a particular test in a file, append the line number of the test to the path or pattern passed to AVA.
165
+
166
+
Given the following test file:
167
+
168
+
`test.js`
169
+
170
+
```js
171
+
1:test('unicorn', t=> {
172
+
2:t.pass();
173
+
3: });
174
+
4:
175
+
5:test('rainbow', t=> {
176
+
6:t.fail();
177
+
7: });
178
+
```
179
+
180
+
Running `npx ava test.js:2` for would run the `unicorn` test. In fact you could use any line number between `1` and `3`.
181
+
182
+
### Running multiple tests
183
+
184
+
To run multiple tests, either target them one by one or select a range of line numbers. As line numbers are given per file, you can run multiple files with different line numbers for each file. If the same file is provided multiple times, line numbers are merged and only run once.
185
+
186
+
### Examples
187
+
188
+
Single line numbers:
189
+
190
+
```console
191
+
npx ava test.js:2,9
192
+
```
193
+
194
+
Range:
195
+
196
+
```console
197
+
npx ava test.js:4-7
198
+
```
199
+
200
+
Mix of single line number and range:
201
+
202
+
```console
203
+
npx ava test.js:4,9-12
204
+
```
205
+
206
+
Different files:
207
+
208
+
```console
209
+
npx ava test.js:3 test2.js:4,7-9
210
+
```
211
+
212
+
When running a file with and without line numbers, line numbers take precedence.
213
+
152
214
## Resetting AVA's cache
153
215
154
216
AVA may cache certain files, especially when you use our [`@ava/babel`](https://github.com/avajs/babel) provider. If it seems like your latest changes aren't being picked up by AVA you can reset the cache by running:
0 commit comments