refactor(tests): Use goog.bootstrap
to allow loading ES modules in playground
#5931
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.
The basics
The details
Resolves
Part of #5904.
Proposed Changes
Change how
tests/playground.html
loads Blockly.Behaviour Before Change
playground.html
would use a<script>
tag to loadtests/playgrounds/load_all.js
<script>
tag to loadblockly_uncompressed.js
from the project root<script>
tags to loadbase.js
anddeps.js
and then finally do agoog.require('Blockly')
call to get the debug module loader to loadcore/*
.load_all.js
would use further<script>
tags to loadmsg/messages.js
,tests/themes/test_themes.js
and@blockly/block-test
.<body onload="...">
would call thestart
function inplayground.html
.Behaviour After Change
playground.html
will use a<script>
tag to loadtests/playgrounds/prepare.js
<script>
tags to loadbase.js
,deps.js
, andmsg/messages.js
.window.BlocklyLoader
, that will:goog.bootstrap()
, passing in a list of the top-level entrypoints (Blockly
,Blockly.blocks.all
,Blockly.Javascript.all
, etc.)msg/messages.js
from where they were temporarily stored intoBlockly.Msg
.Blockly
module exports object.playground.html
will then use an inline<script type=module>
toimport
tests/playgrounds/blockly.mjs
,await
the resolution of the loader Promise, andexport
the returned value.start()
directly, which is safe because the page will have been loaded by this point.(In compiled mode,
prepare.js
will loadblockly_compressed.js
et al. using the same implementation asload_all.js
did previously.)Reason for Changes
Because the debug loader loads ES modules using
<script type=module>
tags, their loading is deferred until after all the top level (non-module
)<script>
tags have been run. This means that any ES modules (and anygoog.module
s that depend on them, including the rootBlockly
module) will not be loaded in time to callBlockly.inject
from the start script.Test Coverage
Tested on:
Also passes
npm test
.Documentation
Once the dust has settled, we probably ought to update any documentation that we have that discusses loading Blockly in uncompiled mode since any previous sample code snippets will not work.
Additional Information & questions
tests/playground.html
, not any of the other playgrounds, tests, samples, etc.Blockly.Msg
had been populated, but moving thegoog.bootstrap
call fromblockly.mjs
(executed after page has loaded) toprepare.js
seems to fixed this problem as well.tests/themes/test_themes.js
and@blockly/block-test
as these were not being loaded in compiled mode.