Skip to content
This repository was archived by the owner on Jul 10, 2026. It is now read-only.

feat: replace jest with vitest - #159

Closed
xorsal wants to merge 5 commits into
devfrom
feat/vitest
Closed

feat: replace jest with vitest#159
xorsal wants to merge 5 commits into
devfrom
feat/vitest

Conversation

@xorsal

@xorsal xorsal commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

🤖 Linear

Closes AZT-XXX

Description

Summary by CodeRabbit

  • Chores

    • Switched JavaScript test runner from Jest to Vitest and updated related dependencies.
    • Added a Vitest configuration file with increased timeouts and sequential test execution.
    • Streamlined CI workflow commands for compilation and testing.
  • Tests

    • Updated test files to import testing functions from Vitest.
    • Skipped the "Token - Multi PXE" test suite.
    • Improved test setup with asynchronous configuration initialization for PXE service.

@coderabbitai

coderabbitai Bot commented Jul 25, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The JavaScript testing framework for the project was migrated from Jest to Vitest. The test script in package.json was updated to run Vitest instead of Jest, and Jest-related dependencies were removed while Vitest was added. Test files were modified to explicitly import Vitest testing functions, and one test suite was skipped with added setup and teardown hooks managing a test store instance. A new Vitest configuration file was added to increase hook and test timeouts to 200 seconds and disable file parallelism. A test utility file was refactored to replace top-level asynchronous initialization with an async initializeConfig function, moving client creation inside functions and adding necessary imports. The GitHub Actions workflow was simplified by removing conditional environment variable usage and replacing direct Jest commands with the Vitest test script.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84752cd and 1fa9a1d.

📒 Files selected for processing (2)
  • src/ts/test/token.test.ts (6 hunks)
  • src/ts/test/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/ts/test/token.test.ts
  • src/ts/test/utils.ts
⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: setup-and-run (ubuntu-latest-m, 12)
  • GitHub Check: benchmark (ubuntu-latest-m, 12)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/vitest

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate unit tests to generate unit tests for 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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
package.json (1)

38-51: Clean up unused Jest artifacts

Since you've migrated to Vitest, consider removing the unused Jest configuration and related dependencies to keep the package.json clean.

  "devDependencies": {
-    "@types/jest": "29.5.11",
    "@types/mocha": "10.0.6",
    "@types/node": "22.5.1",
    "husky": "9.1.7",
    "lint-staged": "15.4.3",
    "prettier": "3.4.2",
    "ts-node": "10.9.2",
    "typescript": "5.7.2",
    "vitest": "3.2.4"
  },
-  "jest": {
-    "testTimeout": 200000
-  },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83476cd and bcacf0b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (5)
  • package.json (2 hunks)
  • src/ts/test/nft.test.ts (1 hunks)
  • src/ts/test/token.test.ts (2 hunks)
  • src/ts/test/utils.ts (2 hunks)
  • vitest.config.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/ts/test/utils.ts (2)
benchmarks/token_contract.benchmark.ts (1)
  • setup (33-41)
benchmarks/nft_contract.benchmark.ts (1)
  • setup (24-32)
🔇 Additional comments (8)
package.json (1)

18-18: LGTM: Clean migration to Vitest

The test script update from Jest to Vitest is correctly implemented.

vitest.config.ts (1)

1-10: LGTM: Well-configured for Aztec sandbox tests

The Vitest configuration appropriately addresses the needs of long-running Aztec sandbox tests with extended timeouts and disabled file parallelism. The timeout values match the original Jest configuration.

src/ts/test/nft.test.ts (1)

18-18: LGTM: Correct Vitest import addition

The explicit import of Vitest testing functions is necessary for the migration and correctly includes all required functions.

src/ts/test/token.test.ts (2)

16-16: LGTM: Correct Vitest import addition

The explicit import of Vitest testing functions is correctly implemented.


452-452: Confirm Intentional Skip of the ‘Token – Multi PXE’ Test Suite

I didn’t find any TODOs or issue references associated with this skip. Please verify:

  • File: src/ts/test/token.test.ts (around line 452)
    // currently skipped – please confirm this is intentional
    describe.skip('Token - Multi PXE', () => {
  • If these tests fail under the Vitest migration or PXE support is incomplete, add a comment or link to the issue explaining the skip.
  • Otherwise, re-enable the suite (change to describe('Token - Multi PXE', …)) so any hidden failures surface.
src/ts/test/utils.ts (3)

18-18: LGTM: Necessary Vitest import

The explicit import of expect from Vitest is required since this utility file uses expect in helper functions.


26-30: LGTM: Improved configuration object construction

The simplified object literal construction improves readability while maintaining the same functionality.


39-39: LGTM: Useful logging addition

The console.log statement provides helpful feedback during test setup, which can aid in debugging test issues.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/tests.yaml (2)

67-69: script -e -c wrapper seems unnecessary and adds indirection

The GitHub runner already fails the step if the wrapped command exits non-zero, so wrapping aztec-nargo compile in script -e -c provides little value while slightly slowing the job and obscuring logs (they are written through a pseudo-TTY).

-        - name: Compile
-          run: script -e -c "aztec-nargo compile"
+        - name: Compile
+          run: aztec-nargo compile

Unless you specifically need the TTY recording produced by script, dropping the wrapper simplifies maintenance and troubleshooting.


82-82: Add a trailing newline to satisfy linters

YAMLlint flags the missing EOF newline. Append one to avoid continual linter noise.

-          run: script -e -c "yarn test:js"
+          run: script -e -c "yarn test:js"
+
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcacf0b and c710965.

📒 Files selected for processing (4)
  • .github/workflows/tests.yaml (2 hunks)
  • src/ts/test/token.test.ts (3 hunks)
  • src/ts/test/utils.ts (1 hunks)
  • vitest.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/ts/test/utils.ts
  • vitest.config.ts
  • src/ts/test/token.test.ts
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/tests.yaml

[error] 82-82: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
.github/workflows/tests.yaml (1)

81-82: Verify Vitest exit codes and reporting are surfaced in CI

Switching to yarn test:js is fine, but make sure the underlying script:

  1. Runs Vitest in CI mode (vitest run) rather than watch mode.
  2. Exits with a non-zero status when tests fail (default for vitest run, but double-check your package.json).
  3. Generates coverage or junit reports if those were previously consumed by the pipeline.

If any of those behaviours were handled by the former Jest invocation flags, update the test:js script accordingly so the workflow keeps the same guarantees.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/tests.yaml (1)

81-82: Add a trailing newline to satisfy YAML-lint

The linter reports a missing end-of-file newline. Appending one keeps the file POSIX-compliant and silences the warning.

           run: script -e -c "yarn test:js"
+
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c710965 and 0046dee.

📒 Files selected for processing (1)
  • .github/workflows/tests.yaml (2 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/tests.yaml

[error] 82-82: no new line character at the end of file

(new-line-at-end-of-file)

⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: setup-and-run (ubuntu-latest-m, 12)
  • GitHub Check: benchmark (ubuntu-latest-m, 12)
🔇 Additional comments (1)
.github/workflows/tests.yaml (1)

68-68: Compilation step looks good

Switching to a direct aztec-nargo compile call keeps the workflow clear and removes the now-unused $AZTEC_NARGO indirection. The script -e wrapper properly forwards the exit code, so failures will bubble up.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/ts/test/utils.ts (1)

42-52: Good refactoring, but consider optimizing node client creation.

The function correctly uses the new lazy initialization pattern. However, there's a minor inefficiency where two node clients are created for the same NODE_URL (one in initializeConfig, one here).

Consider this optimization to reuse the node client:

+let nodeClient: ReturnType<typeof createAztecNodeClient>;

const initializeConfig = async () => {
  if (!l1Contracts) {
-   const node = createAztecNodeClient(NODE_URL);
+   nodeClient = nodeClient || createAztecNodeClient(NODE_URL);
-   l1Contracts = await node.getL1ContractAddresses();
+   l1Contracts = await nodeClient.getL1ContractAddresses();
    // ... rest unchanged
  }
  return fullConfig;
};

export const setupPXE = async () => {
  const config = await initializeConfig();
- const node = createAztecNodeClient(NODE_URL);
+ const node = nodeClient || createAztecNodeClient(NODE_URL);
  // ... rest unchanged
};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0046dee and 84752cd.

📒 Files selected for processing (1)
  • src/ts/test/utils.ts (1 hunks)
🔇 Additional comments (2)
src/ts/test/utils.ts (2)

13-13: LGTM! Clean import updates for Vitest migration.

The type imports for PXEServiceConfig and L1ContractAddresses improve type safety, and the expect import from Vitest correctly replaces Jest's expect function.

Also applies to: 16-16, 19-19


56-109: LGTM! Well-structured utility functions.

The utility functions are well-implemented with good separation of concerns and proper use of the Vitest expect function. The token and NFT deployment helpers follow good patterns and will be useful for testing.

Comment thread src/ts/test/utils.ts
Comment on lines +25 to +40
let l1Contracts: L1ContractAddresses;
let fullConfig: PXEServiceConfig & { l1Contracts: L1ContractAddresses };

const initializeConfig = async () => {
if (!l1Contracts) {
const node = createAztecNodeClient(NODE_URL);
l1Contracts = await node.getL1ContractAddresses();
const config = getPXEServiceConfig();
fullConfig = {
...config,
l1Contracts,
proverEnabled: false,
};
}
return fullConfig;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider error handling and test isolation for the lazy initialization pattern.

The lazy initialization pattern is a good improvement over top-level async calls. However, consider these enhancements:

  1. Add error handling for the network call:
const initializeConfig = async () => {
  if (!l1Contracts) {
-   const node = createAztecNodeClient(NODE_URL);
-   l1Contracts = await node.getL1ContractAddresses();
+   try {
+     const node = createAztecNodeClient(NODE_URL);
+     l1Contracts = await node.getL1ContractAddresses();
+   } catch (error) {
+     logger.error('Failed to initialize L1 contract addresses:', error);
+     throw error;
+   }
    // ... rest of the function
  }
  return fullConfig;
};
  1. Consider test isolation: The global caching might cause issues if tests need different configurations. You may want to add a reset function for test cleanup.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let l1Contracts: L1ContractAddresses;
let fullConfig: PXEServiceConfig & { l1Contracts: L1ContractAddresses };
const initializeConfig = async () => {
if (!l1Contracts) {
const node = createAztecNodeClient(NODE_URL);
l1Contracts = await node.getL1ContractAddresses();
const config = getPXEServiceConfig();
fullConfig = {
...config,
l1Contracts,
proverEnabled: false,
};
}
return fullConfig;
};
let l1Contracts: L1ContractAddresses;
let fullConfig: PXEServiceConfig & { l1Contracts: L1ContractAddresses };
const initializeConfig = async () => {
if (!l1Contracts) {
try {
const node = createAztecNodeClient(NODE_URL);
l1Contracts = await node.getL1ContractAddresses();
} catch (error) {
logger.error('Failed to initialize L1 contract addresses:', error);
throw error;
}
const config = getPXEServiceConfig();
fullConfig = {
...config,
l1Contracts,
proverEnabled: false,
};
}
return fullConfig;
};
🤖 Prompt for AI Agents
In src/ts/test/utils.ts around lines 25 to 40, the lazy initialization function
initializeConfig lacks error handling for the asynchronous network call to
getL1ContractAddresses. Add a try-catch block around the async call to catch and
handle potential errors gracefully. Additionally, to improve test isolation,
implement a reset function that clears the cached l1Contracts and fullConfig
variables, allowing tests to start with a clean state and avoid interference
from previous test runs.

@github-actions

Copy link
Copy Markdown

Benchmark Comparison

Contract: nft

Function Gates DA Gas L2 Gas
Status Base PR Diff Base PR Diff Base PR Diff
burn_private 331,755 331,755 2,816 2,816 44,502 44,502
burn_public 227,539 227,539 3,380 3,380 51,581 51,581
mint_to_private 356,923 356,923 13,517 13,517 44,218 44,218
mint_to_public 227,539 227,539 3,380 3,380 57,811 57,811
transfer_private_to_private 325,803 325,803 12,954 12,954 5,296 5,296
transfer_private_to_public 331,758 331,758 2,816 2,816 37,886 37,886
transfer_public_to_private 353,411 353,411 13,517 13,517 44,618 44,618
transfer_public_to_public 227,539 227,539 2,253 2,253 43,782 43,782

Contract: token

Function Gates DA Gas L2 Gas
Status Base PR Diff Base PR Diff Base PR Diff
burn_private 363,830 363,830 14,081 14,081 34,484 34,484
burn_public 227,539 227,539 3,380 3,380 47,307 47,307
mint_to_private 357,673 357,673 13,517 13,517 32,711 32,711
mint_to_public 227,539 227,539 3,380 3,380 53,313 53,313
transfer_private_to_private 363,311 363,311 24,218 24,218 6,706 6,706
transfer_private_to_public 363,910 363,910 14,081 14,081 46,843 46,843
transfer_private_to_public_with_commitment 394,872 394,872 25,345 25,345 48,504 48,504
transfer_public_to_private 354,161 354,161 13,517 13,517 45,238 45,238
transfer_public_to_public 227,539 227,539 3,380 3,380 59,296 59,296

@xorsal
xorsal marked this pull request as ready for review July 28, 2025 17:44
Comment thread src/ts/test/token.test.ts
});

describe('Token - Multi PXE', () => {
describe.skip('Token - Multi PXE', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do we do about this test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TBF I would remove it. We only test a single flow (private transfer), I'd re add it once they're done changing the PXE's Notes interface oooor push to make them as extensive as the single PXE tests.

I commented it because I wasn't able to start the secondary PXE, I'll try again later.

@xorsal xorsal closed this Oct 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants