- Download nodejs + how to install nodejs
- If it is already installed, check in terminal:
node -v
- Create package.json execute in terminal:
npm init -y
- Edit package.json, add devDependencies (these won't be installed globally, but only for this project)
"devDependencies": {
"@types/jest": "^26.0.20",
"jest": "^26.6.3",
"jest-playwright-preset": "^1.4.5",
"playwright": "^1.27.0",
"typescript": "^4.8.4" ,
"ts-jest": "^26.5.0"
}
- Install dev dependencies by:
npm i
- Configure
typescript
Typescript file will be compiled in javascript so need to:
- create tsconfig.json in order to specify compiler
{
"compilerOptions": {
"target": "ES6",
"strict": true,
"module": "commonjs",
"sourceMap": true
}
}
- Configure
jest
inpackage.json
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
"scripts": {
"test": "jest"
}
- Configure
dotenv
in order to use environment variables (for secrets)
Decided to use this package because it has 0 dependencies.
npm install dotenv --save
- Install
jest-cli
npm i -g jest-cli
npm test
OR
jest test
jest runs by default all tests in parallel, so in order to run them sequentially:
jest -i
jest <test_suite>.test.ts
See documentation about codegen
npx playwright codegen <url_to_test>