Skip to content

Make unit tests run in a browser#1622

Open
peaBerberian wants to merge 15 commits intodevfrom
misc/vitest-browser2
Open

Make unit tests run in a browser#1622
peaBerberian wants to merge 15 commits intodevfrom
misc/vitest-browser2

Conversation

@peaBerberian
Copy link
Collaborator

@peaBerberian peaBerberian commented Dec 31, 2024

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
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

✅ Automated performance checks have passed on commit 0eab5c1dc4688f903aedfd3a01246dea2c786019 with the base branch dev.

Details

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 24.84ms -> 25.17ms (-0.329ms, z: 1.10615) 35.25ms -> 35.40ms
seeking 382.39ms -> 389.69ms (-7.304ms, z: 0.32176) 16.50ms -> 16.55ms
audio-track-reload 31.52ms -> 31.53ms (-0.006ms, z: 0.28477) 46.95ms -> 46.95ms
cold loading multithread 50.50ms -> 49.86ms (0.637ms, z: 10.80065) 74.85ms -> 73.65ms
seeking multithread 44.04ms -> 51.40ms (-7.360ms, z: 0.17874) 19.50ms -> 19.50ms
audio-track-reload multithread 30.12ms -> 30.01ms (0.110ms, z: 1.15136) 43.95ms -> 43.95ms
hot loading multithread 19.81ms -> 19.68ms (0.131ms, z: 3.30380) 28.95ms -> 28.80ms

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

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

Details

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 24.16ms -> 24.36ms (-0.202ms, z: 0.65429) 34.35ms -> 34.35ms
seeking 432.05ms -> 433.34ms (-1.282ms, z: 0.26023) 1515.90ms -> 1515.45ms
audio-track-reload 31.04ms -> 31.04ms (0.002ms, z: 0.01204) 46.50ms -> 46.35ms
cold loading multithread 49.63ms -> 49.07ms (0.561ms, z: 12.68410) 73.50ms -> 72.60ms
seeking multithread 44.33ms -> 50.97ms (-6.637ms, z: 0.38089) 18.90ms -> 18.90ms
audio-track-reload multithread 29.70ms -> 29.64ms (0.067ms, z: 1.46123) 43.50ms -> 43.35ms
hot loading multithread 19.41ms -> 19.24ms (0.175ms, z: 5.36577) 28.50ms -> 28.20ms

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

Labels

Priority: 2 (Medium) This issue or PR has a medium priority. tests Relative to the RxPlayer's tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants