Some basic exercises to discover JS.
Install node.js on your system, you need node 22 ! Depending on the os, you may use the official repositories nodesource builds.
# clone the repository or download the exercises
# Move into the repository
cd ex-js
# Install dependencies
npm i
# Install playwright browser for e2e tests
npx playwright install
Check here if your distribution does not support playwright
Launch the tests by typing
npm run test
, this will launch all tests and rerun them on file changes. You can also launch test from your IDE. You can browse tests, they are located in files ending with.test.js
.
First you need to launch the dev server
npm run dev
, to see your results in the browser. The dev server must be started for the tests to execute correctly. Launch the tests by typingnpx playwright test
or see below if you use docker, if you encounter difficulties, you can run the tests in ui mode, to see which test fails :npx playwright test --ui
.
You can easily run the playwright server on a docker container :
docker run --rm --network host --init -it mcr.microsoft.com/playwright:v1.49.1-noble /bin/sh -c "cd /home/pwuser && npx -y [email protected] run-server --port 8080"
This will start a docker container with the playwright server and all the browsers binary and libraries.
Then, when running your playwright tests, just add an environment variable with the server location :
PW_TEST_CONNECT_WS_ENDPOINT=ws://localhost:8080/ npx playwright test
# Or with UI
PW_TEST_CONNECT_WS_ENDPOINT=ws://localhost:8080/ npx playwright test --ui-port=9090
With this setup, the test logic will run on the host, but the browsers will remain in the container.
More information here.