Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: jsdom too
  • Loading branch information
hi-ogawa committed Apr 4, 2025
commit 61935e3fa8820f61d0e70022542b27d7d5f9d7a3
3 changes: 2 additions & 1 deletion packages/vitest/src/integrations/env/jsdom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Environment } from '../../types/environment'
import type { JSDOMOptions } from '../../types/jsdom-options'
import { populateGlobal } from './utils'

function catchWindowErrors(window: Window) {
Expand Down Expand Up @@ -51,7 +52,7 @@ export default <Environment>{
console = false,
cookieJar = false,
...restOptions
} = jsdom as any
} = jsdom as JSDOMOptions
let dom = new JSDOM(html, {
pretendToBeVisual,
resources:
Expand Down
42 changes: 7 additions & 35 deletions packages/vitest/src/types/jsdom-options.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
export interface JSDOMOptions {
// eslint-disable-next-line ts/ban-ts-comment
// @ts-ignore `jsdom` is optional peeer dep
import type { ConstructorOptions } from 'jsdom'

export type JSDOMOptions = ConstructorOptionsOverride & Omit<ConstructorOptions, keyof ConstructorOptionsOverride>

interface ConstructorOptionsOverride {
/**
* The html content for the test.
*
* @default '<!DOCTYPE html>'
*/
html?: string | ArrayBufferLike
/**
* referrer just affects the value read from document.referrer.
* It defaults to no referrer (which reflects as the empty string).
*/
referrer?: string
/**
* userAgent affects the value read from navigator.userAgent, as well as the User-Agent header sent while fetching subresources.
*
Expand All @@ -24,21 +25,6 @@ export interface JSDOMOptions {
* @default 'http://localhost:3000'.
*/
url?: string
/**
* contentType affects the value read from document.contentType, and how the document is parsed: as HTML or as XML.
* Values that are not "text/html" or an XML mime type will throw.
*
* @default 'text/html'.
*/
contentType?: string
/**
* The maximum size in code units for the separate storage areas used by localStorage and sessionStorage.
* Attempts to store data larger than this limit will cause a DOMException to be thrown. By default, it is set
* to 5,000,000 code units per origin, as inspired by the HTML specification.
*
* @default 5_000_000
*/
storageQuota?: number
/**
* Enable console?
*
Expand All @@ -55,20 +41,6 @@ export interface JSDOMOptions {
* @default true
*/
pretendToBeVisual?: boolean
/**
* `includeNodeLocations` preserves the location info produced by the HTML parser,
* allowing you to retrieve it with the nodeLocation() method (described below).
*
* It defaults to false to give the best performance,
* and cannot be used with an XML content type since our XML parser does not support location info.
*
* @default false
*/
includeNodeLocations?: boolean | undefined
/**
* @default 'dangerously'
*/
runScripts?: 'dangerously' | 'outside-only'
/**
* Enable CookieJar
*
Expand Down