Skip to content

Feature implementation from commits 41a111c..bdd2e01#1

Open
yashuatla wants to merge 15 commits intofeature-base-1from
feature-head-1
Open

Feature implementation from commits 41a111c..bdd2e01#1
yashuatla wants to merge 15 commits intofeature-base-1from
feature-head-1

Conversation

@yashuatla
Copy link
Owner

@yashuatla yashuatla commented Jun 24, 2025

PR Summary

Type System Cleanup and Refactoring

Overview

This PR performs a comprehensive cleanup of the type system across the Vitest codebase, removing deprecated types, renaming types for consistency, and fixing type assertions. It also consolidates type definitions and improves import paths.

Change Types

Type Description
Refactor Cleanup of type system and removal of deprecated types
Enhancement Improved type safety and consistency across the codebase
Removal Removal of deprecated APIs, types, and functions

Affected Modules

Module / File Change Description
vitest/src/public Removed deprecated type exports and renamed UserConfig to TestUserConfig
vitest/src/types Replaced ErrorWithDiff with TestError and removed deprecated interfaces
browser/src Updated import paths and added type assertions
coverage-v8/src Refactored coverage provider implementation and removed experimental flag
mocker/src Moved type definitions to appropriate locations
runner/src Removed deprecated types (Custom, TaskContext, ExtendedContext)
vitest/src/node Updated type references and removed deprecated exports

Breaking Changes

  • Removed defineWorkspace function in favor of direct array exports
  • Removed deprecated types: ErrorWithDiff, Custom, TaskContext, ExtendedContext, WorkspaceProjectConfiguration
  • Renamed UserConfig to TestUserConfig for clarity
  • Removed classname option from JUnit reporter in favor of classnameTemplate
  • Removed contextId property from BrowserCommandContext interface (replaced by sessionId)

Notes for Reviewers

  • Several type assertions to any or specific types were added with TODO comments
  • Import paths were reorganized to improve code organization
  • The PR focuses on type system cleanup without changing runtime behavior
  • Coverage provider implementation was refactored to remove experimental flags

ServerMockResolution,
ServerResolverOptions,
} from './resolver'
export type { ServerResolverOptions } from './resolver'
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Breaking API Change: Removed Type Exports.

Removing ServerIdResolution and ServerMockResolution type exports will break any external code that imports these types, causing compilation failures.

Current Code (Diff):

- export type { ServerResolverOptions } from './resolver'
+ export type { ServerIdResolution, ServerMockResolution, ServerResolverOptions } from './resolver'
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
export type { ServerResolverOptions } from './resolver'
export type { ServerIdResolution, ServerMockResolution, ServerResolverOptions } from './resolver'

*/
ignoreClassMethods?: string[]
}
export interface CoverageV8Options extends BaseCoverageOptions {}
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Breaking API change: Removed V8 coverage options.

Removing specific V8 coverage options will break existing code that relies on these properties, causing compilation failures for consumers of this library.

Current Code (Diff):

+ export interface CoverageV8Options extends BaseCoverageOptions {}
- export interface CoverageV8Options extends BaseCoverageOptions {
-   /**
-    * Ignore empty lines, comments and other non-runtime code, e.g. Typescript types
-    * - Requires `experimentalAstAwareRemapping: false`
-    */
-   ignoreEmptyLines?: boolean
- 
-   /**
-    * Remap coverage with experimental AST based analysis
-    * - Provides more accurate results compared to default mode
-    */
-   experimentalAstAwareRemapping?: boolean
- 
-   /**
-    * Set to array of class method names to ignore for coverage.
-    * - Requires `experimentalAstAwareRemapping: true`
-    *
-    * @default []
-    */
-   ignoreClassMethods?: string[]
- }
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
export interface CoverageV8Options extends BaseCoverageOptions {}
export interface CoverageV8Options extends BaseCoverageOptions {
/**
* Ignore empty lines, comments and other non-runtime code, e.g. Typescript types
* - Requires `experimentalAstAwareRemapping: false`
*/
ignoreEmptyLines?: boolean
/**
* Remap coverage with experimental AST based analysis
* - Provides more accurate results compared to default mode
*/
experimentalAstAwareRemapping?: boolean
/**
* Set to array of class method names to ignore for coverage.
* - Requires `experimentalAstAwareRemapping: true`
*
* @default []
*/
ignoreClassMethods?: string[]
}

* - Provides more accurate results compared to default mode
*/
experimentalAstAwareRemapping?: boolean
export interface CoverageIstanbulOptions extends BaseCoverageOptions {}
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Duplicate interface declaration.

Creating a duplicate declaration of CoverageIstanbulOptions will cause TypeScript compilation errors due to ambiguous interface definitions.

Current Code (Diff):

- export interface CoverageIstanbulOptions extends BaseCoverageOptions {}

globalThis.clearImmediate = currentClearImmediate

if (globalThis.process) {
if (globalThis.process && nextTick) {
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Potential Runtime Exception: Missing null check for nextTick.

The code attempts to call nextTick() without verifying it exists, which would cause a runtime crash if nextTick is undefined in certain environments.

Current Code (Diff):

-     if (globalThis.process) {
+     if (globalThis.process && nextTick) {
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
if (globalThis.process && nextTick) {
if (globalThis.process && nextTick) {

private snapshotClient = getSnapshotClient()
private workerState = getWorkerState()
private __vitest_executor!: VitestExecutor
private __vitest_executor!: any
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Type Safety Removal: VitestExecutor to any.

Changing the type from VitestExecutor to any removes critical compile-time type checking, which could lead to runtime exceptions if the object doesn't have the expected methods.

Current Code (Diff):

-   private __vitest_executor!: any
+   private __vitest_executor!: VitestExecutor
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
private __vitest_executor!: any
private __vitest_executor!: VitestExecutor

🔄 Dependencies Affected

packages

Function: VitestTestRunner.importFile

Issue: The executeId method call on __vitest_executor loses type checking, risking runtime errors

Suggestion: Maintain the VitestExecutor type to ensure type safety for the executeId method call


export interface TypecheckResults {
files: File[]
sourceErrors: TypeCheckError[]
sourceErrors: TestError[]
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Type incompatibility: TypeCheckError[] to TestError[].

Changing sourceErrors from TypeCheckError[] to TestError[] may cause type incompatibilities if these types have different structures or if code elsewhere expects TypeCheckError specifically.

Current Code (Diff):

-   sourceErrors: TestError[]
+   sourceErrors: TypeCheckError[] | TestError[]
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
sourceErrors: TestError[]
sourceErrors: TypeCheckError[] | TestError[]

🔄 Dependencies Affected

packages/vitest/src/typecheck/typechecker.ts

Function: Typechecker.constructor

Issue: The Typechecker class initializes _result with an empty sourceErrors array, but code adding to this array must now add TestError objects instead of TypeCheckError objects

Suggestion: Ensure all code that adds to sourceErrors uses TestError objects or update the type to support both TypeCheckError and TestError


Comment on lines +1 to +2
export function uncovered(condition: boolean) {
return condition ? 1 : 0
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Breaking API Change: Required Parameter Added.

Adding a required parameter to the function signature will break all existing callers that don't provide this parameter.

Current Code (Diff):

- export function uncovered(condition: boolean) {
-   return condition ? 1 : 0
+ export function uncovered(condition: boolean = false) {
+   return condition ? 1 : 0
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
export function uncovered(condition: boolean) {
return condition ? 1 : 0
export function uncovered(condition: boolean = false) {
return condition ? 1 : 0
}

import type { TestUserConfig } from 'vitest/config'
import { assertType, describe, expectTypeOf, test } from 'vitest'
import { defineConfig, defineProject, defineWorkspace, mergeConfig } from 'vitest/config'
import { defineConfig, defineProject, mergeConfig } from 'vitest/config'
Copy link

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Removed required defineWorkspace import.

The defineWorkspace function is removed from imports but is still used in tests, which will cause compilation errors.

Current Code (Diff):

- import { defineConfig, defineProject, mergeConfig } from 'vitest/config'
+ import { defineConfig, defineProject, defineWorkspace, mergeConfig } from 'vitest/config'
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
import { defineConfig, defineProject, mergeConfig } from 'vitest/config'
import { defineConfig, defineProject, defineWorkspace, mergeConfig } from 'vitest/config'

🔄 Dependencies Affected

test/config-types.test-d.ts

Function: define workspace helper test section

Issue: Tests for defineWorkspace helper will fail because the function is no longer imported

Suggestion: Keep the defineWorkspace import to ensure tests can access this function


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.

4 participants