2021-08-24 15:57:45 +02:00
---
id: test-typescript
title: "Advanced: TypeScript"
---
2021-08-23 16:40:03 -04:00
## Manually compile tests with TypeScript
2021-09-13 21:10:31 -07:00
Playwright Test supports TypeScript out of the box. We automatically transform
2021-08-23 16:40:03 -04:00
TypeScript code to javascript to run it.
However if you find that the TypeScript code is not being transpiled correctly,
you can perform your own TypeScript compilation before sending the tests to Playwright.
First I add a `tsconfig.json` file inside my tests directory.
2021-08-24 15:57:45 +02:00
2021-08-23 16:40:03 -04:00
```json
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"moduleResolution": "Node",
"sourceMap": true,
"outDir": "../tests-out",
}
}
```
In my `package.json` , I have two scripts:
2021-08-24 15:57:45 +02:00
2021-08-23 16:40:03 -04:00
```json
{
"scripts": {
"pretest": "tsc --incremental -p tests/tsconfig.json",
"test": "playwright test -c tests-out"
}
}
```
The `pretest` script runs typescript on the tests. `test` will run the tests that have been generated to the `tests-out` directory. The `-c` argument configures the test runner to look for tests inside the `tests-out` directory.
Then `npm run test` will build the tests and run them.