Skip to content

Commit

Permalink
adapt performance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KingSora committed Jul 2, 2024
1 parent 082e275 commit f8367bf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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());
});
}
});
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,6 +16,7 @@ if (!OverlayScrollbars.env().scrollbarsHiding) {
OverlayScrollbars.plugin(ScrollbarsHidingPlugin);
}

const nonDefaultScrollDirection = document.body.classList.contains('ndsd');
const startBtn = document.querySelector<HTMLButtonElement>('#start')!;
const wrapper = document.querySelector<HTMLElement>('#wrapper')!;
const content = document.querySelector<HTMLElement>('#content')!;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div id="controls">
<button id="start">start</button>
<button id="ndsd">non default scroll direction</button>
</div>
<div id="stage">
<div id="wrapper" class="element">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ body {
background: red;
opacity: 0.3;
}

body.ndsd {
direction: rtl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit f8367bf

Please sign in to comment.