mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
fix: Prevent mocha tests failures when window does not have focus. (#9332)
* chore: Add puppeteer-core as a dev dependency. * fix: Make mocha tests run in a fake-focused window. * fix: Make `test:mocha:interactive` use the same gulp codepath as `test`.
This commit is contained in:
@@ -15,9 +15,12 @@ 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.
|
||||
*
|
||||
* @param {boolean} exitOnCompletetion True if the browser should automatically
|
||||
* quit after tests have finished running.
|
||||
* @return {number} 0 on success, 1 on failure.
|
||||
*/
|
||||
async function runMochaTestsInBrowser() {
|
||||
async function runMochaTestsInBrowser(exitOnCompletion = true) {
|
||||
const options = {
|
||||
capabilities: {
|
||||
browserName: 'chrome',
|
||||
@@ -45,6 +48,17 @@ async function runMochaTestsInBrowser() {
|
||||
console.log('Loading URL: ' + url);
|
||||
await browser.url(url);
|
||||
|
||||
// Toggle the devtools setting to emulate focus, so that the window will
|
||||
// always act as if it has focus regardless of the state of the window manager
|
||||
// or operating system. This improves the reliability of FocusManager-related
|
||||
// tests.
|
||||
const puppeteer = await browser.getPuppeteer();
|
||||
await browser.call(async () => {
|
||||
const page = (await puppeteer.pages())[0];
|
||||
const session = await page.createCDPSession();
|
||||
await session.send('Emulation.setFocusEmulationEnabled', { enabled: true });
|
||||
});
|
||||
|
||||
await browser.waitUntil(async() => {
|
||||
const elem = await browser.$('#failureCount');
|
||||
const text = await elem.getAttribute('tests_failed');
|
||||
@@ -74,7 +88,7 @@ async function runMochaTestsInBrowser() {
|
||||
if (parseInt(numOfFailure) !== 0) {
|
||||
return 1;
|
||||
}
|
||||
await browser.deleteSession();
|
||||
if (exitOnCompletion) await browser.deleteSession();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user