Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,29 @@ export default antfu(
],

'import/no-named-as-default': 'off',
},
},
{
files: [`packages/*/*.{js,mjs,d.ts}`],
rules: {
'antfu/no-import-dist': 'off',
'antfu/no-top-level-await': 'off',
},
},
{
files: [`packages/${GLOB_SRC}`],
rules: {
'antfu/no-import-dist': 'off',
'no-restricted-imports': [
'error',
{
paths: ['vitest', 'path', 'vitest/node'],
paths: [
'vitest',
'path',
'vitest/node',
{ name: 'vite', message: 'Import from "src/vite.ts" instead.' },
],
},
],
},
},
{
// these files define vitest as peer dependency
files: [`packages/{coverage-*,ui,browser,web-worker,browser-*}/${GLOB_SRC}`],
// these files define vitest or vite as peer dependency
files: [`packages/{coverage-*,ui,browser,web-worker,browser-*,mocker}/${GLOB_SRC}`],
rules: {
'no-restricted-imports': [
'error',
Expand All @@ -107,6 +108,7 @@ export default antfu(
`**/*.md/${GLOB_SRC}`,
],
rules: {
'no-restricted-imports': 'off',
'prefer-arrow-callback': 'off',
'perfectionist/sort-imports': 'off',
'style/max-statements-per-line': 'off',
Expand Down
9 changes: 7 additions & 2 deletions packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"exports": {
".": {
"module-sync": "./dist/index.js",
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
Expand Down Expand Up @@ -138,7 +139,8 @@
"@vitest/browser-webdriverio": "workspace:*",
"@vitest/ui": "workspace:*",
"happy-dom": "*",
"jsdom": "*"
"jsdom": "*",
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0-0"
},
"peerDependenciesMeta": {
"@edge-runtime/vm": {
Expand Down Expand Up @@ -167,6 +169,9 @@
},
"jsdom": {
"optional": true
},
"vite": {
"optional": false
}
},
"dependencies": {
Expand All @@ -188,7 +193,7 @@
"tinyexec": "^1.0.2",
"tinyglobby": "catalog:",
"tinyrainbow": "catalog:",
"vite": "^6.0.0 || ^7.0.0",
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0-0",
"why-is-node-running": "^2.3.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { File, TaskEventPack, TaskResultPack, TestAnnotation, TestArtifact } from '@vitest/runner'
import type { SerializedError } from '@vitest/utils'
import type { IncomingMessage } from 'node:http'
import type { ViteDevServer } from 'vite'
import type { WebSocket } from 'ws'
import type { Vitest } from '../node/core'
import type { TestCase, TestModule } from '../node/reporters/reported-tasks'
import type { TestSpecification } from '../node/test-specification'
import type { Reporter } from '../node/types/reporter'
import type { LabelColor, ModuleGraphData, UserConsoleLog } from '../types/general'
import type { ViteDevServer } from '../vite'
import type {
ExternalResult,
TransformResultWithSource,
Expand All @@ -22,10 +22,10 @@ import { createBirpc } from 'birpc'
import { parse, stringify } from 'flatted'
import { WebSocketServer } from 'ws'
import { API_PATH } from '../constants'
import { isFileServingAllowed } from '../node/vite'
import { getTestFileEnvironment } from '../utils/environments'
import { getModuleGraph } from '../utils/graph'
import { stringifyReplace } from '../utils/serialization'
import { isFileServingAllowed } from '../vite'
import { isValidApiRequest } from './check'

export function setup(ctx: Vitest, _server?: ViteDevServer): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/ast-collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
import { unique } from '@vitest/utils/helpers'
import { ancestor as walkAst } from 'acorn-walk'
import { relative } from 'pathe'
import { parseAst } from 'vite'
import { createIndexLocationsMap } from '../utils/base'
import { createDebugger } from '../utils/debugger'
import { detectCodeBlock } from '../utils/test-helpers'
import { parseAst } from '../vite'

interface ParsedFile extends File {
start: number
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/cache/fsModuleCache.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { DevEnvironment, FetchResult } from 'vite'
import type { DevEnvironment, FetchResult } from '../../vite'
import type { Vitest } from '../core'
import type { ResolvedConfig } from '../types/config'
import fs, { existsSync, mkdirSync, readFileSync } from 'node:fs'
import { readFile, rename, rm, stat, unlink, writeFile } from 'node:fs/promises'
import { parse, stringify } from 'flatted'
import { dirname, join } from 'pathe'
import c from 'tinyrainbow'
import { searchForWorkspaceRoot } from 'vite'
import { createDebugger } from '../../utils/debugger'
import { searchForWorkspaceRoot } from '../../vite'
import { hash } from '../hash'

const debugFs = createDebugger('vitest:cache:fs')
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/cli/cli-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InlineConfig as ViteInlineConfig, UserConfig as ViteUserConfig } from 'vite'
import type { environments } from '../../integrations/env'
import type { InlineConfig as ViteInlineConfig, UserConfig as ViteUserConfig } from '../../vite'
import type { Vitest, VitestOptions } from '../core'
import type { TestModule, TestSuite } from '../reporters/reported-tasks'
import type { TestSpecification } from '../test-specification'
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ResolvedConfig as ResolvedViteConfig } from 'vite'
import type { ResolvedConfig as ResolvedViteConfig } from '../../vite'
import type { Vitest } from '../core'
import type { Logger } from '../logger'
import type { BenchmarkBuiltinReporters } from '../reporters'
Expand All @@ -15,7 +15,6 @@ import { slash, toArray } from '@vitest/utils/helpers'
import { resolveModule } from 'local-pkg'
import { normalize, relative, resolve } from 'pathe'
import c from 'tinyrainbow'
import { mergeConfig } from 'vite'
import {
configFiles,
defaultBrowserPort,
Expand All @@ -25,6 +24,7 @@ import {
import { benchmarkConfigDefaults, configDefaults } from '../../defaults'
import { isCI, stdProvider } from '../../utils/env'
import { getWorkersCountByPercentage } from '../../utils/workers'
import { mergeConfig } from '../../vite'
import { BaseSequencer } from '../sequencers/BaseSequencer'
import { RandomSequencer } from '../sequencers/RandomSequencer'

Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { CancelReason, File } from '@vitest/runner'
import type { Awaitable } from '@vitest/utils'
import type { Writable } from 'node:stream'
import type { ViteDevServer } from 'vite'
import type { ModuleRunner } from 'vite/module-runner'
import type { SerializedCoverageConfig } from '../runtime/config'
import type { ArgumentsType, ProvidedContext, UserConsoleLog } from '../types/general'
import type { SourceModuleDiagnostic, SourceModuleLocations } from '../types/module-locations'
import type { ViteDevServer } from '../vite'
import type { CliOptions } from './cli/cli-api'
import type { VitestFetchFunction } from './environments/fetchModule'
import type { ProcessPool } from './pool'
Expand All @@ -20,14 +20,14 @@ import { getTasks, hasFailed, limitConcurrency } from '@vitest/runner/utils'
import { SnapshotManager } from '@vitest/snapshot/manager'
import { deepClone, deepMerge, nanoid, noop, toArray } from '@vitest/utils/helpers'
import { join, normalize, relative } from 'pathe'
import { isRunnableDevEnvironment } from 'vite'
import { version } from '../../package.json' with { type: 'json' }
import { WebSocketReporter } from '../api/setup'
import { distDir } from '../paths'
import { wildcardPatternToRegExp } from '../utils/base'
import { NativeModuleRunner } from '../utils/nativeModuleRunner'
import { convertTasksToEvents } from '../utils/tasks'
import { Traces } from '../utils/traces'
import { isRunnableDevEnvironment } from '../vite'
import { astCollectTests, createFailedFileTask } from './ast-collect'
import { BrowserSessions } from './browser/sessions'
import { VitestCache } from './cache'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/coverage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { CoverageMap } from 'istanbul-lib-coverage'
import type { TransformResult } from 'vite'
import type { Vitest } from '../node/core'
import type { BaseCoverageOptions, CoverageModuleLoader, CoverageProvider, ReportContext, ResolvedCoverageOptions } from '../node/types/coverage'
import type { SerializedCoverageConfig } from '../runtime/config'
import type { AfterSuiteRunMeta } from '../types/general'
import type { TransformResult } from '../vite'
import type { TestProject } from './project'
import { existsSync, promises as fs, readdirSync, writeFileSync } from 'node:fs'
import module from 'node:module'
Expand Down
7 changes: 3 additions & 4 deletions packages/vitest/src/node/create.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import type {
InlineConfig as ViteInlineConfig,
UserConfig as ViteUserConfig,
} from 'vite'
} from '../vite'
import type { CliOptions } from './cli/cli-api'
import type { VitestOptions } from './core'
import type { VitestRunMode } from './types/config'
import { resolve } from 'node:path'
import { deepClone, slash } from '@vitest/utils/helpers'
import * as find from 'empathic/find'
import { resolveModule } from 'local-pkg'
import { mergeConfig } from 'vite'
import { configFiles } from '../constants'
import { createServer, mergeConfig } from '../vite'
import { Vitest } from './core'
import { VitestPlugin } from './plugins'
import { createViteServer } from './vite'

export async function createVitest(
mode: VitestRunMode,
Expand Down Expand Up @@ -44,7 +43,7 @@ export async function createVitest(
}

try {
const server = await createViteServer(
const server = await createServer(
mergeConfig(config, mergeConfig(viteOverrides, { root: options.root })),
)

Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/environments/fetchModule.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Span } from '@opentelemetry/api'
import type { DevEnvironment, EnvironmentModuleNode, FetchResult, Rollup, TransformResult } from 'vite'
import type { FetchFunctionOptions } from 'vite/module-runner'
import type { FetchCachedFileSystemResult } from '../../types/general'
import type { OTELCarrier, Traces } from '../../utils/traces'
import type { DevEnvironment, EnvironmentModuleNode, FetchResult, Rollup, TransformResult } from '../../vite'
import type { FileSystemModuleCache } from '../cache/fsModuleCache'
import type { VitestResolver } from '../resolver'
import type { ResolvedConfig } from '../types/config'
import { existsSync, mkdirSync } from 'node:fs'
import { readFile } from 'node:fs/promises'
import { isExternalUrl, unwrapId } from '@vitest/utils/helpers'
import { join } from 'pathe'
import { fetchModule } from 'vite'
import { fetchModule } from '../../vite'
import { hash } from '../hash'
import { normalizeResolvedIdToUrl } from './normalizeUrl'

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/environments/normalizeUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DevEnvironment } from 'vite'
import type { DevEnvironment } from '../../vite'
import { existsSync } from 'node:fs'
import path from 'node:path'
import { cleanUrl, withTrailingSlash, wrapId } from '@vitest/utils/helpers'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/environments/serverRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DevEnvironment } from 'vite'
import type { DevEnvironment } from '../../vite'
import type { ResolvedConfig } from '../types/config'
import type { VitestFetchFunction } from './fetchModule'
import { readFile } from 'node:fs/promises'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/module-diagnostic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ImportDuration } from '@vitest/runner'
import type { EnvironmentModuleGraph, TransformResult } from 'vite'
import type {
ModuleDefinitionDiagnostic,
ModuleDefinitionDurationsDiagnostic,
Expand All @@ -8,6 +7,7 @@ import type {
SourceModuleLocations,
UntrackedModuleDefinitionDiagnostic,
} from '../types/module-locations'
import type { EnvironmentModuleGraph, TransformResult } from '../vite'
import type { TestModule } from './reporters/reported-tasks'
import type { StateManager } from './state'
import { originalPositionFor, TraceMap } from '@jridgewell/trace-mapping'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/coverageTransform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin as VitePlugin } from 'vite'
import type { Plugin as VitePlugin } from '../../vite'
import type { Vitest } from '../core'

export function CoverageTransform(ctx: Vitest): VitePlugin {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/cssEnabler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin as VitePlugin } from 'vite'
import type { Plugin as VitePlugin } from '../../vite'
import type { CSSModuleScopeStrategy, ResolvedConfig } from '../types/config'
import { toArray } from '@vitest/utils/helpers'
import { relative } from 'pathe'
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { UserConfig as ViteConfig, Plugin as VitePlugin } from 'vite'
import type { UserConfig as ViteConfig, Plugin as VitePlugin } from '../../vite'
import type { ResolvedConfig, UserConfig } from '../types/config'
import { deepClone, deepMerge, notNullish } from '@vitest/utils/helpers'
import { relative } from 'pathe'
import * as vite from 'vite'
import { defaultPort } from '../../constants'
import { configDefaults } from '../../defaults'
import { generateScopedClassName } from '../../integrations/css/css-modules'
import { rolldownVersion } from '../../vite'
import { resolveApiServerConfig } from '../config/resolveConfig'
import { Vitest } from '../core'
import { createViteLogger, silenceImportViteIgnoreWarning } from '../viteLogger'
Expand Down Expand Up @@ -121,7 +121,7 @@ export async function VitestPlugin(
},
}

if ('rolldownVersion' in vite) {
if (rolldownVersion) {
config = {
...config,
// eslint-disable-next-line ts/ban-ts-comment
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/metaEnvReplacer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite'
import type { Plugin } from '../../vite'
import { cleanUrl } from '@vitest/utils/helpers'
import MagicString from 'magic-string'
import { stripLiteral } from 'strip-literal'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite'
import type { Plugin } from '../../vite'
import { automockPlugin, hoistMocksPlugin } from '@vitest/mocker/node'
import { normalize } from 'pathe'
import { distDir } from '../../paths'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/normalizeURL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite'
import type { Plugin } from '../../vite'
import { stripLiteral } from 'strip-literal'

const metaUrlLength = 'import.meta.url'.length
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/optimizer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite'
import type { Plugin } from '../../vite'
import { resolve } from 'pathe'
import { VitestCache } from '../cache'

Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/plugins/publicConfig.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type {
ResolvedConfig as ResolvedViteConfig,
UserConfig as ViteUserConfig,
} from 'vite'
} from '../../vite'
import type { ResolvedConfig, UserConfig } from '../types/config'
import { deepClone, slash } from '@vitest/utils/helpers'
import * as find from 'empathic/find'
import { resolve } from 'pathe'
import { mergeConfig, resolveConfig as resolveViteConfig } from 'vite'
import { configFiles } from '../../constants'
import { mergeConfig, resolveConfig as resolveViteConfig } from '../../vite'
import { resolveConfig as resolveVitestConfig } from '../config/resolveConfig'
import { Vitest } from '../core'
import { VitestPlugin } from './index'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/runnerTransform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ResolveOptions, UserConfig, Plugin as VitePlugin } from 'vite'
import type { ResolveOptions, UserConfig, Plugin as VitePlugin } from '../../vite'
import { builtinModules } from 'node:module'
import { normalize } from 'pathe'
import { escapeRegExp } from '../../utils/base'
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/node/plugins/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {
DepOptimizationOptions,
UserConfig as ViteConfig,
} from 'vite'
} from '../../vite'
import type { DepsOptimizationOptions } from '../types/config'
import { dirname } from 'pathe'
import { searchForWorkspaceRoot, version as viteVersion } from 'vite'
import * as vite from 'vite'
import { rootDir } from '../../paths'
import { searchForWorkspaceRoot, version as viteVersion } from '../../vite'
import * as vite from '../../vite'

export function resolveOptimizerConfig(
_testOptions: DepsOptimizationOptions | undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/vitestResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin } from 'vite'
import type { Plugin } from '../../vite'
import type { Vitest } from '../core'
import { join, resolve } from 'pathe'
import { distDir } from '../../paths'
Expand Down
Loading
Loading