Skip to content

test: scaffold Vitest and add initial test suite (100% coverage)#5

Draft
JoseFredes wants to merge 1 commit into
mainfrom
claude/analyze-test-coverage-Ra5Xx
Draft

test: scaffold Vitest and add initial test suite (100% coverage)#5
JoseFredes wants to merge 1 commit into
mainfrom
claude/analyze-test-coverage-Ra5Xx

Conversation

@JoseFredes
Copy link
Copy Markdown
Owner

Summary

The repo had no tests and npm test was a placeholder. This PR sets up a test runner and adds an initial suite that brings line/branch/function coverage on src/ to 100%.

  • Tooling: Vitest + jsdom + @testing-library/react + @vue/test-utils + @vitest/coverage-v8. New scripts: npm test, npm run test:watch, npm run test:coverage.
  • core.ts (test/core.test.ts, 27 tests): input validation (null/undefined/primitives, missing type, the VALID_HTML_TAG regex against attribute-injection attempts like "div onclick=..." and "<script>"), className/style handling, attribute coercion (numeric/boolean/null), event handler wiring + name normalization, and XSS-safe text children.
  • Adapters: parity-style tests for the generic, React, and Vue adapters covering rendering, nested children, event wiring, and HTML-escape behavior.
  • .gitignore fix: the existing .gitIgnore (capital I) was not matched on Linux, so node_modules/ was effectively unignored and node_modules/.package-lock.json was tracked. Renamed to .gitignore, added coverage/, untracked the stray file.

Coverage

File               | % Stmts | % Branch | % Funcs | % Lines
-------------------|---------|----------|---------|--------
All files          |     100 |      100 |     100 |     100
 core.ts           |     100 |      100 |     100 |     100
 generic-adapter   |     100 |      100 |     100 |     100
 react-adapter     |     100 |      100 |     100 |     100
 vue-adapter       |     100 |      100 |     100 |     100

Follow-ups (not in this PR)

  • CI workflow to run npm test on PRs and gate on coverage.
  • Cross-adapter parity tests asserting equivalent output from the same JSON across all three.
  • Property-based fuzzing of renderComponentFromJSON with fast-check.
  • .d.ts drift check (tsd / expect-type) — types/jbricks.d.ts types renderVueComponent as object, while the source returns a defineComponent result.
  • Style-key edge case: core.ts assigns style keys via bracket assignment, which silently no-ops for kebab-case keys (e.g. "background-color"); worth deciding whether to support that and adding a regression test.

Test plan

  • npm test passes (40/40)
  • npm run test:coverage reports 100%
  • CI workflow added in a follow-up PR

Generated by Claude Code

- Add Vitest + jsdom + @testing-library/react + @vue/test-utils as devDeps
- Wire `npm test`, `test:watch`, `test:coverage` scripts
- Add tests for core renderer (validation, props, style, events, attributes, XSS-safe text children)
- Add adapter tests (generic, React, Vue 3) covering rendering, event wiring, and HTML-escape behavior
- 40 tests, 100% line/branch/function coverage on src/
- Fix `.gitIgnore` casing so node_modules and dist are actually ignored on Linux; add coverage/
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