Skip to content

Commit

Permalink
Update TypeScript recipe for mocks, Node.js 20
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Jul 31, 2023
1 parent f047694 commit f2726f1
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions docs/recipes/typescript.md
Expand Up @@ -28,13 +28,44 @@ There are two components to a setup like this:

```json
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=tsx"
]
}
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=tsx"
]
}
```
### When using custom loaders

#### Mocking

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:

`package.json`:

```json
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm",
"--loader=esmock"
]
}
```

#### Node.js 20

In Node.js 20, custom loaders must be specified via the `NODE_OPTIONS` environment variable:

`package.json`:

```json
"scripts": {
"test": "NODE_OPTIONS='--loader=tsx' ava"
}
```

## Writing tests
Expand Down

0 comments on commit f2726f1

Please sign in to comment.