-
Notifications
You must be signed in to change notification settings - Fork 524
use Google Blockly for unit tests #66717
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
Conversation
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
🖼️ Storybook Visual Comparison Report✅ No Storybook eyes differences detected! |
StudioApp.loadBlocks is no longer additive
sanchitmalhotra126
approved these changes
Jan 5, 2026
Contributor
sanchitmalhotra126
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This branch updates our unit tests that rely upon CDO Blockly to use mainline instead.
Blockly Setup Changes
The changes here directly mirror how we set up global Blockly when initializing the Google Blockly Wrapper for our labs.
Changes to Apps Code
Fallbacks for Unloaded Translations
Sometimes when blocks were being created we would hit errors because our translations hadn't loaded. By chaining these function calls and providing a safe English default we avoid the errors.
Registry Issues
In some cases, we need to prevent registering things (custom CSS, keyboard nav styles, context menu options) more than once. If the registry provided an API for checking if something already exists, I used that to create a helper for safe registration. In other cases, I created a simple variable to make sure we only registered once.
domToBlockparameter orderBetween our fork and mainline, the order of parameters in
domToBlockhas swapped. This needed to be updated inapps/src/block_utils.jswhich is evidently just used in tests.isWorkspaceReadOnlyThis util was still marked as a TODO, which means it wasn't actually working. Related, one of our feedback tests assumed that this function would look at a global
Blockly.readOnlyrather than the specificworkspace.readOnly, so it has been updated.Block Limits
An old feature exists that makes it possible to provide feedback if students have used too many of a particular block. A map of block counts is updated with certain Blockly events. However, the tests use specific start blocks to exercise this. Since there no events in the integration tests, the block counts were never actually checked. To fix this, I separated out the main work of the change listener so that we call it directly when blocks are first loaded to the workspace.
Test Changes
SpritelabTest.js
Test relied on modifying
Blockly.blockly_.mainBlockSpaceand attempted to spy on internal event dispatch behavior.I removed all references to
Blockly.blockly_. I also introduced a setter on the Blockly wrapper formainBlockSpaceto allow mocking in tests.Finally, I replaced
jest.spyOn(...).mockImplementation()with a simplejest.fn()fordispatchEvent. This is simpler and doesn't require an existing method to spy on.Bundle Issue
webpackKarma.config.jswas telling webpack not to bundle theblocklypackage and instead use the global one (ie. the wrapper). The keyboard navigation plugin's source file do import directly from'blockly'(while we generally use'blockly/core', which was causing the plugin not to be able to access things it needed.StudioAppTest.js
These tests triggered custom DOM events (
'blocklyBlockSpaceChange') onmainBlockSpace.getCanvas(), which doesn't do anything in Google Blockly. The newfireChangeListenercall properly triggers change listeners added viaworkspace.addChangeListener, which is how things are set up inStudioApp: https://github.com/code-dot-org/code-dot-org/blob/mike/blockly-unit-tests/apps/src/StudioApp.js#L1100CdoUtilsTest.js
This test attempted to overwrite
Blockly.serializationwhich is read-only in Google Blockly. The test wasn't actually usingBlockly.serialization.workspaces.save(). It was stubbinggetProjectSerialization(), which already returns the value we care about.feedbackTests.js
Multiple asserts were being made to count blocks after they were loaded to the workspace (
'counts all other blocks'). These worked becauseloadBlocksToWorkspaceused to callBlockly.Xml.domToBlockSpace, which is additive. Now with mainline Blockly, the process is more complex. We convert the XML to JSON on a headless workspace as use the modern JSON deserialization workspace method which effectively clears the workspace before loading blocks. SinceStudioApp.loadBlocksdoes not just add blocks any more, I removed this whole block of tests. Even without this, we are still appropriately exercisinggetCountableBlocks_.jQuery Issues (multiple files)
I removed jQuery layout/visibility calls because they break under jsdom. Instead, I used native DOM APIs which behave consistently in tests.
Feedback Utils for functions
Several turtle tests were failing due to outdated logic in our
FeedbackUtils. Most prominently, we were not considering blocks on the hidden procedure definitions workspace. This was fixed by using our customgetAllBlocks()util (which checks multiple workspace) instead of the similarly named workspace method that only looked at that single workspace.Additionally, for tests for functions with parameters, we need to us the modern API to access the parameter names. On the fork, procedure definition blocks had a
.parameterNames_array. With mainline Blockly, all procedure blocks (incl. definitions and call blocks) have a method for accessing their procedure model, and in turn its parameters.convertXmlToBlocklyKarma testsSeveral tests check that we are able to create embedded read-only workspaces by converting a string of Blockly XML into blocks. Recently, the Google Blockly version of this util became asynchronous, because we now need to fetch a user's preferred workspace theme before rendering blocks. This needed to be updated to return a promise and the tests needed to be updated to wait for it. Otherwise, we'd be attempting to check for embedded blocks synchronously, which would result in test failure.
Links
Deployment strategy
Follow-up work
Continue unforking.
code-dot-org/blocklyPrivacy
Security
Caching
PR Checklist: