Skip to content

Commit

Permalink
fix: resolve test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
fenghan34 committed Mar 21, 2024
1 parent 5cb8300 commit 09082cb
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/vitest/rollup.config.js
Expand Up @@ -24,6 +24,7 @@ const entries = {
'suite': 'src/suite.ts',
'browser': 'src/browser.ts',
'runners': 'src/runners.ts',
'runners-node': 'src/runtime/runners/node/index.ts',
'environments': 'src/environments.ts',
'spy': 'src/integrations/spy.ts',
'coverage': 'src/coverage.ts',
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/core.ts
Expand Up @@ -16,7 +16,7 @@ import { getCoverageProvider } from '../integrations/coverage'
import { CONFIG_NAMES, configFiles, workspacesFiles as workspaceFiles } from '../constants'
import { rootDir } from '../paths'
import { WebSocketReporter } from '../api/setup'
import type { HangingOps } from '../runtime/runners/with-async-leaks-detecter'
import type { HangingOps } from '../runtime/runners/node/detect-async-leaks'
import { createPool } from './pool'
import type { ProcessPool, WorkspaceSpec } from './pool'
import { createBenchmarkReporters, createReporters } from './reporters/utils'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/logger.ts
Expand Up @@ -5,7 +5,7 @@ import type { ErrorWithDiff } from '../types'
import type { TypeCheckError } from '../typecheck/typechecker'
import { getFullName, toArray } from '../utils'
import { highlightCode } from '../utils/colors'
import type { HangingOps } from '../runtime/runners/with-async-leaks-detecter'
import type { HangingOps } from '../runtime/runners/node/detect-async-leaks'
import { divider } from './reporters/renderers/utils'
import { RandomSequencer } from './sequencers/RandomSequencer'
import type { Vitest } from './core'
Expand Down
1 change: 0 additions & 1 deletion packages/vitest/src/runners.ts
@@ -1,3 +1,2 @@
export { VitestTestRunner } from './runtime/runners/test'
export { NodeBenchmarkRunner } from './runtime/runners/benchmark'
export { VitestTestRunnerWithAsyncLeaksDetecter } from './runtime/runners/with-async-leaks-detecter'
10 changes: 6 additions & 4 deletions packages/vitest/src/runtime/runners/index.ts
Expand Up @@ -8,18 +8,20 @@ import { rpc } from '../rpc'
import { takeCoverageInsideWorker } from '../../integrations/coverage'
import { loadDiffConfig, loadSnapshotSerializers } from '../setup-common'

const runnersFile = resolve(distDir, 'runners.js')
const commonRunnersFile = resolve(distDir, 'runners.js')
const nodeRunnersFile = resolve(distDir, 'runners-node.js')

async function getTestRunnerConstructor(config: ResolvedConfig, executor: VitestExecutor): Promise<VitestRunnerConstructor> {
if (!config.runner) {
const { VitestTestRunner, NodeBenchmarkRunner, VitestTestRunnerWithAsyncLeaksDetecter } = await executor.executeFile(runnersFile)

if (config.detectAsyncLeaks) {
if (config.browser?.enabled)
throw new Error('"--detectAsyncLeaks" flag is not supported in browser mode.')
return VitestTestRunnerWithAsyncLeaksDetecter as VitestRunnerConstructor
const { WithAsyncLeaksDetecter } = await executor.executeFile(nodeRunnersFile)
return WithAsyncLeaksDetecter as VitestRunnerConstructor
}

const { VitestTestRunner, NodeBenchmarkRunner } = await executor.executeFile(commonRunnersFile)

return (config.mode === 'test' ? VitestTestRunner : NodeBenchmarkRunner) as VitestRunnerConstructor
}
const mod = await executor.executeId(config.runner)
Expand Down
@@ -1,8 +1,8 @@
import asyncHooks from 'node:async_hooks'
import { promisify } from 'node:util'
import { relative } from 'pathe'
import { rpc } from '../rpc'
import { VitestTestRunner } from './test'
import { rpc } from '../../rpc'
import { VitestTestRunner } from '../test'

export interface HangingOps {
error: Error
Expand All @@ -11,7 +11,7 @@ export interface HangingOps {

const asyncSleep = promisify(setTimeout)

export class VitestTestRunnerWithAsyncLeaksDetecter extends VitestTestRunner {
export class WithAsyncLeaksDetecter extends VitestTestRunner {
private hangingOps: Map<number, HangingOps> = new Map()

private asyncHook: asyncHooks.AsyncHook = asyncHooks.createHook({
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/runtime/runners/node/index.ts
@@ -0,0 +1 @@
export { WithAsyncLeaksDetecter } from './detect-async-leaks'
2 changes: 1 addition & 1 deletion packages/vitest/src/types/rpc.ts
@@ -1,6 +1,6 @@
import type { FetchResult, RawSourceMap, ViteNodeResolveId } from 'vite-node'
import type { CancelReason } from '@vitest/runner'
import type { HangingOps } from '../runtime/runners/with-async-leaks-detecter'
import type { HangingOps } from '../runtime/runners/node/detect-async-leaks'
import type { EnvironmentOptions, Pool, ResolvedConfig, VitestEnvironment } from './config'
import type { Environment, UserConsoleLog } from './general'
import type { SnapshotResult } from './snapshot'
Expand Down

0 comments on commit 09082cb

Please sign in to comment.