refactor(tests): Use bootstrap instead of uncompressed in generator tests

This entails adding an additional check in bootstrap so as to load
uncompressed when loading from a file: URL, since these are not
localhost URLs - though in fact the generator tests run equally well
in compressed mode, albeit against (for now) the previously-check-in
build products rather than the live code.
This commit is contained in:
Christopher Allen
2022-06-11 18:04:07 +01:00
parent dba4dd29cc
commit a1965aafea
2 changed files with 32 additions and 30 deletions

4
tests/bootstrap.js vendored
View File

@@ -39,12 +39,14 @@
const isIe = navigator.userAgent.indexOf('MSIE') !== -1 ||
navigator.appVersion.indexOf('Trident/') > -1;
const localhosts = ['localhost', '127.0.0.1', '[::1]'];
const isLocalhost = localhosts.includes(location.hostname);
const isFileUrl = location.origin === 'file://';
// Default bootstrap options.
const options = {
// Decide whether to use compmiled mode or not. Please see issue
// #5557 for more information.
loadCompressed: isIe || !localhosts.includes(location.hostname),
loadCompressed: isIe || !(isLocalhost || isFileUrl),
// URL of the blockly repository. This is needed for a few reasons:
//

View File

@@ -3,41 +3,36 @@
<head>
<meta charset="utf-8">
<title>Blockly Generator Tests</title>
<script src="../../blockly_uncompressed.js"></script>
<script src="../../msg/messages.js"></script>
<script>
// Require optional modules needed by tests.
goog.require('Blockly.Dart.all');
goog.require('Blockly.JavaScript.all');
goog.require('Blockly.Lua.all');
goog.require('Blockly.PHP.all');
goog.require('Blockly.Python.all');
goog.require('Blockly.libraryBlocks');
var BLOCKLY_BOOTSTRAP_OPTIONS = {
additionalScripts: [
'msg/messages.js',
'tests/generators/unittest_javascript.js',
'tests/generators/unittest_python.js',
'tests/generators/unittest_php.js',
'tests/generators/unittest_lua.js',
'tests/generators/unittest_dart.js',
'tests/generators/unittest.js',
],
}
</script>
<script src="unittest_javascript.js"></script>
<script src="unittest_python.js"></script>
<script src="unittest_php.js"></script>
<script src="unittest_lua.js"></script>
<script src="unittest_dart.js"></script>
<script src="unittest.js"></script>
<script src="../bootstrap.js"></script>
<script>
'use strict';
var demoWorkspace = null;
var outputCode = '';
function start() {
demoWorkspace = Blockly.inject('blocklyDiv',
{grid:
{spacing: 25,
length: 3,
colour: '#ccc',
snap: true},
media: '../../media/',
toolbox: document.getElementById('toolbox'),
zoom: {controls: true, wheel: true}
});
demoWorkspace = Blockly.inject('blocklyDiv', {
grid: {
spacing: 25,
length: 3,
colour: '#ccc',
snap: true
},
media: '../../media/',
toolbox: document.getElementById('toolbox'),
zoom: {controls: true, wheel: true}
});
changeIndex();
}
@@ -210,6 +205,11 @@ function changeIndex() {
demoWorkspace.getToolbox().flyout_.workspace_.options.oneBasedIndex = oneBasedIndex;
}
</script>
<script type=module>
// Wait for Blockly to finish loading.
import Blockly from "../blockly.mjs";
start();
</script>
<style>
html, body {
@@ -240,7 +240,7 @@ h1 {
}
</style>
</head>
<body onload="start()">
<body>
<div id="blocklyDiv"></div>