Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: avajs/ava
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.1.0
Choose a base ref
...
head repository: avajs/ava
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.1.1
Choose a head ref
  • 5 commits
  • 7 files changed
  • 2 contributors

Commits on Jan 28, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    fatso83 Carl-Erik Kopseng
    Copy the full SHA
    735bf41 View commit details
  2. Fix 'previous failures' in watch mode always incrementing

    The counters used absolute paths for the test files, but the clearing logic used relative paths. Count using relative paths instead.
    
    The number of previous failures is not observable to the test harness, so this does not come with test coverage.
    
    Fixes #3295.
    novemberborn committed Jan 28, 2024
    Copy the full SHA
    db0fdb2 View commit details
  3. Fix external-assertions snapshot for Node.js 20.11

    Vary the snapshots by minor version were appropriate.
    novemberborn committed Jan 28, 2024
    Copy the full SHA
    15dddf3 View commit details

Commits on Jan 29, 2024

  1. Update dependencies

    novemberborn authored Jan 29, 2024
    Copy the full SHA
    5161bf7 View commit details
  2. 6.1.1

    novemberborn committed Jan 29, 2024
    Copy the full SHA
    2e0c2b1 View commit details
Showing with 885 additions and 1,034 deletions.
  1. +11 −33 docs/recipes/typescript.md
  2. +2 −1 lib/watcher.js
  3. +749 −977 package-lock.json
  4. +11 −11 package.json
  5. +103 −6 test/external-assertions/snapshots/test.js.md
  6. BIN test/external-assertions/snapshots/test.js.snap
  7. +9 −6 test/external-assertions/test.js
44 changes: 11 additions & 33 deletions docs/recipes/typescript.md
Original file line number Diff line number Diff line change
@@ -17,12 +17,21 @@ Broadly speaking, there are two ways to run tests written in TypeScript:

**You can use loaders, but you're largely on your own. [Please post questions to our Discussions forum if you're stuck](https://github.com/avajs/ava/discussions/categories/q-a).**

> [!NOTE]
> Custom loaders changed with the release of Node.js 20. This recipe assumes your Node.js version is equal to or higher than the following. For older versions, please see a [previous commit](https://github.com/avajs/ava/blob/aae39b20ba3ef80e5bedb1e5882432a3cd7c44eb/docs/recipes/typescript.md).
>
> | Node.js Major Version | Minimum Version |
> | --------------------- | --------------- |
> | 18 | 18.18.0 |
> | 20 | 20.8.0 |
> | 21 | 21.0.0 |
There are two components to a setup like this:

1. [Make sure AVA recognizes the extensions of your TypeScript files](../06-configuration.md#configuring-module-formats)
2. Install the loader [through `nodeArguments`](../06-configuration.md#node-arguments)

[`tsx`](https://github.com/esbuild-kit/tsx) may be the best loader available. The setup, assuming your TypeScript config outputs ES modules, would look like this:
[`tsimp`](https://github.com/tapjs/tsimp) may be the best loader available. The setup, assuming your TypeScript config outputs ES modules, would look like this:

`package.json`:

@@ -32,41 +41,10 @@ There are two components to a setup like this:
"ts": "module"
},
"nodeArguments": [
"--loader=tsx"
"--import=tsimp"
]
}
```
### 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

3 changes: 2 additions & 1 deletion lib/watcher.js
Original file line number Diff line number Diff line change
@@ -106,7 +106,8 @@ async function * plan({api, filter, globs, projectDir, providers, stdin, abortSi
case 'uncaught-exception':
case 'unhandled-rejection':
case 'worker-failed': {
failureCounts.set(evt.testFile, 1 + (failureCounts.get(evt.testFile) ?? 0));
const path = nodePath.relative(projectDir, evt.testFile);
failureCounts.set(path, 1 + (failureCounts.get(path) ?? 0));
break;
}

Loading