Test Runner: Testing TypeScript
If you write your source files in TypeScript, you can test directly from sources without
compiling using tsc
. Add esbuildPlugin({ ts: true })
to your web-test-runner.config.js
file.
This uses esbuild to transform TS sources on-the-fly.
There are some caveats to using esbuild with TypeScript.
For example, if you use TypeScript paths to alias imports, you may need to build first.
import { esbuildPlugin } from '@web/dev-server-esbuild';
export default {
files: ['src/**/*.test.ts', 'src/**/*.spec.ts'],
plugins: [esbuildPlugin({ ts: true })],
};
Keep in mind that esbuild merely removes TypeScript syntax and transforms decorators, etc;
It does not provide any type checking, and it's not intended to. If you'd like to run tsc
in parallel, you can use concurrently
or npm-run-all
Read more about the esbuild plugin in the docs