@ctrl/dom 0.1.3 → 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.
Files changed (59) hide show
  1. package/dist/aria/_chunks/roles-list-BXCvPLJT.cjs +4 -0
  2. package/dist/aria/_chunks/roles-list-rVVxaIPs.js +4 -0
  3. package/dist/aria/index.cjs +1 -232
  4. package/dist/aria/index.js +1 -198
  5. package/dist/aria/internal.cjs +1 -69
  6. package/dist/aria/internal.js +1 -30
  7. package/dist/cli/_chunks/report-z52LF7nA.js +12 -0
  8. package/dist/cli/_chunks/rolldown-runtime-H3fMLYWS.js +1 -0
  9. package/dist/cli/ctrl-dom.js +2 -181
  10. package/dist/cli/jest-reporter.js +2 -54
  11. package/dist/cli/vitest-reporter.js +2 -81
  12. package/dist/dom/_chunks/src-sZY6a2LC.js +49 -0
  13. package/dist/dom/index.js +1 -3
  14. package/dist/dom/internal.js +1 -434
  15. package/dist/dom/types/window/clock.d.ts +10 -2
  16. package/dist/jest-dom/_chunks/matchers-CGTk9GX9.cjs +31 -0
  17. package/dist/jest-dom/_chunks/matchers-Chf0yHoo.js +31 -0
  18. package/dist/jest-dom/index.cjs +1 -5
  19. package/dist/jest-dom/index.js +1 -6
  20. package/dist/jest-dom/jest-globals.cjs +1 -6
  21. package/dist/jest-dom/jest-globals.js +1 -7
  22. package/dist/jest-dom/matchers.cjs +1 -53
  23. package/dist/jest-dom/matchers.js +1 -3
  24. package/dist/jest-dom/vitest.cjs +1 -6
  25. package/dist/jest-dom/vitest.js +1 -7
  26. package/dist/react/_chunks/pure-CCeTO5Mk.js +1 -0
  27. package/dist/react/_chunks/pure-DQzwul4s.cjs +1 -0
  28. package/dist/react/dont-cleanup-after-each.cjs +1 -3
  29. package/dist/react/dont-cleanup-after-each.js +1 -4
  30. package/dist/react/index.cjs +1 -47
  31. package/dist/react/index.js +1 -35
  32. package/dist/react/pure.cjs +1 -17
  33. package/dist/react/pure.js +1 -5
  34. package/dist/register/index.js +1 -11
  35. package/dist/register/pure.js +1 -147
  36. package/dist/testing-library/_chunks/aria-snapshot-diff-80G4meO2.cjs +14 -0
  37. package/dist/testing-library/_chunks/aria-snapshot-diff-B1L8s_sM.js +14 -0
  38. package/dist/testing-library/agent.cjs +10 -720
  39. package/dist/testing-library/agent.js +10 -712
  40. package/dist/testing-library/index.cjs +19 -2459
  41. package/dist/testing-library/index.js +19 -2380
  42. package/dist/user-event/index.cjs +33 -3924
  43. package/dist/user-event/index.js +33 -3899
  44. package/dist/user-event/types/ctrl-dom.d.ts +1 -1
  45. package/dist/vitest-environment/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
  46. package/dist/vitest-environment/failure-snapshot.js +1 -42
  47. package/dist/vitest-environment/index.js +1 -185
  48. package/dist/vitest-environment/plugin.js +1 -90
  49. package/package.json +1 -1
  50. package/dist/aria/_chunks/roles-list-CYZF-l9K.js +0 -1503
  51. package/dist/aria/_chunks/roles-list-D4WCyRO_.cjs +0 -1754
  52. package/dist/cli/_chunks/report-DdncYfuJ.js +0 -93
  53. package/dist/dom/_chunks/src-Bwp4p8ko.js +0 -47601
  54. package/dist/jest-dom/_chunks/matchers-CDnnXUfG.js +0 -2211
  55. package/dist/jest-dom/_chunks/matchers-D988Ducb.cjs +0 -2516
  56. package/dist/react/_chunks/pure-DZ97z2oT.cjs +0 -498
  57. package/dist/react/_chunks/pure-PtE2hivW.js +0 -420
  58. package/dist/testing-library/_chunks/aria-snapshot-diff-D7PzpXew.cjs +0 -1170
  59. package/dist/testing-library/_chunks/aria-snapshot-diff-Q8Wj33K0.js +0 -985
@@ -1,69 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_roles_list = require("./_chunks/roles-list-D4WCyRO_.cjs");
3
- let _ctrl_dom_internal = require("@ctrl/dom/internal");
4
-
5
- // src/internal.ts
6
- /**
7
- * Testing Library's role filter for one element: with a `role` attribute, its first " "-token
8
- * (or any non-empty token with `queryFallbacks`) must equal `role`; otherwise the implicit
9
- * role must.
10
- */
11
- function tlRoleMatches(impl, role, queryFallbacks) {
12
- const value = (0, _ctrl_dom_internal.attr)(impl, "role");
13
- if (value !== null) {
14
- if (!queryFallbacks) {
15
- const sp = value.indexOf(" ");
16
- return sp === -1 ? value === role : sp === role.length && value.startsWith(role);
17
- }
18
- let start = 0;
19
- const len = value.length;
20
- while (start <= len) {
21
- let end = value.indexOf(" ", start);
22
- if (end === -1) end = len;
23
- if (end > start && end - start === role.length && value.startsWith(role, start)) return true;
24
- start = end + 1;
25
- }
26
- return false;
27
- }
28
- return require_roles_list.implicitRole(impl) === role;
29
- }
30
-
31
- exports.anyTag = require_roles_list.anyTag;
32
- exports.ariaCheckedState = require_roles_list.ariaCheckedState;
33
- exports.ariaPressedState = require_roles_list.ariaPressedState;
34
- exports.computeAccessibleDescriptionImpl = require_roles_list.computeAccessibleDescriptionImpl;
35
- exports.computeAccessibleNameImpl = require_roles_list.computeAccessibleNameImpl;
36
- exports.computeAriaBusy = require_roles_list.computeAriaBusy;
37
- exports.computeAriaChecked = require_roles_list.computeAriaChecked;
38
- exports.computeAriaCurrent = require_roles_list.computeAriaCurrent;
39
- exports.computeAriaExpanded = require_roles_list.computeAriaExpanded;
40
- exports.computeAriaPressed = require_roles_list.computeAriaPressed;
41
- exports.computeAriaSelected = require_roles_list.computeAriaSelected;
42
- exports.computeAriaValueMax = require_roles_list.computeAriaValueMax;
43
- exports.computeAriaValueMin = require_roles_list.computeAriaValueMin;
44
- exports.computeAriaValueNow = require_roles_list.computeAriaValueNow;
45
- exports.computeAriaValueText = require_roles_list.computeAriaValueText;
46
- exports.computeHeadingLevel = require_roles_list.computeHeadingLevel;
47
- exports.computeTextAlternativeImpl = require_roles_list.computeTextAlternativeImpl;
48
- exports.daaExplicitRole = require_roles_list.daaExplicitRole;
49
- exports.daaGetRole = require_roles_list.daaGetRole;
50
- exports.daaImplicitRole = require_roles_list.daaImplicitRole;
51
- exports.getImplicitRoles = require_roles_list.getImplicitRoles;
52
- exports.getRolesImpl = require_roles_list.getRolesImpl;
53
- exports.implOf = require_roles_list.implOf;
54
- exports.implicitRole = require_roles_list.implicitRole;
55
- exports.implicitRoleJestDom = require_roles_list.implicitRoleJestDom;
56
- exports.inputType = require_roles_list.inputType;
57
- exports.isDisabledImpl = require_roles_list.isDisabledImpl;
58
- exports.isDisplayInline = require_roles_list.isDisplayInline;
59
- exports.isDisplayNone = require_roles_list.isDisplayNone;
60
- exports.isInaccessibleImpl = require_roles_list.isInaccessibleImpl;
61
- exports.isInaccessibleWithStyle = require_roles_list.isInaccessibleWithStyle;
62
- exports.isLabelable = require_roles_list.isLabelable;
63
- exports.isSubtreeInaccessibleImpl = require_roles_list.isSubtreeInaccessibleImpl;
64
- exports.isVisibilityHidden = require_roles_list.isVisibilityHidden;
65
- exports.labelsOf = require_roles_list.labelsOf;
66
- exports.queryIdRefs = require_roles_list.queryIdRefs;
67
- exports.tlRole = require_roles_list.tlRole;
68
- exports.tlRoleMatches = tlRoleMatches;
69
- exports.withStyleOverride = require_roles_list.withStyleOverride;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./_chunks/roles-list-BXCvPLJT.cjs");let t=require("@ctrl/dom/internal");function tlRoleMatches(n,r,i){let a=(0,t.attr)(n,`role`);if(a!==null){if(!i){let e=a.indexOf(` `);return e===-1?a===r:e===r.length&&a.startsWith(r)}let e=0,t=a.length;for(;e<=t;){let n=a.indexOf(` `,e);if(n===-1&&(n=t),n>e&&n-e===r.length&&a.startsWith(r,e))return!0;e=n+1}return!1}return e.L(n)===r}exports.anyTag=e.M,exports.ariaCheckedState=e.l,exports.ariaPressedState=e.u,exports.computeAccessibleDescriptionImpl=e.C,exports.computeAccessibleNameImpl=e.w,exports.computeAriaBusy=e.d,exports.computeAriaChecked=e.f,exports.computeAriaCurrent=e.p,exports.computeAriaExpanded=e.m,exports.computeAriaPressed=e.h,exports.computeAriaSelected=e.g,exports.computeAriaValueMax=e._,exports.computeAriaValueMin=e.v,exports.computeAriaValueNow=e.y,exports.computeAriaValueText=e.b,exports.computeHeadingLevel=e.x,exports.computeTextAlternativeImpl=e.T,exports.daaExplicitRole=e.N,exports.daaGetRole=e.P,exports.daaImplicitRole=e.F,exports.getImplicitRoles=e.I,exports.getRolesImpl=e.n,exports.implOf=e.A,exports.implicitRole=e.L,exports.implicitRoleJestDom=e.R,exports.inputType=e.B,exports.isDisabledImpl=e.S,exports.isDisplayInline=e.D,exports.isDisplayNone=e.O,exports.isInaccessibleImpl=e.a,exports.isInaccessibleWithStyle=e.o,exports.isLabelable=e.V,exports.isSubtreeInaccessibleImpl=e.c,exports.isVisibilityHidden=e.k,exports.labelsOf=e.H,exports.queryIdRefs=e.j,exports.tlRole=e.z,exports.tlRoleMatches=tlRoleMatches,exports.withStyleOverride=e.E;
@@ -1,30 +1 @@
1
- import { A as implOf, B as inputType, C as computeAccessibleDescriptionImpl, D as isDisplayInline, E as withStyleOverride, F as daaImplicitRole, H as labelsOf, I as getImplicitRoles, L as implicitRole, M as anyTag, N as daaExplicitRole, O as isDisplayNone, P as daaGetRole, R as implicitRoleJestDom, S as isDisabledImpl, T as computeTextAlternativeImpl, V as isLabelable, _ as computeAriaValueMax, a as isInaccessibleImpl, b as computeAriaValueText, c as isSubtreeInaccessibleImpl, d as computeAriaBusy, f as computeAriaChecked, g as computeAriaSelected, h as computeAriaPressed, j as queryIdRefs, k as isVisibilityHidden, l as ariaCheckedState, m as computeAriaExpanded, n as getRolesImpl, o as isInaccessibleWithStyle, p as computeAriaCurrent, u as ariaPressedState, v as computeAriaValueMin, w as computeAccessibleNameImpl, x as computeHeadingLevel, y as computeAriaValueNow, z as tlRole } from "./_chunks/roles-list-CYZF-l9K.js";
2
- import { attr } from "@ctrl/dom/internal";
3
-
4
- // src/internal.ts
5
- /**
6
- * Testing Library's role filter for one element: with a `role` attribute, its first " "-token
7
- * (or any non-empty token with `queryFallbacks`) must equal `role`; otherwise the implicit
8
- * role must.
9
- */
10
- function tlRoleMatches(impl, role, queryFallbacks) {
11
- const value = attr(impl, "role");
12
- if (value !== null) {
13
- if (!queryFallbacks) {
14
- const sp = value.indexOf(" ");
15
- return sp === -1 ? value === role : sp === role.length && value.startsWith(role);
16
- }
17
- let start = 0;
18
- const len = value.length;
19
- while (start <= len) {
20
- let end = value.indexOf(" ", start);
21
- if (end === -1) end = len;
22
- if (end > start && end - start === role.length && value.startsWith(role, start)) return true;
23
- start = end + 1;
24
- }
25
- return false;
26
- }
27
- return implicitRole(impl) === role;
28
- }
29
-
30
- export { anyTag, ariaCheckedState, ariaPressedState, computeAccessibleDescriptionImpl, computeAccessibleNameImpl, computeAriaBusy, computeAriaChecked, computeAriaCurrent, computeAriaExpanded, computeAriaPressed, computeAriaSelected, computeAriaValueMax, computeAriaValueMin, computeAriaValueNow, computeAriaValueText, computeHeadingLevel, computeTextAlternativeImpl, daaExplicitRole, daaGetRole, daaImplicitRole, getImplicitRoles, getRolesImpl, implOf, implicitRole, implicitRoleJestDom, inputType, isDisabledImpl, isDisplayInline, isDisplayNone, isInaccessibleImpl, isInaccessibleWithStyle, isLabelable, isSubtreeInaccessibleImpl, isVisibilityHidden, labelsOf, queryIdRefs, tlRole, tlRoleMatches, withStyleOverride };
1
+ import{A as e,B as t,C as n,D as r,E as i,F as a,H as o,I as s,L as c,M as l,N as u,O as d,P as f,R as p,S as m,T as h,V as g,_,a as v,b as y,c as b,d as x,f as S,g as C,h as w,j as T,k as E,l as D,m as O,n as k,o as A,p as j,u as M,v as N,w as P,x as F,y as I,z as L}from"./_chunks/roles-list-rVVxaIPs.js";import{attr as R}from"@ctrl/dom/internal";function tlRoleMatches(e,t,n){let r=R(e,`role`);if(r!==null){if(!n){let e=r.indexOf(` `);return e===-1?r===t:e===t.length&&r.startsWith(t)}let e=0,i=r.length;for(;e<=i;){let n=r.indexOf(` `,e);if(n===-1&&(n=i),n>e&&n-e===t.length&&r.startsWith(t,e))return!0;e=n+1}return!1}return c(e)===t}export{l as anyTag,D as ariaCheckedState,M as ariaPressedState,n as computeAccessibleDescriptionImpl,P as computeAccessibleNameImpl,x as computeAriaBusy,S as computeAriaChecked,j as computeAriaCurrent,O as computeAriaExpanded,w as computeAriaPressed,C as computeAriaSelected,_ as computeAriaValueMax,N as computeAriaValueMin,I as computeAriaValueNow,y as computeAriaValueText,F as computeHeadingLevel,h as computeTextAlternativeImpl,u as daaExplicitRole,f as daaGetRole,a as daaImplicitRole,s as getImplicitRoles,k as getRolesImpl,e as implOf,c as implicitRole,p as implicitRoleJestDom,t as inputType,m as isDisabledImpl,r as isDisplayInline,d as isDisplayNone,v as isInaccessibleImpl,A as isInaccessibleWithStyle,g as isLabelable,b as isSubtreeInaccessibleImpl,E as isVisibilityHidden,o as labelsOf,T as queryIdRefs,L as tlRole,tlRoleMatches,i as withStyleOverride};
@@ -0,0 +1,12 @@
1
+ import"./rolldown-runtime-H3fMLYWS.js";import{relative as e,sep as t}from"node:path";import{stripVTControlCharacters as n}from"node:util";function stripAnsi(e){return n(String(e))}const r=/^\s*at (?:(.*?) \()?(?:file:\/\/)?(\/[^():]+|[A-Za-z]:\\[^():]+):(\d+):(\d+)\)?\s*$/;function firstProjectFrame(n,i,a){let o=null;for(let s of String(n??``).split(`
2
+ `)){let n=r.exec(s);if(n===null)continue;let c=n[2];if(c.includes(`${t}node_modules${t}`)||c.includes(`/node_modules/`))continue;let l=`${e(i,c)||c}:${n[3]}:${n[4]}`;if(a===void 0||c===a)return l;o??=l}return o}function messageWithoutFrames(e){let t=stripAnsi(e).split(`
3
+ `),n=[];for(let e of t)/^\s*at .+(:\d+:\d+\)?|\(<anonymous>\)|native\))\s*$/.test(e)||n.push(e);for(;n.length>0&&n[n.length-1].trim()===``;)n.pop();return n.join(`
4
+ `)}function indent(e,t=` `){return e.split(`
5
+ `).map(e=>e===``?e:t+e).join(`
6
+ `)}function budget(e,t){let n=e.split(`
7
+ `);return n.length<=t?e:`${n.slice(0,t).join(`
8
+ `)}\n… ${n.length-t} more lines`}const i=Number(process.env.CTRL_DOM_DEBUG_CONSOLE_LINES)>0?Number(process.env.CTRL_DOM_DEBUG_CONSOLE_LINES):150;function formatReport(e){let t=[];for(let n of e.errors)t.push(`ERROR ${n.name}`,indent(budget(n.message,400))),n.at&&t.push(``,` at ${n.at}`),t.push(``);for(let n of e.failures)t.push(`FAIL ${n.name}`,indent(budget(n.message,400))),n.at&&t.push(``,` at ${n.at}`),t.push(``);if(e.logs.length>0){let n=0,r=0,a=[];for(let t of e.logs){let e=stripAnsi(t.content).replace(/\n$/,``),o=e.split(`
9
+ `).length+1;n+o>i?r++:(n+=o,a.push(`${t.type===`stderr`?`stderr`:`stdout`} | ${t.name}`,indent(e)))}t.push(`Console output:`,...a),r>0&&t.push(`… ${r} more console messages (CTRL_DOM_DEBUG_CONSOLE_LINES raises the budget)`),t.push(``)}let n=[e.failed&&`${e.failed} failed`,e.passed&&`${e.passed} passed`,e.skipped&&`${e.skipped} skipped`].filter(Boolean).join(`, `)||`no tests ran`;return t.push(`${n} · ${e.runner} · ${e.files.join(`, `)||`(no test files)`} · ${(e.durationMs/1e3).toFixed(1)} s`),`${t.join(`
10
+ `)}\n`}function missingSnapshotHint(e,t){return e.length===0||process.env.CTRL_DOM_DEBUG===void 0||e.some(e=>e.message.includes(`when the test failed`))?``:t===`vitest`?`Note: no failure snapshots. Use ctrlDom() from "@ctrl/dom/vitest", or add "@ctrl/dom/vitest-environment/failure-snapshot" to test.setupFiles (the ctrl-dom environment is required).
11
+ `:`Note: no failure snapshots. They need testEnvironment "@ctrl/dom-jest-environment" or preset "@ctrl/dom".
12
+ `}export{stripAnsi as a,missingSnapshotHint as i,formatReport as n,messageWithoutFrames as r,firstProjectFrame as t};
@@ -0,0 +1 @@
1
+ import"node:module";var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name as t};
@@ -1,15 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from "node:module";
3
- import { spawnSync } from "node:child_process";
4
- import { existsSync, readFileSync } from "node:fs";
5
- import { dirname, join, resolve } from "node:path";
6
- import { fileURLToPath } from "node:url";
7
- import { parseArgs } from "node:util";
8
-
9
- // src/ctrl-dom.ts
10
- const here = dirname(fileURLToPath(import.meta.url));
11
- const extension = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
12
- const USAGE = `Usage: ctrl-dom debug <test file>... [options] [-- <runner args>]
2
+ import"./_chunks/rolldown-runtime-H3fMLYWS.js";import{createRequire as e}from"node:module";import{spawnSync as t}from"node:child_process";import{existsSync as n,readFileSync as r}from"node:fs";import{dirname as i,join as a,resolve as o}from"node:path";import{fileURLToPath as s}from"node:url";import{parseArgs as c}from"node:util";const l=i(s(import.meta.url)),u=import.meta.url.endsWith(`.ts`)?`.ts`:`.js`,d=`Usage: ctrl-dom debug <test file>... [options] [-- <runner args>]
13
3
 
14
4
  Runs the test file(s) with Vitest or Jest (whichever the project uses) and CTRL_DOM_DEBUG=aria,
15
5
  and prints a compact report: each failure with its message (closest matches for failed queries,
@@ -27,173 +17,4 @@ Options:
27
17
 
28
18
  Example:
29
19
  npx ctrl-dom debug src/Checkout.test.tsx -t "submits the form"
30
- `;
31
- function fail(message) {
32
- process.stderr.write(`ctrl-dom: ${message}\n`);
33
- process.exit(2);
34
- }
35
- function readJson(path) {
36
- try {
37
- return JSON.parse(readFileSync(path, "utf8"));
38
- } catch {
39
- return null;
40
- }
41
- }
42
- /** The nearest directory at or above `from` with a package.json. */
43
- function projectRoot(from) {
44
- for (let dir = resolve(from);; dir = dirname(dir)) {
45
- if (existsSync(join(dir, "package.json"))) return dir;
46
- if (dirname(dir) === dir) return resolve(from);
47
- }
48
- }
49
- const CONFIGS = {
50
- vitest: [
51
- "vitest.config.ts",
52
- "vitest.config.mts",
53
- "vitest.config.js",
54
- "vitest.config.mjs",
55
- "vitest.config.cts",
56
- "vitest.config.cjs",
57
- "vitest.workspace.ts"
58
- ],
59
- jest: [
60
- "jest.config.js",
61
- "jest.config.cjs",
62
- "jest.config.mjs",
63
- "jest.config.ts",
64
- "jest.config.mts",
65
- "jest.config.json"
66
- ]
67
- };
68
- /** Vitest or Jest: from --config's name, the test files' imports, config files, then dependencies. */
69
- function detectRunner(root, files, config) {
70
- if (config !== void 0) {
71
- const name = config.split(/[\\/]/).pop();
72
- if (/^(vitest|vite)\./.test(name)) return "vitest";
73
- if (name.startsWith("jest.")) return "jest";
74
- }
75
- for (const file of files) {
76
- let source = "";
77
- try {
78
- source = readFileSync(resolve(file), "utf8");
79
- } catch {}
80
- if (/from\s+["']vitest["']|require\(["']vitest["']\)/.test(source)) return "vitest";
81
- if (/from\s+["']@jest\/globals["']|require\(["']@jest\/globals["']\)/.test(source)) return "jest";
82
- }
83
- const pkg = readJson(join(root, "package.json")) ?? {};
84
- const hasConfig = (runner) => CONFIGS[runner].some((name) => existsSync(join(root, name))) || runner === "jest" && pkg.jest !== void 0;
85
- if (hasConfig("vitest") && !hasConfig("jest")) return "vitest";
86
- if (hasConfig("jest") && !hasConfig("vitest")) return "jest";
87
- const deps = {
88
- ...pkg.dependencies,
89
- ...pkg.devDependencies
90
- };
91
- if (deps.vitest && !deps.jest) return "vitest";
92
- if (deps.jest && !deps.vitest) return "jest";
93
- if (hasConfig("vitest") || deps.vitest) return "vitest";
94
- if ([
95
- "vite.config.ts",
96
- "vite.config.js",
97
- "vite.config.mjs"
98
- ].some((name) => existsSync(join(root, name)))) return "vitest";
99
- return null;
100
- }
101
- /** The runner's CLI script, resolved from the project (its `bin` entry). */
102
- function runnerBin(root, runner) {
103
- const require = createRequire(join(root, "package.json"));
104
- let pkgPath = "";
105
- try {
106
- pkgPath = require.resolve(`${runner}/package.json`);
107
- } catch {
108
- fail(`${runner} is not installed in ${root}`);
109
- }
110
- const pkg = readJson(pkgPath) ?? {};
111
- const bin = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.[runner];
112
- if (!bin) fail(`cannot find ${runner}'s CLI in ${pkgPath}`);
113
- return join(dirname(pkgPath), bin);
114
- }
115
- const OPTIONS = {
116
- "test-name": {
117
- type: "string",
118
- short: "t"
119
- },
120
- runner: { type: "string" },
121
- config: { type: "string" },
122
- format: {
123
- type: "string",
124
- default: "aria"
125
- },
126
- lines: { type: "string" },
127
- raw: {
128
- type: "boolean",
129
- default: false
130
- },
131
- help: {
132
- type: "boolean",
133
- short: "h",
134
- default: false
135
- }
136
- };
137
- function parseOptions(args) {
138
- try {
139
- return parseArgs({
140
- args,
141
- allowPositionals: true,
142
- options: OPTIONS
143
- });
144
- } catch (error) {
145
- fail(`${error.message}\n\n${USAGE}`);
146
- }
147
- }
148
- function main(argv) {
149
- const [command, ...rest] = argv;
150
- if (command === void 0 || command === "-h" || command === "--help" || command === "help") {
151
- process.stdout.write(USAGE);
152
- return command === void 0 ? 2 : 0;
153
- }
154
- if (command !== "debug") fail(`unknown command "${command}"\n\n${USAGE}`);
155
- const dashDash = rest.indexOf("--");
156
- const own = dashDash < 0 ? rest : rest.slice(0, dashDash);
157
- const passthrough = dashDash < 0 ? [] : rest.slice(dashDash + 1);
158
- const { values, positionals: files } = parseOptions(own);
159
- if (values.help) {
160
- process.stdout.write(USAGE);
161
- return 0;
162
- }
163
- if (files.length === 0) fail(`no test file given\n\n${USAGE}`);
164
- if (!["aria", "compact"].includes(values.format)) fail(`--format must be aria or compact`);
165
- const root = projectRoot(process.cwd());
166
- const runner = values.runner ?? detectRunner(root, files, values.config);
167
- if (runner !== "vitest" && runner !== "jest") fail(runner ? `--runner must be vitest or jest` : `cannot tell whether ${root} uses Vitest or Jest: pass --runner`);
168
- const args = [runnerBin(root, runner)];
169
- if (runner === "vitest") {
170
- args.push("run", ...files);
171
- if (values.config) args.push("--config", values.config);
172
- if (values["test-name"] !== void 0) args.push("-t", values["test-name"]);
173
- if (!values.raw) args.push(`--reporter=${join(here, `vitest-reporter${extension}`)}`);
174
- } else {
175
- args.push("--runTestsByPath", ...files.map((file) => resolve(file)), "--ci");
176
- if (values.config) args.push("--config", values.config);
177
- if (values["test-name"] !== void 0) args.push("-t", values["test-name"]);
178
- if (!values.raw) args.push(`--reporters=${join(here, `jest-reporter${extension}`)}`);
179
- }
180
- args.push(...passthrough);
181
- const env = {
182
- ...process.env,
183
- CTRL_DOM_DEBUG: values.format,
184
- FORCE_COLOR: "0",
185
- NO_COLOR: "1"
186
- };
187
- if (values.lines !== void 0) env.CTRL_DOM_DEBUG_LINES = values.lines;
188
- process.stdout.write(`ctrl-dom debug: ${runner} ${files.join(" ")}${values["test-name"] !== void 0 ? ` -t ${JSON.stringify(values["test-name"])}` : ""} (CTRL_DOM_DEBUG=${values.format})\n\n`);
189
- const run = spawnSync(process.execPath, args, {
190
- cwd: process.cwd(),
191
- env,
192
- stdio: "inherit"
193
- });
194
- if (run.error) fail(run.error.message);
195
- return run.status ?? 1;
196
- }
197
- if (import.meta.main) process.exitCode = main(process.argv.slice(2));
198
-
199
- export { detectRunner, main };
20
+ `;function fail(e){process.stderr.write(`ctrl-dom: ${e}\n`),process.exit(2)}function readJson(e){try{return JSON.parse(r(e,`utf8`))}catch{return null}}function projectRoot(e){for(let t=o(e);;t=i(t)){if(n(a(t,`package.json`)))return t;if(i(t)===t)return o(e)}}const f={vitest:[`vitest.config.ts`,`vitest.config.mts`,`vitest.config.js`,`vitest.config.mjs`,`vitest.config.cts`,`vitest.config.cjs`,`vitest.workspace.ts`],jest:[`jest.config.js`,`jest.config.cjs`,`jest.config.mjs`,`jest.config.ts`,`jest.config.mts`,`jest.config.json`]};function detectRunner(e,t,i){if(i!==void 0){let e=i.split(/[\\/]/).pop();if(/^(vitest|vite)\./.test(e))return`vitest`;if(e.startsWith(`jest.`))return`jest`}for(let e of t){let t=``;try{t=r(o(e),`utf8`)}catch{}if(/from\s+["']vitest["']|require\(["']vitest["']\)/.test(t))return`vitest`;if(/from\s+["']@jest\/globals["']|require\(["']@jest\/globals["']\)/.test(t))return`jest`}let s=readJson(a(e,`package.json`))??{},hasConfig=t=>f[t].some(t=>n(a(e,t)))||t===`jest`&&s.jest!==void 0;if(hasConfig(`vitest`)&&!hasConfig(`jest`))return`vitest`;if(hasConfig(`jest`)&&!hasConfig(`vitest`))return`jest`;let c={...s.dependencies,...s.devDependencies};return c.vitest&&!c.jest?`vitest`:c.jest&&!c.vitest?`jest`:hasConfig(`vitest`)||c.vitest||[`vite.config.ts`,`vite.config.js`,`vite.config.mjs`].some(t=>n(a(e,t)))?`vitest`:null}function runnerBin(t,n){let r=e(a(t,`package.json`)),o=``;try{o=r.resolve(`${n}/package.json`)}catch{fail(`${n} is not installed in ${t}`)}let s=readJson(o)??{},c=typeof s.bin==`string`?s.bin:s.bin?.[n];return c||fail(`cannot find ${n}'s CLI in ${o}`),a(i(o),c)}const p={"test-name":{type:`string`,short:`t`},runner:{type:`string`},config:{type:`string`},format:{type:`string`,default:`aria`},lines:{type:`string`},raw:{type:`boolean`,default:!1},help:{type:`boolean`,short:`h`,default:!1}};function parseOptions(e){try{return c({args:e,allowPositionals:!0,options:p})}catch(e){fail(`${e.message}\n\n${d}`)}}function main(e){let[n,...r]=e;if(n===void 0||n===`-h`||n===`--help`||n===`help`)return process.stdout.write(d),n===void 0?2:0;n!==`debug`&&fail(`unknown command "${n}"\n\n${d}`);let i=r.indexOf(`--`),s=i<0?r:r.slice(0,i),c=i<0?[]:r.slice(i+1),{values:f,positionals:p}=parseOptions(s);if(f.help)return process.stdout.write(d),0;p.length===0&&fail(`no test file given\n\n${d}`),[`aria`,`compact`].includes(f.format)||fail(`--format must be aria or compact`);let m=projectRoot(process.cwd()),h=f.runner??detectRunner(m,p,f.config);h!==`vitest`&&h!==`jest`&&fail(h?`--runner must be vitest or jest`:`cannot tell whether ${m} uses Vitest or Jest: pass --runner`);let g=[runnerBin(m,h)];h===`vitest`?(g.push(`run`,...p),f.config&&g.push(`--config`,f.config),f[`test-name`]!==void 0&&g.push(`-t`,f[`test-name`]),f.raw||g.push(`--reporter=${a(l,`vitest-reporter${u}`)}`)):(g.push(`--runTestsByPath`,...p.map(e=>o(e)),`--ci`),f.config&&g.push(`--config`,f.config),f[`test-name`]!==void 0&&g.push(`-t`,f[`test-name`]),f.raw||g.push(`--reporters=${a(l,`jest-reporter${u}`)}`)),g.push(...c);let _={...process.env,CTRL_DOM_DEBUG:f.format,FORCE_COLOR:`0`,NO_COLOR:`1`};f.lines!==void 0&&(_.CTRL_DOM_DEBUG_LINES=f.lines),process.stdout.write(`ctrl-dom debug: ${h} ${p.join(` `)}${f[`test-name`]===void 0?``:` -t ${JSON.stringify(f[`test-name`])}`} (CTRL_DOM_DEBUG=${f.format})\n\n`);let v=t(process.execPath,g,{cwd:process.cwd(),env:_,stdio:`inherit`});return v.error&&fail(v.error.message),v.status??1}import.meta.main&&(process.exitCode=main(process.argv.slice(2)));export{detectRunner,main};
@@ -1,55 +1,3 @@
1
- import { i as missingSnapshotHint, n as formatReport, r as messageWithoutFrames, t as firstProjectFrame } from "./_chunks/report-DdncYfuJ.js";
2
- import { relative } from "node:path";
1
+ import"./_chunks/rolldown-runtime-H3fMLYWS.js";import{i as e,n as t,r as n,t as r}from"./_chunks/report-z52LF7nA.js";import{relative as i}from"node:path";var CtrlDomDebugReporter=class{root=process.cwd();start=performance.now();onRunComplete(a,o){let s=[],c=[],l=[],u=[];for(let e of o.testResults){let t=i(this.root,e.testFilePath)||e.testFilePath;if(u.push(t),e.testExecError){let i=e.testExecError;c.push({name:t,message:n(i.stack??i.message??String(i)),at:r(i.stack,this.root,e.testFilePath)})}for(let t of e.testResults){if(t.status!==`failed`)continue;let i=t.failureMessages.join(`
3
2
 
4
- // src/jest-reporter.ts
5
- var CtrlDomDebugReporter = class {
6
- root = process.cwd();
7
- start = performance.now();
8
- onRunComplete(_testContexts, results) {
9
- const failures = [];
10
- const errors = [];
11
- const logs = [];
12
- const files = [];
13
- for (const file of results.testResults) {
14
- const name = relative(this.root, file.testFilePath) || file.testFilePath;
15
- files.push(name);
16
- if (file.testExecError) {
17
- const error = file.testExecError;
18
- errors.push({
19
- name,
20
- message: messageWithoutFrames(error.stack ?? error.message ?? String(error)),
21
- at: firstProjectFrame(error.stack, this.root, file.testFilePath)
22
- });
23
- }
24
- for (const test of file.testResults) {
25
- if (test.status !== "failed") continue;
26
- const text = test.failureMessages.join("\n\n");
27
- failures.push({
28
- name: test.fullName,
29
- message: messageWithoutFrames(text),
30
- at: firstProjectFrame(text, this.root, file.testFilePath)
31
- });
32
- }
33
- for (const entry of file.console ?? []) logs.push({
34
- name,
35
- type: entry.type === "error" || entry.type === "warn" ? "stderr" : "stdout",
36
- content: entry.message
37
- });
38
- }
39
- process.stdout.write(formatReport({
40
- runner: "jest",
41
- root: this.root,
42
- failures,
43
- errors,
44
- logs,
45
- passed: results.numPassedTests,
46
- failed: results.numFailedTests,
47
- skipped: results.numPendingTests + results.numTodoTests,
48
- files,
49
- durationMs: performance.now() - this.start
50
- }));
51
- process.stdout.write(missingSnapshotHint(failures, "jest"));
52
- }
53
- };
54
-
55
- export { CtrlDomDebugReporter as default };
3
+ `);s.push({name:t.fullName,message:n(i),at:r(i,this.root,e.testFilePath)})}for(let n of e.console??[])l.push({name:t,type:n.type===`error`||n.type===`warn`?`stderr`:`stdout`,content:n.message})}process.stdout.write(t({runner:`jest`,root:this.root,failures:s,errors:c,logs:l,passed:o.numPassedTests,failed:o.numFailedTests,skipped:o.numPendingTests+o.numTodoTests,files:u,durationMs:performance.now()-this.start})),process.stdout.write(e(s,`jest`))}};export{CtrlDomDebugReporter as default};
@@ -1,81 +1,2 @@
1
- import { a as stripAnsi, i as missingSnapshotHint, n as formatReport, r as messageWithoutFrames, t as firstProjectFrame } from "./_chunks/report-DdncYfuJ.js";
2
- import { relative } from "node:path";
3
-
4
- // src/vitest-reporter.ts
5
- function formatError(error) {
6
- let message = `${typeof error?.name === "string" && error.name !== "" ? `${error.name}: ` : ""}${messageWithoutFrames(error?.message ?? String(error))}`;
7
- if (typeof error?.diff === "string" && error.diff !== "") message += `\n\n${stripAnsi(error.diff)}`;
8
- return message;
9
- }
10
- function frameOf(error, root, testFile) {
11
- const stack = Array.isArray(error?.stacks) && error.stacks.length > 0 ? error.stacks.map((s) => ` at ${s.file}:${s.line}:${s.column}`).join("\n") : error?.stack;
12
- return firstProjectFrame(stack, root, testFile);
13
- }
14
- var CtrlDomDebugReporter = class {
15
- root = process.cwd();
16
- logs = [];
17
- start = performance.now();
18
- onUserConsoleLog(log) {
19
- this.logs.push(log);
20
- }
21
- onTestRunEnd(testModules, unhandledErrors) {
22
- const names = /* @__PURE__ */ new Map();
23
- const failures = [];
24
- const errors = [];
25
- const files = [];
26
- let passed = 0;
27
- let failed = 0;
28
- let skipped = 0;
29
- for (const module of testModules) {
30
- const file = relative(this.root, module.moduleId) || module.moduleId;
31
- files.push(file);
32
- names.set(module.id, file);
33
- for (const error of module.errors?.() ?? []) errors.push({
34
- name: file,
35
- message: formatError(error),
36
- at: frameOf(error, this.root, module.moduleId)
37
- });
38
- for (const test of module.children.allTests()) {
39
- names.set(test.id, test.fullName);
40
- const result = test.result();
41
- if (result.state === "passed") passed++;
42
- else if (result.state === "failed") {
43
- failed++;
44
- const [first, ...rest] = result.errors ?? [];
45
- let message = first ? formatError(first) : "(failed without an error)";
46
- for (const error of rest) message += `\n\n${formatError(error)}`;
47
- failures.push({
48
- name: test.fullName,
49
- message,
50
- at: first ? frameOf(first, this.root, module.moduleId) : null
51
- });
52
- } else skipped++;
53
- }
54
- }
55
- for (const error of unhandledErrors) errors.push({
56
- name: "Unhandled error",
57
- message: formatError(error),
58
- at: frameOf(error, this.root)
59
- });
60
- const logs = this.logs.map((log) => ({
61
- name: log.taskId !== void 0 && names.get(log.taskId) || "(outside a test)",
62
- type: log.type,
63
- content: log.content
64
- }));
65
- process.stdout.write(formatReport({
66
- runner: "vitest",
67
- root: this.root,
68
- failures,
69
- errors,
70
- logs,
71
- passed,
72
- failed,
73
- skipped,
74
- files,
75
- durationMs: performance.now() - this.start
76
- }));
77
- process.stdout.write(missingSnapshotHint(failures, "vitest"));
78
- }
79
- };
80
-
81
- export { CtrlDomDebugReporter as default };
1
+ import"./_chunks/rolldown-runtime-H3fMLYWS.js";import{a as e,i as t,n,r,t as i}from"./_chunks/report-z52LF7nA.js";import{relative as a}from"node:path";function formatError(t){let n=`${typeof t?.name==`string`&&t.name!==``?`${t.name}: `:``}${r(t?.message??String(t))}`;return typeof t?.diff==`string`&&t.diff!==``&&(n+=`\n\n${e(t.diff)}`),n}function frameOf(e,t,n){let r=Array.isArray(e?.stacks)&&e.stacks.length>0?e.stacks.map(e=>` at ${e.file}:${e.line}:${e.column}`).join(`
2
+ `):e?.stack;return i(r,t,n)}var CtrlDomDebugReporter=class{root=process.cwd();logs=[];start=performance.now();onUserConsoleLog(e){this.logs.push(e)}onTestRunEnd(e,r){let i=/* @__PURE__ */ new Map,o=[],s=[],c=[],l=0,u=0,d=0;for(let t of e){let e=a(this.root,t.moduleId)||t.moduleId;c.push(e),i.set(t.id,e);for(let n of t.errors?.()??[])s.push({name:e,message:formatError(n),at:frameOf(n,this.root,t.moduleId)});for(let e of t.children.allTests()){i.set(e.id,e.fullName);let n=e.result();if(n.state===`passed`)l++;else if(n.state===`failed`){u++;let[r,...i]=n.errors??[],a=r?formatError(r):`(failed without an error)`;for(let e of i)a+=`\n\n${formatError(e)}`;o.push({name:e.fullName,message:a,at:r?frameOf(r,this.root,t.moduleId):null})}else d++}}for(let e of r)s.push({name:`Unhandled error`,message:formatError(e),at:frameOf(e,this.root)});let f=this.logs.map(e=>({name:e.taskId!==void 0&&i.get(e.taskId)||`(outside a test)`,type:e.type,content:e.content}));process.stdout.write(n({runner:`vitest`,root:this.root,failures:o,errors:s,logs:f,passed:l,failed:u,skipped:d,files:c,durationMs:performance.now()-this.start})),process.stdout.write(t(o,`vitest`))}};export{CtrlDomDebugReporter as default};