Skip to content

test: Add support for running the Mocha test suite under Node - #10208

Open
gonfunko wants to merge 13 commits into
mainfrom
refactor-mocha-headless-tests
Open

test: Add support for running the Mocha test suite under Node#10208
gonfunko wants to merge 13 commits into
mainfrom
refactor-mocha-headless-tests

Conversation

@gonfunko

Copy link
Copy Markdown
Contributor

The basics

The details

Resolves

Proposed Changes

This PR adds support for running the existing Mocha test suite under Node, via npm run test:mocha:node, as well as in the browser via the existing npm run test:mocha:interactive. This change was LLM-assisted. The vast majority of the test suite was unchanged; a single-digit number of tests that depended upon specific layout details or focus event behavior were moved to the browser test suite (npm run test:browser). Additionally, the tests now import sinon/chai/etc by Node module resolution, rather than by relative path to the node_modules folder. Reviewing commit-by-commit is recommended.

Reason for Changes

Running the tests in the browser is slow, tricky in CI, and confusing to LLMs. It also means we have very poor test coverage of running Blockly headless/server-side, since before this the only test we had that ran under Node was a minimal smoketest of serialization. Now, 3956 testcases run and pass under both Node and within the browser. Several changes were made to achieve this:

  • The test files were all updated to import Node modules by name, rather than relative path to the node_modules folder. These imports are resolved by Node when running under Node. Browsers do not implement Node's module resolution algorithm, so specifying a path remains necessary there; however, we now use an import map and imports to load the various Node modules when running in the browser.
  • Some markup and test fixtures were factored out to more easily share a single source of truth between the Node and browser Mocha test harnesses.
  • A few bugs in the tests were surfaced and fixed by this process.
  • A single-digit number of test cases that depended on focus and layout specifics were moved out of the Mocha suite and into the browser suite, so that the full set of Mocha tests runs regardless of browser vs node runtime. The dragger-related tests were manually migrated, and the focus and dropdowndiv ones were LLM-migrated, with extensive review.
  • The old Node smoketest and tests for the colour field were removed.
  • A harness for running tests under Node and a minimal mock for some mostly-SVG-related behavior that JSDom doesn't implement were added. These (node-setup.mjs and svg_layout_stubs.js) are the main LLM-generated pieces. I have reviewed them and cut down on the chattiness of the comments, although I left a fair bit where they were actually useful for understanding.

Test Coverage

npm run test:mocha:interactive, npm run test:mocha:node, and npm run test:browser all pass, exercising the Mocha suite in the browser, in Node, and the browser-specific suite in the browser.

@gonfunko
gonfunko requested review from lizschwab and maribethb July 29, 2026 22:31
@gonfunko
gonfunko requested a review from a team as a code owner July 29, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop importing node modules directly in Mocha webdriver tests Look into using imports for mocha tests

3 participants