Skip to content

Add Vitest test suite for pure-logic modules - #1927

Open
sweenzor wants to merge 2 commits into
gildas-lormeau:masterfrom
sweenzor:test-suite
Open

Add Vitest test suite for pure-logic modules#1927
sweenzor wants to merge 2 commits into
gildas-lormeau:masterfrom
sweenzor:test-suite

Conversation

@sweenzor

@sweenzor sweenzor commented Mar 20, 2026

Copy link
Copy Markdown

Some ideas about how a test suite for SingleFile might look. Let me know your thoughts @gildas-lormeau!

Summary

  • Add Vitest with 103 tests covering pure-logic modules that don't require browser APIs
  • Test srcset parser, MHTML utilities (including decodeBinary/decodeBase64), yabson serialization round-trips, and config/download helpers
  • Extract pure functions from config.js and downloads.js into config-utils.js so they are importable without browser dependencies
  • Add @eslint/js to devDependencies: eslint.config.mjs imports it, but ESLint 10 no longer ships it as a transitive dependency, so npx eslint . fails on a fresh checkout without it

Test plan

  • npm test -- all 103 tests pass
  • npm run build -- rollup build still succeeds (confirms extraction didn't break imports)
  • npx eslint . -- no lint errors in new/modified files (downloads.js has pre-existing preserve-caught-error hits from ESLint 10's new recommended rule, unrelated to this change)

@@ -0,0 +1,99 @@
/*
* Copyright 2010-2020 Gildas Lormeau

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Suggested change
* Copyright 2010-2020 Gildas Lormeau
* Copyright 2010-2026 Gildas Lormeau

sweenzor and others added 2 commits July 10, 2026 10:51
Test srcset parser, MHTML utilities, yabson serialization round-trips,
and config/download helpers. Extract pure functions from config.js and
downloads.js into config-utils.js to make them importable without
browser API dependencies.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Remove unused MIGRATION_DEFAULT_VARIABLES_VALUES import in config.js
  (only updateFilenameTemplate needs it, and it lives in config-utils.js)
- Declare TextEncoder/atob globals in mhtml-util.test.js so the test
  file passes eslint
- Add @eslint/js to devDependencies: eslint.config.mjs imports it, but
  eslint 10 no longer ships it as a transitive dependency, so
  "npx eslint ." fails on a fresh checkout
- Add tests for decodeBinary and decodeBase64 (base64 encoding of the
  full byte range, chunk-boundary-sized input, charset handling)
- Collapse leftover double blank lines where functions were extracted

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sweenzor
sweenzor marked this pull request as ready for review July 11, 2026 17:00
@gildas-lormeau

Copy link
Copy Markdown
Owner

Thank you for taking the time to write this. The tests are good, but most of them are not in the right place. Three of the four test files cover code that is vendored into this repository: srcset-parser and the MHTML utilities come from the mhtml-to-html project, and yabson has its own repository. The copies here get replaced wholesale when the upstream changes. This has already happened since this PR was opened, the functions tested by mhtml-util.test.js no longer exist in that shape. The plan is to add these tests in each sub-project, where the code is actually developed. I'll keep this PR open as a reminder and close it once that's done. If you'd like to contribute the yabson and srcset tests upstream, they are very welcome there. The @eslint/js fix you identified was correct and has landed in the meantime.

@sweenzor

sweenzor commented Aug 26, 2026

Copy link
Copy Markdown
Author

Makes sense. I've ported the tests upstream:

I left the MHTML utility tests alone since your suite over there already covers them.

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.

2 participants