gristlabs_grist-core/test/init-mocha-webdriver.js
Paul Fitzpatrick bcbf57d590 (core) bump mocha version to allow parallel tests; move more tests to core
Summary:
This uses a newer version of mocha in grist-core so that tests can be run in parallel. That allows more tests to be moved without slowing things down overall. Tests moved are venerable browser tests; only the ones that "just work" or worked without too much trouble to are moved, in order to keep the diff from growing too large. Will wrestle with more in follow up.

Parallelism is at the file level, rather than the individual test.

The newer version of mocha isn't needed for grist-saas repo; tests are parallelized in our internal CI by other means. I've chosen to allocate files to workers in a cruder way than our internal CI, based on initial characters rather than an automated process. The automated process would need some reworking to be compatible with mocha running in parallel mode.

Test Plan: this diff was tested first on grist-core, then ported to grist-saas so saas repo history will correctly track history of moved files.

Reviewers: jarek

Reviewed By: jarek

Subscribers: jarek

Differential Revision: https://phab.getgrist.com/D3927
2023-06-27 02:55:34 -04:00

66 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Settings that affect tests using mocha-webdriver. This module is imported by any run of mocha,
* by being listed in test/mocha.opts. (Keep in mind that it's imported by non-browser tests, such
* as test/common, as well.)
*/
// This determines when a failed assertion shows a diff with details or
// "expected [ Array(3) ] to deeply equal [ Array(3) ]".
// Increase the threshold since the default (of 40 characters) is often too low.
// You can override it using CHAI_TRUNCATE_THRESHOLD env var; 0 disables it.
require('chai').config.truncateThreshold = process.env.CHAI_TRUNCATE_THRESHOLD ?
parseFloat(process.env.CHAI_TRUNCATE_THRESHOLD) : 4000;
// Set an explicit window size (if not set by an external variable), to ensure that manully-run
// and Jenkins-run tests, headless or not, use a consistent size. (Not that height is still not
// identical between regular and headless browsers.)
//
// The size is picked to be on the small size, to ensure we test issues caused by constrained
// space (e.g. scrolling when needed). 1024x640 is a slight increase over 900x600 we used before.
// Note that https://www.hobo-web.co.uk/best-screen-size/ lists 1366×768 as most common desktop
// size, so it's reasonable to assume a browser that takes up most but not all of such a screen.
if (!process.env.MOCHA_WEBDRIVER_WINSIZE) {
process.env.MOCHA_WEBDRIVER_WINSIZE = "1024x640";
}
// Enable enhanced stacktraces by default. Disable by running with MOCHA_WEBDRIVER_STACKTRACES="".
if (process.env.MOCHA_WEBDRIVER_STACKTRACES === undefined) {
process.env.MOCHA_WEBDRIVER_STACKTRACES = "1";
}
// Default to chrome for mocha-webdriver testing. Override by setting SELENIUM_BROWSER, as usual.
if (!process.env.SELENIUM_BROWSER) {
process.env.SELENIUM_BROWSER = "chrome";
}
// Don't fail on mismatched Chrome versions. Disable with MOCHA_WEBDRIVER_IGNORE_CHROME_VERSION="".
if (process.env.MOCHA_WEBDRIVER_IGNORE_CHROME_VERSION === undefined) {
process.env.MOCHA_WEBDRIVER_IGNORE_CHROME_VERSION = "1";
}
// don't show "Chrome is controlled by..." banner since at time of writing it can
// swallow early clicks on page reload.
if (process.env.MOCHA_WEBDRIVER_NO_CONTROL_BANNER === undefined) {
process.env.MOCHA_WEBDRIVER_NO_CONTROL_BANNER = "1";
}
// Detect whether there is an nbrowser test. If so,
// set an environment variable that will be available
// in individual processes if --parallel is enabled.
for (const arg of process.argv) {
if (arg.includes('/nbrowser/')) {
process.env.MOCHA_WEBDRIVER = '1';
}
}
// If --parallel is enabled, and we are in an individual
// worker process, set up mochaHooks. Watch out: at the
// time of writing, there's no way to have hooks run at the
// start and end of the worker process.
if (process.env.MOCHA_WORKER_ID !== undefined &&
process.env.MOCHA_WEBDRIVER !== undefined) {
const {getMochaHooks} = require('mocha-webdriver');
exports.mochaHooks = getMochaHooks();
}