fix: Fix the compiler test, and check if it worked. (#6638)

* Add tsick.js to rewrite enums.

tsc generates JavaScript which is incompatible with the Closure Compiler's advanced optimizations.

* Remove unused 'outputCode' variable.

* Rename 'run_X_in_browser.js' to 'webdriver.js'

The Mocha and generator tests can both be run either manually or via our webdriver.  In all cases they run in a browser.  These two 'run_X_in_browser.js' files only apply to webdriver, thus they are confusingly named.

Also delete completely unused (and broken) `run_all_tests.sh`

* Linting improvements to mocha/webdriver.js

Still not at 100%.  Complains about require/module/process/__dirname not being defined in multiple places.

* runTestBlock -> runTestFunction

'Block' means something very different in Blockly.

* Removal of `var` from scripts.

* Add webdriver test to verify compile test worked.

* Resolve conficts with 'develop'.

* Address PR comments.
This commit is contained in:
Neil Fraser
2022-11-25 20:45:00 +01:00
committed by GitHub
parent be4b8323c5
commit 5a64a9a7f7
14 changed files with 349 additions and 154 deletions

View File

@@ -12,10 +12,13 @@ goog.module('Main');
// TODO: I think we need to make sure these get exported?
// const {BlocklyOptions} = goog.requireType('Blockly.BlocklyOptions');
const {inject} = goog.require('Blockly.inject');
const {getMainWorkspace} = goog.require('Blockly.common');
const {Msg} = goog.require('Blockly.Msg');
/** @suppress {extraRequire} */
goog.require('Blockly.geras.Renderer');
/** @suppress {extraRequire} */
goog.require('Blockly.VerticalFlyout');
// Blocks
/** @suppress {extraRequire} */
goog.require('Blockly.libraryBlocks.logic');
@@ -30,8 +33,25 @@ goog.require('testBlocks');
function init() {
Object.assign(Msg, window['Blockly']['Msg']);
inject('blocklyDiv', /** @type {BlocklyOptions} */ ({
'toolbox': document.getElementById('toolbox')
}));
};
}
window.addEventListener('load', init);
// Called externally from our test driver to see if Blockly loaded more or less
// correctly. This is not a comprehensive test, but it will catch catastrophic
// fails (by far the most common cases).
window['healthCheck'] = function() {
// Just check that we have a reasonable number of blocks in the flyout.
// Expecting 8 blocks, but leave a wide margin.
try {
const blockCount =
getMainWorkspace().getFlyout().getWorkspace().getTopBlocks().length;
return (blockCount > 5 && blockCount < 100);
} catch (_e) {
return false;
}
};

View File

@@ -0,0 +1,82 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Node.js script to check the health of the compile test in
* Chrome, via webdriver.
*/
const webdriverio = require('webdriverio');
/**
* Run the generator for a given language and save the results to a file.
* @param {Thenable} browser A Thenable managing the processing of the browser
* tests.
*/
async function runHealthCheckInBrowser(browser) {
const result = await browser.execute(() => {
return healthCheck();
})
if (!result) throw Error('Health check failed in advanced compilation test.');
console.log('Health check completed successfully.');
}
/**
* Runs the generator tests in Chrome. It uses webdriverio to
* launch Chrome and load index.html. Outputs a summary of the test results
* to the console and outputs files for later validation.
* @return the Thenable managing the processing of the browser tests.
*/
async function runCompileCheckInBrowser() {
const options = {
capabilities: {
browserName: 'chrome',
},
logLevel: 'warn',
services: ['selenium-standalone']
};
// Run in headless mode on Github Actions.
if (process.env.CI) {
options.capabilities['goog:chromeOptions'] = {
args: ['--headless', '--no-sandbox', '--disable-dev-shm-usage']
};
} else {
// --disable-gpu is needed to prevent Chrome from hanging on Linux with
// NVIDIA drivers older than v295.20. See
// https://github.com/google/blockly/issues/5345 for details.
options.capabilities['goog:chromeOptions'] = {
args: ['--disable-gpu']
};
}
const url = 'file://' + __dirname + '/index.html';
console.log('Starting webdriverio...');
const browser = await webdriverio.remote(options);
console.log('Loading url: ' + url);
await browser.url(url);
await runHealthCheckInBrowser(browser);
await browser.deleteSession();
}
if (require.main === module) {
runCompileCheckInBrowser().catch(e => {
console.error(e);
process.exit(1);
}).then(function(result) {
if (result) {
console.log('Compile test failed');
process.exit(1);
} else {
console.log('Compile test passed');
process.exit(0);
}
});
}
module.exports = {runCompileCheckInBrowser};