twd-js 0.1.0
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/LICENSE +21 -0
- package/README.md +92 -0
- package/dist/twd.es.js +674 -0
- package/dist/twd.umd.js +22 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 BRIKEV
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# twd
|
|
2
|
+
|
|
3
|
+
[](https://github.com/BRIKEV/twd/actions/workflows/ci.yml)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
> ⚠️ This is a **beta release** – expect frequent updates and possible breaking changes.
|
|
7
|
+
|
|
8
|
+
TWD (Testing Web Development) is a tool designed to help integrating testing while developing web applications. It aims to streamline the testing process and make it easier for developers to write and run tests as they build their applications.
|
|
9
|
+
|
|
10
|
+
Right now we only support React, but we plan to add support for other frameworks in the future.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
You can install TWD via npm:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# with npm
|
|
18
|
+
npm install twd
|
|
19
|
+
|
|
20
|
+
# with yarn
|
|
21
|
+
yarn add twd
|
|
22
|
+
|
|
23
|
+
# with pnpm
|
|
24
|
+
pnpm add twd
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## How to use
|
|
28
|
+
|
|
29
|
+
Add the our React Sidebar component to your application:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { StrictMode } from 'react'
|
|
33
|
+
import { createRoot } from 'react-dom/client'
|
|
34
|
+
import './index.css'
|
|
35
|
+
import { TWDSidebar } from '../../../src'
|
|
36
|
+
import router from './routes.ts'
|
|
37
|
+
import { RouterProvider } from 'react-router'
|
|
38
|
+
|
|
39
|
+
createRoot(document.getElementById('root')!).render(
|
|
40
|
+
<StrictMode>
|
|
41
|
+
<RouterProvider router={router} />
|
|
42
|
+
<TWDSidebar />
|
|
43
|
+
</StrictMode>,
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then, create test files with the `.test.ts` or any extension you want. For example:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
// src/app.twd-test.ts
|
|
51
|
+
import { describe, it, twd } from "../../../src/twd";
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
console.log("Reset state before each test");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("App interactions", () => {
|
|
58
|
+
it("clicks the button", async () => {
|
|
59
|
+
const btn = await twd.get("button");
|
|
60
|
+
btn.click();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
After you create your test you need to load them in your application. You can do this by creating a `loadTests.ts` file and importing all your test files there:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// src/loadTests.ts
|
|
69
|
+
import "./app.twd-test";
|
|
70
|
+
import "./another-test-file.twd-test";
|
|
71
|
+
// Import other test files here
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Or if you're using vite you can use Vite's `import.meta.glob` to automatically import all test files in a directory:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// This automatically imports all files ending with .twd.test.ts
|
|
78
|
+
const modules = import.meta.glob("./**/*.twd.test.ts", { eager: true });
|
|
79
|
+
|
|
80
|
+
// You don't need to export anything; simply importing this in App.tsx
|
|
81
|
+
// will cause the test files to execute and register their tests.
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Then, import the `loadTests.ts` file in your main application file (e.g., `main.tsx` or `App.tsx`):
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import './loadTests' // Import test files
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Finally, run your application and open the TWD sidebar to see and run your tests.
|
|
91
|
+
|
|
92
|
+
|
package/dist/twd.es.js
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import ce, { useState as Y } from "react";
|
|
2
|
+
const le = (t, r = 2e3, n = 50) => new Promise((o, s) => {
|
|
3
|
+
const l = Date.now(), i = () => {
|
|
4
|
+
const c = t();
|
|
5
|
+
if (c) return o(c);
|
|
6
|
+
if (Date.now() - l > r) return s(new Error("Timeout waiting for element"));
|
|
7
|
+
setTimeout(i, n);
|
|
8
|
+
};
|
|
9
|
+
i();
|
|
10
|
+
}), g = [];
|
|
11
|
+
let I = [];
|
|
12
|
+
const D = (t, r, n = {}) => {
|
|
13
|
+
g.push({
|
|
14
|
+
name: t,
|
|
15
|
+
fn: r,
|
|
16
|
+
status: "idle",
|
|
17
|
+
logs: [],
|
|
18
|
+
suite: [...I],
|
|
19
|
+
...n
|
|
20
|
+
});
|
|
21
|
+
}, ue = (t) => {
|
|
22
|
+
I.push(t);
|
|
23
|
+
}, de = () => {
|
|
24
|
+
I.pop();
|
|
25
|
+
};
|
|
26
|
+
function fe(t) {
|
|
27
|
+
if (!t.isConnected) return !1;
|
|
28
|
+
let r = t;
|
|
29
|
+
for (; r; ) {
|
|
30
|
+
const n = getComputedStyle(r);
|
|
31
|
+
if (n.display === "none" || n.visibility === "hidden" || n.visibility === "collapse")
|
|
32
|
+
return !1;
|
|
33
|
+
r = r.parentElement;
|
|
34
|
+
}
|
|
35
|
+
return !0;
|
|
36
|
+
}
|
|
37
|
+
const pe = (t, r, ...n) => {
|
|
38
|
+
const o = r.startsWith("not."), s = o ? r.slice(4) : r, i = (() => {
|
|
39
|
+
const c = (t.textContent || "").trim();
|
|
40
|
+
switch (s) {
|
|
41
|
+
// Content
|
|
42
|
+
case "have.text":
|
|
43
|
+
return c === n[0];
|
|
44
|
+
case "contain.text":
|
|
45
|
+
return c.includes(n[0]);
|
|
46
|
+
case "be.empty":
|
|
47
|
+
return c.length === 0;
|
|
48
|
+
// Attributes
|
|
49
|
+
case "have.attr":
|
|
50
|
+
return t.getAttribute(n[0]) === n[1];
|
|
51
|
+
case "have.value":
|
|
52
|
+
return t.value === n[0];
|
|
53
|
+
// State
|
|
54
|
+
case "be.disabled":
|
|
55
|
+
return t.disabled === !0;
|
|
56
|
+
case "be.enabled":
|
|
57
|
+
return t.disabled === !1;
|
|
58
|
+
case "be.checked":
|
|
59
|
+
return t.checked === !0;
|
|
60
|
+
case "be.selected":
|
|
61
|
+
return t.selected === !0;
|
|
62
|
+
case "be.focused":
|
|
63
|
+
return document.activeElement === t;
|
|
64
|
+
// Visibility
|
|
65
|
+
case "be.visible":
|
|
66
|
+
return fe(t);
|
|
67
|
+
// Classes
|
|
68
|
+
case "have.class":
|
|
69
|
+
return t.classList.contains(n[0]);
|
|
70
|
+
default:
|
|
71
|
+
throw new Error(`Unknown assertion: ${s}`);
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
74
|
+
if (o ? i : !i)
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Assertion failed: ${r} ${n.length ? JSON.stringify(n) : ""}`
|
|
77
|
+
);
|
|
78
|
+
}, w = (t) => {
|
|
79
|
+
const r = g.find((n) => n.status === "running");
|
|
80
|
+
r && r.logs?.push(t);
|
|
81
|
+
}, T = [], be = (t, r) => {
|
|
82
|
+
const n = T.findIndex((s) => s.alias === t), o = { alias: t, ...r, executed: !1 };
|
|
83
|
+
n !== -1 ? T[n] = o : T.push(o);
|
|
84
|
+
}, me = async (t) => {
|
|
85
|
+
const r = T.find((n) => n.alias === t && n.executed);
|
|
86
|
+
if (!r)
|
|
87
|
+
throw new Error(`No intercept rule found for ${t}`);
|
|
88
|
+
return await new Promise((n) => setTimeout(n, 0)), r;
|
|
89
|
+
}, he = window.fetch;
|
|
90
|
+
window.fetch = async (t, r) => {
|
|
91
|
+
const n = r?.method?.toUpperCase() || "GET", o = typeof t == "string" ? t : t.toString(), s = T.find(
|
|
92
|
+
(l) => l.method === n && (typeof l.url == "string" ? l.url === o : l.url.test(o))
|
|
93
|
+
);
|
|
94
|
+
return s ? (w(`🛡️ ${s.alias} → ${n} ${o}`), s.executed = !0, s.request = r?.body, new Response(JSON.stringify(s.response), {
|
|
95
|
+
status: s.status || 200,
|
|
96
|
+
headers: s.headers || { "Content-Type": "application/json" }
|
|
97
|
+
})) : he(t, r);
|
|
98
|
+
};
|
|
99
|
+
const xe = (t, r) => {
|
|
100
|
+
for (const n of r) {
|
|
101
|
+
const o = n.charCodeAt(0);
|
|
102
|
+
t.dispatchEvent(
|
|
103
|
+
new KeyboardEvent("keydown", {
|
|
104
|
+
key: n,
|
|
105
|
+
code: `Key${n.toUpperCase()}`,
|
|
106
|
+
keyCode: o,
|
|
107
|
+
which: o,
|
|
108
|
+
bubbles: !0,
|
|
109
|
+
cancelable: !0
|
|
110
|
+
})
|
|
111
|
+
), t.dispatchEvent(
|
|
112
|
+
new KeyboardEvent("keypress", {
|
|
113
|
+
key: n,
|
|
114
|
+
code: `Key${n.toUpperCase()}`,
|
|
115
|
+
keyCode: o,
|
|
116
|
+
which: o,
|
|
117
|
+
bubbles: !0,
|
|
118
|
+
cancelable: !0
|
|
119
|
+
})
|
|
120
|
+
), t.dispatchEvent(
|
|
121
|
+
new InputEvent("beforeinput", {
|
|
122
|
+
bubbles: !0,
|
|
123
|
+
cancelable: !0,
|
|
124
|
+
inputType: "insertText",
|
|
125
|
+
data: n
|
|
126
|
+
})
|
|
127
|
+
), Object.getOwnPropertyDescriptor(
|
|
128
|
+
Object.getPrototypeOf(t),
|
|
129
|
+
"value"
|
|
130
|
+
)?.set?.call(t, t.value + n), t.dispatchEvent(
|
|
131
|
+
new Event("input", {
|
|
132
|
+
bubbles: !0
|
|
133
|
+
})
|
|
134
|
+
), t.dispatchEvent(
|
|
135
|
+
new KeyboardEvent("keyup", {
|
|
136
|
+
key: n,
|
|
137
|
+
code: `Key${n.toUpperCase()}`,
|
|
138
|
+
keyCode: o,
|
|
139
|
+
which: o,
|
|
140
|
+
bubbles: !0,
|
|
141
|
+
cancelable: !0
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return t;
|
|
146
|
+
};
|
|
147
|
+
let _ = null;
|
|
148
|
+
const _e = (t) => {
|
|
149
|
+
_ = t;
|
|
150
|
+
}, Se = (t, r) => {
|
|
151
|
+
ue(t), r(), de();
|
|
152
|
+
}, je = (t, r) => {
|
|
153
|
+
D(t, async () => {
|
|
154
|
+
_ && await _(), await r();
|
|
155
|
+
});
|
|
156
|
+
}, Oe = (t, r) => {
|
|
157
|
+
D(t, async () => {
|
|
158
|
+
_ && await _(), await r();
|
|
159
|
+
}, { only: !0 });
|
|
160
|
+
}, Ae = (t, r) => {
|
|
161
|
+
D(t, async () => {
|
|
162
|
+
}, { skip: !0 });
|
|
163
|
+
}, Ce = {
|
|
164
|
+
get: async (t) => {
|
|
165
|
+
w(`🔎 get("${t}")`);
|
|
166
|
+
const r = await le(() => document.querySelector(t)), n = {
|
|
167
|
+
el: r,
|
|
168
|
+
click: () => {
|
|
169
|
+
w(`🖱️ click(${t})`), r.click();
|
|
170
|
+
},
|
|
171
|
+
type: (o) => (w(`⌨️ type("${o}") into ${t}`), xe(r, o)),
|
|
172
|
+
should: (o, ...s) => (pe(r, o, ...s), n),
|
|
173
|
+
text: () => {
|
|
174
|
+
const o = r.textContent || "";
|
|
175
|
+
return w(`📄 text(${t}) → "${o}"`), o;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
return n;
|
|
179
|
+
},
|
|
180
|
+
visit: (t) => {
|
|
181
|
+
w(`🌍 visit("${t}")`), window.history.pushState({}, "", t), window.dispatchEvent(new PopStateEvent("popstate"));
|
|
182
|
+
},
|
|
183
|
+
mockRequest: be,
|
|
184
|
+
waitFor: me
|
|
185
|
+
};
|
|
186
|
+
var j = { exports: {} }, k = {};
|
|
187
|
+
/**
|
|
188
|
+
* @license React
|
|
189
|
+
* react-jsx-runtime.production.js
|
|
190
|
+
*
|
|
191
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
192
|
+
*
|
|
193
|
+
* This source code is licensed under the MIT license found in the
|
|
194
|
+
* LICENSE file in the root directory of this source tree.
|
|
195
|
+
*/
|
|
196
|
+
var V;
|
|
197
|
+
function ye() {
|
|
198
|
+
if (V) return k;
|
|
199
|
+
V = 1;
|
|
200
|
+
var t = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
201
|
+
function n(o, s, l) {
|
|
202
|
+
var i = null;
|
|
203
|
+
if (l !== void 0 && (i = "" + l), s.key !== void 0 && (i = "" + s.key), "key" in s) {
|
|
204
|
+
l = {};
|
|
205
|
+
for (var c in s)
|
|
206
|
+
c !== "key" && (l[c] = s[c]);
|
|
207
|
+
} else l = s;
|
|
208
|
+
return s = l.ref, {
|
|
209
|
+
$$typeof: t,
|
|
210
|
+
type: o,
|
|
211
|
+
key: i,
|
|
212
|
+
ref: s !== void 0 ? s : null,
|
|
213
|
+
props: l
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return k.Fragment = r, k.jsx = n, k.jsxs = n, k;
|
|
217
|
+
}
|
|
218
|
+
var R = {};
|
|
219
|
+
/**
|
|
220
|
+
* @license React
|
|
221
|
+
* react-jsx-runtime.development.js
|
|
222
|
+
*
|
|
223
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
224
|
+
*
|
|
225
|
+
* This source code is licensed under the MIT license found in the
|
|
226
|
+
* LICENSE file in the root directory of this source tree.
|
|
227
|
+
*/
|
|
228
|
+
var B;
|
|
229
|
+
function ge() {
|
|
230
|
+
return B || (B = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
231
|
+
function t(e) {
|
|
232
|
+
if (e == null) return null;
|
|
233
|
+
if (typeof e == "function")
|
|
234
|
+
return e.$$typeof === se ? null : e.displayName || e.name || null;
|
|
235
|
+
if (typeof e == "string") return e;
|
|
236
|
+
switch (e) {
|
|
237
|
+
case O:
|
|
238
|
+
return "Fragment";
|
|
239
|
+
case H:
|
|
240
|
+
return "Profiler";
|
|
241
|
+
case K:
|
|
242
|
+
return "StrictMode";
|
|
243
|
+
case te:
|
|
244
|
+
return "Suspense";
|
|
245
|
+
case re:
|
|
246
|
+
return "SuspenseList";
|
|
247
|
+
case oe:
|
|
248
|
+
return "Activity";
|
|
249
|
+
}
|
|
250
|
+
if (typeof e == "object")
|
|
251
|
+
switch (typeof e.tag == "number" && console.error(
|
|
252
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
253
|
+
), e.$$typeof) {
|
|
254
|
+
case X:
|
|
255
|
+
return "Portal";
|
|
256
|
+
case Q:
|
|
257
|
+
return (e.displayName || "Context") + ".Provider";
|
|
258
|
+
case Z:
|
|
259
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
260
|
+
case ee:
|
|
261
|
+
var a = e.render;
|
|
262
|
+
return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
263
|
+
case ne:
|
|
264
|
+
return a = e.displayName || null, a !== null ? a : t(e.type) || "Memo";
|
|
265
|
+
case L:
|
|
266
|
+
a = e._payload, e = e._init;
|
|
267
|
+
try {
|
|
268
|
+
return t(e(a));
|
|
269
|
+
} catch {
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
function r(e) {
|
|
275
|
+
return "" + e;
|
|
276
|
+
}
|
|
277
|
+
function n(e) {
|
|
278
|
+
try {
|
|
279
|
+
r(e);
|
|
280
|
+
var a = !1;
|
|
281
|
+
} catch {
|
|
282
|
+
a = !0;
|
|
283
|
+
}
|
|
284
|
+
if (a) {
|
|
285
|
+
a = console;
|
|
286
|
+
var u = a.error, f = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
287
|
+
return u.call(
|
|
288
|
+
a,
|
|
289
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
290
|
+
f
|
|
291
|
+
), r(e);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function o(e) {
|
|
295
|
+
if (e === O) return "<>";
|
|
296
|
+
if (typeof e == "object" && e !== null && e.$$typeof === L)
|
|
297
|
+
return "<...>";
|
|
298
|
+
try {
|
|
299
|
+
var a = t(e);
|
|
300
|
+
return a ? "<" + a + ">" : "<...>";
|
|
301
|
+
} catch {
|
|
302
|
+
return "<...>";
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function s() {
|
|
306
|
+
var e = A.A;
|
|
307
|
+
return e === null ? null : e.getOwner();
|
|
308
|
+
}
|
|
309
|
+
function l() {
|
|
310
|
+
return Error("react-stack-top-frame");
|
|
311
|
+
}
|
|
312
|
+
function i(e) {
|
|
313
|
+
if (W.call(e, "key")) {
|
|
314
|
+
var a = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
315
|
+
if (a && a.isReactWarning) return !1;
|
|
316
|
+
}
|
|
317
|
+
return e.key !== void 0;
|
|
318
|
+
}
|
|
319
|
+
function c(e, a) {
|
|
320
|
+
function u() {
|
|
321
|
+
U || (U = !0, console.error(
|
|
322
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
323
|
+
a
|
|
324
|
+
));
|
|
325
|
+
}
|
|
326
|
+
u.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
327
|
+
get: u,
|
|
328
|
+
configurable: !0
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function b() {
|
|
332
|
+
var e = t(this.type);
|
|
333
|
+
return z[e] || (z[e] = !0, console.error(
|
|
334
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
335
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
336
|
+
}
|
|
337
|
+
function h(e, a, u, f, y, x, P, N) {
|
|
338
|
+
return u = x.ref, e = {
|
|
339
|
+
$$typeof: F,
|
|
340
|
+
type: e,
|
|
341
|
+
key: a,
|
|
342
|
+
props: x,
|
|
343
|
+
_owner: y
|
|
344
|
+
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
|
|
345
|
+
enumerable: !1,
|
|
346
|
+
get: b
|
|
347
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
348
|
+
configurable: !1,
|
|
349
|
+
enumerable: !1,
|
|
350
|
+
writable: !0,
|
|
351
|
+
value: 0
|
|
352
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
353
|
+
configurable: !1,
|
|
354
|
+
enumerable: !1,
|
|
355
|
+
writable: !0,
|
|
356
|
+
value: null
|
|
357
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
358
|
+
configurable: !1,
|
|
359
|
+
enumerable: !1,
|
|
360
|
+
writable: !0,
|
|
361
|
+
value: P
|
|
362
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
363
|
+
configurable: !1,
|
|
364
|
+
enumerable: !1,
|
|
365
|
+
writable: !0,
|
|
366
|
+
value: N
|
|
367
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
368
|
+
}
|
|
369
|
+
function m(e, a, u, f, y, x, P, N) {
|
|
370
|
+
var p = a.children;
|
|
371
|
+
if (p !== void 0)
|
|
372
|
+
if (f)
|
|
373
|
+
if (ae(p)) {
|
|
374
|
+
for (f = 0; f < p.length; f++)
|
|
375
|
+
E(p[f]);
|
|
376
|
+
Object.freeze && Object.freeze(p);
|
|
377
|
+
} else
|
|
378
|
+
console.error(
|
|
379
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
380
|
+
);
|
|
381
|
+
else E(p);
|
|
382
|
+
if (W.call(a, "key")) {
|
|
383
|
+
p = t(e);
|
|
384
|
+
var v = Object.keys(a).filter(function(ie) {
|
|
385
|
+
return ie !== "key";
|
|
386
|
+
});
|
|
387
|
+
f = 0 < v.length ? "{key: someKey, " + v.join(": ..., ") + ": ...}" : "{key: someKey}", J[p + f] || (v = 0 < v.length ? "{" + v.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
388
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
389
|
+
let props = %s;
|
|
390
|
+
<%s {...props} />
|
|
391
|
+
React keys must be passed directly to JSX without using spread:
|
|
392
|
+
let props = %s;
|
|
393
|
+
<%s key={someKey} {...props} />`,
|
|
394
|
+
f,
|
|
395
|
+
p,
|
|
396
|
+
v,
|
|
397
|
+
p
|
|
398
|
+
), J[p + f] = !0);
|
|
399
|
+
}
|
|
400
|
+
if (p = null, u !== void 0 && (n(u), p = "" + u), i(a) && (n(a.key), p = "" + a.key), "key" in a) {
|
|
401
|
+
u = {};
|
|
402
|
+
for (var $ in a)
|
|
403
|
+
$ !== "key" && (u[$] = a[$]);
|
|
404
|
+
} else u = a;
|
|
405
|
+
return p && c(
|
|
406
|
+
u,
|
|
407
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
408
|
+
), h(
|
|
409
|
+
e,
|
|
410
|
+
p,
|
|
411
|
+
x,
|
|
412
|
+
y,
|
|
413
|
+
s(),
|
|
414
|
+
u,
|
|
415
|
+
P,
|
|
416
|
+
N
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
function E(e) {
|
|
420
|
+
typeof e == "object" && e !== null && e.$$typeof === F && e._store && (e._store.validated = 1);
|
|
421
|
+
}
|
|
422
|
+
var S = ce, F = Symbol.for("react.transitional.element"), X = Symbol.for("react.portal"), O = Symbol.for("react.fragment"), K = Symbol.for("react.strict_mode"), H = Symbol.for("react.profiler"), Z = Symbol.for("react.consumer"), Q = Symbol.for("react.context"), ee = Symbol.for("react.forward_ref"), te = Symbol.for("react.suspense"), re = Symbol.for("react.suspense_list"), ne = Symbol.for("react.memo"), L = Symbol.for("react.lazy"), oe = Symbol.for("react.activity"), se = Symbol.for("react.client.reference"), A = S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, W = Object.prototype.hasOwnProperty, ae = Array.isArray, C = console.createTask ? console.createTask : function() {
|
|
423
|
+
return null;
|
|
424
|
+
};
|
|
425
|
+
S = {
|
|
426
|
+
react_stack_bottom_frame: function(e) {
|
|
427
|
+
return e();
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
var U, z = {}, q = S.react_stack_bottom_frame.bind(
|
|
431
|
+
S,
|
|
432
|
+
l
|
|
433
|
+
)(), M = C(o(l)), J = {};
|
|
434
|
+
R.Fragment = O, R.jsx = function(e, a, u, f, y) {
|
|
435
|
+
var x = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
436
|
+
return m(
|
|
437
|
+
e,
|
|
438
|
+
a,
|
|
439
|
+
u,
|
|
440
|
+
!1,
|
|
441
|
+
f,
|
|
442
|
+
y,
|
|
443
|
+
x ? Error("react-stack-top-frame") : q,
|
|
444
|
+
x ? C(o(e)) : M
|
|
445
|
+
);
|
|
446
|
+
}, R.jsxs = function(e, a, u, f, y) {
|
|
447
|
+
var x = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
448
|
+
return m(
|
|
449
|
+
e,
|
|
450
|
+
a,
|
|
451
|
+
u,
|
|
452
|
+
!0,
|
|
453
|
+
f,
|
|
454
|
+
y,
|
|
455
|
+
x ? Error("react-stack-top-frame") : q,
|
|
456
|
+
x ? C(o(e)) : M
|
|
457
|
+
);
|
|
458
|
+
};
|
|
459
|
+
})()), R;
|
|
460
|
+
}
|
|
461
|
+
var G;
|
|
462
|
+
function Ee() {
|
|
463
|
+
return G || (G = 1, process.env.NODE_ENV === "production" ? j.exports = ye() : j.exports = ge()), j.exports;
|
|
464
|
+
}
|
|
465
|
+
var d = Ee();
|
|
466
|
+
const ve = (t) => {
|
|
467
|
+
const r = { children: [] };
|
|
468
|
+
for (const n of t) {
|
|
469
|
+
let o = r;
|
|
470
|
+
n.suite.forEach((s) => {
|
|
471
|
+
let l = o.children.find(
|
|
472
|
+
(i) => "name" in i && !i.status && i.name === s
|
|
473
|
+
);
|
|
474
|
+
l || (l = { name: s, children: [] }, o.children.push(l)), o = l;
|
|
475
|
+
}), o.children.push(n);
|
|
476
|
+
}
|
|
477
|
+
return r.children;
|
|
478
|
+
}, we = ({ node: t, depth: r, idx: n, runTest: o }) => /* @__PURE__ */ d.jsxs("li", { style: { marginBottom: "4px", marginLeft: r * 6 }, children: [
|
|
479
|
+
/* @__PURE__ */ d.jsxs(
|
|
480
|
+
"div",
|
|
481
|
+
{
|
|
482
|
+
style: {
|
|
483
|
+
display: "flex",
|
|
484
|
+
alignItems: "center",
|
|
485
|
+
justifyContent: "space-between",
|
|
486
|
+
padding: "4px 6px",
|
|
487
|
+
borderRadius: "4px",
|
|
488
|
+
background: t.status === "pass" ? "#dcfce7" : t.status === "fail" ? "#fee2e2" : t.status === "skip" ? "#f3f4f6" : t.status === "running" ? "#fef9c3" : "transparent"
|
|
489
|
+
},
|
|
490
|
+
children: [
|
|
491
|
+
/* @__PURE__ */ d.jsxs("span", { children: [
|
|
492
|
+
t.name,
|
|
493
|
+
" ",
|
|
494
|
+
t.only && /* @__PURE__ */ d.jsx("span", { style: { color: "#2563eb" }, children: "(only)" }),
|
|
495
|
+
t.skip && /* @__PURE__ */ d.jsx("span", { style: { color: "#6b7280" }, children: "(skipped)" })
|
|
496
|
+
] }),
|
|
497
|
+
/* @__PURE__ */ d.jsx(
|
|
498
|
+
"button",
|
|
499
|
+
{
|
|
500
|
+
onClick: () => o(n),
|
|
501
|
+
style: {
|
|
502
|
+
background: "transparent",
|
|
503
|
+
border: "1px solid #d1d5db",
|
|
504
|
+
borderRadius: "4px",
|
|
505
|
+
padding: "2px 6px",
|
|
506
|
+
cursor: "pointer",
|
|
507
|
+
fontSize: "12px"
|
|
508
|
+
},
|
|
509
|
+
children: "▶"
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
]
|
|
513
|
+
}
|
|
514
|
+
),
|
|
515
|
+
t.logs && t.logs.length > 0 && /* @__PURE__ */ d.jsx(
|
|
516
|
+
"ul",
|
|
517
|
+
{
|
|
518
|
+
style: {
|
|
519
|
+
borderRadius: "4px",
|
|
520
|
+
maxHeight: "160px",
|
|
521
|
+
overflowY: "auto",
|
|
522
|
+
padding: 0,
|
|
523
|
+
background: "#f3f4f6",
|
|
524
|
+
listStyle: "none",
|
|
525
|
+
marginTop: "4px"
|
|
526
|
+
},
|
|
527
|
+
children: t.logs.map((s, l) => /* @__PURE__ */ d.jsx(
|
|
528
|
+
"li",
|
|
529
|
+
{
|
|
530
|
+
style: {
|
|
531
|
+
fontSize: "12px",
|
|
532
|
+
padding: "4px 6px",
|
|
533
|
+
borderBottom: "1px solid #d1d5db"
|
|
534
|
+
},
|
|
535
|
+
children: s
|
|
536
|
+
},
|
|
537
|
+
l
|
|
538
|
+
))
|
|
539
|
+
}
|
|
540
|
+
)
|
|
541
|
+
] }, t.name), ke = ({ runTest: t, tests: r }) => {
|
|
542
|
+
const [n, o] = Y({}), s = (i, c = 0) => {
|
|
543
|
+
if ("status" in i)
|
|
544
|
+
return /* @__PURE__ */ d.jsx(we, { node: i, depth: c, idx: r.indexOf(i), runTest: t }, i.name);
|
|
545
|
+
const b = n[i.name];
|
|
546
|
+
return /* @__PURE__ */ d.jsxs("li", { style: { marginBottom: "6px", marginLeft: c * 12, textAlign: "left" }, children: [
|
|
547
|
+
/* @__PURE__ */ d.jsxs(
|
|
548
|
+
"div",
|
|
549
|
+
{
|
|
550
|
+
style: {
|
|
551
|
+
fontWeight: "bold",
|
|
552
|
+
cursor: "pointer",
|
|
553
|
+
color: "#374151",
|
|
554
|
+
marginBottom: "4px"
|
|
555
|
+
},
|
|
556
|
+
onClick: () => o((h) => ({ ...h, [i.name]: !h[i.name] })),
|
|
557
|
+
children: [
|
|
558
|
+
i.name,
|
|
559
|
+
" ",
|
|
560
|
+
b ? "▶" : "▼"
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
),
|
|
564
|
+
!b && /* @__PURE__ */ d.jsx("ul", { style: { listStyle: "none", padding: 0 }, children: i.children.map((h) => s(h, c + 1)) })
|
|
565
|
+
] }, i.name);
|
|
566
|
+
}, l = ve(r);
|
|
567
|
+
return /* @__PURE__ */ d.jsx("ul", { style: { listStyle: "none", padding: 0, margin: 0 }, children: l.map((i) => s(i)) });
|
|
568
|
+
}, Re = ({ setOpen: t }) => /* @__PURE__ */ d.jsx(
|
|
569
|
+
"div",
|
|
570
|
+
{
|
|
571
|
+
style: {
|
|
572
|
+
position: "fixed",
|
|
573
|
+
top: "50%",
|
|
574
|
+
left: 0,
|
|
575
|
+
transform: "translateY(-50%)",
|
|
576
|
+
background: "#3b82f6",
|
|
577
|
+
color: "white",
|
|
578
|
+
padding: "6px 10px",
|
|
579
|
+
borderTopRightRadius: "6px",
|
|
580
|
+
borderBottomRightRadius: "6px",
|
|
581
|
+
cursor: "pointer",
|
|
582
|
+
fontSize: "12px"
|
|
583
|
+
},
|
|
584
|
+
onClick: () => t(!0),
|
|
585
|
+
children: "▶ TWD"
|
|
586
|
+
}
|
|
587
|
+
), Pe = () => {
|
|
588
|
+
const [t, r] = Y(0), [n, o] = Y(!0), s = async (i) => {
|
|
589
|
+
const c = g[i];
|
|
590
|
+
c.logs = [];
|
|
591
|
+
const b = console.log, h = console.error;
|
|
592
|
+
if (console.log = (...m) => {
|
|
593
|
+
c.logs?.push("📝 " + m.map(String).join(" ")), b(...m), r((E) => E + 1);
|
|
594
|
+
}, console.error = (...m) => {
|
|
595
|
+
c.logs?.push("❌ " + m.map(String).join(" ")), h(...m), r((E) => E + 1);
|
|
596
|
+
}, c.status = "running", c.skip)
|
|
597
|
+
c.status = "skip";
|
|
598
|
+
else
|
|
599
|
+
try {
|
|
600
|
+
await c.fn(), c.status = "pass";
|
|
601
|
+
} catch (m) {
|
|
602
|
+
c.status = "fail", console.error("Test failed:", c.name, m);
|
|
603
|
+
}
|
|
604
|
+
console.log = b, console.error = h, r((m) => m + 1);
|
|
605
|
+
}, l = async () => {
|
|
606
|
+
const i = g.filter((b) => b.only), c = i.length > 0 ? i : g;
|
|
607
|
+
for (let b = 0; b < c.length; b++) {
|
|
608
|
+
const h = g.indexOf(c[b]);
|
|
609
|
+
await s(h);
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
return n ? /* @__PURE__ */ d.jsxs(
|
|
613
|
+
"div",
|
|
614
|
+
{
|
|
615
|
+
style: {
|
|
616
|
+
position: "fixed",
|
|
617
|
+
top: 0,
|
|
618
|
+
left: 0,
|
|
619
|
+
bottom: 0,
|
|
620
|
+
width: "280px",
|
|
621
|
+
background: "#f9fafb",
|
|
622
|
+
borderRight: "1px solid #e5e7eb",
|
|
623
|
+
padding: "8px",
|
|
624
|
+
fontSize: "14px",
|
|
625
|
+
overflowY: "auto",
|
|
626
|
+
boxShadow: "2px 0 6px rgba(0,0,0,0.1)"
|
|
627
|
+
},
|
|
628
|
+
children: [
|
|
629
|
+
/* @__PURE__ */ d.jsxs("div", { style: { display: "flex", justifyContent: "space-between", marginBottom: "8px" }, children: [
|
|
630
|
+
/* @__PURE__ */ d.jsx("strong", { children: "TWD Tests" }),
|
|
631
|
+
/* @__PURE__ */ d.jsx(
|
|
632
|
+
"button",
|
|
633
|
+
{
|
|
634
|
+
style: {
|
|
635
|
+
background: "transparent",
|
|
636
|
+
border: "none",
|
|
637
|
+
cursor: "pointer",
|
|
638
|
+
fontSize: "14px"
|
|
639
|
+
},
|
|
640
|
+
onClick: () => o(!1),
|
|
641
|
+
children: "✖"
|
|
642
|
+
}
|
|
643
|
+
)
|
|
644
|
+
] }),
|
|
645
|
+
/* @__PURE__ */ d.jsx(
|
|
646
|
+
"button",
|
|
647
|
+
{
|
|
648
|
+
onClick: l,
|
|
649
|
+
style: {
|
|
650
|
+
background: "#3b82f6",
|
|
651
|
+
color: "white",
|
|
652
|
+
padding: "4px 8px",
|
|
653
|
+
borderRadius: "4px",
|
|
654
|
+
border: "none",
|
|
655
|
+
marginBottom: "10px",
|
|
656
|
+
cursor: "pointer"
|
|
657
|
+
},
|
|
658
|
+
children: "▶ Run All"
|
|
659
|
+
}
|
|
660
|
+
),
|
|
661
|
+
/* @__PURE__ */ d.jsx(ke, { tests: g, runTest: s })
|
|
662
|
+
]
|
|
663
|
+
}
|
|
664
|
+
) : /* @__PURE__ */ d.jsx(Re, { setOpen: o });
|
|
665
|
+
};
|
|
666
|
+
export {
|
|
667
|
+
Pe as TWDSidebar,
|
|
668
|
+
_e as beforeEach,
|
|
669
|
+
Se as describe,
|
|
670
|
+
je as it,
|
|
671
|
+
Oe as itOnly,
|
|
672
|
+
Ae as itSkip,
|
|
673
|
+
Ce as twd
|
|
674
|
+
};
|
package/dist/twd.umd.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(function(b,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],g):(b=typeof globalThis<"u"?globalThis:b||self,g(b.TWD={},b.React))})(this,(function(b,g){"use strict";const K=(t,r=2e3,n=50)=>new Promise((o,s)=>{const l=Date.now(),i=()=>{const c=t();if(c)return o(c);if(Date.now()-l>r)return s(new Error("Timeout waiting for element"));setTimeout(i,n)};i()}),v=[];let C=[];const P=(t,r,n={})=>{v.push({name:t,fn:r,status:"idle",logs:[],suite:[...C],...n})},H=t=>{C.push(t)},Z=()=>{C.pop()};function Q(t){if(!t.isConnected)return!1;let r=t;for(;r;){const n=getComputedStyle(r);if(n.display==="none"||n.visibility==="hidden"||n.visibility==="collapse")return!1;r=r.parentElement}return!0}const ee=(t,r,...n)=>{const o=r.startsWith("not."),s=o?r.slice(4):r,i=(()=>{const c=(t.textContent||"").trim();switch(s){case"have.text":return c===n[0];case"contain.text":return c.includes(n[0]);case"be.empty":return c.length===0;case"have.attr":return t.getAttribute(n[0])===n[1];case"have.value":return t.value===n[0];case"be.disabled":return t.disabled===!0;case"be.enabled":return t.disabled===!1;case"be.checked":return t.checked===!0;case"be.selected":return t.selected===!0;case"be.focused":return document.activeElement===t;case"be.visible":return Q(t);case"have.class":return t.classList.contains(n[0]);default:throw new Error(`Unknown assertion: ${s}`)}})();if(o?i:!i)throw new Error(`Assertion failed: ${r} ${n.length?JSON.stringify(n):""}`)},w=t=>{const r=v.find(n=>n.status==="running");r&&r.logs?.push(t)},R=[],te=(t,r)=>{const n=R.findIndex(s=>s.alias===t),o={alias:t,...r,executed:!1};n!==-1?R[n]=o:R.push(o)},re=async t=>{const r=R.find(n=>n.alias===t&&n.executed);if(!r)throw new Error(`No intercept rule found for ${t}`);return await new Promise(n=>setTimeout(n,0)),r},ne=window.fetch;window.fetch=async(t,r)=>{const n=r?.method?.toUpperCase()||"GET",o=typeof t=="string"?t:t.toString(),s=R.find(l=>l.method===n&&(typeof l.url=="string"?l.url===o:l.url.test(o)));return s?(w(`🛡️ ${s.alias} → ${n} ${o}`),s.executed=!0,s.request=r?.body,new Response(JSON.stringify(s.response),{status:s.status||200,headers:s.headers||{"Content-Type":"application/json"}})):ne(t,r)};const oe=(t,r)=>{for(const n of r){const o=n.charCodeAt(0);t.dispatchEvent(new KeyboardEvent("keydown",{key:n,code:`Key${n.toUpperCase()}`,keyCode:o,which:o,bubbles:!0,cancelable:!0})),t.dispatchEvent(new KeyboardEvent("keypress",{key:n,code:`Key${n.toUpperCase()}`,keyCode:o,which:o,bubbles:!0,cancelable:!0})),t.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:n})),Object.getOwnPropertyDescriptor(Object.getPrototypeOf(t),"value")?.set?.call(t,t.value+n),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new KeyboardEvent("keyup",{key:n,code:`Key${n.toUpperCase()}`,keyCode:o,which:o,bubbles:!0,cancelable:!0}))}return t};let S=null;const se=t=>{S=t},ae=(t,r)=>{H(t),r(),Z()},ie=(t,r)=>{P(t,async()=>{S&&await S(),await r()})},ce=(t,r)=>{P(t,async()=>{S&&await S(),await r()},{only:!0})},le=(t,r)=>{P(t,async()=>{},{skip:!0})},ue={get:async t=>{w(`🔎 get("${t}")`);const r=await K(()=>document.querySelector(t)),n={el:r,click:()=>{w(`🖱️ click(${t})`),r.click()},type:o=>(w(`⌨️ type("${o}") into ${t}`),oe(r,o)),should:(o,...s)=>(ee(r,o,...s),n),text:()=>{const o=r.textContent||"";return w(`📄 text(${t}) → "${o}"`),o}};return n},visit:t=>{w(`🌍 visit("${t}")`),window.history.pushState({},"",t),window.dispatchEvent(new PopStateEvent("popstate"))},mockRequest:te,waitFor:re};var O={exports:{}},_={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var W;function de(){if(W)return _;W=1;var t=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(o,s,l){var i=null;if(l!==void 0&&(i=""+l),s.key!==void 0&&(i=""+s.key),"key"in s){l={};for(var c in s)c!=="key"&&(l[c]=s[c])}else l=s;return s=l.ref,{$$typeof:t,type:o,key:i,ref:s!==void 0?s:null,props:l}}return _.Fragment=r,_.jsx=n,_.jsxs=n,_}var j={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var L;function fe(){return L||(L=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Oe?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case N:return"Fragment";case ve:return"Profiler";case Ee:return"StrictMode";case Re:return"Suspense";case Se:return"SuspenseList";case je:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case ge:return"Portal";case ke:return(e.displayName||"Context")+".Provider";case we:return(e._context.displayName||"Context")+".Consumer";case Te:var a=e.render;return e=e.displayName,e||(e=a.displayName||a.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case _e:return a=e.displayName||null,a!==null?a:t(e.type)||"Memo";case M:a=e._payload,e=e._init;try{return t(e(a))}catch{}}return null}function r(e){return""+e}function n(e){try{r(e);var a=!1}catch{a=!0}if(a){a=console;var u=a.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),r(e)}}function o(e){if(e===N)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===M)return"<...>";try{var a=t(e);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function s(){var e=$.A;return e===null?null:e.getOwner()}function l(){return Error("react-stack-top-frame")}function i(e){if(J.call(e,"key")){var a=Object.getOwnPropertyDescriptor(e,"key").get;if(a&&a.isReactWarning)return!1}return e.key!==void 0}function c(e,a){function u(){V||(V=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",a))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function m(){var e=t(this.type);return B[e]||(B[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function x(e,a,u,f,E,y,D,I){return u=y.ref,e={$$typeof:z,type:e,key:a,props:y,_owner:E},(u!==void 0?u:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:m}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function h(e,a,u,f,E,y,D,I){var p=a.children;if(p!==void 0)if(f)if(Ae(p)){for(f=0;f<p.length;f++)k(p[f]);Object.freeze&&Object.freeze(p)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else k(p);if(J.call(a,"key")){p=t(e);var T=Object.keys(a).filter(function(Ce){return Ce!=="key"});f=0<T.length?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}",X[p+f]||(T=0<T.length?"{"+T.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
|
+
let props = %s;
|
|
19
|
+
<%s {...props} />
|
|
20
|
+
React keys must be passed directly to JSX without using spread:
|
|
21
|
+
let props = %s;
|
|
22
|
+
<%s key={someKey} {...props} />`,f,p,T,p),X[p+f]=!0)}if(p=null,u!==void 0&&(n(u),p=""+u),i(a)&&(n(a.key),p=""+a.key),"key"in a){u={};for(var F in a)F!=="key"&&(u[F]=a[F])}else u=a;return p&&c(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),x(e,p,y,E,s(),u,D,I)}function k(e){typeof e=="object"&&e!==null&&e.$$typeof===z&&e._store&&(e._store.validated=1)}var A=g,z=Symbol.for("react.transitional.element"),ge=Symbol.for("react.portal"),N=Symbol.for("react.fragment"),Ee=Symbol.for("react.strict_mode"),ve=Symbol.for("react.profiler"),we=Symbol.for("react.consumer"),ke=Symbol.for("react.context"),Te=Symbol.for("react.forward_ref"),Re=Symbol.for("react.suspense"),Se=Symbol.for("react.suspense_list"),_e=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),je=Symbol.for("react.activity"),Oe=Symbol.for("react.client.reference"),$=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J=Object.prototype.hasOwnProperty,Ae=Array.isArray,Y=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(e){return e()}};var V,B={},q=A.react_stack_bottom_frame.bind(A,l)(),G=Y(o(l)),X={};j.Fragment=N,j.jsx=function(e,a,u,f,E){var y=1e4>$.recentlyCreatedOwnerStacks++;return h(e,a,u,!1,f,E,y?Error("react-stack-top-frame"):q,y?Y(o(e)):G)},j.jsxs=function(e,a,u,f,E){var y=1e4>$.recentlyCreatedOwnerStacks++;return h(e,a,u,!0,f,E,y?Error("react-stack-top-frame"):q,y?Y(o(e)):G)}})()),j}var U;function pe(){return U||(U=1,process.env.NODE_ENV==="production"?O.exports=de():O.exports=fe()),O.exports}var d=pe();const be=t=>{const r={children:[]};for(const n of t){let o=r;n.suite.forEach(s=>{let l=o.children.find(i=>"name"in i&&!i.status&&i.name===s);l||(l={name:s,children:[]},o.children.push(l)),o=l}),o.children.push(n)}return r.children},me=({node:t,depth:r,idx:n,runTest:o})=>d.jsxs("li",{style:{marginBottom:"4px",marginLeft:r*6},children:[d.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 6px",borderRadius:"4px",background:t.status==="pass"?"#dcfce7":t.status==="fail"?"#fee2e2":t.status==="skip"?"#f3f4f6":t.status==="running"?"#fef9c3":"transparent"},children:[d.jsxs("span",{children:[t.name," ",t.only&&d.jsx("span",{style:{color:"#2563eb"},children:"(only)"}),t.skip&&d.jsx("span",{style:{color:"#6b7280"},children:"(skipped)"})]}),d.jsx("button",{onClick:()=>o(n),style:{background:"transparent",border:"1px solid #d1d5db",borderRadius:"4px",padding:"2px 6px",cursor:"pointer",fontSize:"12px"},children:"▶"})]}),t.logs&&t.logs.length>0&&d.jsx("ul",{style:{borderRadius:"4px",maxHeight:"160px",overflowY:"auto",padding:0,background:"#f3f4f6",listStyle:"none",marginTop:"4px"},children:t.logs.map((s,l)=>d.jsx("li",{style:{fontSize:"12px",padding:"4px 6px",borderBottom:"1px solid #d1d5db"},children:s},l))})]},t.name),he=({runTest:t,tests:r})=>{const[n,o]=g.useState({}),s=(i,c=0)=>{if("status"in i)return d.jsx(me,{node:i,depth:c,idx:r.indexOf(i),runTest:t},i.name);const m=n[i.name];return d.jsxs("li",{style:{marginBottom:"6px",marginLeft:c*12,textAlign:"left"},children:[d.jsxs("div",{style:{fontWeight:"bold",cursor:"pointer",color:"#374151",marginBottom:"4px"},onClick:()=>o(x=>({...x,[i.name]:!x[i.name]})),children:[i.name," ",m?"▶":"▼"]}),!m&&d.jsx("ul",{style:{listStyle:"none",padding:0},children:i.children.map(x=>s(x,c+1))})]},i.name)},l=be(r);return d.jsx("ul",{style:{listStyle:"none",padding:0,margin:0},children:l.map(i=>s(i))})},xe=({setOpen:t})=>d.jsx("div",{style:{position:"fixed",top:"50%",left:0,transform:"translateY(-50%)",background:"#3b82f6",color:"white",padding:"6px 10px",borderTopRightRadius:"6px",borderBottomRightRadius:"6px",cursor:"pointer",fontSize:"12px"},onClick:()=>t(!0),children:"▶ TWD"}),ye=()=>{const[t,r]=g.useState(0),[n,o]=g.useState(!0),s=async i=>{const c=v[i];c.logs=[];const m=console.log,x=console.error;if(console.log=(...h)=>{c.logs?.push("📝 "+h.map(String).join(" ")),m(...h),r(k=>k+1)},console.error=(...h)=>{c.logs?.push("❌ "+h.map(String).join(" ")),x(...h),r(k=>k+1)},c.status="running",c.skip)c.status="skip";else try{await c.fn(),c.status="pass"}catch(h){c.status="fail",console.error("Test failed:",c.name,h)}console.log=m,console.error=x,r(h=>h+1)},l=async()=>{const i=v.filter(m=>m.only),c=i.length>0?i:v;for(let m=0;m<c.length;m++){const x=v.indexOf(c[m]);await s(x)}};return n?d.jsxs("div",{style:{position:"fixed",top:0,left:0,bottom:0,width:"280px",background:"#f9fafb",borderRight:"1px solid #e5e7eb",padding:"8px",fontSize:"14px",overflowY:"auto",boxShadow:"2px 0 6px rgba(0,0,0,0.1)"},children:[d.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"8px"},children:[d.jsx("strong",{children:"TWD Tests"}),d.jsx("button",{style:{background:"transparent",border:"none",cursor:"pointer",fontSize:"14px"},onClick:()=>o(!1),children:"✖"})]}),d.jsx("button",{onClick:l,style:{background:"#3b82f6",color:"white",padding:"4px 8px",borderRadius:"4px",border:"none",marginBottom:"10px",cursor:"pointer"},children:"▶ Run All"}),d.jsx(he,{tests:v,runTest:s})]}):d.jsx(xe,{setOpen:o})};b.TWDSidebar=ye,b.beforeEach=se,b.describe=ae,b.it=ie,b.itOnly=ce,b.itSkip=le,b.twd=ue,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "twd-js",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Test While Developing (TWD) - in-browser testing",
|
|
5
|
+
"main": "./dist/twd.umd.js",
|
|
6
|
+
"module": "./dist/twd.es.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/twd.es.js",
|
|
11
|
+
"require": "./dist/twd.umd.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "vite build",
|
|
19
|
+
"test": "vitest",
|
|
20
|
+
"test:ci": "vitest --run --coverage",
|
|
21
|
+
"conventional-changelog": "conventional-changelog -i CHANGELOG.md -s -r 0",
|
|
22
|
+
"dev": "vite"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=17.0.0",
|
|
26
|
+
"react-dom": ">=17.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^19.1.12",
|
|
30
|
+
"@types/react-dom": "^19.1.9",
|
|
31
|
+
"@vitejs/plugin-react": "^5.0.2",
|
|
32
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
33
|
+
"jsdom": "^26.1.0",
|
|
34
|
+
"typescript": "^5.9.2",
|
|
35
|
+
"vite": "^7.1.4",
|
|
36
|
+
"vitest": "^3.2.4"
|
|
37
|
+
}
|
|
38
|
+
}
|