[WIP] Another attempt on adding a headless runner#120
[WIP] Another attempt on adding a headless runner#120DmitrySharabin wants to merge 23 commits intomainfrom
Conversation
- [TestResult] Add `toJSON`/`fromJSON` and shared serialization helpers - Add headless env stub and export - Allow `env.run` delegation and CLI flags for `env`/`headless`/`browser`
- Implement headless env with local server + HTML harness - Launch Playwright Chromium and collect serialized results - Reuse `TestResult.fromJSON()` and node console output for reporting
- Emit progress snapshots from the browser harness - Render intermediate updates via the Node env renderer - Keep headless output aligned with interactive Node experience
- Map browser names to Playwright types/channels - Support Firefox, WebKit, Chrome, and Edge - Keep Chromium as the default
- Move headless serialization to a shared module and use it in harness/Node - Remove `TestResult.toJSON/fromJSON` helpers
- Use `application/json` script tags for payloads - Read JSON via `document.getElementById` to avoid implicit globals
- Add timeout safeguard for headless runs - Include a skipped hang test for manual verification
✅ Deploy Preview for h-test ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
And remove redundant ones.
Set `__HTEST_HEADLESS__` before module imports to avoid CDN fetches in headless runs, and restore awaited diff loading so diffs are ready in non‑headless environments.
The headless browser now serves hTest package sources and project tests from separate URL prefixes, so imports resolve correctly outside the repo.
Don’t miss the actual and expected results passed to `diffChars`.
ddf8060 to
bd53fea
Compare
|
@Zearin, would you be interested in testing our headless runner? As you might have noticed, I tested it on some of your tests. And the result leaves me very optimistic about the runner's future. 😊 |
|
@DmitrySharabin I’ll give it a shot soon! 👍 |
|
Hi @DmitrySharabin! I followed your instructions (with an occasional mindless misstep 🤓). Here is the unabridged output: Output:
|
Based on Playwright.
Some docs: https://deploy-preview-120--h-test.netlify.app/docs/run/headless/
For those who are interested in testing the implementation of the hTest headless runner
Please follow these steps to run your tests in hTest format in the hTest headless runner.
Setup
cd path/to/your/project.npm install -D github:htest-dev/htest#headless-runner(to install hTest directly from the branch associated with this PR)npm install -D playwright(we don't provide Playwright as any dependency, so this step is mandatory)npx playwright install firefox. Playwright supports the following browser engines:chromium,firefox,webkit,chrome,edge.Note
If you try to run your tests in a browser that wasn't downloaded later, you'll get an error with the exact command you need to run to install it.
Running tests
Suppose all your tests are in the
testsfolder inside the project root, and all those tests are supposed to run in the hTest headless runner. In the terminal, runnpx htest --headless tests(you can even use this command as an NPM script insidepackage.json).Note
When running tests in the headless runner for the first time, it might take some time to spin the browser off. All the next runs will be faster.
To run tests from a particular file, tweak the path in the previous command. For example,
npx htest --headless tests/DOMRect.js.As the default runner, hTest uses Chromium (as Playwright does). If you need your tests to run in another (already downloaded) browser, pass its name (or the name of the engine) as a value of the
--browseroption. For example,npx htest --headless --browser webkit tests.Other flags, like

--verboseand--ci, are also supported. For example, runningnpx htest --headless --verbose --ci tests/DOMRect.js, you might get something like this:Warning
Don't run tests that import NPM packages in the headless runner; it won't work. They will throw during import because of unsupported specifiers (unless you are using something like Nudeps, which will fix it for you).
All other types of tests should correctly run in the headless runner. If not, please let us know what doesn't work.