Skip to content

Commit f2726f1

Browse files
Update TypeScript recipe for mocks, Node.js 20
1 parent f047694 commit f2726f1

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

docs/recipes/typescript.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,44 @@ There are two components to a setup like this:
2828

2929
```json
3030
"ava": {
31-
"extensions": {
32-
"ts": "module"
33-
},
34-
"nodeArguments": [
35-
"--loader=tsx"
36-
]
37-
}
31+
"extensions": {
32+
"ts": "module"
33+
},
34+
"nodeArguments": [
35+
"--loader=tsx"
36+
]
37+
}
38+
```
39+
### When using custom loaders
40+
41+
#### Mocking
42+
43+
Mocking with `tsx` (such as with [`esmock`](https://github.com/iambumblehead/esmock)) isn't currently possible (https://github.com/esbuild-kit/tsx/issues/264). [`ts-node`](https://github.com/TypeStrong/ts-node) can be used instead:
44+
45+
`package.json`:
46+
47+
```json
48+
"ava": {
49+
"extensions": {
50+
"ts": "module"
51+
},
52+
"nodeArguments": [
53+
"--loader=ts-node/esm",
54+
"--loader=esmock"
55+
]
56+
}
57+
```
58+
59+
#### Node.js 20
60+
61+
In Node.js 20, custom loaders must be specified via the `NODE_OPTIONS` environment variable:
62+
63+
`package.json`:
64+
65+
```json
66+
"scripts": {
67+
"test": "NODE_OPTIONS='--loader=tsx' ava"
68+
}
3869
```
3970

4071
## Writing tests

0 commit comments

Comments
 (0)