Skip to content

Add minimal test coverage for @kubb/renderer-jsx#3008

Merged
stijnvanhulle merged 7 commits intomainfrom
copilot/add-extra-test-cases
Apr 7, 2026
Merged

Add minimal test coverage for @kubb/renderer-jsx#3008
stijnvanhulle merged 7 commits intomainfrom
copilot/add-extra-test-cases

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

Adds tests covering every component, utility, and helper in @kubb/renderer-jsx. Prior to this, only dom.ts had tests (16 tests). Coverage now spans 41 tests across 9 files, focused on non-obvious behavior and edge cases rather than happy-flow repetition.

🎯 Changes

  • vitest.config.ts — Added tsconfigPaths() plugin to enable .tsx test files and resolve workspace packages (@kubb/ast, @kubb/renderer-jsx/jsx-dev-runtime, etc.)

  • src/types.ts — Extended DOMNodeAttribute to include Array<unknown> (arrays are a valid attribute value used throughout, e.g. name={['Pet']} on File.Export; the renderer was already casting with as DOMNodeAttribute)

  • src/utils.test.ts (12 tests) — Unit tests for squashSourceNodes, squashExportNodes, squashImportNodes, and processFiles, covering node attribute collection, child element kind mapping, edge cases (br → Break, empty jsx, whitespace-only text, ignore list), and file traversal. Uses assert() from vitest to narrow | undefined after Set iterator destructuring.

  • src/createRenderer.test.tsx (2 tests) — Integration test rendering two files in a single pass (models.ts with a Type node + import + export, and client.ts with Const and Function nodes), verifying all collected metadata across both files; plus error propagation test

  • src/context.test.ts (2 tests) — One provide/inject round-trip test per context key (KubbContext, OasContext)

  • src/components/Const.test.tsx (1 test) — Verifies Const emits a Const node

  • src/components/Type.test.tsx (2 tests) — Verifies Type emits a Type node and throws when name does not start with an uppercase letter

  • src/components/Function.test.tsx (2 tests) — Verifies Function emits a Function node and Function.Arrow emits an ArrowFunction node

  • src/components/File.test.tsx (3 tests) — Verifies File.Source / File.Import / File.Export attribute registration

  • src/components/Jsx.test.tsx (1 test) — Verifies Jsx node emission inside a function body

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is for the docs (no release).

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 7, 2026

⚠️ No Changeset found

Latest commit: ce10913

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Agent-Logs-Url: https://github.com/kubb-labs/kubb/sessions/2b69a291-e774-4c12-be40-53dea961337c

Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Copilot AI changed the title [WIP] Add extra test cases for @kubb/renderer-jsx components Add comprehensive test coverage for @kubb/renderer-jsx Apr 7, 2026
Copilot AI requested a review from stijnvanhulle April 7, 2026 20:20
@stijnvanhulle stijnvanhulle marked this pull request as ready for review April 7, 2026 20:31
@autofix-ci
Copy link
Copy Markdown
Contributor

autofix-ci bot commented Apr 7, 2026

Auto fix applied for linting and formating

@dosubot dosubot bot added enhancement New feature or request typescript labels Apr 7, 2026
@stijnvanhulle
Copy link
Copy Markdown
Collaborator

@copilot keep the amount of test cases to the miminal of what is needed. No need to have 'happy flow' test cases

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 7, 2026

More templates

@kubb/adapter-oas

npm i https://pkg.pr.new/@kubb/adapter-oas@3008

@kubb/agent

npm i https://pkg.pr.new/@kubb/agent@3008

@kubb/ast

npm i https://pkg.pr.new/@kubb/ast@3008

@kubb/cli

npm i https://pkg.pr.new/@kubb/cli@3008

@kubb/core

npm i https://pkg.pr.new/@kubb/core@3008

kubb

npm i https://pkg.pr.new/kubb@3008

@kubb/mcp

npm i https://pkg.pr.new/@kubb/mcp@3008

@kubb/oas

npm i https://pkg.pr.new/@kubb/oas@3008

@kubb/parser-ts

npm i https://pkg.pr.new/@kubb/parser-ts@3008

@kubb/plugin-client

npm i https://pkg.pr.new/@kubb/plugin-client@3008

@kubb/plugin-cypress

npm i https://pkg.pr.new/@kubb/plugin-cypress@3008

@kubb/plugin-faker

npm i https://pkg.pr.new/@kubb/plugin-faker@3008

@kubb/plugin-mcp

npm i https://pkg.pr.new/@kubb/plugin-mcp@3008

@kubb/plugin-msw

npm i https://pkg.pr.new/@kubb/plugin-msw@3008

@kubb/plugin-oas

npm i https://pkg.pr.new/@kubb/plugin-oas@3008

@kubb/plugin-react-query

npm i https://pkg.pr.new/@kubb/plugin-react-query@3008

@kubb/plugin-redoc

npm i https://pkg.pr.new/@kubb/plugin-redoc@3008

@kubb/plugin-solid-query

npm i https://pkg.pr.new/@kubb/plugin-solid-query@3008

@kubb/plugin-svelte-query

npm i https://pkg.pr.new/@kubb/plugin-svelte-query@3008

@kubb/plugin-swr

npm i https://pkg.pr.new/@kubb/plugin-swr@3008

@kubb/plugin-ts

npm i https://pkg.pr.new/@kubb/plugin-ts@3008

@kubb/plugin-vue-query

npm i https://pkg.pr.new/@kubb/plugin-vue-query@3008

@kubb/plugin-zod

npm i https://pkg.pr.new/@kubb/plugin-zod@3008

@kubb/renderer-jsx

npm i https://pkg.pr.new/@kubb/renderer-jsx@3008

unplugin-kubb

npm i https://pkg.pr.new/unplugin-kubb@3008

commit: ce10913

Agent-Logs-Url: https://github.com/kubb-labs/kubb/sessions/ce7f1032-d44a-4927-81d6-c8e3b2065cd9

Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
})
})

describe('File component', () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot have component tests cases as part of the component file itself like Const.test.ta

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in e203392. Component tests are now co-located: Const.test.tsx, Type.test.tsx, Function.test.tsx, File.test.tsx, Jsx.test.tsx. createRenderer.test.tsx now only covers the renderer lifecycle (render + error propagation).

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 7, 2026

@copilot keep the amount of test cases to the miminal of what is needed. No need to have 'happy flow' test cases

Reduced to 42 tests total (down from 95) in commit bc18077. Removed all redundant happy-flow variants — each component/function now has one representative test, keeping only non-obvious behavior (error propagation, missing baseName inline render, child node kind mapping, Type lowercase name guard, etc.).

Copilot AI changed the title Add comprehensive test coverage for @kubb/renderer-jsx Add minimal test coverage for @kubb/renderer-jsx Apr 7, 2026
Copilot AI requested a review from stijnvanhulle April 7, 2026 20:44
Agent-Logs-Url: https://github.com/kubb-labs/kubb/sessions/ca825e3c-50cd-4a1e-b228-770c60244f95

Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@stijnvanhulle stijnvanhulle left a comment

Choose a reason for hiding this comment

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

@copilot also add integration test for createRenderer

import { File } from './File.tsx'

describe('File', () => {
it('should render children inline when baseName is missing', async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 5c366ba.

Agent-Logs-Url: https://github.com/kubb-labs/kubb/sessions/ec9f42b6-3109-4fc4-afc2-48802f59fbef

Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 7, 2026

@copilot also add integration test for createRenderer

Added in 5c366ba. The integration test renders two files in a single pass — models.ts (with a Type node, import, and export) and client.ts (with Const and Function nodes) — and verifies all collected metadata across both files.

@copilot keep the amount of test cases to the miminal of what is needed. No need to have 'happy flow' test cases

Down to 41 tests total. Each component has one minimal test (only non-trivial behavior), and the createRenderer test is now a single integration test that exercises multiple components together rather than individual happy-flow cases.

@stijnvanhulle
Copy link
Copy Markdown
Collaborator

@copilot fix typecheck issues and validate the changes and see if we can improve

Agent-Logs-Url: https://github.com/kubb-labs/kubb/sessions/5a8f0df2-e75b-4975-8f5a-5aedcb58a968

Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 7, 2026

@copilot fix typecheck issues and validate the changes and see if we can improve

Fixed in ce10913. Three categories of errors addressed:

  1. types.ts — Added Array<unknown> to DOMNodeAttribute union (arrays are a valid attribute value already used by File.Export/File.Import props; the renderer was already casting with as DOMNodeAttribute).

  2. utils.test.ts — Added assert(node) / assert(node.nodes) after Set iterator destructuring to narrow SourceNode | undefinedSourceNode, and Array<CodeNode> | undefinedArray<CodeNode>. Added assert to the vitest import.

  3. All component tests + createRenderer.test.tsx — Changed ?.nodes[0]?.kind?.nodes?.[0]?.kind because SourceNode.nodes is an optional field (nodes?: Array<CodeNode>), so the intermediate value could be undefined before the index access.

Typecheck now exits clean with 0 errors; all 41 tests pass.

@stijnvanhulle stijnvanhulle merged commit 33e3db5 into main Apr 7, 2026
17 of 18 checks passed
@stijnvanhulle stijnvanhulle deleted the copilot/add-extra-test-cases branch April 7, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants