diff --git a/package.json b/package.json index e867ef847f..fe14168775 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/ts/test-mock/bootstrap.ts b/ts/test-mock/bootstrap.ts index f7ebca3c55..5bc845e3d2 100644 --- a/ts/test-mock/bootstrap.ts +++ b/ts/test-mock/bootstrap.ts @@ -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(); diff --git a/ts/test-mock/playwright.ts b/ts/test-mock/playwright.ts index b82185271a..3fe4edc104 100644 --- a/ts/test-mock/playwright.ts +++ b/ts/test-mock/playwright.ts @@ -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 diff --git a/ts/test-mock/setup-ci.ts b/ts/test-mock/setup-ci.ts new file mode 100644 index 0000000000..0871610349 --- /dev/null +++ b/ts/test-mock/setup-ci.ts @@ -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 { + 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'); +}