doc(test-runner): add example of compiling tests with typescript (#8046)

This commit is contained in:
Joel Einbinder 2021-08-23 16:40:03 -04:00 committed by GitHub
parent fa89b9a554
commit c8f3c65d22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,34 @@
## Manually compile tests with TypeScript
Playwright Test supports TypeScript out the box. We automatically transform
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.
```json
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"moduleResolution": "Node",
"sourceMap": true,
"outDir": "../tests-out",
}
}
```
In my `package.json`, I have two scripts:
```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.