twd-js 1.3.3 → 1.4.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
@@ -36,31 +36,35 @@ pnpm add twd-js
36
36
 
37
37
  ## Quick Start
38
38
 
39
- ### React (Standard)
40
-
41
- Add this to your entry file (e.g., `src/main.tsx`):
42
-
43
- ```tsx
44
- if (import.meta.env.DEV) {
45
- const testModules = import.meta.glob("./**/*.twd.test.ts");
46
- const { initTests, twd, TWDSidebar } = await import('twd-js');
47
- initTests(testModules, <TWDSidebar open={true} position="left" />, createRoot);
48
- twd.initRequestMocking().catch(console.error);
49
- }
50
- ```
51
-
52
- ### Vue / Angular / Other Frameworks (Bundled)
39
+ ### React / Vue / Angular / Other Frameworks (Bundled / recommended)
53
40
 
54
41
  TWD now supports any framework via its bundled version.
55
42
 
56
43
  ```ts
44
+ // Only load the test sidebar and tests in development mode
57
45
  if (import.meta.env.DEV) {
58
46
  const { initTWD } = await import('twd-js/bundled');
59
47
  const tests = import.meta.glob("./**/*.twd.test.ts");
60
- initTWD(tests);
48
+
49
+ // Initialize TWD with tests and optional configuration
50
+ // Request mocking is automatically initialized by default
51
+ initTWD(tests, {
52
+ open: true,
53
+ position: 'left',
54
+ serviceWorker: true, // Enable request mocking (default: true)
55
+ serviceWorkerUrl: '/mock-sw.js' // Custom service worker path (default: '/mock-sw.js')
56
+ });
61
57
  }
62
58
  ```
63
59
 
60
+ ### Set Up Mock Service Worker
61
+
62
+ If you plan to use API mocking, set up the mock service worker:
63
+
64
+ ```bash
65
+ npx twd-js init public
66
+ ```
67
+
64
68
  Check the [Framework Integration Guide](https://brikev.github.io/twd/frameworks) for more details.
65
69
 
66
70
  ## Writing Tests
package/dist/bundled.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { TWDTheme } from './ui/theme';
1
2
  interface TestModule {
2
3
  [key: string]: () => Promise<unknown>;
3
4
  }
@@ -6,6 +7,7 @@ interface InitTWDOptions {
6
7
  position?: "left" | "right";
7
8
  serviceWorker?: boolean;
8
9
  serviceWorkerUrl?: string;
10
+ theme?: Partial<TWDTheme>;
9
11
  }
10
12
  /**
11
13
  * Initialize TWD with tests and optional configuration
@@ -15,6 +17,7 @@ interface InitTWDOptions {
15
17
  * @param options.position The position of the sidebar
16
18
  * @param options.serviceWorker Whether to use the service worker
17
19
  * @param options.serviceWorkerUrl The URL of the service worker
20
+ * @param options.theme Optional theme customization
18
21
  * @returns void
19
22
  * @example
20
23
  * initTWD(testModules, { open: true, position: 'left' });
@@ -22,6 +25,8 @@ interface InitTWDOptions {
22
25
  * initTWD(testModules, { open: true, position: 'left', serviceWorker: false });
23
26
  * @example
24
27
  * initTWD(testModules, { open: true, position: 'left', serviceWorker: true, serviceWorkerUrl: '/mock-sw.js' });
28
+ * @example
29
+ * initTWD(testModules, { open: true, position: 'left', theme: { primary: '#ff0000', background: '#ffffff' } });
25
30
  */
26
31
  export declare const initTWD: (files: TestModule, options?: InitTWDOptions) => void;
27
32
  export {};