Skip to content

Move from vitest to jest#11

Merged
kapicic merged 6 commits intomainfrom
stevan/eng-650
Aug 5, 2025
Merged

Move from vitest to jest#11
kapicic merged 6 commits intomainfrom
stevan/eng-650

Conversation

@kapicic
Copy link
Copy Markdown
Contributor

@kapicic kapicic commented Jul 29, 2025

📋 Pull Request Summary

Remove vitest dependency, vite.config.ts and move to jest.
Migrate existing tests and snapshots

🔗 Related Issues

  • Fixes #
  • Relates to #

📝 Changes Made

🧪 Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Testing Details:

📚 Documentation

  • Code is self-documenting with clear variable/function names
  • Added/updated JSDoc comments for public APIs
  • Updated README.md if needed
  • Updated other documentation files
  • No documentation changes needed

🔄 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test improvements

🚨 Breaking Changes

  • This PR introduces breaking changes
  • Migration guide provided
  • Deprecation warnings added

Breaking Change Details:

📸 Screenshots/Videos

📋 Additional Notes

@kapicic kapicic self-assigned this Jul 29, 2025
Copy link
Copy Markdown
Contributor

@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.

Summary of Changes

Hello @kapicic, 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 undertakes a significant migration of the project's testing infrastructure from Vitest to Jest. This change involves updating dependencies, reconfiguring the test environment, and adapting existing test files to the Jest framework, aiming to standardize the testing setup and potentially leverage Jest's features or ecosystem.

Highlights

  • Testing Framework Migration: Replaced Vitest with Jest as the primary unit and integration testing framework across the project.
  • Configuration Setup: Introduced dedicated Jest configuration files (jest.config.mjs, jest.setup.mjs) to properly set up the testing environment, including JSDOM, TypeScript support via ts-jest, and Next.js specific mocks.
  • Test File Adaptation: Renamed and refactored existing test files (e.g., Markdown.spec.ts, message-parser.spec.ts, diff.spec.ts) to align with Jest's conventions and syntax, including updating imports and mocking strategies.
  • Dependency Management: Updated package.json to remove Vitest and related types, and added Jest, jest-environment-jsdom, ts-jest, and their respective type definitions.
  • Build System Simplification: Removed the vite.config.ts file, as its primary purpose was tied to Vitest's integration.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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.

Copy link
Copy Markdown
Contributor

@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 migrates the testing framework from Vitest to Jest. While the setup of Jest configuration and dependencies seems largely correct, the migration of the actual tests has introduced critical issues.

Specifically, two of the test files (Markdown.test.ts and message-parser.test.ts) have been changed to test mock implementations instead of the actual production code. This completely undermines the purpose of these tests and results in a significant loss of test coverage. It's crucial that these tests are updated to import and test the real components and functions.

Additionally, there are a couple of opportunities to improve the new Jest configuration and test code for better maintainability and adherence to best practices.

Comment thread app/components/chat/Markdown.test.ts Outdated
Comment on lines +3 to +26
const stripCodeFenceFromArtifact = (content: string) => {
if (!content || !content.includes('__liblabArtifact__')) {
return content;
}

const lines = content.split('\n');
const artifactLineIndex = lines.findIndex((line) => line.includes('__liblabArtifact__'));

// Return original content if artifact line not found
if (artifactLineIndex === -1) {
return content;
}

// Check previous line for code fence
if (artifactLineIndex > 0 && lines[artifactLineIndex - 1]?.trim().match(/^```\w*$/)) {
lines[artifactLineIndex - 1] = '';
}

if (artifactLineIndex < lines.length - 1 && lines[artifactLineIndex + 1]?.trim().match(/^```$/)) {
lines[artifactLineIndex + 1] = '';
}

return lines.join('\n');
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The function stripCodeFenceFromArtifact is being re-implemented within the test file. This is a significant issue because the test is no longer testing the actual implementation from app/components/chat/Markdown.tsx. If the original function changes, these tests will not fail, leading to a false sense of security and potential bugs in production.

The function should be imported from its source file instead.

import { stripCodeFenceFromArtifact } from '~/components/chat/Markdown';

Comment thread app/lib/runtime/message-parser.test.ts Outdated
Comment on lines +34 to +50
// Simplified StreamingMessageParser for testing
class StreamingMessageParser {
constructor(private _options: StreamingMessageParserOptions = {}) {}

parse(messageId: string, input: string) {
// Simplified implementation that just strips out liblab artifacts
let output = input;

// Remove liblab artifacts
output = output.replace(/<liblabArtifact[^>]*>.*?<\/liblabArtifact>/gs, '');

// Remove liblab actions
output = output.replace(/<liblabAction[^>]*>.*?<\/liblabAction>/gs, '');

return output;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

A simplified, non-functional version of StreamingMessageParser is defined here for testing. This defeats the purpose of the tests, as they are not running against the actual production code from app/lib/runtime/message-parser.ts.

This mock implementation loses all the original logic for streaming, state management, and callbacks. As a result, the tests for these features are no longer effective, and a significant amount of test coverage has been lost.

Please import and test the real StreamingMessageParser class.

Suggested change
// Simplified StreamingMessageParser for testing
class StreamingMessageParser {
constructor(private _options: StreamingMessageParserOptions = {}) {}
parse(messageId: string, input: string) {
// Simplified implementation that just strips out liblab artifacts
let output = input;
// Remove liblab artifacts
output = output.replace(/<liblabArtifact[^>]*>.*?<\/liblabArtifact>/gs, '');
// Remove liblab actions
output = output.replace(/<liblabAction[^>]*>.*?<\/liblabAction>/gs, '');
return output;
}
}
import { StreamingMessageParser } from '~/lib/runtime/message-parser';

Comment thread app/utils/diff.test.ts
describe('Diff', () => {
it('should strip out Work_dir', () => {
const filePath = `${WORK_DIR}/index.js`;
const filePath = '/home/project/index.js';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The test hardcodes the path /home/project/index.js, which is the mocked value of WORK_DIR. This makes the test brittle. If the mocked value in jest.mock is ever changed, this test will fail unexpectedly.

It's better practice to import the mocked constant and use it to construct the test data. This makes the test more robust and clearly expresses the dependency on the WORK_DIR constant.

Suggested change
const filePath = '/home/project/index.js';
const filePath = `${'/home/project'}/index.js`;

Comment thread jest.config.mjs
Comment on lines +28 to +35
globals: {
'ts-jest': {
useESM: true,
},
},
testEnvironmentOptions: {
customExportConditions: [''],
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The globals configuration for ts-jest is redundant here. The useESM: true option is already configured under the transform property, which is the modern and recommended approach.

According to the ts-jest documentation, using globals for configuration is a legacy method. Removing this block will make the configuration cleaner and align with current best practices.

@kapicic kapicic merged commit 46c443e into main Aug 5, 2025
3 checks passed
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