libreoffice-online/cypress_test/plugins/index.js
Tamás Zolnai a13b1a93bc cypress: try to handle support file better during parallel run.
When we run cypress tests in parallel (e.g. make check -j4), the
tests randomly fail with an uncaught error. The issue might be
because the same support file is shared between the different threads,
and they might access it at the same time. We try to create different
instances of the support file via preprocessing. Let's see whether it
makes the issue go away.

Issue's error message was:
"An uncaught error was detected outside of a test:
SyntaxError: The following error originated from your test code, not from Cypress.
Unexpected end of input"

Signed-off-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Change-Id: I7b256cd686fb2b0e79ab602e95d197388a5aadca
2020-12-17 19:12:44 +01:00

106 lines
2.8 KiB
JavaScript

/* global require */
var process = require('process');
var uuid = require('uuid');
var tasks = require('./tasks');
var blacklists = require('./blacklists');
var selectTests = require('cypress-select-tests');
function plugin(on, config) {
if (config.env.COVERAGE_RUN)
require('@cypress/code-coverage/task')(on, config);
on('task', {
copyFile: tasks.copyFile,
failed: require('cypress-failed-log/src/failed')()
});
if (process.env.ENABLE_VIDEO_REC) {
config.video = true;
}
if (process.env.ENABLE_CONSOLE_LOG) {
require('cypress-log-to-output').install(on, function(type, event) {
if (event.level === 'error' || event.type === 'error') {
return true;
}
return false;
});
}
if (process.env.ENABLE_LOGGING) {
on('before:browser:launch', function(browser, launchOptions) {
if (browser.family === 'chromium') {
launchOptions.args.push('--enable-logging=stderr');
launchOptions.args.push('--v=2');
return launchOptions;
}
});
}
if (process.env.CYPRESS_INTEGRATION === 'php-proxy') {
config.defaultCommandTimeout = 10000;
}
on('file:preprocessor', (file) => {
if (file.outputPath.endsWith('support/index.js')) {
var runUuid = uuid.v4();
var truncLength = file.outputPath.length - ('index.js').length;
file.outputPath = file.outputPath.substring(0, truncLength);
file.outputPath += runUuid + 'index.js';
}
return selectTests(config, pickTests)(file);
});
return config;
}
function getLOVersion(config) {
var versionString = config.env.LO_CORE_VERSION;
if (versionString.includes('Collabora')) {
if (versionString.includes('_6.2.')) {
return 'cp-6-2';
} else if (versionString.includes('_6.4.')) {
return 'cp-6-4';
}
}
return 'master';
}
function removeBlacklistedTest(filename, testsToRun, blackList) {
for (var i = 0; i < blackList.length; i++) {
if (filename.endsWith(blackList[i][0])) {
if (blackList[i][1].length === 0) // skip the whole test suite
return [];
return testsToRun.filter(fullTestName => !blackList[i][1].includes(fullTestName[1]));
}
}
return testsToRun;
}
function pickTests(filename, foundTests, config) {
var coreVersion = getLOVersion(config);
var testsToRun = foundTests;
if (!(coreVersion in blacklists.coreBlackLists))
return testsToRun;
var coreblackList = blacklists.coreBlackLists[coreVersion];
testsToRun = removeBlacklistedTest(filename, testsToRun, coreblackList);
if (process.env.CYPRESS_INTEGRATION === 'nextcloud') {
testsToRun = removeBlacklistedTest(filename, testsToRun, blacklists.nextcloudBlackList);
} else {
testsToRun = removeBlacklistedTest(filename, testsToRun, blacklists.nextcloudOnlyList);
}
if (process.env.CYPRESS_INTEGRATION === 'php-proxy') {
var ProxyblackList = blacklists.phpProxyBlackList;
testsToRun = removeBlacklistedTest(filename, testsToRun, ProxyblackList);
}
return testsToRun;
}
module.exports = plugin;