Skip to content
Merged
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
7 changes: 7 additions & 0 deletions packages/vitest/optional-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable ts/ban-ts-comment */

// @ts-ignore optional peer dep
export type * as jsdomTypes from 'jsdom'

// @ts-ignore optional peer dep
export type * as happyDomTypes from 'happy-dom'
1 change: 1 addition & 0 deletions packages/vitest/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const external = [
'node:http',
'node:console',
'inspector',
'vitest/optional-types.js',
'vite-node/source-map',
'vite-node/client',
'vite-node/server',
Expand Down
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
29 changes: 6 additions & 23 deletions packages/vitest/src/types/happy-dom-options.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
/**
* Happy DOM options.
*/
export interface HappyDOMOptions {
width?: number
height?: number
url?: string
settings?: {
disableJavaScriptEvaluation?: boolean
disableJavaScriptFileLoading?: boolean
disableCSSFileLoading?: boolean
disableIframePageLoading?: boolean
disableComputedStyleRendering?: boolean
enableFileSystemHttpRequests?: boolean
navigator?: {
userAgent?: string
}
device?: {
prefersColorScheme?: string
mediaType?: string
}
}
}
import type { happyDomTypes } from 'vitest/optional-types.js'

export type HappyDOMOptions = Omit<
NonNullable<ConstructorParameters<typeof happyDomTypes.Window>[0]>,
'console'
>
40 changes: 5 additions & 35 deletions packages/vitest/src/types/jsdom-options.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
export interface JSDOMOptions {
import type { jsdomTypes } from 'vitest/optional-types.js'

export type JSDOMOptions = ConstructorOptionsOverride & Omit<jsdomTypes.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 +23,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 +39,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
3 changes: 3 additions & 0 deletions test/dts-config/happy-dom-patch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// happy-dom's dts will break `skipLibCheck: false`.
// for now, override happy-dom type for the sake of testing other packages.
export const Window = {} as any
1 change: 1 addition & 0 deletions test/dts-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": ["./tsconfig.patch.json"],
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
Expand Down
7 changes: 7 additions & 0 deletions test/dts-config/tsconfig.patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"happy-dom": ["./happy-dom-patch.ts"]
}
}
}
1 change: 1 addition & 0 deletions test/dts-fixture/tsconfig.check.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": ["../dts-config/tsconfig.patch.json"],
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
Expand Down
1 change: 1 addition & 0 deletions test/dts-fixture/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": ["../dts-config/tsconfig.patch.json"],
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
Expand Down
1 change: 1 addition & 0 deletions test/dts-playwright/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": ["../dts-config/tsconfig.patch.json"],
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
Expand Down
Loading