Skip to content

test: migrate from Jest to Vitest#19

Merged
GhostTypes merged 4 commits intomainfrom
test/migrate-jest-to-vitest
Feb 8, 2026
Merged

test: migrate from Jest to Vitest#19
GhostTypes merged 4 commits intomainfrom
test/migrate-jest-to-vitest

Conversation

@GhostTypes
Copy link
Copy Markdown
Owner

@GhostTypes GhostTypes commented Feb 8, 2026

Summary

Migrate test suite from Jest to Vitest and set up Biome linter/formatter for improved code quality, performance, and consistency. All 221 tests passing with coverage thresholds maintained.

Changes

Test Framework Migration

  • Removed: @types/jest, jest, ts-jest
  • Added: vitest, @vitest/coverage-v8
  • Created: vitest.config.ts with matching configuration (V8 coverage, same thresholds)
  • Updated: 17 test files to use Vitest syntax:
    • jest.mock()vi.mock()
    • jest.fn()vi.fn()
    • jest.spyOn()vi.spyOn()
    • Added import { describe, it, expect, beforeEach, vi } from 'vitest'
  • Updated: package.json scripts (test, test:watch, test:coverage)
  • Removed: Jest configuration block from package.json
  • Deleted: Obsolete jest.setup.js

Biome Setup

  • Created: biome.json with production-ready configuration
  • Added: @biomejs/biome to devDependencies
  • Added: npm scripts (lint, format, check, ci)
  • Applied: Biome formatting to all TypeScript files:
    • Import organization with type imports grouped
    • Added node: prefix to Node.js builtin imports
    • Converted string concatenation to template literals
    • Removed unused code

Documentation

  • Updated CLAUDE.md test commands to reference Vitest
  • Added nul to .gitignore

Additional Enhancements

  • Added code-review skill for Gemini CLI integration
  • Added printer discovery specification document

Test Results

✅ All 221 tests passing
✅ Coverage thresholds maintained (branches: 40%, functions: 20%, lines: 30%, statements: 30%)
✅ All lint checks passing (0 errors, 15 acceptable warnings)

Benefits

  • Vitest: Faster execution, better TypeScript support, modern tooling
  • Biome: Consistent code formatting, linting, and style enforcement

Migration Notes

Both migrations were reviewed for production readiness. All cleanup items have been addressed and tests verified passing.

🤖 Generated with Claude Code

Migrate test suite from Jest to Vitest for improved performance and
modern TypeScript support. All 221 tests passing with coverage
thresholds maintained.

Changes:
- Remove Jest dependencies (@types/jest, jest, ts-jest)
- Add Vitest dependencies (vitest, @vitest/coverage-v8)
- Create vitest.config.ts with matching configuration
- Update all 17 test files to use Vitest syntax (vi.mock, vi.fn, etc.)
- Update package.json scripts (test, test:watch, test:coverage)
- Remove Jest configuration from package.json
- Delete obsolete jest.setup.js
- Update CLAUDE.md documentation

Also includes:
- Add code-review skill for Gemini CLI integration
- Add printer-discovery specification document

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @GhostTypes, 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 significantly upgrades the project's testing infrastructure by migrating from Jest to Vitest. This change was driven by the desire for improved performance, enhanced TypeScript support, and a more streamlined developer experience. The migration involved updating dependencies, adjusting test scripts, and refactoring existing test files to align with Vitest's API. Additionally, the PR introduces a new automated code review skill for Claude and a comprehensive specification for printer discovery, enhancing both development workflows and project documentation.

Highlights

  • Test Framework Migration: The project's testing suite has been fully migrated from Jest to Vitest. This includes updating dependencies, modifying package.json scripts, creating a new Vitest configuration, and adjusting syntax across 17 existing test files to use Vitest's API (e.g., vi.mock() instead of jest.mock()).
  • Improved Test Performance and Developer Experience: This migration aims to provide significantly faster test execution, better native TypeScript support without ts-jest, and a more modern development experience by leveraging Vitest's Vite-native architecture and compatible API.
  • New Claude Skill for Code Review: A new code-review skill has been added for Gemini CLI integration, enabling automated code analysis, bug detection, security review, and quality assessment of implemented features.
  • New Printer Discovery Specification: A detailed specification document (docs/specs/printer-discovery.md) has been added, outlining the implementation of a universal printer discovery system for various FlashForge printer models.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .claude/skills/code-review/SKILL.md
    • Added a new skill definition for automated code reviews using Gemini CLI.
  • CLAUDE.md
    • Updated documentation to reflect the switch from Jest to Vitest in test commands.
  • docs/specs/printer-discovery.md
    • Added a new specification document detailing the implementation of a universal printer discovery system for FlashForge printers.
  • jest.setup.js
    • Removed the Jest-specific setup file.
  • package.json
    • Updated test scripts (test, test:watch, test:coverage) to use vitest.
    • Removed Jest-related development dependencies (@types/jest, jest, ts-jest).
    • Added Vitest-related development dependencies (vitest, @vitest/coverage-v8).
    • Removed the Jest configuration block.
  • src/api/controls/Control.test.ts
    • Migrated test syntax from Jest to Vitest, including jest.mock to vi.mock and jest.fn to vi.fn.
  • src/api/controls/Files.test.ts
    • Migrated test syntax from Jest to Vitest, including jest.mock to vi.mock and jest.fn to vi.fn.
  • src/api/controls/Info.test.ts
    • Migrated test syntax from Jest to Vitest, including jest.mock to vi.mock and jest.fn to vi.fn.
  • src/api/controls/JobControl.test.ts
    • Migrated test syntax from Jest to Vitest, including jest.mock to vi.mock and jest.fn to vi.fn.
  • src/api/controls/TempControl.test.ts
    • Migrated test syntax from Jest to Vitest, including jest.mock to vi.mock and jest.fn to vi.fn.
  • src/api/filament/Filament.test.ts
    • Updated test imports to use Vitest.
  • src/api/misc/ScientificNotationFloatConverter.test.ts
    • Updated test imports to use Vitest.
  • src/api/misc/Temperature.test.ts
    • Updated test imports to use Vitest.
  • src/api/network/NetworkUtils.test.ts
    • Updated test imports to use Vitest.
  • src/models/MachineInfo.test.ts
    • Updated test imports to use Vitest.
  • src/tcpapi/FlashForgeTcpClient.test.ts
    • Migrated test syntax from Jest to Vitest, including jest.fn to vi.fn and jest.spyOn to vi.spyOn.
  • src/tcpapi/replays/EndstopStatus.test.ts
    • Updated test imports to use Vitest.
  • src/tcpapi/replays/LocationInfo.test.ts
    • Updated test imports to use Vitest.
  • src/tcpapi/replays/PrintStatus.test.ts
    • Updated test imports to use Vitest.
  • src/tcpapi/replays/PrinterInfo.test.ts
    • Updated test imports to use Vitest.
  • src/tcpapi/replays/TempInfo.test.ts
    • Updated test imports to use Vitest.
  • src/tcpapi/replays/ThumbnailInfo.test.ts
    • Migrated test syntax from Jest to Vitest, including jest.mock to vi.mock and jest.clearAllMocks to vi.clearAllMocks.
  • vitest.config.ts
    • Added a new Vitest configuration file, setting up the test environment, coverage thresholds, and include/exclude patterns.
Activity
  • The test suite has been successfully migrated from Jest to Vitest.
  • All 221 tests are passing, and coverage thresholds (branches: 40%, functions: 20%, lines: 30%, statements: 30%) have been maintained.
  • The migration was reviewed by Gemini 3 Flash for production readiness, and all identified cleanup items have been addressed.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

@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 successfully migrates the test suite from Jest to Vitest and introduces new documentation for a code-review skill and a printer-discovery specification. A high-severity security risk has been identified in the code-review skill documentation due to the recommendation of the --yolo flag with untrusted input, which could lead to Remote Code Execution (RCE) via prompt injection. Further review of the new documentation reveals a critical syntax error in the pre-commit hook script and outdated Gemini model names in the code-review skill documentation. For the printer-discovery specification, there's a critical logic error in the network interface filtering, an incorrect enum member in examples, and a minor function name mismatch. The core test migration work is excellent.

Comment thread .claude/skills/code-review/SKILL.md Outdated
Comment on lines +496 to +508
# Run review
gemini --yolo \
-m gemini-3-flash-preview \
-p "$(cat /tmp/review_input.txt)

Please review these changes for:
- Obvious bugs
- Security issues
- Breaking changes
- Missing tests

Report findings concisely. DO NOT modify files." \
> /tmp/review_output.txt
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The gemini command in this pre-commit hook script has a syntax error. The command is split across multiple lines using \, but line 499, which starts the multi-line -p argument, is missing a trailing \ to indicate command continuation. This will cause the script to fail.

I suggest a more robust way to construct the prompt by appending the static text to the temporary file. This avoids complex shell quoting and makes the script easier to read and maintain.

Suggested change
# Run review
gemini --yolo \
-m gemini-3-flash-preview \
-p "$(cat /tmp/review_input.txt)
Please review these changes for:
- Obvious bugs
- Security issues
- Breaking changes
- Missing tests
Report findings concisely. DO NOT modify files." \
> /tmp/review_output.txt
# Run review
cat >> /tmp/review_input.txt <<'EOF'
Please review these changes for:
- Obvious bugs
- Security issues
- Breaking changes
- Missing tests
Report findings concisely. DO NOT modify files.
EOF
gemini --yolo \
-m gemini-3-flash-preview \
-p "$(cat /tmp/review_input.txt)" \
> /tmp/review_output.txt

Comment thread .claude/skills/code-review/SKILL.md Outdated

## Best Practices

1. **Always use `--yolo`** - Enables Gemini to run tests and read files without permission prompts
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

The skill instructions recommend using the --yolo flag with the Gemini CLI as a 'Best Practice'. The --yolo flag automatically approves all tool uses, including shell command execution and file system access. Since the code review process involves incorporating untrusted data (the code changes being reviewed) directly into the prompt, this creates a significant risk of Remote Code Execution (RCE) via Prompt Injection. An attacker could craft malicious code changes containing instructions that trick the LLM into executing arbitrary commands on the user's machine or CI environment. It is highly recommended to remove the --yolo flag from the default instructions and warn users about the risks of auto-approving tool calls when processing untrusted input.

Suggested change
1. **Always use `--yolo`** - Enables Gemini to run tests and read files without permission prompts
1. **Avoid using `--yolo` by default** - Require manual approval for tool uses (test execution, file reading) to prevent prompt injection attacks from malicious code.

Comment thread docs/specs/printer-discovery.md Outdated
printerName: string,
productType: number
): PrinterModel {
if (printerName === 'AD5X') return PrinterModel.ADX;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The code example uses PrinterModel.ADX, but the PrinterModel enum defined earlier in the specification (line 221) uses AD5X. This should be PrinterModel.AD5X to match the enum definition. This error is repeated in several other code examples throughout the document (e.g., lines 927, 1042, 1064, 1242).

Suggested change
if (printerName === 'AD5X') return PrinterModel.ADX;
if (printerName === 'AD5X') return PrinterModel.AD5X;

Comment thread docs/specs/printer-discovery.md Outdated
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
// Skip internal and loopback
if (iface.internal || !iface.family === 'IPv4') continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

The logic for filtering network interfaces contains a bug due to incorrect operator precedence in !iface.family === 'IPv4'. This expression is evaluated as (!iface.family) === 'IPv4', which will always be false because !iface.family evaluates to false (as family is a non-empty string). This prevents the code from correctly skipping non-IPv4 interfaces as intended. To fix this, use the not-equals operator !==.

Suggested change
if (iface.internal || !iface.family === 'IPv4') continue;
if (iface.internal || iface.family !== 'IPv4') continue;

Comment thread .claude/skills/code-review/SKILL.md Outdated
Comment on lines +182 to +197
**Model selection strategy:**

1. **First choice:** `gemini-3-pro-preview` - Most capable, best for deep analysis
```bash
gemini --yolo -m gemini-3-pro-preview -p "Review prompt here"
```

2. **Fallback 1:** `gemini-3-flash-preview` - Fast, still very capable
```bash
gemini --yolo -m gemini-3-flash-preview -p "Review prompt here"
```

3. **Fallback 2:** `gemini-2.5-pro` - Reliable backup
```bash
gemini --yolo -m gemini-2.5-pro -p "Review prompt here"
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The Gemini model names used here and throughout the document (e.g., gemini-3-pro-preview, gemini-3-flash-preview, gemini-2.5-pro) appear to be outdated. To ensure the example commands are functional, please update them to the current, recommended model names provided in the Google AI documentation, such as gemini-1.5-pro-latest or gemini-1.5-flash-latest.

Comment thread docs/specs/printer-discovery.md Outdated
Set up production-ready Biome configuration for consistent code quality
and formatting across the TypeScript codebase.

Changes:
- Add biome.json with recommended rules and formatter settings
- Add @biomejs/biome to devDependencies
- Add lint, format, check, and ci scripts to package.json
- Apply Biome formatting to all TypeScript files (import organization,
  type imports, template literals, whitespace)
- Add 'nul' to .gitignore

Code quality improvements:
- Organized imports alphabetically with type imports grouped
- Added 'node:' prefix to Node.js builtin imports
- Converted string concatenation to template literals
- Removed unused interface (ThumbnailResponse)

All 221 tests continue to pass after formatting changes.
@GhostTypes GhostTypes self-assigned this Feb 8, 2026
@GhostTypes GhostTypes added the enhancement New feature or request label Feb 8, 2026
@GhostTypes

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

Comprehensive type safety improvements eliminating all 'any' types from
production code and resolving all Biome lint warnings.

Type Safety Fixes:
- Replace 'any' with proper types (Filament, GenericResponse, Record<string, unknown>)
- Add PrinterStatusInfo interface for private methods
- Fix error handling with AxiosError types and type guards
- Fix implicit any annotations in parser code
- Remove unused private properties

New Type Utilities:
- Add src/types/errors.ts with reusable type guards (isErrorWithCause,
  isAxiosErrorWithResponse, isGenericResponse)

Test Improvements:
- Replace non-null assertions with explicit null checks
- Fix empty mock implementations to use vi.fn()
- Document intentional empty catch blocks

Bug Fixes:
- Fix printer-discovery.md typo (PrinterModel.ADX -> AD5X)
- Fix logic bug (!iface.family === 'IPv4' -> iface.family !== 'IPv4')

Results:
- 0 'any' types in production code
- 0 Biome lint warnings (down from 17)
- All 221 tests passing
- Zero breaking changes to public API
@GhostTypes
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@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 is an excellent and comprehensive update to the project's tooling and code quality standards. The migration from Jest to Vitest is well-executed across all test files, which will improve test performance and the developer experience. The introduction of Biome for linting and formatting has already paid off by enforcing a consistent style throughout the codebase, as seen in the numerous formatting improvements. Additionally, the new printer-discovery.md specification is a high-quality, detailed document that will be invaluable for future development. All changes, from dependency updates in package.json to script modifications, are correct and align with the goals stated in the description. Overall, this is a fantastic contribution that significantly modernizes the repository.

@GhostTypes GhostTypes merged commit 2678617 into main Feb 8, 2026
1 check passed
@GhostTypes GhostTypes deleted the test/migrate-jest-to-vitest branch February 8, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant