Reduce mock test flake on CI

This commit is contained in:
trevor-signal 2023-12-05 17:33:10 -05:00 committed by GitHub
parent 62040e5c1a
commit e41973c238
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 3 deletions

View file

@ -41,7 +41,7 @@
"test-electron": "node ts/scripts/test-electron.js",
"test-release": "node ts/scripts/test-release.js",
"test-node": "cross-env LANG=en-us electron-mocha --timeout 10000 --file test/setup-test-node.js --recursive test/modules ts/test-node ts/test-both",
"test-mock": "mocha ts/test-mock/**/*_test.js",
"test-mock": "mocha --require ts/test-mock/setup-ci.js ts/test-mock/**/*_test.js",
"test-eslint": "mocha .eslint/rules/**/*.test.js --ignore-leaks",
"test-node-coverage": "nyc --reporter=lcov --reporter=text mocha --recursive test/modules ts/test-node ts/test-both",
"test-lint-intl": "ts-node ./build/intl-linter/linter.ts --test",

View file

@ -359,6 +359,12 @@ export class Bootstrap {
const { logsDir } = this;
await fs.rename(logsDir, outDir);
const page = await app?.getWindow();
if (process.env.TRACING) {
await page
?.context()
.tracing.stop({ path: path.join(outDir, 'trace.zip') });
}
if (app) {
const window = await app.getWindow();
const screenshot = await window.screenshot();

View file

@ -62,13 +62,20 @@ export class App extends EventEmitter {
SIGNAL_CI_CONFIG: this.options.config,
},
locale: 'en',
timeout: 20 * SECOND,
timeout: 30 * SECOND,
});
// wait for the first window to load
await pTimeout(
(async () => {
const page = await this.privApp?.firstWindow();
const page = await this.getWindow();
if (process.env.TRACING) {
await page.context().tracing.start({
name: 'tracing',
screenshots: true,
snapshots: true,
});
}
await page?.waitForLoadState('load');
})(),
20 * SECOND

25
ts/test-mock/setup-ci.ts Normal file
View file

@ -0,0 +1,25 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import createDebug from 'debug';
import { Bootstrap } from './bootstrap';
const debug = createDebug('mock:test:setup-ci');
// Sadly, we can reduce flakiness in CI by launching the app once first
export async function mochaGlobalSetup(): Promise<void> {
if (!process.env.CI) {
return;
}
debug('Launching app before running all tests');
const bootstrap = new Bootstrap();
await bootstrap.init();
const app = await bootstrap.link();
debug('Closing app before running all tests');
await app.close();
await bootstrap.teardown();
debug('Done');
}