Skip to content
Rudimentary TypeScript support
JavaScript
Branch: master
Clone or download
Latest commit f622e6b Feb 16, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add rudimentary implementation Jan 26, 2020
test Improve integration with AVA Feb 2, 2020
.editorconfig Add rudimentary implementation Jan 26, 2020
.gitignore Add rudimentary implementation Jan 26, 2020
.npmrc Add rudimentary implementation Jan 26, 2020
README.md Clarify which build files are ignored by AVA Feb 16, 2020
index.js
package.json 1.1.1 Feb 16, 2020

README.md

@ava/typescript

Adds rudimentary TypeScript support to AVA.

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.

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 test using npx ava src/test.ts.

Enabling TypeScript support

Add this package to your project:

npm install --save-dev @ava/typescript

Then, enable TypeScript support either in package.json or ava.config.*:

package.json:

{
	"ava": {
		"typescript": {
			"rewritePaths": {
				"src/": "build/"
			}
		}
	}
}

Both keys and values of the rewritePaths object must end with a /. Paths are relative to your project directory.

Output files are expected to have the .js extension.

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.

Add additional extensions

You can configure AVA to recognize additional file extensions. To add (partial†) JSX support:

package.json:

{
	"ava": {
		"typescript": {
			"extensions": [
				"ts",
				"tsx"
			],
			"rewritePaths": {
				"src/": "build/"
			}
		}
	}
}

See also AVA's extensions option.

† Note that the preserve mode for JSX is not (yet) supported.

You can’t perform that action at this time.