Skip to content

Make unit tests run in a browser - #1622

Open
peaBerberian wants to merge 13 commits into
devfrom
misc/vitest-browser2
Open

Make unit tests run in a browser#1622
peaBerberian wants to merge 13 commits into
devfrom
misc/vitest-browser2

Conversation

@peaBerberian

@peaBerberian peaBerberian commented Dec 31, 2024

Copy link
Copy Markdown
Collaborator

This mega-PR rewrites unit tests so they can be run in a web browser (for now Chrome + Firefox), through webdriverio - just like our integration and memory tests.

This allows us to run unit tests in the actual environment where the RxPlayer will run and to have a common script + environment for unit, integration and memory tests, thus simplifying the project.

The main difficulty was linked to our over-reliance on vitest's doMock+importActual functions, the second which has a different behavior when run in a web browser: multiple importActual calls in the same test file won't re-evaluate that imported file. This means that doMock performed in-between importActual calls for the same file won't have an impact on that file.

This might be fixed in the future, but I wanted to see how most people succeeded to run vitest in a browser. It seems that relying on a top-level mock function is much more idiomatic, while relying on the hoisted function to also declare hoisted mocks whose implementation can change in-between tests.

Though, to ensure portability between test frameworks if we ever change it (JavaScript is like that sometimes), I try to limit reliance on that vitest-specific vi.mock/vi.hoisted concept, by prefering just mocking through only the more portable spyOn when possible.

@peaBerberian peaBerberian added the tests Relative to the RxPlayer's tests label Dec 31, 2024
@peaBerberian
peaBerberian force-pushed the misc/vitest-browser2 branch 2 times, most recently from 25327f8 to f7d5638 Compare December 31, 2024 16:49
@peaBerberian
peaBerberian force-pushed the misc/env-detector-refacto branch from d05cafc to c6858a6 Compare January 28, 2025 14:03
@peaBerberian peaBerberian added the Priority: 3 (Low) This issue or PR has a low priority. label Feb 26, 2025
@peaBerberian
peaBerberian force-pushed the misc/env-detector-refacto branch from c6858a6 to 8bed678 Compare April 22, 2025 13:30
@peaBerberian
peaBerberian force-pushed the misc/vitest-browser2 branch from d598ebd to b311011 Compare April 22, 2025 13:46
@peaBerberian
peaBerberian force-pushed the misc/env-detector-refacto branch from 8bed678 to 5876dd2 Compare April 22, 2025 18:27
@peaBerberian
peaBerberian force-pushed the misc/vitest-browser2 branch 2 times, most recently from c1519dc to 79b04e5 Compare April 22, 2025 20:15
@canalplus canalplus deleted a comment from github-actions Bot Apr 22, 2025
@peaBerberian
peaBerberian force-pushed the misc/env-detector-refacto branch from 5876dd2 to 5661c8b Compare June 30, 2025 10:46
@peaBerberian
peaBerberian force-pushed the misc/vitest-browser2 branch from 0c9775a to 68ec707 Compare June 30, 2025 12:40
@canalplus canalplus deleted a comment from github-actions Bot Jun 30, 2025
@canalplus canalplus deleted a comment from github-actions Bot Jun 30, 2025
@peaBerberian
peaBerberian changed the base branch from misc/env-detector-refacto to dev July 8, 2025 10:51
@peaBerberian
peaBerberian force-pushed the misc/vitest-browser2 branch from 68ec707 to 049153c Compare July 8, 2025 11:44
@peaBerberian
peaBerberian force-pushed the misc/vitest-browser2 branch from 049153c to 747a27d Compare August 1, 2025 13:26
@canalplus canalplus deleted a comment from github-actions Bot Aug 1, 2025
@canalplus canalplus deleted a comment from github-actions Bot Aug 1, 2025
@peaBerberian
peaBerberian force-pushed the misc/vitest-browser2 branch 2 times, most recently from 79d70d3 to 745d8ce Compare August 29, 2025 17:06
@peaBerberian peaBerberian added this to the 4.5.0 milestone Sep 19, 2025
@peaBerberian
peaBerberian force-pushed the dev branch 5 times, most recently from aab2c57 to 06215ab Compare September 25, 2025 15:29
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@canalplus canalplus deleted a comment from github-actions Bot Dec 19, 2025
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

✅ Automated performance checks have passed on commit 6ed1ae612544e1b25c96bd0f5ca378d3e4ea22e5 with the base branch dev.

Details

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 38.72ms -> 41.00ms (corrected: -1.866ms, A/A bias: -0.415ms, z: 0.02887) 32.80ms -> 32.40ms (corrected: 0.050ms, A/A bias: 0.250ms, z: 0.61103)
seeking 145.08ms -> 120.11ms (corrected: 32.567ms, A/A bias: -7.593ms, z: 0.73612) 12.60ms -> 12.70ms (corrected: 0.150ms, A/A bias: 0.075ms, z: 0.42820)
audio-track-reload 33.90ms -> 33.82ms (corrected: 0.150ms, A/A bias: -0.078ms, z: 0.51962) 32.80ms -> 32.85ms (corrected: 0.425ms, A/A bias: -0.250ms, z: 1.51073)
loading over active content 23.82ms -> 24.06ms (corrected: -1.070ms, A/A bias: 0.824ms, z: 1.35677) 22.15ms -> 22.50ms (corrected: 0.225ms, A/A bias: 0.575ms, z: 1.35677)
large multi-period manifest 98.02ms -> 100.33ms (corrected: -3.201ms, A/A bias: 0.894ms, z: 1.31828) 91.10ms -> 93.50ms (corrected: -2.375ms, A/A bias: 0.400ms, z: 1.31828)
cold loading multithread 55.57ms -> 57.52ms (corrected: -1.821ms, A/A bias: -0.134ms, z: 0.96225) 54.40ms -> 53.10ms (corrected: 0.875ms, A/A bias: 0.150ms, z: 3.60844)
seeking multithread 90.29ms -> 105.15ms (corrected: -27.551ms, A/A bias: 12.691ms, z: 1.18357) 15.00ms -> 15.00ms (corrected: -0.225ms, A/A bias: 0.250ms, z: 1.01036)
audio-track-reload multithread 32.42ms -> 32.66ms (corrected: -0.450ms, A/A bias: 0.203ms, z: 1.42413) 31.65ms -> 31.60ms (corrected: 0.450ms, A/A bias: -0.150ms, z: 1.99186)
hot loading multithread 22.44ms -> 24.88ms (corrected: -2.305ms, A/A bias: -0.132ms, z: 0.42339) 21.50ms -> 21.60ms (corrected: -0.125ms, A/A bias: 0.050ms, z: 0.88046)

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

✅ Automated performance checks have passed on commit 2a6a15c54d2747b86f74d0df09f2925eaecd0c72 with the base branch dev.

Details

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 36.33ms -> 36.87ms (corrected: 0.003ms, A/A bias: -0.545ms, z: 1.03923) 30.00ms -> 30.20ms (corrected: -0.350ms, A/A bias: 0.250ms, z: 1.68394)
seeking 152.05ms -> 176.98ms (corrected: -17.504ms, A/A bias: -7.422ms, z: 0.26943) 11.95ms -> 12.00ms (corrected: 0.425ms, A/A bias: -0.025ms, z: 0.36084)
audio-track-reload 32.36ms -> 32.59ms (corrected: -0.301ms, A/A bias: 0.076ms, z: 1.09697) 31.20ms -> 31.50ms (corrected: 0.075ms, A/A bias: -0.075ms, z: 0.12028)
loading over active content 23.14ms -> 23.25ms (corrected: -0.202ms, A/A bias: 0.091ms, z: 0.14915) 20.65ms -> 21.30ms (corrected: -1.225ms, A/A bias: 0.950ms, z: 0.14915)
large multi-period manifest 95.30ms -> 94.51ms (corrected: -0.409ms, A/A bias: 1.201ms, z: 0.19245) 85.25ms -> 86.80ms (corrected: -5.350ms, A/A bias: 6.200ms, z: 0.19245)
cold loading multithread 53.06ms -> 52.36ms (corrected: 0.653ms, A/A bias: 0.053ms, z: 1.69356) 50.60ms -> 49.90ms (corrected: 0.775ms, A/A bias: -0.050ms, z: 2.96854)
seeking multithread 121.66ms -> 106.88ms (corrected: 14.865ms, A/A bias: -0.080ms, z: 0.03849) 13.80ms -> 13.90ms (corrected: 0.050ms, A/A bias: -0.025ms, z: 0.47631)
audio-track-reload multithread 31.46ms -> 31.53ms (corrected: -0.059ms, A/A bias: -0.011ms, z: 0.07698) 30.35ms -> 30.30ms (corrected: 0.150ms, A/A bias: -0.200ms, z: 0.08660)
hot loading multithread 21.19ms -> 21.22ms (corrected: -0.058ms, A/A bias: 0.028ms, z: 0.05774) 19.70ms -> 19.70ms (corrected: -0.125ms, A/A bias: 0.150ms, z: 1.19319)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status-unknown tests Relative to the RxPlayer's tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants