This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: you now need to explicitly add `happy-dom` or `jsdom` as a dev dependency based on which `domEnvironment` you want to be in. (`happy-dom` is set by default.)
- Loading branch information
Showing
10 changed files
with
359 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { importModule } from 'local-pkg' | ||
import { EnvironmentNuxt } from '../types' | ||
|
||
export default <EnvironmentNuxt> async function (_, { happyDom = {} }) { | ||
const { Window, GlobalWindow } = await importModule('happy-dom') as typeof import('happy-dom') | ||
const window = new (GlobalWindow || Window)(happyDom) as any | ||
|
||
return { | ||
window, | ||
teardown() { | ||
window.happyDOM.cancelAsync() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { importModule } from 'local-pkg' | ||
import { EnvironmentNuxt } from '../types' | ||
|
||
export default <EnvironmentNuxt> async function (global, { jsdom = {} }) { | ||
const { | ||
CookieJar, | ||
JSDOM, | ||
ResourceLoader, | ||
VirtualConsole, | ||
} = await importModule('jsdom') as typeof import('jsdom') | ||
const { | ||
html = '<!DOCTYPE html>', | ||
userAgent, | ||
url = 'http://localhost:3000', | ||
contentType = 'text/html', | ||
pretendToBeVisual = true, | ||
includeNodeLocations = false, | ||
runScripts = 'dangerously', | ||
resources, | ||
console = false, | ||
cookieJar = false, | ||
...restOptions | ||
} = jsdom as any | ||
const window = new JSDOM( | ||
html, | ||
{ | ||
pretendToBeVisual, | ||
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : undefined), | ||
runScripts, | ||
url, | ||
virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : undefined, | ||
cookieJar: cookieJar ? new CookieJar() : undefined, | ||
includeNodeLocations, | ||
contentType, | ||
userAgent, | ||
...restOptions, | ||
}, | ||
).window as any | ||
|
||
return { | ||
window, | ||
teardown() {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { App } from "h3" | ||
|
||
export type NuxtBuiltinEnvironment = 'happy-dom' | 'jsdom' | ||
export interface NuxtWindow extends Window { | ||
__app: App | ||
__registry: Set<string> | ||
__NUXT__: any | ||
$fetch: any | ||
fetch: any | ||
IntersectionObserver: any | ||
Headers: any | ||
} | ||
export type EnvironmentNuxt = (global: any, options: Record<string, any>) => Promise<{ | ||
window: NuxtWindow, | ||
teardown(): void | ||
}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.