From f8367bf5ead0753c33eb4ea5dc85b6514feb5c69 Mon Sep 17 00:00:00 2001 From: Rene Haas Date: Tue, 2 Jul 2024 12:16:09 +0200 Subject: [PATCH] adapt performance tests --- .../performance/timing/handleEnvironment.ts | 21 +++++++++++++++++++ .../performance/timing/index.browser.ts | 11 ++++++++-- .../playwright/performance/timing/index.html | 1 + .../playwright/performance/timing/index.scss | 4 ++++ .../performance/timing/index.test.ts | 5 +++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 packages/overlayscrollbars/test/playwright/performance/timing/handleEnvironment.ts diff --git a/packages/overlayscrollbars/test/playwright/performance/timing/handleEnvironment.ts b/packages/overlayscrollbars/test/playwright/performance/timing/handleEnvironment.ts new file mode 100644 index 00000000..f4c01d83 --- /dev/null +++ b/packages/overlayscrollbars/test/playwright/performance/timing/handleEnvironment.ts @@ -0,0 +1,21 @@ +{ + const { body } = document; + const url = new URL(window.location.toString()); + const params = url.searchParams; + + /** + * ndsd: non default scroll direction = true + */ + ['ndsd'].forEach((param) => { + const paramValue = Boolean(params.get(param)); + + if (paramValue) { + body.classList.add(param); + } else { + document.getElementById(param)?.addEventListener('click', () => { + params.set(param, 'true'); + window.location.assign(url.toString()); + }); + } + }); +} diff --git a/packages/overlayscrollbars/test/playwright/performance/timing/index.browser.ts b/packages/overlayscrollbars/test/playwright/performance/timing/index.browser.ts index f3f5339b..48466526 100644 --- a/packages/overlayscrollbars/test/playwright/performance/timing/index.browser.ts +++ b/packages/overlayscrollbars/test/playwright/performance/timing/index.browser.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import '~/index.scss'; import './index.scss'; +import './handleEnvironment'; import { OverlayScrollbars } from '~/overlayscrollbars'; import { ScrollbarsHidingPlugin } from '~/plugins'; import { resize, setTestResult, timeout, waitForOrFailTest } from '@~local/browser-testing'; @@ -15,6 +16,7 @@ if (!OverlayScrollbars.env().scrollbarsHiding) { OverlayScrollbars.plugin(ScrollbarsHidingPlugin); } +const nonDefaultScrollDirection = document.body.classList.contains('ndsd'); const startBtn = document.querySelector('#start')!; const wrapper = document.querySelector('#wrapper')!; const content = document.querySelector('#content')!; @@ -90,12 +92,17 @@ startBtn.addEventListener('click', async () => { completed(); }); const forceUpdateTestResult = await forceUpdateTest.run(); + const scrollDirectionStr = nonDefaultScrollDirection ? 'non-default' : 'default'; console.error( - `No Force Update (10k runs / sample): { samples: ${noForceUpdateTestResult.samples}, timeMs: ${noForceUpdateTestResult.timeMs} }` + `[ScrollDirection: ${scrollDirectionStr}] [force: false]: (10k runs / sample): { samples: ${ + noForceUpdateTestResult.samples + }, timeMs: ${noForceUpdateTestResult.timeMs.toFixed(3)} }` ); console.error( - `Force Update (1k runs / sample): { samples: ${forceUpdateTestResult.samples}, timeMs: ${forceUpdateTestResult.timeMs} }` + `[ScrollDirection: ${scrollDirectionStr}] [force: true]: (1k runs / sample): { samples: ${ + forceUpdateTestResult.samples + }, timeMs: ${forceUpdateTestResult.timeMs.toFixed(3)} }` ); setTestResult(true); diff --git a/packages/overlayscrollbars/test/playwright/performance/timing/index.html b/packages/overlayscrollbars/test/playwright/performance/timing/index.html index 4c999790..55240ed4 100644 --- a/packages/overlayscrollbars/test/playwright/performance/timing/index.html +++ b/packages/overlayscrollbars/test/playwright/performance/timing/index.html @@ -1,5 +1,6 @@
+
diff --git a/packages/overlayscrollbars/test/playwright/performance/timing/index.scss b/packages/overlayscrollbars/test/playwright/performance/timing/index.scss index 1973b030..b7bea63d 100644 --- a/packages/overlayscrollbars/test/playwright/performance/timing/index.scss +++ b/packages/overlayscrollbars/test/playwright/performance/timing/index.scss @@ -53,3 +53,7 @@ body { background: red; opacity: 0.3; } + +body.ndsd { + direction: rtl; +} diff --git a/packages/overlayscrollbars/test/playwright/performance/timing/index.test.ts b/packages/overlayscrollbars/test/playwright/performance/timing/index.test.ts index 91efae32..a35287b2 100644 --- a/packages/overlayscrollbars/test/playwright/performance/timing/index.test.ts +++ b/packages/overlayscrollbars/test/playwright/performance/timing/index.test.ts @@ -7,4 +7,9 @@ test.describe('performance.timing', () => { test('default', async ({ page }) => { await expectSuccess(page); }); + + test('non default scroll direction', async ({ page }) => { + await page.click('#ndsd'); + await expectSuccess(page); + }); });