Skip to content

chore: update jest version to 29#37587

Merged
ayushpahwa merged 7 commits intoreleasefrom
chore/update-jest-version
Nov 21, 2024
Merged

chore: update jest version to 29#37587
ayushpahwa merged 7 commits intoreleasefrom
chore/update-jest-version

Conversation

@ayushpahwa
Copy link
Contributor

@ayushpahwa ayushpahwa commented Nov 20, 2024

Description

Update version of the jest package to leverage new node features. Changes needed to make the new version compatible

  1. ts-jest had to be moved from globals to the transform block since it is a transformer and with new version, it is deprecated to keep them in globals.
  2. For snapshot tests, the keyword Array before tests is no longer needed, it is implicit.
  3. With new jest version, features of node js v20 can be utilised. One of these is crypto.subtle.digest. Our usage of the peculiar/webcrypto lib has this but was not being utilised since global.crypto is immutable and hence needs to be deleted before the new lib can be properly used. Reference

Fixes #37586

Automation

/test sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11946938998
Commit: 99c7f2b
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Thu, 21 Nov 2024 08:25:00 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes

    • Updated the Jest configuration to improve TypeScript handling and suppress specific diagnostic messages.
    • Enhanced the testing environment by correctly configuring global objects and mocking necessary APIs.
  • New Features

    • Upgraded several dependencies to their latest versions, enhancing compatibility and potentially introducing new features.
    • Improved type safety and error handling in AST node manipulation functions.
  • Chores

    • Streamlined the setup for testing, including the mocking of web workers and other APIs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes in this pull request primarily involve updates to the Jest configuration, dependency versions in package.json, and modifications to the test setup in setup.ts. The Jest configuration now includes enhanced options for TypeScript handling, while the package.json reflects upgrades to several dependencies, particularly related to Jest. The test setup file has been adjusted to improve the mocking of global objects and APIs, ensuring a more robust testing environment.

Changes

File Path Change Summary
app/client/jest.config.js Updated transform property for ts-jest with new options; modified moduleNameMapper; removed ts-jest from globals.
app/client/package.json Updated dependency versions for @types/jest, jest, jest-environment-jsdom, and ts-jest.
app/client/test/setup.ts Replaced global crypto with @peculiar/webcrypto; updated API mocking; mocked IntersectionObserver and ResizeObserver; defined WorkerStub.

Assessment against linked issues

Objective Addressed Explanation
Upgrade version of jest from 27 to 29

Possibly related PRs

Suggested labels

Enhancement, Test, JS Objects, Javascript Product

Suggested reviewers

  • ApekshaBhosale
  • sharat87
  • pratapaprasanna

🎉 In the land of code where Jest does play,
Dependencies danced and upgraded today.
With mocks and stubs, the tests now shine,
A seamless config, oh how divine!
TypeScript's embrace, a joyful embrace,
In the realm of testing, we've found our place! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 20, 2024
@ayushpahwa ayushpahwa added the ok-to-test Required label for CI label Nov 21, 2024
@github-actions github-actions bot added Task A simple Todo Tech Debt Issues or Tasks which are tech debts labels Nov 21, 2024
@ayushpahwa ayushpahwa marked this pull request as ready for review November 21, 2024 04:43
@ayushpahwa ayushpahwa requested a review from KelvinOm as a code owner November 21, 2024 04:43
@ayushpahwa ayushpahwa requested review from KelvinOm, riodeuno and znamenskii-ilia and removed request for KelvinOm November 21, 2024 04:43
Copy link
Contributor

@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: 2

🧹 Outside diff range and nitpick comments (2)
app/client/test/setup.ts (2)

89-89: Use jest.fn() for consistency

Other DOM method mocks use jest.fn(). Consider using the same pattern here.

-Element.prototype.scrollTo = () => { };
+Element.prototype.scrollTo = jest.fn();

96-97: Remove unnecessary eslint disable comment

The eslint disable comment is redundant for an empty arrow function.

-    // eslint-disable-next-line @typescript-eslint/no-empty-function
-    this.onmessage = () => { };
+    this.onmessage = () => {};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 81b7727 and 7db3516.

⛔ Files ignored due to path filters (2)
  • app/client/src/components/propertyControls/__snapshots__/IconSelectControl.test.tsx.snap is excluded by !**/*.snap
  • app/client/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • app/client/jest.config.js (2 hunks)
  • app/client/package.json (3 hunks)
  • app/client/test/setup.ts (3 hunks)
🧰 Additional context used
🪛 Biome
app/client/test/setup.ts

[error] 7-8: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🔇 Additional comments (3)
app/client/package.json (2)

263-263: LGTM: Jest version updates are consistent

The Jest-related package versions are properly synchronized to v29.x, which aligns with the PR objectives.

Also applies to: 332-332, 334-334


357-357: Verify ts-jest configuration changes

The ts-jest version update requires moving from globals to transform block as mentioned in the PR objectives.

Run this script to verify the ts-jest configuration:

✅ Verification successful

ts-jest configuration is already properly set up

The ts-jest configuration is correctly set up in all Jest config files using the transform block rather than globals. The main config and all package configs are using the modern configuration approach. The only ts-jest settings in globals are for specific options like isolatedModules, which is the correct usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if ts-jest is properly configured in transform block

# Look for jest config files
fd -e js -e json -e ts "jest.config"

# Check ts-jest configuration in found files
rg -A 10 "transform.*ts-jest" 

Length of output: 586


Script:

#!/bin/bash
# Let's check the content of jest config files to see the ts-jest configuration
for config in $(fd -e js -e json -e ts "jest.config"); do
    echo "=== Content of $config ==="
    cat "$config"
    echo -e "\n"
done

Length of output: 13463

app/client/jest.config.js (1)

71-71: New moduleNameMapper entry for 'entities/*' looks good

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (2)
app/client/packages/ast/src/jsObject/index.ts (1)

Line range hint 165-165: Consider using a more specific type instead of any

The any type reduces type safety. Consider using the Node type from acorn or a more specific type that matches the expected structure of an export declaration node.

Example improvement:

- ExportDefaultDeclaration(node: any) {
+ ExportDefaultDeclaration(node: Node & { declaration?: { properties: Property[] } }) {
app/client/packages/ast/src/actionCreator/index.ts (1)

Test coverage needs to be added for findNodeAt and getQueryParam functions

The test file shows good coverage for most AST manipulation functions, but lacks tests for:

  • findNodeAt utility function
  • getQueryParam function

Please add test cases for these functions to maintain test coverage after the Jest upgrade.

🔗 Analysis chain

Line range hint 239-1429: Verify test coverage for AST manipulation functions.

While the TypeScript improvements look good, let's ensure the test coverage remains intact after the Jest upgrade.


Let me check the test coverage for these AST manipulation functions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if tests exist for the modified AST functions

# Look for test files that cover these functions
fd -e test.ts -e spec.ts . | grep -i "actionCreator"

# Search for specific test cases
rg -l "findNodeAt|getQueryParam" -g "*.test.ts" -g "*.spec.ts"

Length of output: 387


Script:

#!/bin/bash
# Check test content for AST manipulation functions
cat app/client/packages/ast/src/actionCreator/index.test.ts

# Check if there are any test cases for findNodeAt and getQueryParam
rg "findNodeAt|getQueryParam" -A 5 -B 5 app/client/packages/ast/src/actionCreator/index.test.ts

Length of output: 12545

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7db3516 and 99c7f2b.

📒 Files selected for processing (2)
  • app/client/packages/ast/src/actionCreator/index.ts (8 hunks)
  • app/client/packages/ast/src/jsObject/index.ts (1 hunks)
🔇 Additional comments (5)
app/client/packages/ast/src/jsObject/index.ts (1)

89-89: LGTM: Type annotation improves type safety

The explicit Node type annotation from acorn enhances type checking for the AST visitor function.

app/client/packages/ast/src/actionCreator/index.ts (4)

239-239: LGTM: Unused parameter properly marked.

The type parameter is renamed to _type to indicate it's intentionally unused in the callback.


Line range hint 720-738: LGTM: Type annotations added to CallExpression visitor.

The type annotation for the node parameter improves type safety in the AST traversal.


Line range hint 987-1017: LGTM: Consistent handling of unused parameters.

All findNodeAt callback functions consistently mark the unused type parameter with an underscore prefix.

Also applies to: 1018-1070, 1071-1114, 1115-1134, 1391-1406


1429-1429: LGTM: Unused parameter properly marked.

The number parameter is renamed to _number to indicate it's intentionally unused in the function.

@ayushpahwa ayushpahwa merged commit cc83b16 into release Nov 21, 2024
@ayushpahwa ayushpahwa deleted the chore/update-jest-version branch November 21, 2024 10:35
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo Tech Debt Issues or Tasks which are tech debts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Upgrade Jest version

3 participants