This guide outlines how to test Idiomorph, focusing on running tests headlessly or in a browser environment, running individual tests, and other testing concerns.
- Ensure you have a currently supported Node.js and npm installed.
- Install dependencies by running:
npm install npx playwright install
To run all tests in headless mode, execute:
npm test
This will run all the tests using headless Chrome.
To run all tests against all browsers in headless mode, execute:
npm run ci
This will run the tests using Playwright’s headless browser setup across Chrome, Firefox, and WebKit (Safari-adjacent). This is ultimately what gets run in Github Actions to verify PRs. This build will fail if there is an it.only
left in the codebase, thanks to a custom --fail-only
command line argument.
To run all tests against Chrome with experimental moveBefore
support added, execute:
npm run test-move-before
This will start headless Chrome in a new profile with the atomic-move
experimental flag set. This runs in a separate job in CI.
To run a specific test file headlessly, for example test/core.js
, use the following command:
npm test test/core.js
If you want to run only one specific test, you can temporarily change it("...
to it.only("...
in the test file, and then specify the test file as above. Don't forget to undo this before you commit!
To run tests in a non-headless mode (with a visible browser window):
npm run debug
This will start the server, and open the test runner in a browser. From there you can choose a test file to run.
If the DEFAULT_TWO_PASS
environment variable is set before running the tests, Idiomorph will default to two-pass mode. This is useful for running the entire test suite with two-pass on.
On each push and PR, GitHub Actions runs the following test matrix:
- Normal baseline
npm run ci
run - With experimental moveBefore enabled in the browser
- With two-pass mode forced
- With both moveBefore enabled and two-pass mode forced
After a test run completes, you can open coverage/lcov-report/index.html
to view the code coverage report. On Ubuntu you can run:
xdg-open coverage/lcov-report/index.html
- All tests are located in the
test/
directory. Only .js files in this directory will be discovered by the test runner, so support files can go in subdirectories. - The
web-test-runner.config.mjs
file in the root directory contains the boilerplate HTML for the test runs, including<script>
tags for the test dependencies.