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
Support compilation using `tsc` before AVA runs tests.
This is a breaking change. To retain the old behavior you must configure `compile: false`.
Co-authored-by: Mark Wubben <[email protected]>
Copy file name to clipboardexpand all lines: README.md
+7-4
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# @ava/typescript
2
2
3
-
Adds rudimentary [TypeScript](https://www.typescriptlang.org/) support to [AVA](https://avajs.dev).
3
+
Adds [TypeScript](https://www.typescriptlang.org/) support to [AVA](https://avajs.dev).
4
4
5
-
This is designed to work for projects that precompile their TypeScript code, including tests. It allows AVA to load the resulting JavaScript, while configuring AVA to use the TypeScript paths.
5
+
This is designed to work for projects that precompile TypeScript. It allows AVA to load the compiled JavaScript, while configuring AVA to treat the TypeScript files as test files.
6
6
7
-
In other words, say you have a test file at `src/test.ts`. You've configured TypeScript to output to `build/`. Using `@ava/typescript` you can run the `build/test.js` file using `npx ava src/test.ts`. AVA won't pick up any of the JavaScript files present in the `build/` directory, unless they have a TypeScript counterpart in `src/`.
7
+
In other words, say you have a test file at `src/test.ts`. You've configured TypeScript to output to `build/`. Using `@ava/typescript` you can run the testusing `npx ava src/test.ts`.
8
8
9
9
## Enabling TypeScript support
10
10
@@ -24,14 +24,17 @@ Then, enable TypeScript support either in `package.json` or `ava.config.*`:
24
24
"typescript": {
25
25
"rewritePaths": {
26
26
"src/": "build/"
27
-
}
27
+
},
28
+
"compile": false
28
29
}
29
30
}
30
31
}
31
32
```
32
33
33
34
Both keys and values of the `rewritePaths` object must end with a `/`. Paths are relative to your project directory.
34
35
36
+
You can enable compilation via the `compile` property. If `false`, AVA will assume you have already compiled your project. If set to `'tsc'`, AVA will run the TypeScript compiler before running your tests. This can be inefficient when using AVA in watch mode.
37
+
35
38
Output files are expected to have the `.js` extension.
36
39
37
40
AVA searches your entire project for `*.js`, `*.cjs`, `*.mjs` and `*.ts` files (or other extensions you've configured). It will ignore such files found in the `rewritePaths` targets (e.g. `build/`). If you use more specific paths, for instance `build/main/`, you may need to change AVA's `files` configuration to ignore other directories.
thrownewError(`Unexpected Typescript configuration for AVA. ${help}`);
45
82
}
46
83
47
-
if(!valid){
48
-
thrownewError(`Unexpected Typescript configuration for AVA. See https://github.com/avajs/typescript/blob/v${pkg.version}/README.md for allowed values.`);
0 commit comments