twd-js 1.7.2 → 1.7.3
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/README.md +26 -4
- package/dist/asserts/index.d.ts +2 -0
- package/dist/bundled.d.ts +1 -1
- package/dist/bundled.es.js +8 -4
- package/dist/cli.js +11 -11
- package/dist/commands/mockBridge.d.ts +117 -0
- package/dist/commands/url.d.ts +33 -0
- package/dist/commands/viewport.d.ts +2 -0
- package/dist/commands/visit.d.ts +1 -0
- package/dist/constants/version.d.ts +1 -0
- package/dist/global.d.ts +20 -0
- package/dist/index.cjs.js +26 -26
- package/dist/index.d.ts +8 -664
- package/dist/index.es.js +540 -525
- package/dist/initializers/initSidebar.d.ts +29 -0
- package/dist/initializers/initTests.d.ts +36 -0
- package/dist/mock-sw.js +1 -1
- package/dist/plugin/removeMockServiceWorker.d.ts +18 -0
- package/dist/plugin/twdHmr.d.ts +45 -0
- package/dist/proxies/domMessage.d.ts +1 -0
- package/dist/proxies/eventsMessage.d.ts +1 -0
- package/dist/proxies/screenDom.d.ts +45 -0
- package/dist/proxies/userEvent.d.ts +4 -0
- package/dist/runner-ci.d.ts +12 -28
- package/dist/runner.d.ts +52 -63
- package/dist/twd-types.d.ts +120 -0
- package/dist/twd.d.ts +291 -0
- package/dist/ui/ClosedSidebar.d.ts +6 -0
- package/dist/ui/Icons/BaseIcon.d.ts +7 -0
- package/dist/ui/Icons/ChevronDown.d.ts +2 -0
- package/dist/ui/Icons/ChevronRight.d.ts +2 -0
- package/dist/ui/Icons/Loader.d.ts +2 -0
- package/dist/ui/Icons/MockRequestIcon.d.ts +2 -0
- package/dist/ui/Icons/Play.d.ts +2 -0
- package/dist/ui/LogItem.d.ts +6 -0
- package/dist/ui/MockRulesButton.d.ts +1 -0
- package/dist/ui/MockedComponent.d.ts +6 -0
- package/dist/ui/SearchInput.d.ts +6 -0
- package/dist/ui/SkipOnlyName.d.ts +8 -0
- package/dist/ui/TWDSidebar.d.ts +20 -0
- package/dist/ui/TestList.d.ts +8 -0
- package/dist/ui/TestListItem.d.ts +19 -0
- package/dist/ui/componentMocks.d.ts +3 -0
- package/dist/ui/hooks/useLayout.d.ts +6 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/utils/buildTreeFromHandlers.d.ts +16 -0
- package/dist/ui/utils/chaiErrorFormat.d.ts +22 -0
- package/dist/ui/utils/filterTree.d.ts +2 -0
- package/dist/ui/utils/formatLogs.d.ts +30 -0
- package/dist/ui/utils/screenReaderMessages.d.ts +9 -0
- package/dist/ui/utils/styles.d.ts +7 -0
- package/dist/ui/utils/theme.d.ts +74 -0
- package/dist/ui.d.ts +2 -10
- package/dist/utils/assertionMessage.d.ts +1 -0
- package/dist/utils/log.d.ts +1 -0
- package/dist/utils/wait.d.ts +3 -0
- package/dist/utils/waitFor.d.ts +2 -0
- package/dist/vite-plugin.d.ts +2 -67
- package/package.json +31 -7
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# TWD
|
|
1
|
+
# TWD (Testing while developing)
|
|
2
2
|
|
|
3
3
|
[](https://github.com/BRIKEV/twd/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/twd-js)
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
[](https://qlty.sh/gh/BRIKEV/projects/twd)
|
|
7
7
|
[](https://qlty.sh/gh/BRIKEV/projects/twd)
|
|
8
8
|
|
|
9
|
-
<p>
|
|
10
|
-
<img src="./images/
|
|
9
|
+
<p align="center">
|
|
10
|
+
<img src="./images/twd-skill.gif" alt="TWD running with an AI agent" width="800">
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
|
-
TWD
|
|
13
|
+
TWD is a library designed to seamlessly integrate testing into your web development workflow. It streamlines the process of writing, running, and managing tests directly in your application, with a modern UI and powerful mocking capabilities.
|
|
14
14
|
|
|
15
15
|
**📖 [Full Documentation](https://brikev.github.io/twd/) | 🚀 [Getting Started](https://brikev.github.io/twd/getting-started) | 📚 [API Reference](https://brikev.github.io/twd/api/)**
|
|
16
16
|
|
|
@@ -166,6 +166,28 @@ Each example includes a complete setup guide and demonstrates best practices for
|
|
|
166
166
|
|
|
167
167
|
Contributions are welcome! Please open issues or pull requests on [GitHub](https://github.com/BRIKEV/twd).
|
|
168
168
|
|
|
169
|
+
## Contributors ✨
|
|
170
|
+
|
|
171
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
172
|
+
<!-- prettier-ignore-start -->
|
|
173
|
+
<!-- markdownlint-disable -->
|
|
174
|
+
<table>
|
|
175
|
+
<tbody>
|
|
176
|
+
<tr>
|
|
177
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kevinccbsg"><img src="https://avatars.githubusercontent.com/u/12685053?v=4?s=100" width="100px;" alt="Kevin Julián Martínez Escobar"/><br /><sub><b>Kevin Julián Martínez Escobar</b></sub></a><br /><a href="https://github.com/BRIKEV/twd/commits?author=kevinccbsg" title="Code">💻</a></td>
|
|
178
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DamonCaos"><img src="https://avatars.githubusercontent.com/u/169996368?v=4?s=100" width="100px;" alt="Javier Rodriguez"/><br /><sub><b>Javier Rodriguez</b></sub></a><br /><a href="https://github.com/BRIKEV/twd/commits?author=DamonCaos" title="Documentation">📖</a></td>
|
|
179
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/codesthenos"><img src="https://avatars.githubusercontent.com/u/166174180?v=4?s=100" width="100px;" alt="Guillermo Ruiz Arranz"/><br /><sub><b>Guillermo Ruiz Arranz</b></sub></a><br /><a href="https://github.com/BRIKEV/twd/commits?author=codesthenos" title="Code">💻</a></td>
|
|
180
|
+
</tr>
|
|
181
|
+
</tbody>
|
|
182
|
+
</table>
|
|
183
|
+
|
|
184
|
+
<!-- markdownlint-restore -->
|
|
185
|
+
<!-- prettier-ignore-end -->
|
|
186
|
+
|
|
187
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
188
|
+
|
|
189
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!
|
|
190
|
+
|
|
169
191
|
## License
|
|
170
192
|
|
|
171
193
|
This project is licensed under the [MIT License](./LICENSE).
|
package/dist/bundled.d.ts
CHANGED
package/dist/bundled.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ln = Object.create, Or = Object.defineProperty, on = Object.getOwnPropertyDescriptor, sn = Object.getOwnPropertyNames, un = Object.getPrototypeOf, dn = Object.prototype.hasOwnProperty, w = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), cn = (e, t, r, a) => {
|
|
1
|
+
var ln = Object.create, Or = Object.defineProperty, on = Object.getOwnPropertyDescriptor, sn = Object.getOwnPropertyNames, un = Object.getPrototypeOf, dn = Object.prototype.hasOwnProperty, w = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), cn = (e, t, r, a) => {
|
|
2
2
|
if (t && typeof t == "object" || typeof t == "function")
|
|
3
3
|
for (var n = sn(t), i = 0, s = n.length, d; i < s; i++)
|
|
4
4
|
d = n[i], !dn.call(e, d) && d !== r && Or(e, d, {
|
|
@@ -990,7 +990,9 @@ var In = () => /* @__PURE__ */ N("svg", {
|
|
|
990
990
|
node: l,
|
|
991
991
|
depth: c,
|
|
992
992
|
id: l.id,
|
|
993
|
-
runTest: () =>
|
|
993
|
+
runTest: () => {
|
|
994
|
+
t(l.id);
|
|
995
|
+
}
|
|
994
996
|
}, l.id);
|
|
995
997
|
const o = a[l.id];
|
|
996
998
|
return /* @__PURE__ */ N("li", {
|
|
@@ -1287,7 +1289,7 @@ var Jn = (e) => {
|
|
|
1287
1289
|
}
|
|
1288
1290
|
};
|
|
1289
1291
|
window.__testRunner = Gr;
|
|
1290
|
-
var $t = "1.7.
|
|
1292
|
+
var $t = "1.7.3", Zn = () => typeof window < "u" ? (window.__TWD_MOCK_STATE__ || (window.__TWD_MOCK_STATE__ = {
|
|
1291
1293
|
rules: [],
|
|
1292
1294
|
counts: {}
|
|
1293
1295
|
}), window.__TWD_MOCK_STATE__) : {
|
|
@@ -1530,7 +1532,9 @@ var il = (e) => e instanceof Error && "actual" in e && "expected" in e, Yr = (e)
|
|
|
1530
1532
|
className: "twd-sidebar-header-buttons",
|
|
1531
1533
|
children: [
|
|
1532
1534
|
/* @__PURE__ */ N("button", {
|
|
1533
|
-
onClick:
|
|
1535
|
+
onClick: () => {
|
|
1536
|
+
R();
|
|
1537
|
+
},
|
|
1534
1538
|
className: "twd-btn twd-btn-primary",
|
|
1535
1539
|
children: /* @__PURE__ */ N("span", {
|
|
1536
1540
|
"aria-live": "polite",
|
package/dist/cli.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
4
|
-
import { fileURLToPath } from
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
5
|
|
|
6
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
|
|
8
8
|
const [, , command, targetDir, ...flags] = process.argv;
|
|
9
9
|
|
|
10
|
-
if (command !==
|
|
11
|
-
console.error(
|
|
10
|
+
if (command !== 'init') {
|
|
11
|
+
console.error('Usage: npx twd-js init <public-dir> [--save]');
|
|
12
12
|
process.exit(1);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (!targetDir) {
|
|
16
|
-
console.error(
|
|
16
|
+
console.error('❌ You must provide a target public dir');
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const save = flags.includes(
|
|
21
|
-
const src = path.join(__dirname,
|
|
22
|
-
const dest = path.resolve(process.cwd(), targetDir,
|
|
20
|
+
const save = flags.includes('--save');
|
|
21
|
+
const src = path.join(__dirname, '../dist/mock-sw.js');
|
|
22
|
+
const dest = path.resolve(process.cwd(), targetDir, 'mock-sw.js');
|
|
23
23
|
|
|
24
24
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
25
25
|
fs.copyFileSync(src, dest);
|
|
26
26
|
|
|
27
27
|
console.log(`✅ mock-sw.js copied to ${dest}`);
|
|
28
28
|
if (save) {
|
|
29
|
-
console.log(
|
|
29
|
+
console.log('💡 Remember to register it in your app:');
|
|
30
30
|
console.log(`
|
|
31
31
|
if ("serviceWorker" in navigator) {
|
|
32
32
|
navigator.serviceWorker.register("/mock-sw.js");
|
|
33
33
|
}
|
|
34
34
|
`);
|
|
35
|
-
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export type Rule = {
|
|
2
|
+
/** HTTP method to match (e.g. `"GET"`, `"POST"`). */
|
|
3
|
+
method: string;
|
|
4
|
+
/** URL string or RegExp to match against the request URL. */
|
|
5
|
+
url: string | RegExp;
|
|
6
|
+
/** The mocked response body returned to the client. */
|
|
7
|
+
response: unknown;
|
|
8
|
+
/** Unique identifier for this mock rule, used with `waitForRequest`. */
|
|
9
|
+
alias: string;
|
|
10
|
+
/** Whether this rule has been matched by an actual request. Set automatically by the service worker. */
|
|
11
|
+
executed?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The parsed request body sent by the client.
|
|
14
|
+
* For JSON requests this is the parsed object, for form data an object of key/value pairs, for text a string.
|
|
15
|
+
* Access fields directly: `rule.request.email`, **not** `rule.request.body.email`.
|
|
16
|
+
*/
|
|
17
|
+
request?: any;
|
|
18
|
+
/** HTTP status code for the mocked response (default: `200`). */
|
|
19
|
+
status?: number;
|
|
20
|
+
/** Headers to include in the mocked response. */
|
|
21
|
+
responseHeaders?: Record<string, string>;
|
|
22
|
+
/** Whether the `url` field should be treated as a regex pattern. */
|
|
23
|
+
urlRegex?: boolean;
|
|
24
|
+
/** Delay in milliseconds before returning the mocked response. */
|
|
25
|
+
delay?: number;
|
|
26
|
+
/** Number of times this rule has been matched. Updated automatically by the service worker. */
|
|
27
|
+
hitCount?: number;
|
|
28
|
+
};
|
|
29
|
+
export interface Options {
|
|
30
|
+
/** HTTP method to match (e.g. `"GET"`, `"POST"`). */
|
|
31
|
+
method: string;
|
|
32
|
+
/** URL string or RegExp to match against the request URL. */
|
|
33
|
+
url: string | RegExp;
|
|
34
|
+
/** The mocked response body returned to the client. */
|
|
35
|
+
response: unknown;
|
|
36
|
+
/** HTTP status code for the mocked response (default: `200`). */
|
|
37
|
+
status?: number;
|
|
38
|
+
/** Headers to include in the mocked response. */
|
|
39
|
+
responseHeaders?: Record<string, string>;
|
|
40
|
+
/** Whether the `url` field should be treated as a regex pattern. */
|
|
41
|
+
urlRegex?: boolean;
|
|
42
|
+
/** Delay in milliseconds before returning the mocked response. */
|
|
43
|
+
delay?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Initialize the mocking service worker.
|
|
47
|
+
* Call this once before using `mockRequest` or `waitFor`.
|
|
48
|
+
*/
|
|
49
|
+
export declare const initRequestMocking: (path?: string) => Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Mock a network request.
|
|
52
|
+
*
|
|
53
|
+
* @param alias Identifier for the mock rule. Useful for `waitFor()`.
|
|
54
|
+
* @param options Options to configure the mock:
|
|
55
|
+
* - `method`: HTTP method ("GET", "POST", …)
|
|
56
|
+
* - `url`: URL string or RegExp to match
|
|
57
|
+
* - `response`: Body of the mocked response
|
|
58
|
+
* - `status`: (optional) HTTP status code (default: 200)
|
|
59
|
+
* - `responseHeaders`: (optional) Response headers
|
|
60
|
+
* - `urlRegex`: (optional) Whether the URL is a regex (default: false)
|
|
61
|
+
* - `delay`: (optional) Delay in ms before returning the response
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* mockRequest("getUser", {
|
|
66
|
+
* method: "GET",
|
|
67
|
+
* url: /\/api\/user\/\d+/,
|
|
68
|
+
* response: { id: 1, name: "Kevin" },
|
|
69
|
+
* status: 200,
|
|
70
|
+
* responseHeaders: { "x-mock": "true" }
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const mockRequest: (alias: string, options: Options) => Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* wait for a list of mocked requests to be made.
|
|
77
|
+
* @param aliases The aliases of the mock rules to wait for
|
|
78
|
+
* @returns The matched rules (with body if applicable)
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* await waitForRequests(["getUser", "postComment"]);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare const waitForRequests: (aliases: string[]) => Promise<Rule[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Wait for a mocked request to be made.
|
|
87
|
+
* @param alias The alias of the mock rule to wait for
|
|
88
|
+
* @param retries The number of retries to make
|
|
89
|
+
* @param retryDelay The delay between retries
|
|
90
|
+
* @returns The matched rule (with body if applicable)
|
|
91
|
+
*/
|
|
92
|
+
export declare const waitForRequest: (alias: string, retries?: number, retryDelay?: number) => Promise<Rule>;
|
|
93
|
+
/**
|
|
94
|
+
* Get the current list of request mock rules.
|
|
95
|
+
* @returns The current list of request mock rules.
|
|
96
|
+
*/
|
|
97
|
+
export declare const getRequestMockRules: () => Rule[];
|
|
98
|
+
/**
|
|
99
|
+
* Clear all request mock rules.
|
|
100
|
+
*/
|
|
101
|
+
export declare const clearRequestMockRules: () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Get the number of times a specific mock rule was hit.
|
|
104
|
+
* @param alias The alias of the mock rule
|
|
105
|
+
* @returns The number of times the rule was matched
|
|
106
|
+
*/
|
|
107
|
+
export declare const getRequestCount: (alias: string) => number;
|
|
108
|
+
/**
|
|
109
|
+
* Get a snapshot of all mock rule hit counts.
|
|
110
|
+
* @returns An object mapping rule aliases to their hit counts
|
|
111
|
+
*/
|
|
112
|
+
export declare const getRequestCounts: () => Record<string, number>;
|
|
113
|
+
/**
|
|
114
|
+
* Reset the initialized state. Only use in tests.
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
export declare const resetMockingState: () => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All supported assertion names for the `should` function in url command
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* twd.url().should("contain.url", "/new-page");
|
|
6
|
+
* twd.url().should("eq", "http://localhost:3000/new-page");
|
|
7
|
+
*/
|
|
8
|
+
export type URLAssertionName = 'eq' | 'contain.url';
|
|
9
|
+
/**
|
|
10
|
+
* Negatable assertion names (e.g., 'not.have.text').
|
|
11
|
+
*/
|
|
12
|
+
export type Negatable<T extends string> = T | `not.${T}`;
|
|
13
|
+
/**
|
|
14
|
+
* All assertion names, including negated ones.
|
|
15
|
+
*/
|
|
16
|
+
export type AnyURLAssertion = Negatable<URLAssertionName>;
|
|
17
|
+
export type URLCommandAPI = {
|
|
18
|
+
location: Location;
|
|
19
|
+
should: (name: AnyURLAssertion, value: string, retries?: number) => Promise<string>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Argument types for each assertion.
|
|
23
|
+
*/
|
|
24
|
+
export type URLAssertionArgs = {
|
|
25
|
+
(name: 'contain.url', urlPart: string): URLCommandAPI;
|
|
26
|
+
(name: 'not.contain.url', urlPart: string): URLCommandAPI;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* URL command for assertions on the current URL.
|
|
30
|
+
* @returns URLCommandAPI
|
|
31
|
+
*/
|
|
32
|
+
declare const urlCommand: () => URLCommandAPI;
|
|
33
|
+
export default urlCommand;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const visit: (url: string, reload?: boolean) => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TWD_VERSION = "1.7.3";
|
package/dist/global.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// global.d.ts
|
|
2
|
+
export {};
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
__testRunner?: any;
|
|
7
|
+
__TWD_STATE__?: any;
|
|
8
|
+
__TWD_MOCK_STATE__?: any;
|
|
9
|
+
__twdCollectMock?: (mock: {
|
|
10
|
+
alias: string;
|
|
11
|
+
url: string;
|
|
12
|
+
method: string;
|
|
13
|
+
status: number;
|
|
14
|
+
response: unknown;
|
|
15
|
+
responseHeaders?: Record<string, string>;
|
|
16
|
+
urlRegex: boolean;
|
|
17
|
+
testId: string;
|
|
18
|
+
}) => void;
|
|
19
|
+
}
|
|
20
|
+
}
|