twd-js 1.7.3 → 1.8.0-beta.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 +3 -3
- package/dist/plugin/twd.d.ts +75 -0
- package/dist/vite-plugin.cjs.js +2 -1
- package/dist/vite-plugin.d.ts +1 -0
- package/dist/vite-plugin.es.js +51 -11
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://qlty.sh/gh/BRIKEV/projects/twd)
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
<img src="
|
|
10
|
+
<img src="https://raw.githubusercontent.com/BRIKEV/twd/main/images/twd-skill.gif" alt="TWD running with an AI agent" width="800">
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
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.
|
|
@@ -101,7 +101,7 @@ describe("Hello World Page", () => {
|
|
|
101
101
|
3. **Run your app** - The TWD sidebar will appear automatically in development mode!
|
|
102
102
|
|
|
103
103
|
<p align="center">
|
|
104
|
-
<img src="
|
|
104
|
+
<img src="https://raw.githubusercontent.com/BRIKEV/twd/main/images/twd_side_bar_success.png" alt="TWD Sidebar in action" width="800">
|
|
105
105
|
</p>
|
|
106
106
|
|
|
107
107
|
## Key Concepts
|
|
@@ -155,7 +155,7 @@ Full documentation is available at [twd.dev](https://twd.dev) (coming soon) or i
|
|
|
155
155
|
|
|
156
156
|
Check out our working examples for various frameworks:
|
|
157
157
|
|
|
158
|
-
- **[Examples Directory](
|
|
158
|
+
- **[Examples Directory](https://github.com/BRIKEV/twd/tree/main/examples)** - Local examples for React, Vue, and Astro
|
|
159
159
|
- **[Vue Example](https://github.com/BRIKEV/twd-vue-example)** - Vue 3 with advanced scenarios
|
|
160
160
|
- **[Solid Example](https://github.com/BRIKEV/twd-solid-example)** - Solid.js integration
|
|
161
161
|
- **[Angular Example](https://github.com/BRIKEV/twd-angular-example)** - Angular setup
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { TWDTheme } from '../ui/utils/theme';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the TWD Vite plugin.
|
|
5
|
+
*/
|
|
6
|
+
export interface TwdPluginOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Glob pattern used to discover TWD test files via `import.meta.glob`.
|
|
9
|
+
* @default "/**\/*.twd.test.ts"
|
|
10
|
+
*/
|
|
11
|
+
testFilePattern?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the TWD sidebar starts open.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
open?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Side of the viewport the sidebar is anchored to.
|
|
19
|
+
* @default "left"
|
|
20
|
+
*/
|
|
21
|
+
position?: 'left' | 'right';
|
|
22
|
+
/**
|
|
23
|
+
* Whether to register the Mock Service Worker for request mocking.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
serviceWorker?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* URL of the Mock Service Worker script served by the app.
|
|
29
|
+
* @default "/mock-sw.js"
|
|
30
|
+
*/
|
|
31
|
+
serviceWorkerUrl?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Optional theme overrides for the sidebar UI.
|
|
34
|
+
*/
|
|
35
|
+
theme?: Partial<TWDTheme>;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to show the search input in the sidebar.
|
|
38
|
+
*/
|
|
39
|
+
search?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* CSS selector for the host element used to mount the sidebar.
|
|
42
|
+
*/
|
|
43
|
+
rootSelector?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Vite plugin that auto-wires TWD into a dev server.
|
|
47
|
+
* It exposes a virtual module that calls `initTWD` with a glob of test files
|
|
48
|
+
* and injects a `<script type="module">` tag into `index.html` via
|
|
49
|
+
* `transformIndexHtml`, so apps don't need a manual TWD entry point.
|
|
50
|
+
*
|
|
51
|
+
* This plugin only runs in development mode (serve) and does not affect Vitest test runs.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Configuration options for the plugin
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { twd } from 'twd-js/vite-plugin';
|
|
57
|
+
*
|
|
58
|
+
* export default defineConfig({
|
|
59
|
+
* plugins: [
|
|
60
|
+
* // ... other plugins
|
|
61
|
+
* twd(),
|
|
62
|
+
* ],
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* // Custom options
|
|
68
|
+
* twd({
|
|
69
|
+
* testFilePattern: '/src/**\/*.twd.test.tsx',
|
|
70
|
+
* position: 'right',
|
|
71
|
+
* open: false,
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function twd(options?: TwdPluginOptions): Plugin;
|
package/dist/vite-plugin.cjs.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./index.cjs.js");let d=require("fs"),u=require("path");function a(){return{name:"remove-mock-sw",apply:"build",closeBundle(){try{(0,d.rmSync)((0,u.resolve)("dist/mock-sw.js")),console.log("🧹 Removed mock-sw.js from build")}catch{console.log("🧹 No mock-sw.js found in build")}}}}function m(n={}){const{testFilePattern:t=".twd.test.ts"}=n,o=typeof t=="function"?t:e=>e.endsWith(t);return{name:"twd-hmr",apply:"serve",handleHotUpdate({file:e,server:r}){if(o(e))return r.ws.send({type:"full-reload",path:"*"}),[]}}}var i="virtual:twd/init",s=`\0${i}`,p="/**/*.twd.test.ts",f={open:!0,position:"left",serviceWorker:!0,serviceWorkerUrl:"/mock-sw.js"};function v(n={}){const{testFilePattern:t=p,...o}=n,e={...f,...o};return{name:"twd",apply:"serve",resolveId(r){return r===i?s:null},load(r){if(r!==s)return null;const l=JSON.stringify(t),c=JSON.stringify(e);return["import { initTWD } from 'twd-js/bundled';",`const tests = import.meta.glob(${l});`,`initTWD(tests, ${c});`].join(`
|
|
2
|
+
`)},transformIndexHtml(){return[{tag:"script",attrs:{type:"module",src:`/@id/${i}`},injectTo:"head"}]}}}exports.removeMockServiceWorker=a;exports.twd=v;exports.twdHmr=m;
|
package/dist/vite-plugin.d.ts
CHANGED
package/dist/vite-plugin.es.js
CHANGED
|
@@ -1,33 +1,73 @@
|
|
|
1
|
-
import { rmSync as
|
|
2
|
-
import { resolve as
|
|
3
|
-
function
|
|
1
|
+
import { rmSync as d } from "fs";
|
|
2
|
+
import { resolve as a } from "path";
|
|
3
|
+
function v() {
|
|
4
4
|
return {
|
|
5
5
|
name: "remove-mock-sw",
|
|
6
6
|
apply: "build",
|
|
7
7
|
closeBundle() {
|
|
8
8
|
try {
|
|
9
|
-
|
|
9
|
+
d(a("dist/mock-sw.js")), console.log("🧹 Removed mock-sw.js from build");
|
|
10
10
|
} catch {
|
|
11
11
|
console.log("🧹 No mock-sw.js found in build");
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const { testFilePattern:
|
|
16
|
+
function w(n = {}) {
|
|
17
|
+
const { testFilePattern: t = ".twd.test.ts" } = n, o = typeof t == "function" ? t : (e) => e.endsWith(t);
|
|
18
18
|
return {
|
|
19
19
|
name: "twd-hmr",
|
|
20
20
|
apply: "serve",
|
|
21
|
-
handleHotUpdate({ file:
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
21
|
+
handleHotUpdate({ file: e, server: r }) {
|
|
22
|
+
if (o(e))
|
|
23
|
+
return r.ws.send({
|
|
24
24
|
type: "full-reload",
|
|
25
25
|
path: "*"
|
|
26
26
|
}), [];
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
var s = "virtual:twd/init", i = `\0${s}`, u = "/**/*.twd.test.ts", m = {
|
|
31
|
+
open: !0,
|
|
32
|
+
position: "left",
|
|
33
|
+
serviceWorker: !0,
|
|
34
|
+
serviceWorkerUrl: "/mock-sw.js"
|
|
35
|
+
};
|
|
36
|
+
function T(n = {}) {
|
|
37
|
+
const { testFilePattern: t = u, ...o } = n, e = {
|
|
38
|
+
...m,
|
|
39
|
+
...o
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
name: "twd",
|
|
43
|
+
apply: "serve",
|
|
44
|
+
resolveId(r) {
|
|
45
|
+
return r === s ? i : null;
|
|
46
|
+
},
|
|
47
|
+
load(r) {
|
|
48
|
+
if (r !== i) return null;
|
|
49
|
+
const l = JSON.stringify(t), c = JSON.stringify(e);
|
|
50
|
+
return [
|
|
51
|
+
"import { initTWD } from 'twd-js/bundled';",
|
|
52
|
+
`const tests = import.meta.glob(${l});`,
|
|
53
|
+
`initTWD(tests, ${c});`
|
|
54
|
+
].join(`
|
|
55
|
+
`);
|
|
56
|
+
},
|
|
57
|
+
transformIndexHtml() {
|
|
58
|
+
return [{
|
|
59
|
+
tag: "script",
|
|
60
|
+
attrs: {
|
|
61
|
+
type: "module",
|
|
62
|
+
src: `/@id/${s}`
|
|
63
|
+
},
|
|
64
|
+
injectTo: "head"
|
|
65
|
+
}];
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
30
69
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
70
|
+
v as removeMockServiceWorker,
|
|
71
|
+
T as twd,
|
|
72
|
+
w as twdHmr
|
|
33
73
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twd-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-beta.0",
|
|
4
4
|
"description": "Test While Developing (TWD) - in-browser testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"react-dom": ">=17.0.0"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@eslint/js": "^
|
|
97
|
+
"@eslint/js": "^10.0.1",
|
|
98
98
|
"@preact/preset-vite": "^2.10.5",
|
|
99
99
|
"@testing-library/jest-dom": "^6.9.1",
|
|
100
100
|
"@testing-library/react": "^16.3.2",
|
|
@@ -104,15 +104,15 @@
|
|
|
104
104
|
"@vitest/coverage-v8": "^4.1.5",
|
|
105
105
|
"@vitest/eslint-plugin": "^1.6.16",
|
|
106
106
|
"conventional-changelog": "^7.2.0",
|
|
107
|
-
"eslint": "^
|
|
107
|
+
"eslint": "^10.3.0",
|
|
108
108
|
"eslint-config-prettier": "^10.1.8",
|
|
109
109
|
"globals": "^17.6.0",
|
|
110
110
|
"husky": "^9.1.7",
|
|
111
111
|
"jsdom": "^29.1.1",
|
|
112
|
-
"lint-staged": "^
|
|
112
|
+
"lint-staged": "^17.0.2",
|
|
113
113
|
"prettier": "^3.8.3",
|
|
114
114
|
"typescript": "~5.9.3",
|
|
115
|
-
"typescript-eslint": "^8.59.
|
|
115
|
+
"typescript-eslint": "^8.59.2",
|
|
116
116
|
"vite": "^8.0.10",
|
|
117
117
|
"vite-plugin-dts": "^5.0.0",
|
|
118
118
|
"vitepress": "^2.0.0-alpha.12",
|