Skip to content

Enable Jest ESLint plugin with recommended config #1728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alexeyr-ci2
Copy link
Collaborator

@alexeyr-ci2 alexeyr-ci2 commented Apr 10, 2025

Summary

Include the Jest ESLint plugin and fix the tests accordingly.

Pull Request checklist

  • Add/update test to cover these changes
  • [ ] Update documentation
  • [ ] Update CHANGELOG file

This change is Reviewable

Summary by CodeRabbit

  • New Features
    • Enhanced the linting configuration to better integrate with Jest testing framework.
  • Tests
    • Streamlined assertions and removed unnecessary assertion counts for improved test clarity and consistency.
    • Reorganized test suites to ensure a cleaner and more isolated testing environment.
  • Chores
    • Upgraded development dependencies, including the addition of eslint-plugin-jest and an update to typescript-eslint.
    • Adjusted script handling for package.json dependencies.

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

A new Jest-specific configuration has been added to the ESLint settings to better support test files. The changes include importing the Jest plugin and adding a configuration block that applies to files matching Jest test patterns. In several test files, assertion methods have been updated from toEqual to toBe, and explicit expect.assertions calls have been removed. Some tests also saw improvements in error handling and organization. The package dependencies have been updated accordingly.

Changes

Files Summary of Changes
eslint.config.ts Added a Jest-specific configuration block with file patterns, imported eslint-plugin-jest, extended Jest’s recommended configurations, and removed legacy Mocha/Jest globals.
node_package/tests/Authenticity.test.js, node_package/tests/ReactOnRails.test.jsx, node_package/tests/serverRenderReactComponent.test.ts Changed assertions from toEqual to toBe for function type and string/HTML equality checks.
node_package/tests/Authenticity.test.js, node_package/tests/ReactOnRails.test.jsx, node_package/tests/renderFunction.test.jsx, node_package/tests/scriptSanitizedVal.test.js, node_package/tests/buildConsoleReplay.test.js Removed explicit expect.assertions calls to streamline tests.
node_package/tests/ComponentRegistry.test.js Refactored error handling by declaring an error variable outside the catch block and moving the assertion to check the error message after the catch.
node_package/tests/StoreRegistry.test.js, node_package/tests/buildConsoleReplay.test.js Improved test organization by adding a beforeEach hook for state cleanup and updating suite/test descriptions for clarity.
package.json Added "eslint-plugin-jest": "^28.11.0" as a new dependency and updated "typescript-eslint" from ^8.26.1 to ^8.29.1.
script/convert Added a line to remove the "eslint-plugin-jest" entry from package.json.

Possibly related PRs

Suggested reviewers

  • Judahmeek

Poem

I’m a rabbit, hopping with glee,
Configuring tests so sprightly and free.
With Jest in our ESLint, oh what a sight,
Assertions now bouncy and shining bright.
Bugs scurry off as I nibble each byte,
A carrot of code, my pure delight! 🐇
Hop on, let’s code into the night!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 d687a6f and fc64ba1.

📒 Files selected for processing (1)
  • script/convert (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • script/convert
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-dummy-app-webpack-test-bundles (oldest)
  • GitHub Check: rspec-package-tests (oldest)
  • GitHub Check: build
  • GitHub Check: rspec-package-tests (newest)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@alexeyr-ci2 alexeyr-ci2 marked this pull request as ready for review April 10, 2025 16:04
}
expect(error.message).toMatch(/Could not find component/);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Avoids conditional expect (though expect.assertions will catch the problem if there is no error too, we could just disable the rule here instead).

@@ -8,28 +8,22 @@ meta.content = testToken;
document.head.appendChild(meta);

describe('authenticityToken', () => {
expect.assertions(2);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

eslint-plugin-jest bans these expect.assertions(...) calls outside actual tests.

The ones in them are allowed but not actually useful, they are good in two cases:

  1. testing async logic with callbacks instead of async/await;
  2. conditional expect including in try/catch, also banned by the plugin.

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.

2 participants