@rezejs/testing-library 0.0.0 → 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/dist/index.d.ts +24 -0
- package/dist/index.js +78 -0
- package/package.json +25 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-PRESENT Konstantin Kireyev <https://github.com/knst0>
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JSX } from "reze-js";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export interface Mounted {
|
|
4
|
+
el: HTMLElement;
|
|
5
|
+
dispose: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface Deferred<M> {
|
|
8
|
+
load: () => Promise<M>;
|
|
9
|
+
calls: () => number;
|
|
10
|
+
resolve: (module: M) => void;
|
|
11
|
+
reject: (error: Error) => void;
|
|
12
|
+
}
|
|
13
|
+
/** Renders `code` into a fresh `<tag>` appended to the body; the returned `dispose` is idempotent. */
|
|
14
|
+
export declare function mount(code: () => JSX.Element, tag?: string): Mounted;
|
|
15
|
+
/** Disposes every live mount and empties the body; register with `afterEach(cleanup)`. */
|
|
16
|
+
export declare function cleanup(): void;
|
|
17
|
+
export declare const tick: () => void;
|
|
18
|
+
/** Yields one macrotask, letting pending promises and async components settle. */
|
|
19
|
+
export declare function settle(): Promise<void>;
|
|
20
|
+
/** Controllable promise source for async tests; `reject` resets so `load` can be retried. */
|
|
21
|
+
export declare function deferred<M>(): Deferred<M>;
|
|
22
|
+
/** Dispatches a bubbling, cancelable `type` event built with the constructor that matches it; returns the dispatch result. */
|
|
23
|
+
export declare function fire(target: Element, type: string, init?: EventInit): boolean;
|
|
24
|
+
//#endregion
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { render } from "reze-js";
|
|
2
|
+
import { flush } from "reze-js/internal/runtime";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const live = /* @__PURE__ */ new Set();
|
|
5
|
+
/** Renders `code` into a fresh `<tag>` appended to the body; the returned `dispose` is idempotent. */
|
|
6
|
+
function mount(code, tag = "div") {
|
|
7
|
+
const el = document.createElement(tag);
|
|
8
|
+
document.body.appendChild(el);
|
|
9
|
+
const unmount = render(code, el);
|
|
10
|
+
const dispose = () => {
|
|
11
|
+
if (live.delete(dispose)) unmount();
|
|
12
|
+
};
|
|
13
|
+
live.add(dispose);
|
|
14
|
+
return {
|
|
15
|
+
el,
|
|
16
|
+
dispose
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Disposes every live mount and empties the body; register with `afterEach(cleanup)`. */
|
|
20
|
+
function cleanup() {
|
|
21
|
+
for (const dispose of live) dispose();
|
|
22
|
+
document.body.textContent = "";
|
|
23
|
+
}
|
|
24
|
+
const tick = flush;
|
|
25
|
+
/** Yields one macrotask, letting pending promises and async components settle. */
|
|
26
|
+
function settle() {
|
|
27
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
28
|
+
setTimeout(resolve, 0);
|
|
29
|
+
return promise;
|
|
30
|
+
}
|
|
31
|
+
/** Controllable promise source for async tests; `reject` resets so `load` can be retried. */
|
|
32
|
+
function deferred() {
|
|
33
|
+
let current = Promise.withResolvers();
|
|
34
|
+
let calls = 0;
|
|
35
|
+
return {
|
|
36
|
+
load: () => {
|
|
37
|
+
calls++;
|
|
38
|
+
return current.promise;
|
|
39
|
+
},
|
|
40
|
+
calls: () => calls,
|
|
41
|
+
resolve: (module) => current.resolve(module),
|
|
42
|
+
reject: (error) => {
|
|
43
|
+
current.reject(error);
|
|
44
|
+
current = Promise.withResolvers();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const MouseTypes = {
|
|
49
|
+
click: true,
|
|
50
|
+
dblclick: true,
|
|
51
|
+
mousedown: true,
|
|
52
|
+
mouseup: true,
|
|
53
|
+
mousemove: true,
|
|
54
|
+
mouseover: true,
|
|
55
|
+
mouseout: true,
|
|
56
|
+
mouseenter: true,
|
|
57
|
+
mouseleave: true,
|
|
58
|
+
contextmenu: true
|
|
59
|
+
};
|
|
60
|
+
const KeyTypes = {
|
|
61
|
+
keydown: true,
|
|
62
|
+
keyup: true,
|
|
63
|
+
keypress: true
|
|
64
|
+
};
|
|
65
|
+
/** Dispatches a bubbling, cancelable `type` event built with the constructor that matches it; returns the dispatch result. */
|
|
66
|
+
function fire(target, type, init = {}) {
|
|
67
|
+
const options = {
|
|
68
|
+
bubbles: true,
|
|
69
|
+
cancelable: true,
|
|
70
|
+
...init
|
|
71
|
+
};
|
|
72
|
+
if (MouseTypes[type]) return target.dispatchEvent(new MouseEvent(type, options));
|
|
73
|
+
if (KeyTypes[type]) return target.dispatchEvent(new KeyboardEvent(type, options));
|
|
74
|
+
if (type.startsWith("focus") || type === "blur") return target.dispatchEvent(new FocusEvent(type, options));
|
|
75
|
+
return target.dispatchEvent(new Event(type, options));
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { cleanup, deferred, fire, mount, settle, tick };
|
package/package.json
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rezejs/testing-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"author": "Konstantin Kireyev <https://github.com/knst0>",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/knst0/reze-js.git"
|
|
8
|
+
"url": "git+https://github.com/knst0/reze-js.git",
|
|
9
|
+
"directory": "packages/testing-library"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"reze-js": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "vp pack",
|
|
30
|
+
"test": "vp test run"
|
|
8
31
|
}
|
|
9
32
|
}
|