twd-js 0.8.0 → 1.0.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/README.md CHANGED
@@ -6,12 +6,16 @@
6
6
  [![Maintainability](https://qlty.sh/gh/BRIKEV/projects/twd/maintainability.svg)](https://qlty.sh/gh/BRIKEV/projects/twd)
7
7
  [![Code Coverage](https://qlty.sh/gh/BRIKEV/projects/twd/coverage.svg)](https://qlty.sh/gh/BRIKEV/projects/twd)
8
8
 
9
- > ⚠️ This is a **beta release** – expect frequent updates and possible breaking changes.
9
+ <p>
10
+ <img src="./images/logo_full_sized.png" alt="TWD Logo" width="400">
11
+ </p>
10
12
 
11
13
  TWD (Testing Web Development) 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.
12
14
 
13
15
  Currently, TWD supports React, with plans to add more frameworks soon.
14
16
 
17
+ **For complete and updated documentation, tutorials, and examples, visit: [https://brikev.github.io/twd/](https://brikev.github.io/twd/)**
18
+
15
19
  ## Table of Contents
16
20
 
17
21
  - [Features](#features)
@@ -105,23 +109,29 @@ pnpm add twd-js
105
109
 
106
110
  ```ts
107
111
  // src/app.twd.test.ts
108
- import { describe, it, twd } from "twd-js";
109
-
110
- beforeEach(() => {
111
- // Reset state before each test
112
- });
113
-
114
- describe("App interactions", () => {
115
- it("clicks the button", async () => {
116
- twd.visit("/");
117
- const btn = await twd.get("button");
118
- btn.click();
119
- const message = await twd.get("#message");
120
- message.should("have.text", "Hello");
112
+ import { twd, userEvent } from "twd-js";
113
+ import { describe, it } from "twd-js/runner";
114
+
115
+ describe("Hello World Page", () => {
116
+ it("should display the welcome title and counter button", async () => {
117
+ await twd.visit("/");
118
+
119
+ const title = await twd.get("[data-testid='welcome-title']");
120
+ title.should("be.visible").should("have.text", "Welcome to TWD");
121
+
122
+ const counterButton = await twd.get("[data-testid='counter-button']");
123
+ counterButton.should("be.visible").should("have.text", "Count is 0");
124
+
125
+ await userEvent.click(counterButton.el);
126
+ counterButton.should("have.text", "Count is 1");
121
127
  });
122
128
  });
123
129
  ```
124
130
 
131
+ <p align="center">
132
+ <img src="./images/twd_side_bar_success.png" alt="TWD Sidebar in action" width="800">
133
+ </p>
134
+
125
135
  3. **Auto-load your tests:**
126
136
 
127
137
 
@@ -182,23 +192,23 @@ pnpm add twd-js
182
192
  TWD uses a familiar testing structure with `describe`, `it`, `beforeEach`, and other common testing functions:
183
193
 
184
194
  ```ts
185
- import { describe, it, itSkip, itOnly, beforeEach, twd, userEvent } from "twd-js";
186
-
195
+ import { twd, userEvent } from "twd-js";
196
+ import { describe, it, beforeEach } from "twd-js/runner";
187
197
 
188
198
  describe("User authentication", () => {
189
199
  beforeEach(() => {
190
200
  // Reset state before each test
191
201
  });
192
202
  it("should login successfully", async () => {
193
- twd.visit("/login");
203
+ await twd.visit("/login");
194
204
  // Your test logic here
195
205
  });
196
206
 
197
- itSkip("skipped test", () => {
207
+ it.skip("skipped test", () => {
198
208
  // This test will be skipped
199
209
  });
200
210
 
201
- itOnly("only this test runs", () => {
211
+ it.only("only this test runs", () => {
202
212
  // Only this test will run when .only is present
203
213
  });
204
214
  });
@@ -369,8 +379,8 @@ console.log("Response:", rule.response);
369
379
  |----------|-------------|---------|
370
380
  | `describe(name, fn)` | Groups related tests | `describe("User login", () => {...})` |
371
381
  | `it(name, fn)` | Defines a test case | `it("should login", async () => {...})` |
372
- | `itOnly(name, fn)` | Runs only this test | `itOnly("focused test", () => {...})` |
373
- | `itSkip(name, fn)` | Skips this test | `itSkip("broken test", () => {...})` |
382
+ | `it.only(name, fn)` | Runs only this test | `it.only("focused test", () => {...})` |
383
+ | `it.skip(name, fn)` | Skips this test | `it.skip("broken test", () => {...})` |
374
384
  | `beforeEach(fn)` | Runs before each test | `beforeEach(() => {...})` |
375
385
 
376
386
  ### TWD Commands
@@ -413,11 +423,12 @@ All assertions can be negated with `not.` prefix (e.g., `not.be.disabled`).
413
423
  ### Basic Form Testing
414
424
 
415
425
  ```ts
416
- import { describe, it, twd, userEvent } from "twd-js";
426
+ import { twd, userEvent } from "twd-js";
427
+ import { describe, it } from "twd-js/runner";
417
428
 
418
429
  describe("Contact form", () => {
419
430
  it("submits form data", async () => {
420
- twd.visit("/contact");
431
+ await twd.visit("/contact");
421
432
 
422
433
  const user = userEvent.setup();
423
434
  const emailInput = await twd.get("input#email");
@@ -438,24 +449,25 @@ describe("Contact form", () => {
438
449
  ### API Mocking with Authentication
439
450
 
440
451
  ```ts
441
- import { describe, it, twd, userEvent } from "twd-js";
452
+ import { twd, userEvent } from "twd-js";
453
+ import { describe, it } from "twd-js/runner";
442
454
 
443
455
  describe("Protected routes", () => {
444
456
  it("redirects to login when unauthorized", async () => {
445
- twd.visit("/dashboard");
457
+ await twd.visit("/dashboard");
446
458
  await twd.wait(100);
447
459
  twd.url().should("contain.url", "/login");
448
460
  });
449
461
 
450
462
  it("loads dashboard with valid session", async () => {
451
463
  // Mock authentication check
452
- twd.mockRequest("authCheck", {
464
+ await twd.mockRequest("authCheck", {
453
465
  method: "GET",
454
466
  url: "/api/auth/me",
455
467
  response: { id: 1, name: "John Doe" }
456
468
  });
457
469
 
458
- twd.visit("/dashboard");
470
+ await twd.visit("/dashboard");
459
471
  await twd.waitForRequest("authCheck");
460
472
 
461
473
  const welcome = await twd.get("h1");
@@ -4,7 +4,7 @@ export type Rule = {
4
4
  response: unknown;
5
5
  alias: string;
6
6
  executed?: boolean;
7
- request?: unknown;
7
+ request?: any;
8
8
  status?: number;
9
9
  responseHeaders?: Record<string, string>;
10
10
  urlRegex?: boolean;
@@ -1 +1 @@
1
- export declare const visit: (url: string) => Promise<void>;
1
+ export declare const visit: (url: string, reload?: boolean) => Promise<void>;
@@ -1 +1 @@
1
- export declare const TWD_VERSION = "0.8.0";
1
+ export declare const TWD_VERSION = "1.0.0";