Skip to content

test: Refactor mocha test infrastructure - #10309

Open
gonfunko wants to merge 9 commits into
mainfrom
mocha-tests
Open

test: Refactor mocha test infrastructure#10309
gonfunko wants to merge 9 commits into
mainfrom
mocha-tests

Conversation

@gonfunko

Copy link
Copy Markdown
Contributor

The basics

The details

Resolves

Proposed Changes

This PR refactors the Mocha test infrastructure. This change was LLM assisted with extensive manual review and edits. Reviewing commit by commit is recommended.

At a high level, this PR makes CI run the Mocha tests under node, and makes npm run test:mocha:interactive more convenient for day to day use by devs. More specifically:

  • A bunch of tooling that served to communicate tests results back from the browser to the CLI has been removed; when tests are run under Node in CI, that all just gets outputted directly, and now that the interactive in-browser version is meant for humans, and doesn't need to copy the test results from the browser to the shell.
  • Removing that infrastructure removes the need for Webdriver's involvement in the in-browser tests.
  • When running the Mocha tests under Node, passing test output is suppressed and only failures are reported.
  • The in-browser test page now opens in your default browser, and the full test suite passes under Chrome, Firefox and Safari.
  • Edits to tests and Blockly's source both hot-reload the in-browser test suite.
  • Tests are found dynamically and bundled with sinon, chai, and locally-built Blockly, so dependencies are resolved via node rather than hardcoded paths to node_modules. This bundling/compilation step also lays the groundwork for writing core tests in Typescript. This did require a new dev dependency on esbuild, but (a) that has no transitive dependencies itself and (b) is very widely used, so I think it's reasonable.
  • Various dead code and a gulp-related NPM package have been removed, as they existed in test_tasks.js only to support an old test that measured Blockly's build size and was removed some time ago.

Mocha is copied from its resolved path in node_modules into the build/test directory and loaded from there. Mocha distributes pre-built browser versions, and their own guidance indicates that these should be used. Because the path is resolved, we don't hardcode node_modules anywhere.

Reason for Changes

This improves the speed and reliability of CI, since it no longer runs the test in a browser, improves developer experience when running tests with hot reload, improves reliability of tests (once we start moving them to Typescript), and removes a lot of complex code and hacks (importing modules by path).

Test Coverage

Tests continue to pass, both in the browser and in Node.

@gonfunko
gonfunko requested a review from a team as a code owner August 21, 2026 20:34
@gonfunko
gonfunko requested a review from maribethb August 21, 2026 20:34
@gonfunko gonfunko changed the title Mocha tests test: Refactor mocha test infrastructure Aug 21, 2026
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

2 participants