Skip to content

test: unit test conventions, lint rules and coverage gates - #5226

Open
dsilhavy wants to merge 15 commits into
developmentfrom
feature/test-conventions
Open

dsilhavy wants to merge 15 commits into
developmentfrom
feature/test-conventions

Conversation

@dsilhavy

Copy link
Copy Markdown
Collaborator

Second step of #5210. It writes down how unit tests are written from now on, enforces it with lint rules, and stops coverage from dropping.

Changes

  • test/unit/README.md describes the test conventions and coverage rules; AGENTS.md links to it.
  • @vitest/eslint-plugin rejects focused, skipped and commented-out tests, duplicate titles, tests without an assertion, done callbacks and chai assert. Files not converted yet are listed in eslint.config.mjs; the area PRs only shrink these lists.
  • npm run test:coverage fails below a floor of 57.33% lines (Chromium). On pull requests, CI fails when less than 80% of the changed executable lines in src/ are covered.
  • Existing tests are fixed for the new rules, and the retrieveManifest tests use fake XHR instead of real network requests.
  • Unused test helpers and mocks are removed.

Verification

  • npm run ci:verify passes locally: 4488/4488 tests in Chromium and Firefox.
  • npm run test:coverage passes: 57.41% lines.
  • The changed-lines check passes with no changed src/ lines, and fails below the threshold and without a coverage report.
  • CI has not run yet.

@dsilhavy dsilhavy added this to the 5.3.1 milestone Nov 27, 2026
@dsilhavy dsilhavy changed the title #test: unit test conventions, lint rules and coverage gates test: unit test conventions, lint rules and coverage gates Nov 27, 2026
Nothing imports them. The helpers date from the old in-browser test page.
Replaces chai assert with expect, removes empty hooks and commented-out tests, merges duplicate hooks and describe blocks, gives duplicate test titles distinct names, trims trailing spaces in titles, and fixes titles that did not match what the test checks.
retrieveManifest starts a real manifest request. It reached the network and finished at a random time after the test, which made coverage differ between runs.
Rejects focused, skipped and commented-out tests, duplicate titles and hooks, tests without an assertion, done callbacks, and chai assert/should and chai-spies imports. Files that still use done callbacks or have tests without an assertion are listed in DONE_CALLBACK_FILES and NO_EXPECT_FILES; the area PRs of #5210 shrink these lists.
npm run test:coverage fails below the floor in vite.config.js (57.33% lines on Chromium). On pull requests, the coverage summary fails when less than 80% of the changed executable lines in src/ are covered (--min-changed=80).
test/unit/README.md describes structure, assertions, mocks, lint rules and the coverage rules agreed in #5210. Linked from AGENTS.md.
With --min-changed, a malformed coverage summary, a missing base ref or an invalid threshold let the check pass. The check now passes only once the coverage of the changed lines is known.
lcov.info lists a statement only on its first line. A change to a later line of a multiline statement, for example a condition on its own line, counted as a change without executable code and could not fail the check. The check now reads the statement spans from coverage-final.json and gives such a line the hit count of the innermost statement it belongs to. Blank lines, comments and lines with only closing brackets still do not count.
…summary

--min-changed= read as 0, and --min-changed 80 (with a space) left the check off and read 80 as the coverage folder. Arguments are now parsed with node:util parseArgs: both forms work, and unknown options, extra arguments and missing or malformed thresholds exit with code 2.
When ci:verify failed, the coverage step was skipped and the summary failed a second time with "no coverage report found".
The two tests checked spy.notCalled before registering the spy and before calling setPlaybackQuality, so they could never fail.
…t test

The title says the test covers on-receive and on-start mode, but nothing required the on-receive handler to run, and an assertion error inside it never reached done. The handler now records the event, and the on-start handler asserts it.
No behaviour change: the coverage summary produces the same output. changed-lines.mjs decides which changed lines are executable and how often they ran; it is tested against coverage objects from @vitest/istanbul-lib-instrument, the instrumenter @vitest/coverage-istanbul uses. coverage-summary.test.mjs covers the arguments and the cases in which --min-changed must fail. npm run test:scripts runs both with node --test and is part of ci:verify.
The hand-written comment scan read /* inside a string such as '*/*', a regular expression or a template literal as the start of a comment, and dropped the following lines until the next */. Uncovered changes on those lines passed the check. acorn tokenizes the file instead; a line has code when it holds a token other than closing brackets, ';' or ','.
istanbul does not instrument the expression of 'export default <expression>', such as export default FactoryMaker.getClassFactory(...). A change to only that line counted as a change without executable code and passed, even in a file no test loads. These lines now get the module load count: the highest count of the statements outside every function.
@dsilhavy
dsilhavy force-pushed the feature/test-conventions branch from 7a4930f to 159bc99 Compare November 29, 2026 07:12
@dsilhavy dsilhavy moved this to In Progress in dash.js Version 5.3.1 Nov 29, 2026

This branch has not been deployed

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant