mirror of
https://github.com/google/blockly.git
synced 2026-01-10 18:37:09 +01:00
refactor(tests): Rename blockly.mjs to bootstrap_done.mjs; simplify
Since blockly.mjs is no longer returning just the exports object from core/blockly.js (see PR #5995), it might be better named after its actual purpose: to wait for bootstrapping to be done. Remove all the code that was used to pass the blockly.js exports object along from the bootstrap callback to the blockly.mjs export, since there's no reason to go to a lot of trouble to set a local variable named Blockly to the same value as a global variable named Blockly. (Something like this may be needed again in future, but certainly in a different form.)
This commit is contained in:
8
tests/bootstrap.js
vendored
8
tests/bootstrap.js
vendored
@@ -13,8 +13,8 @@
|
||||
* uncompressed mode.
|
||||
*
|
||||
* You must use a <script> tag to load this script first, then
|
||||
* import blockly.mjs in a <script type=module> to obtain the
|
||||
* loaded module.
|
||||
* import bootstrap_done.mjs in a <script type=module> to wait for
|
||||
* bootstrapping to finish.
|
||||
*
|
||||
* See tests/playground.html for example usage.
|
||||
*
|
||||
@@ -174,13 +174,11 @@
|
||||
// goog.addDependency calls and a call to goog.bootstrap
|
||||
// requesting the loading of the final target, which will cause
|
||||
// all the previous ones to be loaded recursively. Wrap this in a
|
||||
// promise and save it so it can be awaited in blockly.mjs.
|
||||
// promise and save it so it can be awaited in bootstrap_done.mjs.
|
||||
document.write(
|
||||
'<script>\n' + scriptDeps.join('') +
|
||||
' window.BlocklyLoader.done = new Promise((resolve, reject) => {\n' +
|
||||
' goog.bootstrap([' + requires.map(quote).join() + '], resolve);\n' +
|
||||
' }).then(() => {\n' +
|
||||
' return goog.module.get(\'Blockly\');\n' +
|
||||
' });\n' +
|
||||
'</script>\n');
|
||||
} else {
|
||||
|
||||
@@ -20,20 +20,17 @@
|
||||
*
|
||||
* See tests/playground.html for example usage.
|
||||
*/
|
||||
|
||||
let Blockly;
|
||||
|
||||
if (window.BlocklyLoader) {
|
||||
// Uncompiled mode. Use top-level await
|
||||
// Uncompressed mode. Use top-level await
|
||||
// (https://v8.dev/features/top-level-await) to block loading of
|
||||
// this module until goog.bootstrap()ping of Blockly is finished.
|
||||
await window.BlocklyLoader.done;
|
||||
Blockly = globalThis.Blockly;
|
||||
// Note that this module previously did an export default of the
|
||||
// value returned by the BlocklyLoader.done promise. This was
|
||||
// changed in PR #5995 because library blocks and generators cannot
|
||||
// be accessed via that the core/blockly.js exports object.
|
||||
} else if (window.Blockly) {
|
||||
// Compiled mode. Retrieve the pre-installed Blockly global.
|
||||
Blockly = globalThis.Blockly;
|
||||
// Compiled mode. Nothing more to do.
|
||||
} else {
|
||||
throw new Error('neither window.Blockly nor window.BlocklyLoader found');
|
||||
}
|
||||
|
||||
export default Blockly;
|
||||
@@ -206,8 +206,9 @@ function changeIndex() {
|
||||
}
|
||||
</script>
|
||||
<script type=module>
|
||||
// Wait for Blockly to finish loading.
|
||||
import Blockly from "../blockly.mjs";
|
||||
// Wait for Blockly to finish loading before running tests.
|
||||
import '../bootstrap_done.mjs';
|
||||
|
||||
start();
|
||||
</script>
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@
|
||||
|
||||
<script type=module>
|
||||
// Wait for Blockly to finish loading before running tests.
|
||||
import Blockly from "../blockly.mjs";
|
||||
import '../bootstrap_done.mjs';
|
||||
|
||||
let runner = mocha.run(function(failures) {
|
||||
var failureDiv = document.getElementById('failureCount');
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
compressed when it is being hosted or on Internet Explorer. -->
|
||||
<script src="bootstrap.js"></script>
|
||||
<script type=module>
|
||||
import Blockly from './blockly.mjs';
|
||||
// Wait for Blockly to finish loading.
|
||||
import './bootstrap_done.mjs';
|
||||
|
||||
const IS_UNCOMPRESSED = Boolean(window.BlocklyLoader); // See bootstrap.js
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
</script>
|
||||
<script src="bootstrap.js"></script>
|
||||
<script type=module>
|
||||
import Blockly from './blockly.mjs';
|
||||
// Wait for Blockly to finish loading.
|
||||
import './bootstrap_done.mjs';
|
||||
|
||||
const IS_UNCOMPRESSED = Boolean(window.BlocklyLoader); // See bootstrap.js
|
||||
var workspace = null;
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
<script src="../bootstrap.js"></script>
|
||||
|
||||
<script type="module">
|
||||
import Blockly from '../blockly.mjs';
|
||||
'use strict';
|
||||
// Wait for Blockly to finish loading.
|
||||
import './bootstrap_done.mjs';
|
||||
|
||||
function start() {
|
||||
setBackgroundColour();
|
||||
|
||||
Reference in New Issue
Block a user