No need to uninstall and reinstall Playwright to switch from TypeScript to JavaScript. Just tweak your project's configuration settings and scripts.
tsconfig.json
First, head to your project's tests
folder. If there's no tsconfig.json
file, create one. Then, add or modify the compiler options:
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"moduleResolution": "Node",
"sourceMap": true,
"outDir": "../tests-out"
}
}
These options tell TypeScript to target ESNext, use the CommonJS module system, generate source maps, and output transpiled JavaScript files into a tests-out
directory.
package.json
Next, open your package.json
file. In the "scripts"
section, add or modify these scripts:
{
"scripts": {
...
"pretest": "<command-to-run-typescript> -p tests/tsconfig.json",
"test": "<command-to-run-playwright> -c tests-out"
}
}
Replace <command-to-run-typescript>
with a command to run TypeScript compilation on your tests, like "tsc --incremental"
or "npx tsc --incremental"
. Replace <command-to-run-playwright>
with a command to run Playwright tests, like "playwright test"
or "npx playwright test"
.
The pretest
script runs TypeScript compilation on your tests using the tsconfig.json
file. The test
script executes the JavaScript tests in the tests-out
directory.
After saving these changes, run npm run test
to build and run your tests using JavaScript instead of TypeScript.
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].