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
AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.
6
6
7
-
Out of the box AVA does not load TypeScript test files, however. Rudimentary support is available via the [`@ava/typescript`] package. You can also use AVA with [`ts-node`]. Read on for details.
8
-
9
7
This guide assumes you've already set up TypeScript for your project. Note that AVA's definition expects at least version 3.7.5.
10
8
11
-
## Enabling AVA's TypeScript support
9
+
## Enabling AVA's support for TypeScript test files
10
+
11
+
Out of the box AVA does not load TypeScript test files. You can use our [`@ava/typescript`] package, which is designed to work for projects that precompile TypeScript using the `tsc` command. Please see [`@ava/typescript`] for setup instructions.
12
+
13
+
### Using `ts-node`
14
+
15
+
You can use [`ts-node`] to do live testing without transpiling to js files. This can be especially helpful when you're using a bundler.
16
+
17
+
`npm i --save-dev typescript ts-node`
12
18
13
-
Currently, AVA's TypeScript support is designed to work for projects that precompile TypeScript. Please see [`@ava/typescript`] for setup instructions.
19
+
`package.json`:
20
+
21
+
```json
22
+
{
23
+
"ava": {
24
+
"extensions": [
25
+
"ts"
26
+
],
27
+
"require": [
28
+
"ts-node/register"
29
+
]
30
+
}
31
+
}
32
+
```
14
33
15
-
Read on until the end to learn how to use [`ts-node`] with AVA.
34
+
It's worth noting that with this configuration tests will fail if there are TypeScript build errors. If you want to test while ignoring these errors you can use `ts-node/register/transpile-only` instead of `ts-node/register`.
16
35
17
36
## Writing tests
18
37
@@ -153,27 +172,6 @@ test('throwsAsync', async t => {
153
172
154
173
Note that, despite the typing, the assertion returns `undefined` if it fails. Typing the assertions as returning `Error | undefined` didn't seem like the pragmatic choice.
155
174
156
-
## On the fly compilation using `ts-node`
157
-
158
-
If [`@ava/typescript`] doesn't do the trick you can use [`ts-node`]. Make sure it's installed and then configure AVA to recognize TypeScript files and register [`ts-node`]:
159
-
160
-
`package.json`:
161
-
162
-
```json
163
-
{
164
-
"ava": {
165
-
"extensions": [
166
-
"ts"
167
-
],
168
-
"require": [
169
-
"ts-node/register"
170
-
]
171
-
}
172
-
}
173
-
```
174
-
175
-
It's worth noting that with this configuration tests will fail if there are TypeScript build errors. If you want to test while ignoring these errors you can use `ts-node/register/transpile-only` instead of `ts-node/register`.
176
-
177
175
### Using module path mapping
178
176
179
177
`ts-node`[does not support module path mapping](https://github.com/TypeStrong/ts-node/issues/138), however you can use [`tsconfig-paths`](https://github.com/dividab/tsconfig-paths#readme).
0 commit comments