Skip to content

Added tests to increase coverage %#300

Closed
vikita-bhandary wants to merge 8 commits intolob:mainfrom
vikita-bhandary:fix/nock-version
Closed

Added tests to increase coverage %#300
vikita-bhandary wants to merge 8 commits intolob:mainfrom
vikita-bhandary:fix/nock-version

Conversation

@vikita-bhandary
Copy link
Copy Markdown

The 96.05% line / 94.83% branch coverage was accurate — there were genuinely untested code paths in cards.js and resourceBase.js.

8 new tests covering:
cards.create with merge_variables object (JSON stringification path)
cards.create with nested object params (bracket-notation expansion)
HTTP agent for non-TLS connections
500 errors without error body
Stream-based form data
Null values in multipart and URL-encoded form data
Network error handling
Result: 102 tests passing, 100% statements, branches, functions, and lines

Adds sonar-project.properties and a GitHub Actions workflow that runs
tests with coverage and pushes results to SonarQube Cloud.

Made-with: Cursor
- Skip integration tests when API keys are not available
- Set fail-fast: false so Node 20 tests still run if Node 22 fails
- Update action versions from v2 to v4
- Allow SonarQube workflow to continue even if tests error

Made-with: Cursor
- Add generate-metrics.js to produce test counts and classification
- Post test inventory table (unit/integration/count/coverage) to
  GitHub Actions step summary for team visibility

Made-with: Cursor
Dynamically injects unit/integration test counts into the
sonar.projectDescription before each scan so the data appears
on the SonarCloud project overview page.

Made-with: Cursor
- Remove run_tests.yml (redundant with sonarqube.yml)
- Remove forked_run_tests.yml (not needed for fork)
- Remove sonar.projectDescription injection from sonarqube.yml

Made-with: Cursor
Cover merge_variables and nested object handling in cards.create,
HTTP agent for non-TLS, 500 errors without error body, stream-based
form data, null value edge cases, and network error handling in
resourceBase.

Made-with: Cursor
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the project's test suite and infrastructure. The primary goal was to achieve comprehensive code coverage by addressing previously untested code paths in core functionalities. Additionally, new tooling has been introduced to generate project metrics and integrate with SonarQube for continuous code quality analysis.

Highlights

  • Increased Test Coverage: Achieved 100% statement, branch, function, and line coverage by adding new test cases for previously untested code paths.
  • New Test Cases for cards.js: Added tests for cards.create with merge_variables (JSON stringification) and nested object parameters (bracket-notation expansion).
  • New Test Cases for resourceBase.js: Introduced tests for HTTP agent handling with non-TLS connections, 500 errors without an error body, stream-based form data, null values in multipart and URL-encoded form data, and network error handling.
  • Metrics Generation Script: Added a new script (scripts/generate-metrics.js) to generate a JSON metrics file, capturing repository info, test file counts, and coverage summary from LCOV.
  • SonarQube Configuration: Included a sonar-project.properties file to configure SonarQube analysis for the project.
  • Dependency Updates: Updated nock and @mswjs/interceptors development dependencies in package-lock.json.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • package-lock.json
    • Updated @mswjs/interceptors from 0.39.8 to 0.41.3.
    • Updated nock from 14.0.10 to 14.0.11.
  • scripts/generate-metrics.js
    • Added a new script to generate a metrics.json file containing repository, test, and coverage information.
  • sonar-project.properties
    • Added SonarQube configuration for project analysis, specifying sources, tests, and LCOV report paths.
  • test/cards.js
    • Added a test case for cards.create with merge_variables.
    • Added a test case for cards.create with nested object parameters.
  • test/resourceBase.js
    • Added Stream module import.
    • Removed a redundant comment for HTTP agent test.
    • Added a test case for custom HTTP agent with non-TLS connections.
    • Added a test case for handling 500 errors without an error body.
    • Added a test case for stream-based form data.
    • Added a test case for handling null values in multipart form data.
    • Added a test case for handling null values in URL-encoded form data.
    • Added a test case for graceful network error handling.
Ignored Files
  • Ignored by pattern: .github/workflows/** (3)
    • .github/workflows/forked_run_tests.yml
    • .github/workflows/run_tests.yml
    • .github/workflows/sonarqube.yml
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully increases test coverage by adding several new tests for edge cases in cards.js and resourceBase.js. Additionally, it introduces a script for generating repository metrics and a configuration file for SonarQube. My review focuses on these new files, with suggestions to improve the robustness of the metrics script and correct the SonarQube configuration to ensure test coverage is reported accurately.

Comment on lines +30 to +32
} catch {
return { name: path.basename(repoRoot), version: "unknown", repository: "" };
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The catch block is empty. While there's a fallback mechanism, swallowing the error silently is not ideal. If package.json is unreadable or malformed, the script will proceed with default values without any indication of what went wrong. It's a good practice to log the error to stderr to aid in debugging.

  } catch (error) {
    console.error('Failed to read or parse package.json:', error);
    return { name: path.basename(repoRoot), version: "unknown", repository: "" };
  }


function classifyTests() {
const testDir = path.join(repoRoot, "test");
const allTestFiles = findTestFiles(testDir, /\.(test|spec)\.js$|^(?!setup)[a-zA-Z]+\.js$/);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The regular expression to find test files seems a bit fragile. The part ^(?!setup)[a-zA-Z]+\.js$ will only match files whose names consist exclusively of alphabetic characters (e.g., cards.js), and will fail to match test files with names containing numbers, hyphens, or other characters (e.g., my-test-1.js). This could lead to an inaccurate count of test files if naming conventions change in the future. Consider making the pattern less restrictive to allow for more characters in the filename.

Comment on lines +9 to +10
sonar.test.inclusions=test/**/*.js,test/integration/**/*.test.js
sonar.exclusions=test/**
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

There are a couple of potential issues with the SonarQube configuration:

  1. sonar.exclusions=test/** on line 10 might prevent test files from being analyzed for coverage. Since you've already separated source and test files with sonar.sources=lib and sonar.tests=test, this exclusion is redundant and could be harmful. It's generally recommended to remove it and rely on the sonar.sources and sonar.tests properties for separation.
  2. The pattern test/integration/**/*.test.js in sonar.test.inclusions on line 9 is redundant, as it's already covered by test/**/*.js. You can simplify this to just sonar.test.inclusions=test/**/*.js.
sonar.test.inclusions=test/**/*.js

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant