-
Notifications
You must be signed in to change notification settings - Fork 3.9k
test: Refactor mocha test infrastructure #10309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
06b2834
test: Remove in-browser Mocha test dependency on webdriver and gulp
gonfunko fb2dad0
chore: Remove dead code that supported the old metadata size check test
gonfunko d453ee4
chore: Remove dead comment
gonfunko 22300c2
test: Make browser-specific test browser-agnostic
gonfunko 9f4e48d
test: Don't output the details of every testcase when run under node
gonfunko 510fc50
test: Enable hot reloading of Mocha tests
gonfunko 701b307
test: Log Mocha failures to console to provide sourcemapped stacktraces
gonfunko 5ac1c4b
chore: Remove unused imports and package
gonfunko 3fbcc19
test: Bundle block-test
gonfunko 916543d
Merge branch 'main' into mocha-tests
gonfunko a984757
chore(deps): Bump Closure compiler version
gonfunko b966742
chore(deps): Rebuild package-lock.json
gonfunko 2fcc4c8
Merge branch 'main' into mocha-tests
gonfunko aa882d7
chore(deps): Try fixing package-lock.json again
gonfunko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Raspberry Pi Foundation | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import {globSync} from 'glob'; | ||
| import * as fs from 'node:fs/promises'; | ||
| import {createRequire} from 'node:module'; | ||
| import * as path from 'node:path'; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
|
|
||
| const TEST_DIR = 'tests/mocha'; | ||
| const OUT_DIR = 'build/tests'; | ||
| const ENTRY_POINT = path.posix.join(OUT_DIR, 'bundle-entry.js'); | ||
|
|
||
| /** | ||
| * Writes out a file that loads the in-browser Mocha test bootstrap code and | ||
| * the tests themselves, and acts as an entrypoint for esbuild to enumerate and | ||
| * bundle the various scripts that make up the test suite. | ||
| */ | ||
| async function writeEntryPoint() { | ||
| const tests = globSync('**/*_test.{js,ts}', {cwd: TEST_DIR}).sort(); | ||
| const dir = path.posix.relative(path.posix.dirname(ENTRY_POINT), TEST_DIR); | ||
|
|
||
| await fs.writeFile( | ||
| ENTRY_POINT, | ||
| [ | ||
| `import '${dir}/browser-setup.js';`, | ||
| ...tests.map((file) => `import '${dir}/${file}';`), | ||
| ].join('\n'), | ||
| ); | ||
| } | ||
|
|
||
| await fs.mkdir(OUT_DIR, {recursive: true}); | ||
| // Resolve and copy Mocha's prebuilt browser distribution. | ||
| await fs.copyFile( | ||
| require.resolve('mocha/mocha.js'), | ||
| path.join(OUT_DIR, 'mocha.js'), | ||
| ); | ||
| // Write out the esbuild entrypoint that imports the test files. | ||
| await writeEntryPoint(); | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Raspberry Pi Foundation | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @fileoverview Browser harness for the Blockly unit suite. | ||
| * | ||
| * This is the browser counterpart to node-setup.mjs: it loads Blockly, exposes | ||
| * the globals the tests expect, installs the shared DOM fixtures and configures | ||
| * Mocha. It is bundled, along with every test module, into | ||
| * build/tests/mocha-bundle.js, which is loaded by the test page. | ||
| */ | ||
|
|
||
| // Prevent Prettier from reordering imports to load blocks before Blockly. | ||
| // organize-imports-ignore | ||
| import * as Blockly from '#core/blockly.js'; | ||
| import '#blocks/blocks.js'; | ||
| import {javascriptGenerator} from '#generators/javascript.js'; | ||
| import {config as chaiConfig} from 'chai'; | ||
| import sinon from 'sinon'; | ||
| import 'mocha/mocha.css'; | ||
| import {installFixtures} from './test_helpers/dom_fixtures.js'; | ||
| import '@blockly/block-test'; | ||
|
|
||
| chaiConfig.showDiff = false; | ||
|
|
||
| globalThis.Blockly = Blockly; | ||
| globalThis.javascriptGenerator = javascriptGenerator; | ||
| globalThis.sinon = sinon; | ||
|
|
||
| // The focusable trees, toolbox definitions and #blocklyDiv the tests expect. | ||
| // Shared with the Node harness so both run against identical markup. | ||
| installFixtures(); | ||
|
|
||
| mocha.setup({ | ||
| ui: 'tdd', | ||
| failZero: true, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.