Skip to content

Proposal: move unit tests to tests/unit#1841

Open
peaBerberian wants to merge 1 commit into
devfrom
unit-tests-moved
Open

Proposal: move unit tests to tests/unit#1841
peaBerberian wants to merge 1 commit into
devfrom
unit-tests-moved

Conversation

@peaBerberian
Copy link
Copy Markdown
Collaborator

@peaBerberian peaBerberian commented Apr 30, 2026

Current unit test situation

Until now, unit tests have been alongside source files as __tests__/*.test.ts files relative to the files they test.

Lately, I spent some efforts to make them easier to write: mainly I added re-usable mocks to simplify the reliance on many modules, such as a PlaybackObserver (which emits playback metrics), doing fake but valid Manifest generation etc.

It was difficult to know how to architecture this alternative co-located code, leading to a few deep arcane imports here and there. I had a few issues already, like the previous time I did a dev release, where a source file mistakenly imported some test-only mock (it was a barrel file which mistakenly pleased and source files, and tests).

Proposal

Instead, I decided to take another road, which is the one taken by all other test suites (integration, memory, performance, conformance) in the RxPlayer: putting them in its own /tests/ directory, here /tests/unit/.

Key points:

  • The root tsconfig.json had complex inclusion/exclusion rules mostly due to unit tests. By moving them I simplified it and removed the awkward tsconfig.unit-tests.json file in root by the better-placed tests/unit/tsconfig.json which is now consequently automatically picked up by LSP in most editors (contrarily to before)

  • Unit tests are now in tests/unit/src/ where they mirror the path of the source file it tests. This is checked by CI by a new script (which saw that a few tests already were not named accordingly or did not follow some moved file)

  • mocks are in tests/unit/mocks

  • Unit tests imports are relative, which may lead to few awkward paths, like ../../../../src/.

    I could have made a typescript/vitest alias here, but I don't think this very minor disagreement (even more with LSP) justify the added complexity for naive code analysis tooling.

// I did not find for example how to exclude some files (our unit tests)
// easily by running typescript directly from NodeJS.
// So we just spawn a separate process running tsc:
// We just spawn a separate process running tsc:
Copy link
Copy Markdown
Collaborator Author

@peaBerberian peaBerberian Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: text not needed anymore here because we do not exclude unit tests at build now: they aren't included by our root tsconfig.json anymore

@peaBerberian peaBerberian force-pushed the unit-tests-moved branch 2 times, most recently from 77affe2 to cda052c Compare April 30, 2026 15:46
@github-actions
Copy link
Copy Markdown

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

Details

Performance tests 1st run output

No significative change in performance for tests:

Name Mean Median
loading 24.76ms -> 24.69ms (0.073ms, z: 1.05200) 35.10ms -> 35.10ms
seeking 228.15ms -> 205.54ms (22.602ms, z: 0.55744) 18.00ms -> 18.15ms
audio-track-reload 32.08ms -> 32.16ms (-0.073ms, z: 1.09943) 47.40ms -> 47.55ms
cold loading multithread 53.78ms -> 53.65ms (0.125ms, z: 12.79723) 76.65ms -> 75.30ms
seeking multithread 149.88ms -> 140.48ms (9.397ms, z: 0.44128) 19.95ms -> 19.95ms
audio-track-reload multithread 31.51ms -> 31.26ms (0.244ms, z: 2.23605) 46.05ms -> 45.75ms
hot loading multithread 20.97ms -> 20.96ms (0.013ms, z: 1.29484) 30.60ms -> 30.60ms

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant