Skip to content

[docs-utils] 1️⃣ Add unit tests and improve stats#247700

Merged
clintandrewhall merged 8 commits intoelastic:mainfrom
clintandrewhall:feat/docs-utils/1-test-coverage
Jan 15, 2026
Merged

[docs-utils] 1️⃣ Add unit tests and improve stats#247700
clintandrewhall merged 8 commits intoelastic:mainfrom
clintandrewhall:feat/docs-utils/1-test-coverage

Conversation

@clintandrewhall
Copy link
Copy Markdown
Contributor

Summary

This PR adds comprehensive unit test coverage for kbn-docs-utils and enhance API declarations with source location metadata.

Note

This PR is a subset of #247688 for ease of review.

This PR was written with Cursor and claude-4.5-opus-high.

API declaration improvements

  • Add lineNumber and columnNumber to ApiDeclaration type
  • Add getSourceLocationForNode() utility for source positions
  • Update buildBasicApiDeclaration to capture line/column info

Test infrastructure

  • Configure Jest coverage collection for src/**/*.{ts,tsx}
  • Add stats snapshot generation alongside other test snapshots
  • Add update_fixture_comments.js script for syncing expected issues comments in fixture files

Fixture updates

  • Expand test fixtures with additional API patterns
  • Add expected issues comments to fixture files
  • Regenerate snapshot files with new metadata

Test Coverage Report

This PR adds comprehensive unit test coverage for @kbn/docs-utils and enhances API declarations with source location metadata.

Coverage Comparison

Metric Before After Change
Lines 44.49% 82.66% +38.17%
Statements 44.31% 82.59% +38.28%
Functions 43.95% 90.08% +46.13%
Branches 45.08% 78.49% +33.41%
Total Tests 26 263 +237

Highlights

  • 10x increase in test count — from 26 to 263 tests
  • Function coverage improved by 46% — now at 90%
  • Refined Jest coverage configuration to focus on kbn-docs-utils source files

Files with 100% Line Coverage

  • src/stats.ts
  • src/trim_deleted_docs_from_nav.ts
  • src/get_paths_by_package.ts
  • src/get_plugin_api.ts
  • src/count_eslint_disable.ts
  • src/build_api_declarations/build_basic_api_declaration.ts
  • src/build_api_declarations/extract_import_refs.ts
  • src/build_api_declarations/js_doc_utils.ts
  • src/build_api_declarations/build_variable_dec.ts
  • src/build_api_declarations/build_call_signature_dec.ts
  • src/build_api_declarations/get_references.ts
  • src/mdx/build_plugin_deprecations_table.ts
  • src/mdx/get_all_doc_file_ids.ts
  • src/mdx/write_deprecations_doc_by_api.ts
  • src/mdx/write_deprecations_doc_by_plugin.ts
  • src/mdx/write_deprecations_due_by_team.ts
  • src/mdx/write_plugin_directory_doc.ts

Changes Included

  • Add comprehensive unit tests for all major modules
  • Add lineNumber and columnNumber to ApiDeclaration type
  • Add getSourceLocationForNode() utility
  • Configure Jest coverage collection for src/**/*.{ts,tsx}
  • Add test helper mocks in src/__test_helpers__/
  • Expand test fixtures with additional API patterns
  • Add stats snapshot generation

Add comprehensive unit test coverage for kbn-docs-utils and enhance
API declarations with source location metadata.

API declaration improvements:
- Add lineNumber and columnNumber to ApiDeclaration type
- Add getSourceLocationForNode() utility for source positions
- Update buildBasicApiDeclaration to capture line/column info

Test infrastructure:
- Configure Jest coverage collection for src/**/*.{ts,tsx}
- Add stats snapshot generation alongside other test snapshots
- Add update_fixture_comments.js script for syncing expected
  issues comments in fixture files

Fixture updates:
- Expand test fixtures with additional API patterns
- Add expected issues comments to fixture files
- Regenerate snapshot files with new metadata
@clintandrewhall clintandrewhall requested a review from a team December 31, 2025 20:59
@clintandrewhall clintandrewhall requested a review from a team as a code owner December 31, 2025 20:59
@clintandrewhall clintandrewhall added review Team:Operations Kibana-Operations Team release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting APIDocs Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// v9.4.0 labels Dec 31, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive unit test coverage for @kbn/docs-utils and enhances API declarations with source location metadata. The changes improve test coverage from 44% to 82% (10x increase in test count from 26 to 263 tests) and add lineNumber and columnNumber fields to ApiDeclaration for better navigation.

Key changes:

  • Enhanced ApiDeclaration type with source position metadata
  • Added getSourceLocationForNode() utility function
  • Comprehensive unit tests for core functionality
  • Bug fixes in deprecation table generation (slice vs splice)
  • Stats snapshot generation for validation
  • Test fixture expansion with expected issues comments
  • Jest coverage configuration improvements

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/kbn-docs-utils/src/types.ts Added lineNumber and columnNumber optional fields to ApiDeclaration
packages/kbn-docs-utils/src/build_api_declarations/utils.ts Added getSourceLocationForNode() utility to extract source positions
packages/kbn-docs-utils/src/utils.test.ts Added 370+ lines of comprehensive unit tests
packages/kbn-docs-utils/src/stats.test.ts Added 700 lines of stats collection tests
packages/kbn-docs-utils/src/trim_deleted_docs_from_nav.test.ts Added nav trimming tests
packages/kbn-docs-utils/src/mdx/*.test.ts Added extensive MDX generation tests
packages/kbn-docs-utils/src/mdx/*_due_by_team.ts Fixed slice/splice bug in reference truncation
packages/kbn-docs-utils/src/mdx/*_doc_by_plugin.ts Fixed slice/splice bug
packages/kbn-docs-utils/src/mdx/build_plugin_deprecations_table.ts Fixed slice/splice bug and removed unused params
packages/kbn-docs-utils/src/integration_tests/api_doc_suite.test.ts Added validation tests and stats snapshot generation
packages/kbn-docs-utils/src/integration_tests/__fixtures__/**/*.ts Added expected issues comments to fixture files
packages/kbn-docs-utils/src/integration_tests/snapshots/*.json Updated with lineNumber/columnNumber metadata
packages/kbn-docs-utils/src/integration_tests/snapshots/*.mdx Updated date fields to 2025-12-31
packages/kbn-docs-utils/jest.integration.config.js Added coverage configuration
Various new test files Added unit tests for find_plugins, get_paths_by_package, get_plugin_api_map, get_declaration_nodes_for_plugin

@clintandrewhall clintandrewhall enabled auto-merge (squash) January 15, 2026 17:33
@clintandrewhall clintandrewhall merged commit f5d5c82 into elastic:main Jan 15, 2026
13 checks passed
@clintandrewhall clintandrewhall deleted the feat/docs-utils/1-test-coverage branch January 15, 2026 21:16
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #43 / serverless security UI Security ML Trained models list page navigation renders trained models list

Metrics [docs]

✅ unchanged

History

@clintandrewhall clintandrewhall changed the title [kbn-docs-utils] Phase 1: Add unit tests and improve stats [docs-utils] 1️⃣ Add unit tests and improve stats Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

APIDocs backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes review Team:Operations Kibana-Operations Team Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants