Skip to content

feat: add unit tests for pure utility functions#1245

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/analyze-e2e-testing-infra
Draft

feat: add unit tests for pure utility functions#1245
Copilot wants to merge 2 commits intomainfrom
copilot/analyze-e2e-testing-infra

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 16, 2026

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 in src/utils/ and src/lib/. This PR adds the missing layer.

A secondary fix is included: tsconfig.json was missing "rootDir": "src", causing tsc to output to build/src/… instead of the intended build/…. This is corrected so all existing import paths (../../build/stand-alone/crawl.js, etc.) continue to work.

Changes

File Description
tsconfig.json Added "rootDir": "src" so compiled output lands in build/ as all existing code expects
tests/run-unit.ts Lightweight test runner using node:test — no server startup required
tests/unit/markdown.test.ts 17 tests for tidyMarkdown (link normalisation, blank-line collapsing, whitespace stripping)
tests/unit/ip.test.ts 34 tests for parseIp, parseCIDR, CIDR.test(), isIPInNonPublicRange, ipBufferToString
tests/unit/languages.test.ts 24 tests for bcp47ToIso639_3 (BCP-47 → ISO 639-3 mapping)
tests/unit/misc.test.ts 23 tests for cleanAttribute, tryDecodeURIComponent, isScalarLike
tests/unit/pseudo-boolean.test.ts 21 tests for PseudoBoolean.from (string/boolean/null coercion)
tests/unit/search-query.test.ts 20 tests for parseSearchQuery (site:, -site: operators, mixed queries)
package.json Added test:unit script

Running

npm run test:unit

Result: 139 tests, 0 failures.

Notes

  • The test:unit script runs tsc -p tests/tsconfig.json && node tests-build/run-unit.js, matching the same pattern as the existing test:e2e script.
  • The npm run build script still requires licensed/GeoLite2-City.mmdb for the integrity check; the unit tests work around this by running tsc -p . (or relying on a pre-built build/) directly.

Copilot AI and others added 2 commits April 16, 2026 09:57
- 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>
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