mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
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:
100
tests/mocha/webdriver.js
Normal file
100
tests/mocha/webdriver.js
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Node.js script to run Mocha tests in Chrome, via webdriver.
|
||||
*/
|
||||
const webdriverio = require('webdriverio');
|
||||
const {posixPath} = require('../../scripts/helpers');
|
||||
|
||||
|
||||
/**
|
||||
* Runs the Mocha tests in this directory in Chrome. It uses webdriverio to
|
||||
* launch Chrome and load index.html. Outputs a summary of the test results
|
||||
* to the console.
|
||||
* @return {number} 0 on success, 1 on failure.
|
||||
*/
|
||||
async function runMochaTestsInBrowser() {
|
||||
const options = {
|
||||
capabilities: {
|
||||
browserName: 'chrome',
|
||||
},
|
||||
services: [
|
||||
['selenium-standalone'],
|
||||
],
|
||||
logLevel: 'warn',
|
||||
};
|
||||
// Run in headless mode on Github Actions.
|
||||
if (process.env.CI) {
|
||||
options.capabilities['goog:chromeOptions'] = {
|
||||
args: [
|
||||
'--headless', '--no-sandbox', '--disable-dev-shm-usage',
|
||||
'--allow-file-access-from-files',
|
||||
],
|
||||
};
|
||||
} 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: ['--allow-file-access-from-files', '--disable-gpu'],
|
||||
};
|
||||
}
|
||||
|
||||
const url = 'file://' + posixPath(__dirname) + '/index.html';
|
||||
console.log('Starting webdriverio...');
|
||||
const browser = await webdriverio.remote(options);
|
||||
console.log('Loading URL: ' + url);
|
||||
await browser.url(url);
|
||||
|
||||
await browser.waitUntil(async() => {
|
||||
const elem = await browser.$('#failureCount');
|
||||
const text = await elem.getAttribute('tests_failed');
|
||||
return text !== 'unset';
|
||||
}, {
|
||||
timeout: 50000,
|
||||
});
|
||||
|
||||
const elem = await browser.$('#failureCount');
|
||||
const numOfFailure = await elem.getAttribute('tests_failed');
|
||||
|
||||
if (numOfFailure > 0) {
|
||||
console.log('============Blockly Mocha Test Failures================');
|
||||
const failureMessagesEls = await browser.$$('#failureMessages p');
|
||||
if (!failureMessagesEls.length) {
|
||||
console.log('There is at least one test failure, but no messages reported. Mocha may be failing because no tests are being run.');
|
||||
}
|
||||
for (const el of failureMessagesEls) {
|
||||
console.log(await el.getText());
|
||||
}
|
||||
}
|
||||
|
||||
console.log('============Blockly Mocha Test Summary=================');
|
||||
console.log(numOfFailure + ' tests failed');
|
||||
console.log('============Blockly Mocha Test Summary=================');
|
||||
if (parseInt(numOfFailure) !== 0) {
|
||||
return 1;
|
||||
}
|
||||
await browser.deleteSession();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
runMochaTestsInBrowser().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}).then(function(result) {
|
||||
if (result) {
|
||||
console.log('Mocha tests failed');
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log('Mocha tests passed');
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {runMochaTestsInBrowser};
|
||||
Reference in New Issue
Block a user