feat: add unit tests for pure utility functions#1245
Draft
Conversation
- Add tests/run-unit.ts: lightweight runner (no server required) - Add tests/unit/markdown.test.ts: tidyMarkdown (17 tests) - Add tests/unit/ip.test.ts: parseIp, parseCIDR, CIDR, isIPInNonPublicRange, ipBufferToString (34 tests) - Add tests/unit/languages.test.ts: bcp47ToIso639_3 (24 tests) - Add tests/unit/misc.test.ts: cleanAttribute, tryDecodeURIComponent, isScalarLike (23 tests) - Add tests/unit/pseudo-boolean.test.ts: PseudoBoolean.from (21 tests) - Add tests/unit/search-query.test.ts: parseSearchQuery (20 tests) - Add test:unit script to package.json - Fix tsconfig.json: add rootDir: src so build output goes to build/ not build/src/ Agent-Logs-Url: https://github.com/jina-ai/reader/sessions/58c83868-cb51-4d81-a656-d38455c51832 Co-authored-by: nomagick <565869+nomagick@users.noreply.github.com>
Agent-Logs-Url: https://github.com/jina-ai/reader/sessions/58c83868-cb51-4d81-a656-d38455c51832 Co-authored-by: nomagick <565869+nomagick@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
nomagick
April 16, 2026 10:05
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a proper unit test suite for
jina-ai/reader, targeting pure utility functions that can be tested without starting the server, Puppeteer, or making any network calls.Background
The existing
tests/e2e/suite uses supertest against a live server. While comprehensive for HTTP-level behaviour, it has no coverage for the many small pure functions insrc/utils/andsrc/lib/. This PR adds the missing layer.A secondary fix is included:
tsconfig.jsonwas missing"rootDir": "src", causingtscto output tobuild/src/…instead of the intendedbuild/…. This is corrected so all existing import paths (../../build/stand-alone/crawl.js, etc.) continue to work.Changes
tsconfig.json"rootDir": "src"so compiled output lands inbuild/as all existing code expectstests/run-unit.tsnode:test— no server startup requiredtests/unit/markdown.test.tstidyMarkdown(link normalisation, blank-line collapsing, whitespace stripping)tests/unit/ip.test.tsparseIp,parseCIDR,CIDR.test(),isIPInNonPublicRange,ipBufferToStringtests/unit/languages.test.tsbcp47ToIso639_3(BCP-47 → ISO 639-3 mapping)tests/unit/misc.test.tscleanAttribute,tryDecodeURIComponent,isScalarLiketests/unit/pseudo-boolean.test.tsPseudoBoolean.from(string/boolean/null coercion)tests/unit/search-query.test.tsparseSearchQuery(site:,-site:operators, mixed queries)package.jsontest:unitscriptRunning
Result: 139 tests, 0 failures.
Notes
test:unitscript runstsc -p tests/tsconfig.json && node tests-build/run-unit.js, matching the same pattern as the existingtest:e2escript.npm run buildscript still requireslicensed/GeoLite2-City.mmdbfor the integrity check; the unit tests work around this by runningtsc -p .(or relying on a pre-builtbuild/) directly.