mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 14:11:50 +03:00
doc(test-runner): add example of compiling tests with typescript (#8046)
This commit is contained in:
parent
fa89b9a554
commit
c8f3c65d22
34
docs/src/test-typescript-js.md
Normal file
34
docs/src/test-typescript-js.md
Normal 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.
|
Loading…
Reference in New Issue
Block a user