@ctrl/dom 0.1.4 → 0.1.5
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/aria/_chunks/roles-list-BXCvPLJT.cjs +4 -0
- package/dist/aria/_chunks/roles-list-rVVxaIPs.js +4 -0
- package/dist/aria/index.cjs +1 -232
- package/dist/aria/index.js +1 -198
- package/dist/aria/internal.cjs +1 -69
- package/dist/aria/internal.js +1 -30
- package/dist/cli/_chunks/report-z52LF7nA.js +12 -0
- package/dist/cli/_chunks/rolldown-runtime-H3fMLYWS.js +1 -0
- package/dist/cli/ctrl-dom.js +2 -181
- package/dist/cli/jest-reporter.js +2 -54
- package/dist/cli/vitest-reporter.js +2 -81
- package/dist/dom/_chunks/src-sZY6a2LC.js +49 -0
- package/dist/dom/index.js +1 -3
- package/dist/dom/internal.js +1 -434
- package/dist/dom/types/window/clock.d.ts +2 -2
- package/dist/jest-dom/_chunks/matchers-CGTk9GX9.cjs +31 -0
- package/dist/jest-dom/_chunks/matchers-Chf0yHoo.js +31 -0
- package/dist/jest-dom/index.cjs +1 -5
- package/dist/jest-dom/index.js +1 -6
- package/dist/jest-dom/jest-globals.cjs +1 -6
- package/dist/jest-dom/jest-globals.js +1 -7
- package/dist/jest-dom/matchers.cjs +1 -53
- package/dist/jest-dom/matchers.js +1 -3
- package/dist/jest-dom/vitest.cjs +1 -6
- package/dist/jest-dom/vitest.js +1 -7
- package/dist/react/_chunks/pure-CCeTO5Mk.js +1 -0
- package/dist/react/_chunks/pure-DQzwul4s.cjs +1 -0
- package/dist/react/dont-cleanup-after-each.cjs +1 -3
- package/dist/react/dont-cleanup-after-each.js +1 -4
- package/dist/react/index.cjs +1 -47
- package/dist/react/index.js +1 -35
- package/dist/react/pure.cjs +1 -17
- package/dist/react/pure.js +1 -5
- package/dist/register/index.js +1 -11
- package/dist/register/pure.js +1 -147
- package/dist/testing-library/_chunks/aria-snapshot-diff-80G4meO2.cjs +14 -0
- package/dist/testing-library/_chunks/aria-snapshot-diff-B1L8s_sM.js +14 -0
- package/dist/testing-library/agent.cjs +10 -720
- package/dist/testing-library/agent.js +10 -712
- package/dist/testing-library/index.cjs +19 -2459
- package/dist/testing-library/index.js +19 -2380
- package/dist/user-event/index.cjs +33 -3924
- package/dist/user-event/index.js +33 -3899
- package/dist/user-event/types/ctrl-dom.d.ts +1 -1
- package/dist/vitest-environment/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
- package/dist/vitest-environment/failure-snapshot.js +1 -42
- package/dist/vitest-environment/index.js +1 -185
- package/dist/vitest-environment/plugin.js +1 -90
- package/package.json +1 -1
- package/dist/aria/_chunks/roles-list-CYZF-l9K.js +0 -1503
- package/dist/aria/_chunks/roles-list-D4WCyRO_.cjs +0 -1754
- package/dist/cli/_chunks/report-DdncYfuJ.js +0 -93
- package/dist/dom/_chunks/src-Cp3oLry4.js +0 -47610
- package/dist/jest-dom/_chunks/matchers-CDnnXUfG.js +0 -2211
- package/dist/jest-dom/_chunks/matchers-D988Ducb.cjs +0 -2516
- package/dist/react/_chunks/pure-DZ97z2oT.cjs +0 -498
- package/dist/react/_chunks/pure-PtE2hivW.js +0 -420
- package/dist/testing-library/_chunks/aria-snapshot-diff-D7PzpXew.cjs +0 -1170
- package/dist/testing-library/_chunks/aria-snapshot-diff-Q8Wj33K0.js +0 -985
|
@@ -46,7 +46,7 @@ export declare const ctrlDomCss: CtrlDomCss | null;
|
|
|
46
46
|
export declare function skipIdleTime(ms: number): boolean;
|
|
47
47
|
/**
|
|
48
48
|
* Whether immediates other than @ctrl/dom's clock's own are queued (src/window/clock.ts); on
|
|
49
|
-
* another DOM, any queued immediate.
|
|
49
|
+
* another DOM, any queued immediate.
|
|
50
50
|
*/
|
|
51
51
|
export declare function immediatesPending(): boolean;
|
|
52
52
|
/** The NodeImpl behind an @ctrl/dom wrapper, or null for nodes of other DOM implementations. */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name as t};
|
|
@@ -1,42 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { appendToErrorMessage, captureFailureSnapshot, envDebugFormat, formatFailureSnapshot, resetFailureSnapshot } from "@ctrl/dom/testing-library/agent";
|
|
3
|
-
|
|
4
|
-
// src/failure-snapshot.ts
|
|
5
|
-
if (envDebugFormat() !== null) installFailureSnapshots();
|
|
6
|
-
function currentDocument() {
|
|
7
|
-
return typeof document === "undefined" ? void 0 : document;
|
|
8
|
-
}
|
|
9
|
-
function installFailureSnapshots() {
|
|
10
|
-
let state = null;
|
|
11
|
-
let captured = null;
|
|
12
|
-
const capture = () => {
|
|
13
|
-
if (captured === null && state?.result?.state === "fail") captured = captureFailureSnapshot(currentDocument());
|
|
14
|
-
};
|
|
15
|
-
beforeEach((context) => {
|
|
16
|
-
state = context.task;
|
|
17
|
-
captured = null;
|
|
18
|
-
resetFailureSnapshot(currentDocument());
|
|
19
|
-
context.onTestFailed(() => {
|
|
20
|
-
capture();
|
|
21
|
-
const snapshot = captured;
|
|
22
|
-
captured = null;
|
|
23
|
-
state = null;
|
|
24
|
-
const error = context.task.result?.errors?.[0];
|
|
25
|
-
if (snapshot === null || error === void 0) return;
|
|
26
|
-
appendToErrorMessage(error, formatFailureSnapshot(snapshot, typeof error.message === "string" ? error.message : ""));
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
afterEach(capture);
|
|
30
|
-
const global = globalThis;
|
|
31
|
-
const original = global.afterEach;
|
|
32
|
-
if (typeof original === "function") global.afterEach = function afterEach(fn, timeout) {
|
|
33
|
-
if (typeof fn !== "function" || fn.length !== 0) return original.call(this, fn, timeout);
|
|
34
|
-
const hook = fn;
|
|
35
|
-
return original.call(this, function() {
|
|
36
|
-
capture();
|
|
37
|
-
return hook.apply(this, arguments);
|
|
38
|
-
}, timeout);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { };
|
|
1
|
+
import"./_chunks/rolldown-runtime-BhWHdk3m.js";import{afterEach as e,beforeEach as t}from"vitest";import{appendToErrorMessage as n,captureFailureSnapshot as r,envDebugFormat as i,formatFailureSnapshot as a,resetFailureSnapshot as o}from"@ctrl/dom/testing-library/agent";i()!==null&&installFailureSnapshots();function currentDocument(){return typeof document>`u`?void 0:document}function installFailureSnapshots(){let i=null,s=null,capture=()=>{s===null&&i?.result?.state===`fail`&&(s=r(currentDocument()))};t(e=>{i=e.task,s=null,o(currentDocument()),e.onTestFailed(()=>{capture();let t=s;s=null,i=null;let r=e.task.result?.errors?.[0];t!==null&&r!==void 0&&n(r,a(t,typeof r.message==`string`?r.message:``))})}),e(capture);let c=globalThis,l=c.afterEach;typeof l==`function`&&(c.afterEach=function afterEach(e,t){if(typeof e!=`function`||e.length!==0)return l.call(this,e,t);let n=e;return l.call(this,function(){return capture(),n.apply(this,arguments)},t)})}export{};
|
|
@@ -1,185 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { constants, createContext } from "node:vm";
|
|
4
|
-
|
|
5
|
-
// src/index.ts
|
|
6
|
-
let dom = null;
|
|
7
|
-
let internal = null;
|
|
8
|
-
/**
|
|
9
|
-
* Imports the DOM on the worker's first setup. Every Vitest worker pays this import
|
|
10
|
-
* (jsdom-startup README: isolated forks start a fresh worker per file), so with `compileCache`
|
|
11
|
-
* Node's on-disk compile cache is enabled first: it keeps V8 code (and stripped TypeScript) for
|
|
12
|
-
* the bundles across workers. Once on, it stays on for every module the worker loads after it,
|
|
13
|
-
* which only pays off for large files: deserializing hundreds of tiny ones (aria-query's roles,
|
|
14
|
-
* stock user-event) is slower than compiling them (comparison/: +6% wall time over 100 files with
|
|
15
|
-
* stock Testing Library, -11% with @ctrl/dom's).
|
|
16
|
-
*/
|
|
17
|
-
async function load(options) {
|
|
18
|
-
if (dom !== null) return;
|
|
19
|
-
if (compileCache(options)) enableCompileCache?.();
|
|
20
|
-
[dom, internal] = await Promise.all([import("../dom/index.js"), import("../dom/internal.js")]);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The global key under which the environment publishes the DOM modules it loaded (the same one
|
|
24
|
-
* @ctrl/dom-jest-environment uses). In VM pools Vitest evaluates a test file's modules inside the vm
|
|
25
|
-
* context, so an import of @ctrl/dom from test code (or from our Testing Library bundles) would
|
|
26
|
-
* otherwise evaluate a second DOM: its classes fail `instanceof` against the installed globals and
|
|
27
|
-
* every file pays for the evaluation. Published `@ctrl/dom` and `@ctrl/dom/internal` resolve to
|
|
28
|
-
* bridges that return these objects (scripts/release.ts, writeBridges).
|
|
29
|
-
*/
|
|
30
|
-
const DOM_MODULES = Symbol.for("ctrl-dom.dom.modules");
|
|
31
|
-
function publishModules(global) {
|
|
32
|
-
Object.defineProperty(global, DOM_MODULES, {
|
|
33
|
-
value: {
|
|
34
|
-
dom,
|
|
35
|
-
internal
|
|
36
|
-
},
|
|
37
|
-
configurable: true,
|
|
38
|
-
enumerable: false,
|
|
39
|
-
writable: false
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Exceptions nobody handled (listener exceptions, reportError(), React's uncaught errors) go to
|
|
44
|
-
* the worker as `uncaughtException`, which Vitest reports as an unhandled error that fails the
|
|
45
|
-
* run — what Vitest's jsdom environment does with its window "error" listener.
|
|
46
|
-
* https://html.spec.whatwg.org/#report-an-exception
|
|
47
|
-
*/
|
|
48
|
-
function reportToHost(error) {
|
|
49
|
-
process.emit("uncaughtException", error, "uncaughtException");
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* jsdom's "Not implemented" diagnostics (navigation, window.alert, form submission, ...; only
|
|
53
|
-
* under the jsdom profiles, @ctrl/dom window/not-implemented.ts), forwarded as under Vitest's
|
|
54
|
-
* jsdom environment, whose JSDOM gets jsdom's default virtual console: `console.error(e.stack,
|
|
55
|
-
* e.detail)` on the test's console.
|
|
56
|
-
*/
|
|
57
|
-
function forwardNotImplemented(global) {
|
|
58
|
-
return (error) => (global.console ?? console).error(error.stack, error.detail);
|
|
59
|
-
}
|
|
60
|
-
/** Same default URL as Vitest's jsdom and happy-dom environments. */
|
|
61
|
-
const DEFAULT_URL = "http://localhost:3000/";
|
|
62
|
-
/** The environment by path, as the ctrlDom() plugin configures it. */
|
|
63
|
-
const SELF = fileURLToPath(import.meta.url);
|
|
64
|
-
/** This environment's options out of Vitest's `environmentOptions` (see the header). */
|
|
65
|
-
function ownOptions(options) {
|
|
66
|
-
return options?.["ctrl-dom"] ?? options?.ctrlDom ?? options?.[SELF] ?? {};
|
|
67
|
-
}
|
|
68
|
-
function windowOptions(options) {
|
|
69
|
-
const { timeSkip: _timeSkip, compileCache: _compileCache, ...rest } = ownOptions(options);
|
|
70
|
-
return {
|
|
71
|
-
...rest,
|
|
72
|
-
compat: rest.compat ?? "jsdom-30",
|
|
73
|
-
url: rest.url ?? DEFAULT_URL
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function timeSkip(options) {
|
|
77
|
-
const env = process.env.CTRL_DOM_TIME_SKIP;
|
|
78
|
-
if (env === "1") return true;
|
|
79
|
-
if (env === "0") return false;
|
|
80
|
-
return ownOptions(options).timeSkip !== false;
|
|
81
|
-
}
|
|
82
|
-
function compileCache(options) {
|
|
83
|
-
const env = process.env.CTRL_DOM_COMPILE_CACHE;
|
|
84
|
-
if (env === "1") return true;
|
|
85
|
-
if (env === "0") return false;
|
|
86
|
-
return ownOptions(options).compileCache === true;
|
|
87
|
-
}
|
|
88
|
-
const VM_HOST_GLOBALS = [
|
|
89
|
-
"setTimeout",
|
|
90
|
-
"clearTimeout",
|
|
91
|
-
"setInterval",
|
|
92
|
-
"clearInterval",
|
|
93
|
-
"queueMicrotask",
|
|
94
|
-
"structuredClone",
|
|
95
|
-
"atob",
|
|
96
|
-
"btoa",
|
|
97
|
-
"fetch",
|
|
98
|
-
"crypto",
|
|
99
|
-
"performance",
|
|
100
|
-
"URL",
|
|
101
|
-
"URLSearchParams",
|
|
102
|
-
"AbortController",
|
|
103
|
-
"AbortSignal",
|
|
104
|
-
"Blob",
|
|
105
|
-
"File",
|
|
106
|
-
"TextEncoder",
|
|
107
|
-
"TextDecoder",
|
|
108
|
-
"ReadableStream",
|
|
109
|
-
"WritableStream",
|
|
110
|
-
"TransformStream",
|
|
111
|
-
"Headers",
|
|
112
|
-
"Request",
|
|
113
|
-
"Response",
|
|
114
|
-
"FormData",
|
|
115
|
-
"BroadcastChannel",
|
|
116
|
-
"MessageChannel",
|
|
117
|
-
"MessagePort",
|
|
118
|
-
"WebSocket",
|
|
119
|
-
"DOMException",
|
|
120
|
-
"Buffer"
|
|
121
|
-
];
|
|
122
|
-
const environment = {
|
|
123
|
-
name: "ctrl-dom",
|
|
124
|
-
viteEnvironment: "client",
|
|
125
|
-
prewarmModules: false,
|
|
126
|
-
async setup(global, options) {
|
|
127
|
-
await load(options);
|
|
128
|
-
const { createWindow, installGlobals } = dom;
|
|
129
|
-
const { setUncaughtExceptionHandler, setNotImplementedHandler, installClock, VirtualClock, subscribeTestFailures } = internal;
|
|
130
|
-
const window = createWindow(windowOptions(options));
|
|
131
|
-
const uninstall = installGlobals(window, global);
|
|
132
|
-
publishModules(global);
|
|
133
|
-
const clock = installClock(new VirtualClock({ skip: timeSkip(options) }), global);
|
|
134
|
-
setUncaughtExceptionHandler(reportToHost);
|
|
135
|
-
setNotImplementedHandler(forwardNotImplemented(global));
|
|
136
|
-
const unsubscribeFailures = subscribeTestFailures(() => window.document);
|
|
137
|
-
return { teardown() {
|
|
138
|
-
unsubscribeFailures();
|
|
139
|
-
setUncaughtExceptionHandler(null);
|
|
140
|
-
setNotImplementedHandler(null);
|
|
141
|
-
clock.uninstall();
|
|
142
|
-
window.close();
|
|
143
|
-
uninstall();
|
|
144
|
-
delete global[DOM_MODULES];
|
|
145
|
-
} };
|
|
146
|
-
},
|
|
147
|
-
async setupVM(options) {
|
|
148
|
-
await load(options);
|
|
149
|
-
const { createWindow, installGlobals } = dom;
|
|
150
|
-
const { setUncaughtExceptionHandler, setNotImplementedHandler, captureInterfaceBaseline, guardInterfaceDefinitions, restoreInterfaces, installClock, VirtualClock, subscribeTestFailures } = internal;
|
|
151
|
-
const window = createWindow(windowOptions(options));
|
|
152
|
-
const context = createContext(constants.DONT_CONTEXTIFY);
|
|
153
|
-
const host = globalThis;
|
|
154
|
-
for (const name of VM_HOST_GLOBALS) if (host[name] !== void 0) Object.defineProperty(context, name, {
|
|
155
|
-
value: host[name],
|
|
156
|
-
writable: true,
|
|
157
|
-
enumerable: false,
|
|
158
|
-
configurable: true
|
|
159
|
-
});
|
|
160
|
-
captureInterfaceBaseline();
|
|
161
|
-
const uninstall = installGlobals(window, context);
|
|
162
|
-
publishModules(context);
|
|
163
|
-
const clock = installClock(new VirtualClock({ skip: timeSkip(options) }), context);
|
|
164
|
-
guardInterfaceDefinitions(context);
|
|
165
|
-
setUncaughtExceptionHandler(reportToHost);
|
|
166
|
-
setNotImplementedHandler(forwardNotImplemented(context));
|
|
167
|
-
const unsubscribeFailures = subscribeTestFailures(() => window.document);
|
|
168
|
-
return {
|
|
169
|
-
getVmContext() {
|
|
170
|
-
return context;
|
|
171
|
-
},
|
|
172
|
-
teardown() {
|
|
173
|
-
unsubscribeFailures();
|
|
174
|
-
setUncaughtExceptionHandler(null);
|
|
175
|
-
setNotImplementedHandler(null);
|
|
176
|
-
clock.clock.dispose();
|
|
177
|
-
window.close();
|
|
178
|
-
uninstall();
|
|
179
|
-
restoreInterfaces();
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export { environment as default };
|
|
1
|
+
import"./_chunks/rolldown-runtime-BhWHdk3m.js";import{enableCompileCache as e}from"node:module";import{fileURLToPath as t}from"node:url";import{constants as n,createContext as r}from"node:vm";let i=null,a=null;async function load(t){i===null&&(compileCache(t)&&e?.(),[i,a]=await Promise.all([import(`@ctrl/dom`),import(`@ctrl/dom/internal`)]))}const o=Symbol.for(`ctrl-dom.dom.modules`);function publishModules(e){Object.defineProperty(e,o,{value:{dom:i,internal:a},configurable:!0,enumerable:!1,writable:!1})}function reportToHost(e){process.emit(`uncaughtException`,e,`uncaughtException`)}function forwardNotImplemented(e){return t=>(e.console??console).error(t.stack,t.detail)}const s=t(import.meta.url);function ownOptions(e){return e?.[`ctrl-dom`]??e?.ctrlDom??e?.[s]??{}}function windowOptions(e){let{timeSkip:t,compileCache:n,...r}=ownOptions(e);return{...r,compat:r.compat??`jsdom-30`,url:r.url??`http://localhost:3000/`}}function timeSkip(e){let t=process.env.CTRL_DOM_TIME_SKIP;return t===`1`||t!==`0`&&ownOptions(e).timeSkip!==!1}function compileCache(e){let t=process.env.CTRL_DOM_COMPILE_CACHE;return t===`1`||t!==`0`&&ownOptions(e).compileCache===!0}const c=/* @__PURE__ */ `setTimeout.clearTimeout.setInterval.clearInterval.queueMicrotask.structuredClone.atob.btoa.fetch.crypto.performance.URL.URLSearchParams.AbortController.AbortSignal.Blob.File.TextEncoder.TextDecoder.ReadableStream.WritableStream.TransformStream.Headers.Request.Response.FormData.BroadcastChannel.MessageChannel.MessagePort.WebSocket.DOMException.Buffer`.split(`.`),l={name:`ctrl-dom`,viteEnvironment:`client`,prewarmModules:!1,async setup(e,t){await load(t);let{createWindow:n,installGlobals:r}=i,{setUncaughtExceptionHandler:s,setNotImplementedHandler:c,installClock:l,VirtualClock:u,subscribeTestFailures:d}=a,f=n(windowOptions(t)),p=r(f,e);publishModules(e);let m=l(new u({skip:timeSkip(t)}),e);s(reportToHost),c(forwardNotImplemented(e));let h=d(()=>f.document);return{teardown(){h(),s(null),c(null),m.uninstall(),f.close(),p(),delete e[o]}}},async setupVM(e){await load(e);let{createWindow:t,installGlobals:o}=i,{setUncaughtExceptionHandler:s,setNotImplementedHandler:l,captureInterfaceBaseline:u,guardInterfaceDefinitions:d,restoreInterfaces:f,installClock:p,VirtualClock:m,subscribeTestFailures:h}=a,g=t(windowOptions(e)),_=r(n.DONT_CONTEXTIFY),v=globalThis;for(let e of c)v[e]!==void 0&&Object.defineProperty(_,e,{value:v[e],writable:!0,enumerable:!1,configurable:!0});u();let y=o(g,_);publishModules(_);let b=p(new m({skip:timeSkip(e)}),_);d(_),s(reportToHost),l(forwardNotImplemented(_));let x=h(()=>g.document);return{getVmContext(){return _},teardown(){x(),s(null),l(null),b.clock.dispose(),g.close(),y(),f()}}}};export{l as default};
|
|
@@ -1,90 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
// src/plugin.ts
|
|
4
|
-
const extension = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
|
|
5
|
-
const environment = fileURLToPath(new URL(`./index${extension}`, import.meta.url));
|
|
6
|
-
const failureSnapshot = fileURLToPath(new URL(`./failure-snapshot${extension}`, import.meta.url));
|
|
7
|
-
const DEBUG_FORMATS = /* @__PURE__ */ new Set([
|
|
8
|
-
"aria",
|
|
9
|
-
"compact",
|
|
10
|
-
"html"
|
|
11
|
-
]);
|
|
12
|
-
const ENVIRONMENT_NAME = "ctrl-dom";
|
|
13
|
-
const ENVIRONMENT_PACKAGE = `vitest-environment-${ENVIRONMENT_NAME}`;
|
|
14
|
-
const TESTING_LIBRARY = [
|
|
15
|
-
{
|
|
16
|
-
find: /^@testing-library\/react(\/.*)?$/,
|
|
17
|
-
replacement: "@ctrl/dom/react$1"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
find: /^@testing-library\/dom$/,
|
|
21
|
-
replacement: "@ctrl/dom/testing-library"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
find: /^@testing-library\/user-event$/,
|
|
25
|
-
replacement: "@ctrl/dom/user-event"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
find: /^@testing-library\/jest-dom(\/.*)?$/,
|
|
29
|
-
replacement: "@ctrl/dom/jest-dom$1"
|
|
30
|
-
}
|
|
31
|
-
];
|
|
32
|
-
/**
|
|
33
|
-
* Turns on Node's compile cache as the worker process starts, before Vitest's own worker modules
|
|
34
|
-
* load, rather than at environment setup (CtrlDomEnvironmentOptions.compileCache): Vitest's
|
|
35
|
-
* runner, chai and the module runner then load from it too. A `data:` URL, so there is no file to
|
|
36
|
-
* resolve. Node ignores it under NODE_DISABLE_COMPILE_CACHE (Vitest's v8 coverage sets that).
|
|
37
|
-
*/
|
|
38
|
-
const COMPILE_CACHE_IMPORT = "--import=data:text/javascript,import{enableCompileCache}from\"node:module\";enableCompileCache?.()";
|
|
39
|
-
/**
|
|
40
|
-
* @internal The Node flags the plugin adds to a project's workers: the compile cache from process
|
|
41
|
-
* start (with `compileCache`), in every pool. Exported for comparison/, which mirrors the plugin's
|
|
42
|
-
* setup without loading Vitest's config machinery.
|
|
43
|
-
*/
|
|
44
|
-
function workerExecArgv({ compileCache = false }) {
|
|
45
|
-
const flags = [];
|
|
46
|
-
const env = process.env.CTRL_DOM_COMPILE_CACHE;
|
|
47
|
-
if (env === "1" || env !== "0" && compileCache) flags.push(COMPILE_CACHE_IMPORT);
|
|
48
|
-
return flags;
|
|
49
|
-
}
|
|
50
|
-
/** @ctrl/dom's Vitest environment plus (by default) the Testing Library aliases. */
|
|
51
|
-
function ctrlDom(options = {}) {
|
|
52
|
-
const { testingLibrary = true, debug, ...rest } = options;
|
|
53
|
-
const environmentOptions = {
|
|
54
|
-
compileCache: testingLibrary,
|
|
55
|
-
...rest
|
|
56
|
-
};
|
|
57
|
-
const shellDebug = process.env.CTRL_DOM_DEBUG;
|
|
58
|
-
const agentMode = DEBUG_FORMATS.has(String(shellDebug ?? debug ?? "").trim().toLowerCase());
|
|
59
|
-
return {
|
|
60
|
-
name: "@ctrl/dom",
|
|
61
|
-
enforce: "pre",
|
|
62
|
-
resolveId(id) {
|
|
63
|
-
return id === ENVIRONMENT_PACKAGE ? environment : null;
|
|
64
|
-
},
|
|
65
|
-
config(config) {
|
|
66
|
-
const configured = config.test?.environment;
|
|
67
|
-
return {
|
|
68
|
-
...testingLibrary ? { resolve: { alias: TESTING_LIBRARY } } : {},
|
|
69
|
-
test: {
|
|
70
|
-
...configured === void 0 || configured === ENVIRONMENT_NAME ? { environment } : {},
|
|
71
|
-
environmentOptions: { [ENVIRONMENT_NAME]: environmentOptions },
|
|
72
|
-
...debug && shellDebug === void 0 ? { env: { CTRL_DOM_DEBUG: debug } } : {},
|
|
73
|
-
...agentMode ? { setupFiles: [failureSnapshot] } : {}
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
configureVitest({ project }) {
|
|
78
|
-
const config = project.config;
|
|
79
|
-
if (config.browser?.enabled) return;
|
|
80
|
-
const flags = workerExecArgv({
|
|
81
|
-
pool: config.pool,
|
|
82
|
-
execArgv: config.execArgv,
|
|
83
|
-
compileCache: environmentOptions.compileCache === true
|
|
84
|
-
});
|
|
85
|
-
if (flags.length > 0) config.execArgv = [...config.execArgv ?? [], ...flags];
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export { ctrlDom, ctrlDom as default, workerExecArgv };
|
|
1
|
+
import"./_chunks/rolldown-runtime-BhWHdk3m.js";import{fileURLToPath as e}from"node:url";const t=import.meta.url.endsWith(`.ts`)?`.ts`:`.js`,n=e(new URL(`./index${t}`,import.meta.url)),r=e(new URL(`./failure-snapshot${t}`,import.meta.url)),i=/* @__PURE__ */ new Set([`aria`,`compact`,`html`]),a=`ctrl-dom`,o=`vitest-environment-${a}`,s=[{find:/^@testing-library\/react(\/.*)?$/,replacement:`@ctrl/dom/react$1`},{find:/^@testing-library\/dom$/,replacement:`@ctrl/dom/testing-library`},{find:/^@testing-library\/user-event$/,replacement:`@ctrl/dom/user-event`},{find:/^@testing-library\/jest-dom(\/.*)?$/,replacement:`@ctrl/dom/jest-dom$1`}];function workerExecArgv({compileCache:e=!1}){let t=[],n=process.env.CTRL_DOM_COMPILE_CACHE;return(n===`1`||n!==`0`&&e)&&t.push(`--import=data:text/javascript,import{enableCompileCache}from"node:module";enableCompileCache?.()`),t}function ctrlDom(e={}){let{testingLibrary:t=!0,debug:c,...l}=e,u={compileCache:t,...l},d=process.env.CTRL_DOM_DEBUG,f=i.has(String(d??c??``).trim().toLowerCase());return{name:`@ctrl/dom`,enforce:`pre`,resolveId(e){return e===o?n:null},config(e){let i=e.test?.environment;return{...t?{resolve:{alias:s}}:{},test:{...i===void 0||i===a?{environment:n}:{},environmentOptions:{[a]:u},...c&&d===void 0?{env:{CTRL_DOM_DEBUG:c}}:{},...f?{setupFiles:[r]}:{}}}},configureVitest({project:e}){let t=e.config;if(t.browser?.enabled)return;let n=workerExecArgv({pool:t.pool,execArgv:t.execArgv,compileCache:u.compileCache===!0});n.length>0&&(t.execArgv=[...t.execArgv??[],...n])}}}export{ctrlDom,ctrlDom as default,workerExecArgv};
|
package/package.json
CHANGED