Skip to content

Conversation

@tommie
Copy link
Contributor

@tommie tommie commented Jul 25, 2024

Adds Jest as a test framework and tests for JSON parsing.

Closes #646.

Summary by CodeRabbit

  • Tests

    • Added Jest-based tests and new CI test job; pre-commit now runs tests before building
    • Test script updated to run tests then lint
  • Chores

    • Updated development dependencies and TypeScript config (build root adjusted)
  • Refactor

    • Internal initialization and input parsing logic refined (minor behavioral change)

tommie added 2 commits July 25, 2024 09:30
JSON is a subset of YAML, making it redundant.
Makes tools into a function to be able to mock it.
It does not need to be exported.
@EndBug EndBug added the status: pinned Should not be labeled as stale label Aug 1, 2024
@EndBug EndBug requested a review from Copilot October 30, 2025 21:21
Copy link

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 Jest-based unit testing infrastructure to the project and modifies the toolkit initialization to be lazy-loaded. The changes enable proper testing of utility functions that previously required GitHub Actions environment variables at module load time.

Key changes:

  • Converted toolkit initialization from eager to lazy loading to support testing
  • Removed redundant JSON parsing step from parseInputArray (YAML parser handles JSON)
  • Added Jest testing framework with configuration and CI integration

Reviewed Changes

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

Show a summary per file
File Description
tsconfig.json Changed rootDir to "." to support compiling test files
src/util.ts Refactored toolkit to lazy initialization and simplified parseInputArray to only use YAML parser
test/util.test.ts Added unit tests for parseInputArray function with environment setup
package.json Added jest dependencies and updated test scripts
jest.config.js Added Jest configuration for ts-jest
.husky/pre-commit Added test execution to pre-commit hook
.github/workflows/test.yml Added CI test job

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Walkthrough

Adds Jest-based tests and CI Test job, updates pre-commit to run tests, introduces jest.config.js, refactors src/util.ts for lazy Toolkit initialization and removes JSON parsing in parseInputArray, adds tests for parseInputArray, and adjusts tsconfig rootDir.

Changes

Cohort / File(s) Summary
CI workflow
.github/workflows/test.yml
Adds a new parallel Test job running checkout, setup-node (with npm cache), npm ci, and npm run test.
Pre-commit hook
.husky/pre-commit
Injects npm run test before the existing build and git add lib steps so tests run prior to build.
Jest config & test runner
jest.config.js, package.json
Adds jest.config.js using ts-jest preset and node env. Updates package.json to replace the placeholder test script with jest && npm run lint, removes pretest/posttest hooks, and adds devDependencies (jest, ts-jest, @types/jest, eslint-plugin-prettier).
Util refactor
src/util.ts
Converts exported module-level tools into an internal, lazily-initialized variable with a getToolkit() accessor; removes the JSON-parse fallback from parseInputArray, relying on YAML parsing and single-element fallback.
Tests added
test/util.test.ts
Adds tests for parseInputArray covering array parsing, single-string passthrough, non-string elements, and invalid JSON-like input behavior.
TypeScript config
tsconfig.json
Changes compilerOptions.rootDir from "./src" to "."; other options unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller as caller
  participant Util as src/util.ts
  participant Toolkit as Toolkit (init)

  rect rgb(240,248,255)
  note right of Util: getToolkit lazy-init flow
  Caller->>Util: call getToolkit() / getUserInfo()
  alt tools undefined
    Util->>Toolkit: new Toolkit(...)
    Toolkit-->>Util: Toolkit instance
    Util-->>Caller: return tools
  else tools defined
    Util-->>Caller: return existing tools
  end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review lazy initialization in src/util.ts for thread-safety and side-effects.
  • Verify parseInputArray removal of JSON fallback matches intended behavior and tests.
  • Confirm jest.config.js + package.json scripts/deps work in CI job and that tsconfig.json rootDir change doesn't break builds.

"I hop and I test with a twitch of my nose,
Jest runs the fields where the green coverage grows,
Toolkit sleeps till it's called with a cheer,
No stray JSON ghosts will be hopping near,
A bunny-approved change — quick, bright, and clear!" 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several changes extend beyond removing JSON parsing: Jest testing framework added, pre-commit hook updated, tsconfig rootDir modified, and tools lazy-initialization introduced. Clarify whether testing infrastructure setup, pre-commit changes, and tsconfig modifications align with project requirements or should be addressed in separate PRs.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly matches the main objective: removing redundant JSON array parsing as described in the changeset.
Linked Issues check ✅ Passed The PR successfully removes JSON parsing logic from parseInputArray while preserving YAML parsing, directly addressing issue #646's requirement.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 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 3da7387 and dbf7245.

📒 Files selected for processing (1)
  • .github/workflows/test.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/test.yml
⏰ 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: Build

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.

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: 1

🧹 Nitpick comments (1)
.github/workflows/test.yml (1)

23-27: Update action versions for consistency.

The Test job uses older action versions (v4) while the Build and Lint jobs use newer versions (v5/v6). This inconsistency can lead to unexpected behavior and maintenance overhead.

Apply this diff to align with the other jobs:

-      - uses: actions/checkout@v4
-      - uses: actions/setup-node@v4
+      - uses: actions/checkout@v5
+      - uses: actions/setup-node@v6
         with:
           cache: npm
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c59d9b8 and 3da7387.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • .github/workflows/test.yml (1 hunks)
  • .husky/pre-commit (1 hunks)
  • jest.config.js (1 hunks)
  • package.json (2 hunks)
  • src/util.ts (2 hunks)
  • test/util.test.ts (1 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
test/util.test.ts (1)
src/util.ts (1)
  • parseInputArray (83-95)
src/util.ts (1)
src/io.ts (2)
  • input (25-25)
  • output (35-35)
🪛 actionlint (1.7.8)
.github/workflows/test.yml

21-21: label "ubuntu-20.04" is unknown. available labels are "windows-latest", "windows-latest-8-cores", "windows-2025", "windows-2022", "windows-11-arm", "ubuntu-latest", "ubuntu-latest-4-cores", "ubuntu-latest-8-cores", "ubuntu-latest-16-cores", "ubuntu-24.04", "ubuntu-24.04-arm", "ubuntu-22.04", "ubuntu-22.04-arm", "macos-latest", "macos-latest-xl", "macos-latest-xlarge", "macos-latest-large", "macos-26-xlarge", "macos-26", "macos-15-intel", "macos-15-xlarge", "macos-15-large", "macos-15", "macos-14-xl", "macos-14-xlarge", "macos-14-large", "macos-14", "macos-13-xl", "macos-13-xlarge", "macos-13-large", "macos-13", "self-hosted", "x64", "arm", "arm64", "linux", "macos", "windows". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file

(runner-label)

🔇 Additional comments (9)
tsconfig.json (1)

4-4: LGTM! Root directory change enables test compilation.

The change from "./src" to "." allows TypeScript to properly compile test files alongside source files, which is necessary for the Jest testing infrastructure being introduced.

package.json (2)

12-12: LGTM! Test script properly chains Jest and linting.

The test script correctly runs Jest tests followed by linting, ensuring code quality checks happen after functional tests pass.


24-34: LGTM! Jest dependencies are appropriate.

All necessary dependencies for Jest with TypeScript support are correctly added:

  • jest and @types/jest for the test framework
  • ts-jest for TypeScript transformation
  • eslint-plugin-prettier for code formatting
.husky/pre-commit (1)

1-3: LGTM! Pre-commit hook now validates tests before build.

Running tests before building ensures that broken code cannot be committed, improving code quality and reducing CI failures.

test/util.test.ts (2)

4-16: LGTM! Environment setup ensures Toolkit initialization works.

The environment variable setup in beforeAll provides the required GitHub context variables that the Toolkit needs, preventing initialization errors during tests.


18-32: LGTM! Comprehensive test coverage for parseInputArray.

The test suite effectively covers all critical paths:

  • Valid YAML/JSON string arrays
  • Single string inputs (fallback behavior)
  • Non-string elements (type validation)
  • Invalid input (error handling)

This validates the YAML-only parsing approach and confirms JSON arrays work through YAML parsing.

jest.config.js (1)

1-5: LGTM! Jest configuration is appropriate.

The minimal configuration with ts-jest preset and node environment is perfect for testing GitHub Actions TypeScript code.

src/util.ts (2)

9-23: LGTM! Lazy initialization prevents import side effects.

The lazy initialization pattern through getToolkit() is a good improvement that avoids side effects during module import, making tests cleaner and stack traces more coherent (as discussed in past review comments).


80-95: LGTM! Redundant JSON parsing successfully removed.

The removal of the separate JSON parsing path is correct because YAML is a superset of JSON, so YAML.load() can parse JSON arrays natively. The test suite confirms this works correctly for:

  • JSON arrays: ["a", "bcd"]
  • Single strings: "hello" (falls back to single-element array)
  • Non-string elements: [42] (falls back to single-element array)
  • Invalid input: " (falls back to single-element array)

This change fulfills the PR objective of removing redundant JSON parsing while maintaining all necessary functionality.

@EndBug EndBug merged commit 1c95e2b into EndBug:main Nov 12, 2025
7 of 8 checks passed
@EndBug
Copy link
Owner

EndBug commented Nov 12, 2025

@all-contributors please add @tommie for their code and test contribution

@allcontributors
Copy link
Contributor

@EndBug

I've put up a pull request to add @tommie! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: pinned Should not be labeled as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON parsing is redundant

2 participants