twd-js 1.8.0 → 1.8.1

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
@@ -1,4 +1,4 @@
1
- # TWD (Testing while developing)
1
+ # TWD Test While Developing
2
2
 
3
3
  [![CI](https://github.com/BRIKEV/twd/actions/workflows/ci.yml/badge.svg)](https://github.com/BRIKEV/twd/actions/workflows/ci.yml)
4
4
  [![npm version](https://img.shields.io/npm/v/twd-js.svg)](https://www.npmjs.com/package/twd-js)
@@ -7,184 +7,98 @@
7
7
  [![Code Coverage](https://qlty.sh/gh/BRIKEV/projects/twd/coverage.svg)](https://qlty.sh/gh/BRIKEV/projects/twd)
8
8
 
9
9
  <p align="center">
10
- <img src="https://raw.githubusercontent.com/BRIKEV/twd/main/images/twd-skill.gif" alt="TWD running with an AI agent" width="800">
10
+ <img src="https://raw.githubusercontent.com/BRIKEV/twd/main/images/twd-skill.gif" alt="TWD running with an AI agent: tests written and executed in a real browser sidebar" width="800">
11
11
  </p>
12
12
 
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.
13
+ > **Frontend tests that run in your real browser.** Same DOM, same routes, same state as your dev server. For React, Vue, Angular, and Solid.
14
14
 
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/)**
15
+ ## The problem
16
16
 
17
- ## Features
17
+ Testing gets pushed to next week, and next week never comes. When it does happen, tests usually run in a different environment from where you're building, so testing feels like overhead the moment you finish a feature.
18
18
 
19
- - 🧪 **In-browser test runner** with a beautiful sidebar UI
20
- - ⚡ **Instant feedback** as you develop
21
- - 🔥 **Mock Service Worker** integration for API/request mocking
22
- - 📝 **Simple, readable test syntax** (inspired by popular test frameworks)
23
- - 🧩 **Automatic test discovery** with Vite support
24
- - 🎯 **Testing Library support** - Use `screenDom` for semantic, accessible queries
25
- - 🛠️ **Works with React** (support for more frameworks coming)
19
+ The tooling pushes you the same way. You end up writing more code for the tests than for the feature itself, between setup, mocks, and helpers. Adding tests starts to feel like shipping a second app on top of the one you already finished.
26
20
 
27
- ## Installation
21
+ As AI writes more of your code, the gap widens. Agents generate test files that look correct but never actually execute in a real browser. The mocks those tests rely on quietly drift from the real API over time. Fields get renamed, mocks stay frozen, tests pass, production breaks.
28
22
 
29
- ```bash
30
- npm install twd-js
31
- # or
32
- yarn add twd-js
33
- # or
34
- pnpm add twd-js
35
- ```
36
-
37
- ## Quick Start
23
+ ## The solution
38
24
 
39
- ### Vite-based projects (React, Vue, Solid, and more)
25
+ TWD puts tests inside your dev server. A sidebar appears in your real browser, runs tests against the same DOM your users see, and updates as you code. When you're ready, plug in an AI agent that writes tests, runs them via a WebSocket bridge, and iterates until they pass. When you ship, validate every mock against your OpenAPI spec to catch drift before a user does.
40
26
 
41
- Add the `twd()` plugin to your `vite.config.ts`. The plugin auto-loads the sidebar and discovers test files in dev — no entry-file changes required.
42
-
43
- ```ts
44
- // vite.config.ts
45
- import { defineConfig } from 'vite';
46
- import react from '@vitejs/plugin-react'; // or vue, solid, etc.
47
- import { twd } from 'twd-js/vite-plugin';
48
-
49
- export default defineConfig({
50
- plugins: [
51
- react(),
52
- twd({
53
- testFilePattern: '/**/*.twd.test.{ts,tsx}',
54
- open: true,
55
- position: 'left',
56
- }),
57
- ],
58
- });
59
- ```
27
+ > **Test what you own. Mock what you don't.**
60
28
 
61
- ### Set Up Mock Service Worker
29
+ Full pitch and docs at **[twd.dev](https://twd.dev)**.
62
30
 
63
- If you plan to use API mocking, set up the mock service worker:
31
+ ## Quick start
64
32
 
65
33
  ```bash
66
- npx twd-js init public
34
+ npm install --save-dev twd-js
67
35
  ```
68
36
 
69
- ### Non-Vite projects (Angular, Webpack, etc.)
70
-
71
- If your project doesn't use Vite, initialize TWD manually in your dev entry point:
72
-
73
- ```ts
74
- // Only load the test sidebar and tests in development mode
75
- if (import.meta.env.DEV) {
76
- const { initTWD } = await import('twd-js/bundled');
77
- const tests = import.meta.glob('./**/*.twd.test.ts');
78
-
79
- initTWD(tests, {
80
- open: true,
81
- position: 'left',
82
- serviceWorker: true, // Enable request mocking (default: true)
83
- serviceWorkerUrl: '/mock-sw.js', // Custom service worker path (default: '/mock-sw.js')
84
- });
85
- }
86
- ```
87
-
88
- Check the [Framework Integration Guide](https://brikev.github.io/twd/frameworks) for more details.
89
-
90
- ## Writing Tests
37
+ Add the Vite plugin (auto-loads the sidebar and discovers your test files):
91
38
 
92
39
  ```ts
93
- // src/app.twd.test.ts
94
- import { twd, userEvent, screenDom } from "twd-js";
95
- import { describe, it } from "twd-js/runner";
96
-
97
- describe("Hello World Page", () => {
98
- it("should display the welcome title and counter button", async () => {
99
- await twd.visit("/");
100
-
101
- // Use Testing Library queries (Recommended - semantic & accessible)
102
- const title = screenDom.getByRole("heading", { name: /welcome to twd/i });
103
- twd.should(title, "be.visible");
104
- twd.should(title, "have.text", "Welcome to TWD");
105
-
106
- const counterButton = screenDom.getByRole("button", { name: /count is/i });
107
- twd.should(counterButton, "be.visible");
108
- twd.should(counterButton, "have.text", "Count is 0");
109
-
110
- const user = userEvent.setup();
111
- await user.click(counterButton);
112
- twd.should(counterButton, "have.text", "Count is 1");
113
-
114
- // Alternative: Use TWD's native selectors for direct element access
115
- // const title = await twd.get("h1");
116
- // title.should("be.visible").should("have.text", "Welcome to TWD");
117
- });
118
- });
119
- ```
120
-
121
- 3. **Run your app** - The TWD sidebar will appear automatically in development mode!
122
-
123
- <p align="center">
124
- <img src="https://raw.githubusercontent.com/BRIKEV/twd/main/images/twd_side_bar_success.png" alt="TWD Sidebar in action" width="800">
125
- </p>
126
-
127
- ## Key Concepts
128
-
129
- ### Element Selection
130
-
131
- TWD supports two approaches:
132
-
133
- **Testing Library Queries (Recommended):**
134
- ```ts
135
- const button = screenDom.getByRole("button", { name: /submit/i });
136
- twd.should(button, "be.visible");
137
- ```
40
+ // vite.config.ts
41
+ import { defineConfig } from 'vite'
42
+ import { twd } from 'twd-js/vite-plugin'
138
43
 
139
- **Native Selectors:**
140
- ```ts
141
- const button = await twd.get("button");
142
- button.should("be.visible");
44
+ export default defineConfig({
45
+ plugins: [twd({ open: true })],
46
+ })
143
47
  ```
144
48
 
145
- ### User Interactions
49
+ Write a test next to your code:
146
50
 
147
51
  ```ts
148
- const user = userEvent.setup();
149
- await user.click(button);
150
- await user.type(input, "Hello World");
52
+ // src/App.twd.test.ts
53
+ import { twd, screenDom } from 'twd-js'
54
+ import { describe, it } from 'twd-js/runner'
55
+
56
+ describe('App', () => {
57
+ it('shows the heading', async () => {
58
+ await twd.visit('/')
59
+ const heading = await screenDom.findByRole('heading', { level: 1 })
60
+ twd.should(heading, 'be.visible')
61
+ })
62
+ })
151
63
  ```
152
64
 
153
- ### API Mocking
65
+ Run `npm run dev` and open the app. The TWD sidebar appears in your browser; click play to run the test.
154
66
 
155
- ```ts
156
- twd.mockRequest("getUser", {
157
- method: "GET",
158
- url: "/api/user",
159
- response: { id: 1, name: "John" }
160
- });
67
+ → **[Full setup guide](https://twd.dev/getting-started)** · **[Framework integration](https://twd.dev/frameworks)** (Angular, non-Vite, Astro, React Router)
161
68
 
162
- const rule = await twd.waitForRequest("getUser");
163
- ```
69
+ ## The TWD ecosystem
164
70
 
165
- ## Documentation
71
+ One package today. The rest when you need it.
166
72
 
167
- Full documentation is available at [twd.dev](https://twd.dev) (coming soon) or in the `docs` folder.
73
+ | Tool | What it does |
74
+ | --- | --- |
75
+ | **[twd-js](https://twd.dev/twd-js)** | The core sidebar. Frontend tests that run in your real browser. |
76
+ | **[twd-relay](https://twd.dev/twd-relay)** | Token-efficient browser testing for AI agents. Structured pass/fail over WebSocket. No Playwright, no screenshots. |
77
+ | **[twd-cli](https://twd.dev/contract-testing)** | Headless CI runs with coverage and OpenAPI contract validation. |
168
78
 
169
- - [Getting Started](docs/getting-started.md)
170
- - [Framework Integration](docs/frameworks.md)
171
- - [Writing Tests](docs/writing-tests.md)
172
- - [API Mocking](docs/api-mocking.md)
79
+ ## Examples & showcase
173
80
 
174
- ## Examples
81
+ - **[twd-shadcn](https://github.com/BRIKEV/twd-shadcn)** — React + shadcn/ui with a [live demo](https://brikev.github.io/twd-shadcn/) you can interact with
82
+ - **[twd-react-router](https://github.com/BRIKEV/twd-react-router)** — React Router (Framework Mode) with `createRoutesStub` and loader mocking
83
+ - **[twd-tanstack-example](https://github.com/BRIKEV/twd-tanstack-example)** — TanStack Router integration
84
+ - **[twd-vue-example](https://github.com/BRIKEV/twd-vue-example)** — Vue 3
85
+ - **[twd-angular-example](https://github.com/BRIKEV/twd-angular-example)** — Angular
86
+ - **[twd-auth0](https://github.com/BRIKEV/twd-auth0)** — Auth0 session mocking
175
87
 
176
- Check out our working examples for various frameworks:
88
+ **[All examples and community content](https://twd.dev/community)**
177
89
 
178
- - **[Examples Directory](https://github.com/BRIKEV/twd/tree/main/examples)** - Local examples for React, Vue, and Astro
179
- - **[Vue Example](https://github.com/BRIKEV/twd-vue-example)** - Vue 3 with advanced scenarios
180
- - **[Solid Example](https://github.com/BRIKEV/twd-solid-example)** - Solid.js integration
181
- - **[Angular Example](https://github.com/BRIKEV/twd-angular-example)** - Angular setup
90
+ ## Documentation
182
91
 
183
- Each example includes a complete setup guide and demonstrates best practices for testing with TWD including ci integration.
92
+ - **[Getting Started](https://twd.dev/getting-started)** Install, set up, write your first test
93
+ - **[Writing Tests](https://twd.dev/writing-tests)** — Selectors, assertions, interactions, navigation
94
+ - **[API Mocking](https://twd.dev/api-mocking)** — Mock Service Worker patterns
95
+ - **[AI Integration](https://twd.dev/ai-overview)** — Connect Claude Code (or any agent) via twd-relay
96
+ - **[Contract Testing Setup](https://twd.dev/contract-testing-setup)** — Validate mocks against OpenAPI specs in CI
97
+ - **[API Reference](https://twd.dev/api/)** — Test functions, commands, assertions
184
98
 
185
99
  ## Contributing
186
100
 
187
- Contributions are welcome! Please open issues or pull requests on [GitHub](https://github.com/BRIKEV/twd).
101
+ Open issues or pull requests on [GitHub](https://github.com/BRIKEV/twd). If you're starting out in tech and looking for a beginner-friendly first PR, see the [open issues](https://github.com/BRIKEV/twd/issues). Reach out and the maintainer will help with setup and walk you through it.
188
102
 
189
103
  ## Contributors ✨
190
104
 
@@ -207,8 +121,8 @@ Contributions are welcome! Please open issues or pull requests on [GitHub](https
207
121
 
208
122
  <!-- ALL-CONTRIBUTORS-LIST:END -->
209
123
 
210
- This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!
124
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome.
211
125
 
212
126
  ## License
213
127
 
214
- This project is licensed under the [MIT License](./LICENSE).
128
+ [MIT](./LICENSE)