@pokujs/dom 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dom-env.js +35 -13
- package/dist/dom-env.js.map +1 -1
- package/dist/plugin-setup.js +11 -1
- package/dist/plugin-setup.js.map +1 -1
- package/package.json +7 -5
package/dist/dom-env.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GlobalWindow } from 'happy-dom';
|
|
2
2
|
const applyReactActEnvironment = (enabled) => {
|
|
3
3
|
if (!enabled)
|
|
4
4
|
return;
|
|
@@ -7,18 +7,6 @@ const applyReactActEnvironment = (enabled) => {
|
|
|
7
7
|
reactGlobal.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
|
-
export const setupHappyDomEnvironment = async (options) => {
|
|
11
|
-
if (!globalThis.window || !globalThis.document) {
|
|
12
|
-
GlobalRegistrator.register({
|
|
13
|
-
url: options.runtimeOptions.domUrl,
|
|
14
|
-
});
|
|
15
|
-
const nativeDispatchEvent = globalThis.window.dispatchEvent;
|
|
16
|
-
if (typeof nativeDispatchEvent === 'function') {
|
|
17
|
-
globalThis.dispatchEvent = nativeDispatchEvent.bind(globalThis.window);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
applyReactActEnvironment(Boolean(options.enableReactActEnvironment));
|
|
21
|
-
};
|
|
22
10
|
const defineGlobal = (key, value) => {
|
|
23
11
|
Object.defineProperty(globalThis, key, {
|
|
24
12
|
configurable: true,
|
|
@@ -26,6 +14,40 @@ const defineGlobal = (key, value) => {
|
|
|
26
14
|
value,
|
|
27
15
|
});
|
|
28
16
|
};
|
|
17
|
+
export const setupHappyDomEnvironment = async (options) => {
|
|
18
|
+
if (!globalThis.window || !globalThis.document) {
|
|
19
|
+
// Save native event primitives before installing Happy DOM globals.
|
|
20
|
+
// Deno's runtime calls globalThis.dispatchEvent('beforeunload') on exit
|
|
21
|
+
// using its own native Event constructor — if Happy DOM's dispatchEvent
|
|
22
|
+
// is installed instead, the type check inside it throws a TypeError.
|
|
23
|
+
const existingDispatchEvent = globalThis.dispatchEvent;
|
|
24
|
+
const existingEvent = globalThis.Event;
|
|
25
|
+
const existingCustomEvent = globalThis.CustomEvent;
|
|
26
|
+
const happyWindow = new GlobalWindow({ url: options.runtimeOptions.domUrl });
|
|
27
|
+
defineGlobal('window', happyWindow);
|
|
28
|
+
defineGlobal('document', happyWindow.document);
|
|
29
|
+
defineGlobal('navigator', happyWindow.navigator);
|
|
30
|
+
defineGlobal('HTMLElement', happyWindow.HTMLElement);
|
|
31
|
+
defineGlobal('Element', happyWindow.Element);
|
|
32
|
+
defineGlobal('Node', happyWindow.Node);
|
|
33
|
+
defineGlobal('Text', happyWindow.Text);
|
|
34
|
+
defineGlobal('SVGElement', happyWindow.SVGElement);
|
|
35
|
+
defineGlobal('MutationObserver', happyWindow.MutationObserver);
|
|
36
|
+
defineGlobal('requestAnimationFrame', happyWindow.requestAnimationFrame);
|
|
37
|
+
defineGlobal('cancelAnimationFrame', happyWindow.cancelAnimationFrame);
|
|
38
|
+
// Prefer the runtime's native Event constructors so that Deno's internal
|
|
39
|
+
// event dispatch (e.g. beforeunload) continues to work correctly.
|
|
40
|
+
defineGlobal('Event', typeof existingEvent === 'function' ? existingEvent : happyWindow.Event);
|
|
41
|
+
defineGlobal('CustomEvent', typeof existingCustomEvent === 'function' ? existingCustomEvent : happyWindow.CustomEvent);
|
|
42
|
+
if (typeof existingDispatchEvent === 'function') {
|
|
43
|
+
globalThis.dispatchEvent = existingDispatchEvent;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
globalThis.dispatchEvent = happyWindow.dispatchEvent.bind(happyWindow);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
applyReactActEnvironment(Boolean(options.enableReactActEnvironment));
|
|
50
|
+
};
|
|
29
51
|
export const setupJsdomEnvironment = async (options) => {
|
|
30
52
|
if (!globalThis.window || !globalThis.document) {
|
|
31
53
|
let mod;
|
package/dist/dom-env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom-env.js","sourceRoot":"","sources":["../src/dom-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"dom-env.js","sourceRoot":"","sources":["../src/dom-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAazC,MAAM,wBAAwB,GAAG,CAAC,OAAgB,EAAE,EAAE;IACpD,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,MAAM,WAAW,GAAG,UAA4B,CAAC;IACjD,IAAI,OAAO,WAAW,CAAC,wBAAwB,KAAK,WAAW,EAAE,CAAC;QAChE,WAAW,CAAC,wBAAwB,GAAG,IAAI,CAAC;IAC9C,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,GAA4B,EAAE,KAAc,EAAE,EAAE;IACpE,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE;QACrC,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,IAAI;QACd,KAAK;KACN,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,OAAmC,EACnC,EAAE;IACF,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QAC/C,oEAAoE;QACpE,wEAAwE;QACxE,wEAAwE;QACxE,qEAAqE;QACrE,MAAM,qBAAqB,GAAG,UAAU,CAAC,aAAa,CAAC;QACvD,MAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC;QACvC,MAAM,mBAAmB,GAAG,UAAU,CAAC,WAAW,CAAC;QAEnD,MAAM,WAAW,GAAG,IAAI,YAAY,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,cAAc,CAAC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CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxC,YAAY,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QACpD,YAAY,CAAC,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC9D,YAAY,CAAC,uBAAuB,EAAE,GAAG,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;QACxE,YAAY,CAAC,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACxE,CAAC;IAED,wBAAwB,CAAC,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC;AACvE,CAAC,CAAC"}
|
package/dist/plugin-setup.js
CHANGED
|
@@ -10,6 +10,11 @@ import { pathToFileURL } from 'node:url';
|
|
|
10
10
|
import { createRequire } from 'node:module';
|
|
11
11
|
import { canHandleRuntime, isNodeRuntime } from "./plugin-command.js";
|
|
12
12
|
const TSX_LOADER_MODULE = 'tsx/esm/api';
|
|
13
|
+
// Once tsx is registered in a Node.js process it cannot be safely deregistered
|
|
14
|
+
// and re-registered (tsx's hook worker re-instantiation fails with an invalid
|
|
15
|
+
// URL scheme). Under isolation:'none' everything runs in the same process for
|
|
16
|
+
// its lifetime, so keeping the loader registered permanently is correct.
|
|
17
|
+
const TSX_LOADER_REGISTERED_KEY = Symbol.for('@pokujs/dom.tsx-loader-registered');
|
|
13
18
|
const appendMissingRuntimeArgs = (runtimeOptionArgs) => {
|
|
14
19
|
for (const arg of runtimeOptionArgs) {
|
|
15
20
|
if (process.argv.includes(arg))
|
|
@@ -21,6 +26,9 @@ const loadDomSetupModule = async (domSetupPath) => {
|
|
|
21
26
|
await import(__rewriteRelativeImportExtension(pathToFileURL(domSetupPath).href));
|
|
22
27
|
};
|
|
23
28
|
const registerNodeTsxLoader = async (packageTag) => {
|
|
29
|
+
const g = globalThis;
|
|
30
|
+
if (g[TSX_LOADER_REGISTERED_KEY])
|
|
31
|
+
return () => { };
|
|
24
32
|
const requireFromCwd = createRequire(`${process.cwd()}/`);
|
|
25
33
|
try {
|
|
26
34
|
const resolvedModulePath = requireFromCwd.resolve(TSX_LOADER_MODULE);
|
|
@@ -28,7 +36,9 @@ const registerNodeTsxLoader = async (packageTag) => {
|
|
|
28
36
|
if (typeof mod.register !== 'function') {
|
|
29
37
|
throw new Error('Missing register() export from tsx loader API');
|
|
30
38
|
}
|
|
31
|
-
|
|
39
|
+
mod.register();
|
|
40
|
+
g[TSX_LOADER_REGISTERED_KEY] = true;
|
|
41
|
+
return () => { };
|
|
32
42
|
}
|
|
33
43
|
catch (error) {
|
|
34
44
|
throw new Error(`[${packageTag}] isolation "none" in Node.js requires a working "tsx" installation to load .tsx/.jsx test files.`, { cause: error });
|
package/dist/plugin-setup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-setup.js","sourceRoot":"","sources":["../src/plugin-setup.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAMtE,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC,MAAM,wBAAwB,GAAG,CAAC,iBAA2B,EAAE,EAAE;IAC/D,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,SAAS;QACzC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,KAAK,EAAE,YAAoB,EAAE,EAAE;IACxD,MAAM,MAAM,kCAAC,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,EAAC,CAAC;AACjD,CAAC,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
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared DOM testing core for Poku framework adapters.",
|
|
6
6
|
"type": "module",
|
|
@@ -25,8 +25,14 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"test": "npm run test:node",
|
|
27
27
|
"test:node": "node --import=tsx ./node_modules/poku/lib/bin/index.js tests --showLogs",
|
|
28
|
+
"test:node:none": "node --import=tsx ./node_modules/poku/lib/bin/index.js tests --showLogs --isolation=none",
|
|
29
|
+
"test:node:process": "node --import=tsx ./node_modules/poku/lib/bin/index.js tests --showLogs --isolation=process",
|
|
28
30
|
"test:bun": "bun ./node_modules/poku/lib/bin/index.js tests --showLogs",
|
|
31
|
+
"test:bun:none": "bun ./node_modules/poku/lib/bin/index.js tests --showLogs --isolation=none",
|
|
32
|
+
"test:bun:process": "bun ./node_modules/poku/lib/bin/index.js tests --showLogs --isolation=process",
|
|
29
33
|
"test:deno": "deno run -A npm:poku tests --showLogs",
|
|
34
|
+
"test:deno:none": "deno run -A npm:poku tests --showLogs --isolation=none",
|
|
35
|
+
"test:deno:process": "deno run -A npm:poku tests --showLogs --isolation=process",
|
|
30
36
|
"clean": "rimraf dist",
|
|
31
37
|
"build": "npm run clean && tsc -p tsconfig.dist.json",
|
|
32
38
|
"typecheck": "tsc -p tsconfig.build.json --noEmit",
|
|
@@ -56,15 +62,11 @@
|
|
|
56
62
|
"provenance": true
|
|
57
63
|
},
|
|
58
64
|
"peerDependencies": {
|
|
59
|
-
"@happy-dom/global-registrator": ">=20",
|
|
60
65
|
"happy-dom": ">=20",
|
|
61
66
|
"jsdom": ">=22",
|
|
62
67
|
"poku": ">=4.1.0"
|
|
63
68
|
},
|
|
64
69
|
"peerDependenciesMeta": {
|
|
65
|
-
"@happy-dom/global-registrator": {
|
|
66
|
-
"optional": true
|
|
67
|
-
},
|
|
68
70
|
"happy-dom": {
|
|
69
71
|
"optional": true
|
|
70
72
|
},
|