insomnia/packages/insomnia-smoke-test/playwright/test.ts
James Gatz e1b4bb2def
Adds tracing with Playwright (#4439)
* base tracing with playwright

* use github reporter on CI

* Use the config to capture traces

Co-authored-by: Filipe Freire <livrofubia@gmail.com>
2022-02-10 14:48:32 +01:00

66 lines
1.8 KiB
TypeScript

// Read more about creating fixtures https://playwright.dev/docs/test-fixtures
import { ElectronApplication, test as baseTest, TraceMode } from '@playwright/test';
import path from 'path';
import {
cwd,
executablePath,
mainPath,
randomDataPath,
} from './paths';
interface EnvOptions {
INSOMNIA_DATA_PATH: string;
}
export const test = baseTest.extend<{
app: ElectronApplication;
}>({
app: async ({ playwright, trace }, use, testInfo) => {
const options: EnvOptions = {
INSOMNIA_DATA_PATH: randomDataPath(),
};
const electronApp = await playwright._electron.launch({
cwd,
executablePath,
args: process.env.BUNDLE === 'package' ? [] : [mainPath],
env: {
...process.env,
...options,
PLAYWRIGHT: 'true',
},
});
const appContext = electronApp.context();
const traceMode: TraceMode = typeof trace === 'string' ? trace as TraceMode : trace.mode;
const defaultTraceOptions = { screenshots: true, snapshots: true, sources: true };
const traceOptions = typeof trace === 'string' ? defaultTraceOptions : { ...defaultTraceOptions, ...trace, mode: undefined };
const captureTrace = (traceMode === 'on' || traceMode === 'retain-on-failure' || (traceMode === 'on-first-retry' && testInfo.retry === 1));
if (captureTrace) {
await appContext.tracing.start(traceOptions);
}
await use(electronApp);
if (captureTrace) {
await appContext.tracing.stop({
path: path.join(testInfo.outputDir, 'trace.zip'),
});
}
await electronApp.close();
},
page: async ({ app }, use) => {
const page = await app.firstWindow();
if (process.platform === 'win32') await page.reload();
await page.click("text=Don't share usage analytics");
await use(page);
},
});