Skip to content

Harden tests and coverage checks#21

Merged
jonmartin721 merged 4 commits intomainfrom
touchup/testing-hardening
Mar 11, 2026
Merged

Harden tests and coverage checks#21
jonmartin721 merged 4 commits intomainfrom
touchup/testing-hardening

Conversation

@jonmartin721
Copy link
Owner

Summary

  • add an explicit coverage script and make validate run coverage
  • fail tests on unexpected console error and warn output by default
  • update noisy tests to mock expected console calls cleanly

Testing

  • npm run validate
  • full jest coverage run in pre-push hook

@gemini-code-assist
Copy link

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 robustness of the test suite by integrating comprehensive code coverage checks into the validation workflow and enforcing stricter control over console output during tests. These changes aim to improve code quality, prevent silent errors, and ensure that all console messages are intentionally handled, leading to a more reliable and maintainable codebase.

Highlights

  • Enhanced Test Coverage: A dedicated test:coverage script was introduced, and the main validate command was updated to include comprehensive code coverage checks, ensuring that coverage is always part of the standard validation process.
  • Stricter Console Output Handling: A global console guard was implemented in tests/setup.js to automatically fail tests that produce unexpected console.error or console.warn output, promoting cleaner test environments and preventing silent issues.
  • Updated Test Files for Console Mocks: Multiple test files (background.test.js, export-import-controller.test.js, options-main.test.js, options.test.js, phase1.test.js, state-manager.test.js) were updated to explicitly mock console.error and console.warn where expected, aligning with the new console guard policy.
  • Refactored Chrome API Mocks: Chrome API mocks in tests/setup.js were refactored for improved consistency and maintainability, including the addition of a mock for chrome.runtime.lastError.
  • Enabled Previously Skipped Test: A previously skipped test in tests/options-token-controller.test.js was enabled, along with an added mock for chrome.storage.local.set, expanding test coverage for token management.
Changelog
  • package.json
    • Added test:coverage script.
    • Updated validate script to use test:coverage.
  • tests/background.test.js
    • Added jest.spyOn(console, 'error') and jest.spyOn(console, 'warn') mocks in beforeEach and restored them in afterEach.
  • tests/export-import-controller.test.js
    • Added jest.spyOn(console, 'error') mock in beforeEach and restored it in afterEach.
  • tests/options-main.test.js
    • Added jest.spyOn(console, 'error') mock in beforeEach and restored it in afterEach.
  • tests/options-token-controller.test.js
    • Added a mock implementation for chrome.storage.local.set.
    • Unskipped the clearToken clears all fields when confirmed test.
  • tests/options.test.js
    • Added jest.spyOn(console, 'error') mock in beforeEach and restored it in afterEach.
  • tests/phase1.test.js
    • Added jest.spyOn(console, 'error') mocks in beforeEach and restored them in afterEach for 'Dark Mode' and 'Error Display' describe blocks.
  • tests/setup.js
    • Refactored chrome.storage mocks into a createStorageArea helper function.
    • Added chrome.runtime.lastError mock.
    • Implemented a global console guard (installConsoleGuard, allowUnexpectedConsole) to catch unexpected console.error and console.warn calls, failing tests if unhandled.
  • tests/state-manager.test.js
    • Added jest.spyOn(console, 'error') mock in beforeEach and restored it in afterEach.
Activity
  • The pull request was created by jonmartin721.
  • The pull request includes changes to package.json and several test files to harden testing and coverage checks.
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.

@sentry
Copy link

sentry bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link

@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 effectively hardens the test suite by introducing coverage checks and a global guard against unexpected console logs. No vulnerabilities or significant security issues were found in the provided changes. My feedback focuses on a couple of areas for improvement: refactoring duplicated test setup code for better maintainability, and removing a redundant mock that is now covered by the enhanced global test setup.

Comment on lines 21 to 28
jest.spyOn(console, 'error').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
console.error.mockRestore();
console.warn.mockRestore();
});

Choose a reason for hiding this comment

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

medium

This pattern of mocking console.error and console.warn in beforeEach/afterEach is repeated across several test files (export-import-controller.test.js, options-main.test.js, etc.). To improve maintainability and reduce code duplication, consider creating a shared test utility. For example, you could create a helper function in a test utility file that sets up these mocks, and then call it in the describe block of the relevant test suites.

Comment on lines +20 to +22
chrome.storage.local.set.mockImplementation((items, callback) => {
if (callback) callback();
});

Choose a reason for hiding this comment

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

medium

The global test setup in tests/setup.js now provides a comprehensive mock for chrome.storage.local.set that handles callbacks and returns a promise. This local mock is now redundant and can be removed. The global mock is sufficient for the clearToken test to pass.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e06972b50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

tests/setup.js Outdated
Comment on lines +123 to +125
state.allowed ||
console[method] !== state.guard ||
state.guard.getMockImplementation() !== state.initialImplementation;

Choose a reason for hiding this comment

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

P2 Badge Keep console guard active when tests replace mock implementation

This logic treats any test that calls console.error.mockImplementation(...) or console.warn.mockImplementation(...) as "explicitly handled", so unexpected extra console output is never reported for that test. In this same commit several suites now install broad console.error spies in beforeEach, which effectively disables the new hardening and allows regressions that add new warnings/errors to pass silently.

Useful? React with 👍 / 👎.

@jonmartin721 jonmartin721 merged commit 8457f9c into main Mar 11, 2026
2 checks passed
@jonmartin721 jonmartin721 deleted the touchup/testing-hardening branch March 11, 2026 21:04
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