improve tests and setup test workflow

This commit is contained in:
Rene Haas
2022-08-17 11:18:50 +02:00
parent 4b1e85b1ff
commit e7178b3ce8
9 changed files with 74 additions and 40 deletions
@@ -1,9 +1,13 @@
const { expect } = require('@playwright/test');
const startSelector = '#start';
const resultSelector = '#testResult';
// default timeout = // 10mins
module.exports = async (page, timeout = 10 * 60 * 1000) => {
await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
await page.click(startSelector, { timeout: 1000 });
await page.locator(resultSelector).waitFor({ state: 'visible', timeout });
await expect(page.locator(resultSelector)).toHaveClass('passed', { timeout: 1000 });
};
@@ -25,7 +25,7 @@ const createRollupBundle = async (testDir, useEsbuild, dev) => {
}
}
if (code === 'BUNDLE_END') {
bundleOutput = output;
bundleOutput = output[0];
if (result) {
result.close();
}
@@ -59,26 +59,32 @@ module.exports = (useEsbuild = true) => {
let close;
let output;
const isDev = (config, timeout) =>
config.globalTimeout === 0 && timeout === 0 && config.workers === 1;
// eslint-disable-next-line no-empty-pattern
test.beforeAll(async ({}, { file, config, timeout }) => {
const isDev = config.globalTimeout === 0 && timeout === 0 && config.workers === 1;
if (isDev) {
if (isDev(config, timeout)) {
test.setTimeout(0);
}
({ close, url, output } = await createRollupBundle(dirname(file), useEsbuild, isDev));
({ close, url, output } = await createRollupBundle(
dirname(file),
useEsbuild,
isDev(config, timeout)
));
});
test.beforeEach(async ({ page, browserName }, { config }) => {
await page.goto(url);
if (browserName === 'chromium' && config.quiet) {
test.beforeEach(async ({ page, browserName }, { config, timeout }) => {
await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForTimeout(500);
if (browserName === 'chromium' && !isDev(config, timeout)) {
await page.coverage.startJSCoverage();
}
});
test.afterEach(async ({ page, browserName }, { file, config }) => {
if (browserName === 'chromium' && config.quiet) {
test.afterEach(async ({ page, browserName }, { file, config, timeout }) => {
if (browserName === 'chromium' && !isDev(config, timeout)) {
const coverage = await page.coverage.stopJSCoverage();
await collectCoverage(originalCwd, dirname(output), coverage, file);
}