Skip to content

Conversation

@danielsitek
Copy link
Owner

@danielsitek danielsitek commented Nov 9, 2025

This pull request significantly expands the test coverage for the gulpTateruCli plugin in src/index.spec.ts. The new tests cover various edge cases, error handling, and integration scenarios to ensure the plugin behaves correctly under different conditions and with different configuration options.

Expanded test coverage and validation:

  • Added tests to verify that null files are passed through the plugin without processing, and that errors from the core function are properly emitted as PluginError instances.
  • Added tests for handling the env option independently, and for simultaneous use of custom formatter and minify functions, ensuring they work together as expected.
  • Introduced tests to confirm the correct handling of various file types, and to ensure that generated Vinyl files have the correct properties set.

Robustness and edge-case handling:

  • Added tests to check that the plugin gracefully handles nonexistent pages and languages by not generating any files.
  • Included tests for asynchronous custom formatter and minify functions to ensure the plugin supports async processing.

Summary by CodeRabbit

  • Tests
    • Added extensive test coverage for stream-based flows, including null-file passthrough, error propagation and PluginError behavior, environment-specific runs, and handling of missing pages/languages (zero outputs).
    • Validates formatter+minifier integration (sync and async), multi-file-type processing, produced file metadata and buffer contents, and various page/env/lang combinations with event-driven assertions.

@coderabbitai
Copy link

coderabbitai bot commented Nov 9, 2025

Walkthrough

Adds a comprehensive suite of tests to src/index.spec.ts validating gulpTateruCli behavior across null-file passthrough, error handling, env isolation, formatter/minify (sync & async), multi-file-type handling, Vinyl properties, and missing page/lang cases. No production code changed.

Changes

Cohort / File(s) Summary
Test suite expansion
src/index.spec.ts
Adds ~9+ tests exercising: null-file passthrough; invalid core config → PluginError (with plugin field); env option isolation; combined formatter + minify (sync & async) and output formatting; formatter invoked for multiple file types (html, txt, xml, webmanifest); Vinyl properties (path, base, cwd, Buffer contents); nonexistent page → zero outputs; nonexistent language → zero outputs. Tests use streams, events, and callbacks.

Sequence Diagram(s)

No sequence diagram — changes are test additions only and do not alter runtime control flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single test file with repeated patterns; focus on correctness of assertions and async handling.
  • Pay attention to:
    • PluginError assertions and the plugin field.
    • Proper use of test callbacks/promises to avoid flakiness.
    • Formatter/minify output assertions and multi-file-type coverage.

Possibly related PRs

  • Updated naming #2 — Related rename/export changes for gulpTateruCli/PLUGIN_NAME that tests reference.
  • Github actions #1 — Earlier test-suite edits to src/index.spec.ts with overlapping coverage.

Poem

🐇 I hopped through streams and ran each case,

Buffers snug, errors found their place,
Formatter danced and minify spun,
Pages checked till testing's done,
A carrot cheer — the suite's embrace 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Better test coverage' is too vague and generic; it does not convey specific information about what tests were added or what the changeset improves. Consider a more descriptive title that highlights the main testing improvement, such as 'Add comprehensive test coverage for error handling and formatter/minify integration' or 'Expand tests for null files, PluginError, and custom callbacks'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/ds-better-test-coverage

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dab6f6b and a8faabf.

📒 Files selected for processing (1)
  • src/index.spec.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.spec.ts (1)
src/index.ts (3)
  • gulpTateruCli (63-108)
  • Formatter (12-15)
  • Minify (23-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (9)
src/index.spec.ts (9)

193-207: Excellent null file passthrough test.

This test correctly verifies that null files are passed through unchanged, matching the production code behavior. Using toBe() ensures the exact same instance is returned.


248-266: LGTM: Clean integration test for env option.

This test properly verifies that the env option works independently, following the established pattern.


268-298: Excellent integration test for formatter and minify together.

The test correctly verifies both functions are applied: the formatter prefix confirms formatting occurred, and the whitespace assertion confirms minification worked. The assertions are well-chosen.


300-324: Well-designed test capturing file type handling.

The use of a formatter that captures the fileType parameter is an elegant way to verify multiple file types are processed. The defensive fileType ?? 'unknown' properly handles the optional parameter.


326-349: Comprehensive Vinyl properties validation.

This test provides good coverage of the essential Vinyl file properties that downstream gulp plugins depend on. The assertions are appropriate.


351-370: Valuable edge case test.

This test ensures the plugin gracefully handles nonexistent pages by generating zero files rather than crashing or producing errors. Good defensive coverage.


372-391: Good parallel edge case for nonexistent language.

This test mirrors the nonexistent page test and ensures consistent graceful handling across different option types.


393-431: Excellent async formatter and minify test.

This test properly simulates asynchronous operations and correctly verifies both functions execute. The assertions are accurate: the formatter prefix confirms formatting, and the complete absence of whitespace confirms minification (since this minify removes all whitespace, not just collapses it).


209-246: Request manual verification of test scenario reliability.

The error handling in the plugin implementation is correct—errors from core() are properly caught and wrapped in PluginError with the correct plugin name. However, the test's assumption that the specific scenario triggers a core() error needs verification.

Looking at other tests in the same file, there's a pattern where invalid configurations (nonexistent page, nonexistent language) return gracefully with 0 files rather than throwing errors. This suggests core() may handle the invalid cwd path and nonexistent template similarly—returning gracefully instead of throwing. If so, the test won't catch an error as intended.

Confirm whether calling core() with an invalid cwd path or nonexistent template paths actually throws an error, or if it handles these conditions gracefully like other invalid configurations.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Nov 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2a9fa47) to head (a8faabf).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##             main        #5       +/-   ##
============================================
+ Coverage   90.00%   100.00%   +10.00%     
============================================
  Files           1         1               
  Lines          20        20               
  Branches        3         3               
============================================
+ Hits           18        20        +2     
+ Misses          2         0        -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/index.spec.ts (1)

209-246: Clarify the error source in the test comment.

The test comment on line 213 states "Using an invalid cwd path should cause an error in core", but the actual error is likely triggered by the nonexistent template file (nonexistent.html.twig) rather than the invalid cwd path alone. The test will still function correctly, but the comment could mislead future maintainers about what's actually being tested.

Consider updating the comment to:

-    // Create a config that will cause core() to fail
-    // Using an invalid cwd path should cause an error in core
+    // Create a config that will cause core() to fail
+    // Using nonexistent template paths should cause an error in core
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a9fa47 and 0094f38.

📒 Files selected for processing (1)
  • src/index.spec.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.spec.ts (1)
src/index.ts (3)
  • gulpTateruCli (63-108)
  • Formatter (12-15)
  • Minify (23-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (8)
src/index.spec.ts (8)

193-207: LGTM! Null file passthrough verified correctly.

This test correctly verifies that null Vinyl files pass through unchanged, which aligns with the implementation in src/index.ts (lines 67-69).


248-266: LGTM! Env option test is clean and focused.

This test appropriately validates the env option in isolation, following the established test pattern.


268-298: LGTM! Combined formatter and minify test is well-structured.

This test correctly validates that both formatter and minify functions can work together, with appropriate assertions for each transformation.


300-324: LGTM! File type handling test provides good coverage.

This test effectively validates that different file types (html, txt, xml, webmanifest) are correctly passed to the formatter function.


326-349: LGTM! Vinyl file properties are properly validated.

This test provides good sanity checks for generated Vinyl files, ensuring they have the expected structure and properties.


351-370: LGTM! Nonexistent page handling is verified.

This test correctly validates graceful handling of nonexistent pages, expecting zero files without errors.


372-391: LGTM! Nonexistent language handling is verified.

This test appropriately validates graceful handling of nonexistent languages, mirroring the nonexistent page test pattern.


393-431: LGTM! Async formatter and minify functions are properly tested.

This test effectively validates that asynchronous formatter and minify functions work correctly, with appropriate async simulation and verification of both transformations.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/index.spec.ts (1)

209-246: Consider clarifying the error trigger source.

The test correctly validates that errors from the core function are wrapped in PluginError with the proper plugin name. However, the comment at line 213 suggests the invalid cwd path causes the error, but the nonexistent template file ('nonexistent.html.twig') might be the actual trigger. Consider updating the comment to reflect that any invalid configuration will cause an error, or verify which specific element triggers the failure.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90eeb9c and dab6f6b.

📒 Files selected for processing (1)
  • src/index.spec.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.spec.ts (1)
src/index.ts (3)
  • gulpTateruCli (63-108)
  • Formatter (12-15)
  • Minify (23-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (8)
src/index.spec.ts (8)

193-207: LGTM! Null file passthrough test is well-structured.

The test correctly verifies that null files pass through unchanged, aligning with the production code behavior at lines 65-67 in src/index.ts.


248-266: LGTM! Good isolation of the env option.

This test appropriately validates the env option in isolation, complementing the existing multi-option test and improving overall coverage.


268-298: LGTM! Excellent integration test for formatter and minify.

The test correctly validates that both formatter and minify functions work together, with appropriate assertions checking both the formatter prefix and the minification effect on whitespace.


300-324: LGTM! Comprehensive file type coverage validation.

The test effectively validates that the formatter is invoked for multiple file types, with good defensive coding in the test double at line 303 handling the optional fileType parameter.


326-349: LGTM! Proper validation of Vinyl file properties.

The test correctly verifies that generated files are properly structured Vinyl instances with appropriate properties, aligning with the production code's Vinyl file creation logic.


351-370: LGTM! Good edge case coverage for nonexistent pages.

The test appropriately validates that requesting a nonexistent page generates zero files without throwing errors, demonstrating graceful handling of invalid page references.


372-391: LGTM! Good edge case coverage for nonexistent languages.

The test appropriately validates that requesting a nonexistent language generates zero files without errors, complementing the nonexistent page test and ensuring robust edge case handling.


393-431: LGTM! Validates async formatter and minify handling.

The test correctly validates that asynchronous formatter and minify functions work properly. The use of setTimeout effectively simulates real async operations, and both transformations are appropriately verified.

Note: The 1ms timeout is sufficiently short that flakiness is unlikely, but if test instability occurs in CI environments under heavy load, consider increasing the delay slightly.

@danielsitek danielsitek merged commit 3e20caf into main Nov 9, 2025
12 checks passed
@danielsitek danielsitek deleted the feature/ds-better-test-coverage branch November 9, 2025 18:00
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.

1 participant