Skip to content

Commit a522866

Browse files
committed
chore: update version
1 parent 491df53 commit a522866

4 files changed

Lines changed: 128 additions & 62 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
## <small>0.1.2 (2025-09-11)</small>
1+
## 0.2.0 (2025-09-18)
2+
3+
* Feat/add cli command (#19) ([b70110f](github.com/BRIKEV/twd/commits/b70110f)), closes [#19](github.com/BRIKEV/twd/issues/19)
4+
* Feat/add UI tests (#20) ([491df53](github.com/BRIKEV/twd/commits/491df53)), closes [#20](github.com/BRIKEV/twd/issues/20)
5+
* Feat/improve networkintercept (#17) ([b39b723](github.com/BRIKEV/twd/commits/b39b723)), closes [#17](github.com/BRIKEV/twd/issues/17)
6+
* Feat/url command (#15) ([7542950](github.com/BRIKEV/twd/commits/7542950)), closes [#15](github.com/BRIKEV/twd/issues/15)
7+
8+
9+
## 0.1.2 (2025-09-11)
210

311
* chore: update version ([e8599da](https://github.com/BRIKEV/twd/commit/e8599da))
412
* Feat/improve assertion messages (#14) ([a2a36a2](https://github.com/BRIKEV/twd/commit/a2a36a2)), closes [#14](https://github.com/BRIKEV/twd/issues/14)

README.md

Lines changed: 116 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33
[![CI](https://github.com/BRIKEV/twd/actions/workflows/ci.yml/badge.svg)](https://github.com/BRIKEV/twd/actions/workflows/ci.yml)
44
[![npm version](https://img.shields.io/npm/v/twd-js.svg)](https://www.npmjs.com/package/twd-js)
55
[![license](https://img.shields.io/github/license/brikev/twd.svg)](./LICENSE)
6+
[![Maintainability](https://qlty.sh/gh/BRIKEV/projects/twd/maintainability.svg)](https://qlty.sh/gh/BRIKEV/projects/twd)
7+
[![Code Coverage](https://qlty.sh/gh/BRIKEV/projects/twd/coverage.svg)](https://qlty.sh/gh/BRIKEV/projects/twd)
68

79
> ⚠️ This is a **beta release** – expect frequent updates and possible breaking changes.
810
9-
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.
1011

11-
Right now we only support React, but we plan to add support for other frameworks in the future.
12+
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.
13+
14+
Currently, TWD supports React, with plans to add more frameworks soon.
15+
16+
---
17+
18+
## Features
19+
20+
- 🧪 **In-browser test runner** with a beautiful sidebar UI
21+
-**Instant feedback** as you develop
22+
- 🔥 **Mock Service Worker** integration for API/request mocking
23+
- 📝 **Simple, readable test syntax** (inspired by popular test frameworks)
24+
- 🧩 **Automatic test discovery** with Vite support
25+
- 🛠️ **Works with React** (support for more frameworks coming)
1226

1327
## Installation
1428

@@ -25,74 +39,118 @@ yarn add twd-js
2539
pnpm add twd-js
2640
```
2741

28-
## How to use
2942

30-
Add the our React Sidebar component to your application:
43+
## Quick Start
3144

32-
```tsx
33-
import { StrictMode } from 'react'
34-
import { createRoot } from 'react-dom/client'
35-
import './index.css'
36-
import { TWDSidebar } from 'twd-js'
37-
import router from './routes.ts'
38-
import { RouterProvider } from 'react-router'
45+
1. **Add the TWD Sidebar to your React app:**
3946

40-
createRoot(document.getElementById('root')!).render(
41-
<StrictMode>
42-
<RouterProvider router={router} />
43-
<TWDSidebar />
44-
</StrictMode>,
45-
)
46-
```
47+
```tsx
48+
import { StrictMode } from 'react';
49+
import { createRoot } from 'react-dom/client';
50+
import App from './App';
51+
import './index.css';
52+
import { TWDSidebar } from 'twd-js';
4753

48-
Then, create test files with the `twd.test.ts` or any extension you want. For example:
49-
50-
```ts
51-
// src/app.twd.test.ts
52-
import { describe, it, twd } from "twd-js";
53-
54-
beforeEach(() => {
55-
console.log("Reset state before each test");
56-
});
57-
58-
describe("App interactions", () => {
59-
it("clicks the button", async () => {
60-
twd.visit("/"); // Visit the root URL
61-
const btn = await twd.get("button");
62-
btn.click();
63-
const message = await twd.get("#message");
64-
// have.text
65-
const haveText = await twd.get("#message");
66-
haveText.should("have.text", "Hello");
67-
});
68-
});
69-
```
54+
createRoot(document.getElementById('root')!).render(
55+
<StrictMode>
56+
<App />
57+
<TWDSidebar />
58+
</StrictMode>,
59+
);
60+
```
7061

71-
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:
62+
2. **Write your tests:**
7263

73-
```ts
74-
// src/loadTests.ts
75-
import "./app.twd.test";
76-
import "./another-test-file.twd.test";
77-
// Import other test files here
78-
```
64+
Create files ending with `.twd.test.ts` (or any extension you prefer):
65+
66+
```ts
67+
// src/app.twd.test.ts
68+
import { describe, it, twd } from "twd-js";
69+
70+
beforeEach(() => {
71+
// Reset state before each test
72+
});
73+
74+
describe("App interactions", () => {
75+
it("clicks the button", async () => {
76+
twd.visit("/");
77+
const btn = await twd.get("button");
78+
btn.click();
79+
const message = await twd.get("#message");
80+
message.should("have.text", "Hello");
81+
});
82+
});
83+
```
84+
85+
3. **Auto-load your tests:**
86+
87+
- With Vite:
88+
89+
```ts
90+
// src/loadTests.ts
91+
const modules = import.meta.glob("./**/*.twd.test.ts", { eager: true });
92+
// No need to export anything
93+
```
94+
95+
- Or manually:
96+
97+
```ts
98+
// src/loadTests.ts
99+
import "./app.twd.test";
100+
import "./another-test-file.twd.test";
101+
```
102+
103+
Import `loadTests.ts` in your main entry (e.g., `main.tsx`):
79104

80-
Or if you're using vite you can use Vite's `import.meta.glob` to automatically import all test files in a directory:
105+
```tsx
106+
import './loadTests';
107+
```
81108

82-
```ts
83-
// This automatically imports all files ending with .twd.test.ts
84-
const modules = import.meta.glob("./**/*.twd.test.ts", { eager: true });
109+
4. **Run your app and open the TWD sidebar** to see and run your tests in the browser.
85110

86-
// You don't need to export anything; simply importing this in App.tsx
87-
// will cause the test files to execute and register their tests.
111+
---
112+
113+
## Mock Service Worker (API Mocking)
114+
115+
TWD provides a CLI to easily set up a mock service worker for API/request mocking in your app.
116+
117+
### Install the mock service worker
118+
119+
Run the following command in your project root:
120+
121+
```bash
122+
npx twd-mock init <public-dir> [--save]
88123
```
89124

90-
Then, import the `loadTests.ts` file in your main application file (e.g., `main.tsx` or `App.tsx`):
125+
- Replace `<public-dir>` with the path to your app's public/static directory (e.g., `public/` or `dist/`).
126+
- Use `--save` to print a registration snippet for your app.
127+
128+
This will copy `mock-sw.js` to your public directory.
129+
130+
### Register the service worker in your app
91131

92-
```tsx
93-
import './loadTests' // Import test files
132+
Add this snippet to your app's entry point (e.g., `main.tsx`):
133+
134+
```js
135+
if ("serviceWorker" in navigator) {
136+
navigator.serviceWorker.register("/mock-sw.js?v=1");
137+
}
94138
```
95139

96-
Finally, run your application and open the TWD sidebar to see and run your tests.
140+
---
141+
142+
## More Usage Examples
143+
144+
See the [examples](https://github.com/BRIKEV/twd/tree/main/examples) directory for more scenarios and advanced usage.
145+
146+
---
147+
148+
## Contributing
149+
150+
Contributions are welcome! Please open issues or pull requests on [GitHub](https://github.com/BRIKEV/twd).
151+
152+
---
153+
154+
## License
97155

98-
You can check the [examples](https://github.com/BRIKEV/twd/tree/main/examples) directory for more usage scenarios.
156+
This project is licensed under the [MIT License](./LICENSE).

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twd-js",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"description": "Test While Developing (TWD) - in-browser testing",
55
"main": "./dist/twd.umd.js",
66
"module": "./dist/twd.es.js",

0 commit comments

Comments
 (0)