Tilted sphere with longitudinal stripes Modern Web Guides Docs Blog Toggle darkmode

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

concurrently --kill-others --names tsc,wtr \"npm run tsc:watch\" \"wtr --watch\"

Example: Using concurrently to typecheck and test simultaneously

Read more about the esbuild plugin in the docs