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
+35
View File
@@ -0,0 +1,35 @@
name: Test
on:
push:
branches:
- master
permissions:
contents: read
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Run Jest
run: npm run jest
- uses: codecov/codecov-action@v3
with:
files: ./coverage1.xml,./coverage2.xml
flags: unittests
# - name: Run Playwright
# run: npm run playwright
# - uses: codecov/codecov-action@v3
# with:
# files: ./coverage1.xml,./coverage2.xml
# flags: uitests
@@ -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);
}
@@ -5,7 +5,6 @@ playwrightRollup();
test.describe('DOMObserver', () => {
test('test', async ({ page }) => {
await page.click('#start');
await expectSuccess(page);
});
});
@@ -5,14 +5,12 @@ playwrightRollup();
test.describe('SizeObserver', () => {
test('with ResizeOserver', async ({ page }) => {
await page.click('#start');
await expectSuccess(page);
});
test('with ResizeOserver polyfill', async ({ page }) => {
await page.click('#roPolyfill');
await page.waitForTimeout(500);
await page.click('#start');
await expectSuccess(page);
});
});
@@ -5,23 +5,19 @@ playwrightRollup();
test.describe('TrinsicObserver', () => {
test('with IntersectionObserver', async ({ page }) => {
await page.click('#start');
await expectSuccess(page);
});
test('with ResizeObserver', async ({ page }) => {
await page.click('#ioPolyfill');
await page.waitForTimeout(500);
await page.click('#start');
await expectSuccess(page);
});
test('with ResizeObserver polyfill', async ({ page }) => {
await page.click('#ioPolyfill');
await page.waitForTimeout(500);
await page.click('#roPolyfill');
await page.waitForTimeout(500);
await page.click('#start');
await expectSuccess(page);
});
});
@@ -5,7 +5,6 @@ playwrightRollup();
test.describe('StructureSetup.nesting', () => {
test('nesting updates', async ({ page }) => {
await page.click('#start');
await expectSuccess(page);
});
});
@@ -830,7 +830,7 @@ const start = async () => {
setTestResult(true);
};
startBtn?.addEventListener('click', start);
startBtn!.addEventListener('click', start);
if (!useContentElement) {
envElms.forEach((elm) => {
@@ -4,22 +4,20 @@ import { test, Page } from '@playwright/test';
playwrightRollup();
test.describe('StructureSetup.update', () => {
[false].forEach(async (targetIsViewport) => {
[false].forEach((targetIsViewport) => {
const isOrIsNot = targetIsViewport ? 'is' : 'is not';
const setTargetIsVp = async (page: Page) => {
if (targetIsViewport) {
await page.click('#tvp');
await page.waitForTimeout(500);
}
};
test.describe(`target ${isOrIsNot} viewport`, () => {
[false, true].forEach(async (nativeScrollbarStyling) => {
[false, true].forEach((nativeScrollbarStyling) => {
const withText = nativeScrollbarStyling ? 'with' : 'without';
const nss = async (page: Page) => {
const nsh = async (page: Page) => {
if (!nativeScrollbarStyling) {
await page.click('#nss');
await page.waitForTimeout(500);
await page.click('#nsh');
}
};
@@ -28,17 +26,17 @@ test.describe('StructureSetup.update', () => {
test('default', async ({ page }) => {
await setTargetIsVp(page);
await nss(page);
await page.click('#start');
await nsh(page);
await expectSuccess(page);
});
test('with fully overlaid scrollbars', async ({ page }) => {
await setTargetIsVp(page);
await nss(page);
await nsh(page);
await page.click('#fo');
await page.waitForTimeout(500);
await page.click('#start');
await expectSuccess(page);
});
@@ -49,21 +47,20 @@ test.describe('StructureSetup.update', () => {
);
await setTargetIsVp(page);
await nss(page);
await nsh(page);
await page.click('#po');
await page.waitForTimeout(500);
await page.click('#start');
await expectSuccess(page);
});
test('without flexbox glue & css custom props', async ({ page }) => {
await setTargetIsVp(page);
await nss(page);
await nsh(page);
await page.click('#fbg');
await page.waitForTimeout(500);
await page.click('#ccp');
await page.waitForTimeout(500);
await page.click('#start');
await expectSuccess(page);
});
});