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

Use tests/bootstrap.js instead of blockly_uncompressed.js to load
blockly in uncompressed mode in the Mocha tests.

This entails adding a new item, despFiles, to BLOCKLY_BOOTSTRAP_OPTIONS,
to allow tests/deps.mocha.js to be loaded at the appropriate point.

Mention of blockly_uncompressed.js is removed from
tests/mocah/.mocharc.js; it's not clear to me what effect the "file:"
directive in this file might have previously had and I was not able to
find documentation for it on mochajs.org, but in any case removing it
appears to have had no ill effect.
This commit is contained in:
Christopher Allen
2022-06-11 16:27:38 +01:00
parent df7a2fd6ca
commit dba4dd29cc
3 changed files with 110 additions and 93 deletions

22
tests/bootstrap.js vendored
View File

@@ -58,6 +58,11 @@
// from somewhere in tests/.
root: window.location.href.replace(/\/tests\/.*$/, '/'),
// List of deps files to load. Paths relative to root.
depsFiles: [
'build/deps.js',
],
// List of goog.modules to goog.require.
requires: [
'Blockly',
@@ -69,7 +74,8 @@
'Blockly.Python.all',
],
// List of scripts to load in compressed mode, instead of requires.
// List of scripts to load in compressed mode, instead of
// requires. Paths relative to root.
compressedScripts: [
'blockly_compressed.js',
'blocks_compressed.js',
@@ -82,6 +88,7 @@
// Additional scripts to be loaded after Blockly is loaded,
// whether Blockly is loaded from compressed or uncompressed.
// Paths relative to root.
additionalScripts: [
'msg/messages.js',
],
@@ -112,10 +119,15 @@
// goog.module).
document.write(
'<script src="' + options.root + '/closure/goog/base.js"></script>');
// Load dependency graph info from build/deps.js. To update
// deps.js, run `npm run build:deps`.
document.write(
'<script src="' + options.root + '/build/deps.js"></script>');
// Load dependency graph info from the specified deps files -
// typically just build/deps.js. To update deps after changing
// any module's goog.requires / imports, run `npm run build:deps`.
for (let i = 0; i < options.depsFiles.length; i++) {
document.write(
'<script src="' + options.root + options.depsFiles[i] + '">' +
'</script>');
}
const requiresString = options.requires.map(quote).join();
const scriptsString = options.additionalScripts.map(quote).join();

View File

@@ -2,6 +2,5 @@
module.exports = {
ui: 'tdd',
file: '../blockly_uncompressed.js',
reporter: 'landing'
};

View File

@@ -5,9 +5,6 @@
<title>Mocha Tests for Blockly</title>
<link href="../../node_modules/mocha/mocha.css" rel="stylesheet" />
<script src="../../blockly_uncompressed.js"></script>
<script src="../../build/deps.mocha.js"></script>
<script src="../../msg/messages.js"></script>
</head>
<style>
#blocklyDiv {
@@ -21,6 +18,9 @@
<div id="mocha"></div>
<div id="failureCount" style="display:none" tests_failed="unset"></div>
<div id="failureMessages" style="display:none"></div>
<!-- Load mocha et al. before bootstrapping so that we can safely
goog.require() the test modules that make calls to (e.g.)
suite() at the top level. -->
<script src="../../node_modules/chai/chai.js"></script>
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/sinon/pkg/sinon.js"></script>
@@ -29,92 +29,95 @@
ui: 'tdd',
failZero: true,
});
</script>
<script>
// Require optional modules needed by tests.
goog.require('Blockly.Dart');
goog.require('Blockly.Dart.texts');
goog.require('Blockly.JavaScript');
goog.require('Blockly.JavaScript.texts');
goog.require('Blockly.Lua');
goog.require('Blockly.Lua.texts');
goog.require('Blockly.PHP');
goog.require('Blockly.PHP.texts');
goog.require('Blockly.Python');
goog.require('Blockly.Python.texts');
goog.require('Blockly.libraryBlocks.colour');
goog.require('Blockly.libraryBlocks.logic');
goog.require('Blockly.libraryBlocks.lists');
goog.require('Blockly.libraryBlocks.loops');
goog.require('Blockly.libraryBlocks.math');
goog.require('Blockly.libraryBlocks.procedures');
goog.require('Blockly.libraryBlocks.texts');
goog.require('Blockly.libraryBlocks.variables');
goog.require('Blockly.libraryBlocks.variablesDynamic');
var BLOCKLY_BOOTSTRAP_OPTIONS = {
loadCompressed: false,
depsFiles: ['build/deps.js', 'build/deps.mocha.js'],
requires: [
// Blockly modules needed by tests.
'Blockly',
'Blockly.libraryBlocks',
'Blockly.Dart',
'Blockly.Dart.texts',
'Blockly.JavaScript',
'Blockly.JavaScript.texts',
'Blockly.Lua',
'Blockly.Lua.texts',
'Blockly.PHP',
'Blockly.PHP.texts',
'Blockly.Python',
'Blockly.Python.texts',
// Run tests.
goog.require('Blockly.test.astNode');
goog.require('Blockly.test.blockChangeEvent');
goog.require('Blockly.test.blockCreateEvent');
goog.require('Blockly.test.blockJson');
goog.require('Blockly.test.blocks');
goog.require('Blockly.test.comments');
goog.require('Blockly.test.commentDeserialization');
goog.require('Blockly.test.connectionChecker');
goog.require('Blockly.test.connectionDb');
goog.require('Blockly.test.connection');
goog.require('Blockly.test.contextMenuItem');
goog.require('Blockly.test.cursor');
goog.require('Blockly.test.dropdown');
goog.require('Blockly.test.event');
goog.require('Blockly.test.extensions');
goog.require('Blockly.test.fieldAngle');
goog.require('Blockly.test.fieldCheckbox');
goog.require('Blockly.test.fieldColour');
goog.require('Blockly.test.fieldDropdown');
goog.require('Blockly.test.fieldImage');
goog.require('Blockly.test.fieldLabelSerialization');
goog.require('Blockly.test.fieldLabel');
goog.require('Blockly.test.fieldMultiline');
goog.require('Blockly.test.fieldNumber');
goog.require('Blockly.test.fieldRegistry');
goog.require('Blockly.test.fieldTest');
goog.require('Blockly.test.fieldTextInput');
goog.require('Blockly.test.fieldVariable');
goog.require('Blockly.test.flyout');
goog.require('Blockly.test.generator');
goog.require('Blockly.test.gesture');
goog.require('Blockly.test.input');
goog.require('Blockly.test.insertionMarker');
goog.require('Blockly.test.jsoDeserialization');
goog.require('Blockly.test.jsoSerialization');
goog.require('Blockly.test.json');
goog.require('Blockly.test.keydown');
goog.require('Blockly.test.lists');
goog.require('Blockly.test.logicTernary');
goog.require('Blockly.test.metrics');
goog.require('Blockly.test.mutator');
goog.require('Blockly.test.names');
goog.require('Blockly.test.procedures');
goog.require('Blockly.test.registry');
goog.require('Blockly.test.serialization');
goog.require('Blockly.test.shortcutRegistry');
goog.require('Blockly.test.theme');
goog.require('Blockly.test.toolbox');
goog.require('Blockly.test.tooltip');
goog.require('Blockly.test.trashcan');
goog.require('Blockly.test.utils');
goog.require('Blockly.test.variableMap');
goog.require('Blockly.test.variableModel');
goog.require('Blockly.test.variables');
goog.require('Blockly.test.widgetDiv');
goog.require('Blockly.test.workspaceComment');
goog.require('Blockly.test.workspaceSvg');
goog.require('Blockly.test.workspace');
goog.require('Blockly.test.xml');
goog.require('Blockly.test.zoomControls');
// Test modules.
'Blockly.test.astNode',
'Blockly.test.blockChangeEvent',
'Blockly.test.blockCreateEvent',
'Blockly.test.blockJson',
'Blockly.test.blocks',
'Blockly.test.comments',
'Blockly.test.commentDeserialization',
'Blockly.test.connectionChecker',
'Blockly.test.connectionDb',
'Blockly.test.connection',
'Blockly.test.contextMenuItem',
'Blockly.test.cursor',
'Blockly.test.dropdown',
'Blockly.test.event',
'Blockly.test.extensions',
'Blockly.test.fieldAngle',
'Blockly.test.fieldCheckbox',
'Blockly.test.fieldColour',
'Blockly.test.fieldDropdown',
'Blockly.test.fieldImage',
'Blockly.test.fieldLabelSerialization',
'Blockly.test.fieldLabel',
'Blockly.test.fieldMultiline',
'Blockly.test.fieldNumber',
'Blockly.test.fieldRegistry',
'Blockly.test.fieldTest',
'Blockly.test.fieldTextInput',
'Blockly.test.fieldVariable',
'Blockly.test.flyout',
'Blockly.test.generator',
'Blockly.test.gesture',
'Blockly.test.input',
'Blockly.test.insertionMarker',
'Blockly.test.jsoDeserialization',
'Blockly.test.jsoSerialization',
'Blockly.test.json',
'Blockly.test.keydown',
'Blockly.test.lists',
'Blockly.test.logicTernary',
'Blockly.test.metrics',
'Blockly.test.mutator',
'Blockly.test.names',
'Blockly.test.procedures',
'Blockly.test.registry',
'Blockly.test.serialization',
'Blockly.test.shortcutRegistry',
'Blockly.test.theme',
'Blockly.test.toolbox',
'Blockly.test.tooltip',
'Blockly.test.trashcan',
'Blockly.test.utils',
'Blockly.test.variableMap',
'Blockly.test.variableModel',
'Blockly.test.variables',
'Blockly.test.widgetDiv',
'Blockly.test.workspaceComment',
'Blockly.test.workspaceSvg',
'Blockly.test.workspace',
'Blockly.test.xml',
'Blockly.test.zoomControls',
],
additionalScripts: [
'msg/messages.js',
'tests/playgrounds/screenshot.js',
'node_modules/@blockly/dev-tools/dist/index.js',
],
}
</script>
<script src="../bootstrap.js"></script>
<div id="blocklyDiv"></div>
@@ -175,7 +178,10 @@
<block type="test_field_block"></block>
</xml>
<script>
<script type=module>
// Wait for Blockly to finish loading before running tests.
import Blockly from "../blockly.mjs";
let runner = mocha.run(function(failures) {
var failureDiv = document.getElementById('failureCount');
failureDiv.setAttribute('tests_failed', failures);