Skip to content

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 linting configuration with improved Jest integration for test files.
  • Tests
    • Removed explicit assertion count checks across multiple test suites for clearer test code.
    • Refined test descriptions and reorganized setup hooks for better test isolation.
    • Adjusted error handling structure in asynchronous tests without changing behavior.
    • Updated some assertions to use strict equality checks for improved precision.
  • Chores
    • Added eslint-plugin-jest and updated typescript-eslint dependency versions.
    • Updated scripts to manage package.json dependencies more effectively.

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, such as adding a beforeEach hook and refining error assertion placement. The package dependencies have been updated accordingly, and the conversion script was modified to remove the Jest plugin from package.json when cleaning dependencies.

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 Renamed test suite description, added a beforeEach hook to clear the store registry, updated a test case description, and removed expect.assertions calls.
node_package/tests/buildConsoleReplay.test.js Removed expect.assertions calls, deleted a redundant test case, and clarified a test description regarding empty console history.
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.

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!


📜 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 4efa4de and b4f1f5a.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (11)
  • eslint.config.ts (2 hunks)
  • node_package/tests/Authenticity.test.js (1 hunks)
  • node_package/tests/ComponentRegistry.test.js (1 hunks)
  • node_package/tests/ReactOnRails.test.jsx (1 hunks)
  • node_package/tests/StoreRegistry.test.js (2 hunks)
  • node_package/tests/buildConsoleReplay.test.js (2 hunks)
  • node_package/tests/renderFunction.test.jsx (0 hunks)
  • node_package/tests/scriptSanitizedVal.test.js (0 hunks)
  • node_package/tests/serverRenderReactComponent.test.ts (1 hunks)
  • package.json (1 hunks)
  • script/convert (1 hunks)
💤 Files with no reviewable changes (2)
  • node_package/tests/renderFunction.test.jsx
  • node_package/tests/scriptSanitizedVal.test.js
✅ Files skipped from review due to trivial changes (2)
  • node_package/tests/ComponentRegistry.test.js
  • package.json
🚧 Files skipped from review as they are similar to previous changes (7)
  • node_package/tests/buildConsoleReplay.test.js
  • node_package/tests/serverRenderReactComponent.test.ts
  • script/convert
  • node_package/tests/Authenticity.test.js
  • node_package/tests/StoreRegistry.test.js
  • eslint.config.ts
  • node_package/tests/ReactOnRails.test.jsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: dummy-app-integration-tests (oldest)
  • GitHub Check: dummy-app-integration-tests (newest)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/eslint-jest branch from 4efa4de to b4f1f5a Compare April 27, 2025 06:40
@alexeyr-ci2 alexeyr-ci2 merged commit 57938d0 into master Apr 27, 2025
11 checks passed
@alexeyr-ci2 alexeyr-ci2 deleted the alexeyr/eslint-jest branch April 27, 2025 09:59
@coderabbitai coderabbitai bot mentioned this pull request Jun 6, 2025
2 tasks
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.

3 participants