Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 23, 2025
1 parent dd2384e commit 4e7bf0b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/vitest/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const external = [
'node:fs',
'node:stream',
'node:vm',
'node:http',
'inspector',
'vite-node/source-map',
'vite-node/client',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function isHostAllowed(vitestConfig: VitestResolvedConfig, viteConfig: ResolvedC
)
}

export function isWebsocketRequestAllowed(vitestConfig: VitestResolvedConfig, viteConfig: ResolvedConfig, req: IncomingMessage): boolean {
export function isValidApiRequest(vitestConfig: VitestResolvedConfig, viteConfig: ResolvedConfig, req: IncomingMessage): boolean {
const url = new URL(req.url ?? '', 'http://localhost')

// validate token. token is injected in ui/tester/orchestrator html, which is cross origin proteced.
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getModuleGraph, isPrimitive, noop, stringifyReplace } from '../utils'
import type { WorkspaceProject } from '../node/workspace'
import { parseErrorStacktrace } from '../utils/source-map'
import type { TransformResultWithSource, WebSocketEvents, WebSocketHandlers } from './types'
import { isWebsocketRequestAllowed } from './hostCheck'
import { isValidApiRequest } from './check'

export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, _server?: ViteDevServer) {
const ctx = 'ctx' in vitestOrWorkspace ? vitestOrWorkspace.ctx : vitestOrWorkspace
Expand All @@ -35,7 +35,7 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, _server?: Vi
if (pathname !== API_PATH)
return

if (!isWebsocketRequestAllowed(ctx.config, server.config, request)) {
if (!isValidApiRequest(ctx.config, server.config, request)) {
socket.destroy()
return
}
Expand Down
4 changes: 1 addition & 3 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export type VitestEnvironment = BuiltinEnvironment | (string & Record<never, nev
export type { Pool, PoolOptions }
export type CSSModuleScopeStrategy = 'stable' | 'scoped' | 'non-scoped'

export type ApiConfig = Pick<ServerOptions, 'port' | 'strictPort' | 'host' | 'middlewareMode'> & {
allowedHosts?: string[] | true
}
export type ApiConfig = Pick<ServerOptions, 'port' | 'strictPort' | 'host' | 'middlewareMode'>

export type { JSDOMOptions, HappyDOMOptions }

Expand Down
26 changes: 4 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e7bf0b

Please sign in to comment.