twd-js 0.5.0 → 0.5.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
@@ -72,10 +72,11 @@ pnpm add twd-js
72
72
  if (import.meta.env.DEV) {
73
73
  // Use Vite's glob import to find all test files
74
74
  const testModules = import.meta.glob("./**/*.twd.test.ts");
75
- const { initViteLoadTests, twd } = await import('twd-js');
76
- // Initialize the TWD sidebar and load tests
77
- initViteLoadTests(testModules, { open: true, position: 'left' });
78
- // Optionally initialize request mocking
75
+ const { initTests, twd, TWDSidebar } = await import('twd-js');
76
+ const { createRoot } = await import('react-dom/client');
77
+ // You need to pass the test modules, the sidebar component, and createRoot function
78
+ initTests(testModules, <TWDSidebar open={true} position="left" />, createRoot);
79
+ // if you want to use mock requests, you can initialize it here
79
80
  twd.initRequestMocking()
80
81
  .then(() => {
81
82
  console.log("Request mocking initialized");
@@ -88,7 +89,6 @@ pnpm add twd-js
88
89
  createRoot(document.getElementById("root")!).render(
89
90
  <StrictMode>
90
91
  <App />
91
- <TWDSidebar open={false} />
92
92
  </StrictMode>
93
93
  );
94
94
  ```
@@ -140,9 +140,10 @@ pnpm add twd-js
140
140
  if (import.meta.env.DEV) {
141
141
  // Use Vite's glob import to find all test files
142
142
  const testModules = import.meta.glob("./**/*.twd.test.ts");
143
- const { initViteLoadTests, twd } = await import('twd-js');
144
- // Initialize the TWD sidebar and load tests
145
- initViteLoadTests(testModules, { open: true, position: 'left' });
143
+ const { initTests, twd, TWDSidebar } = await import('twd-js');
144
+ const { createRoot } = await import('react-dom/client');
145
+ // You need to pass the test modules, the sidebar component, and createRoot function
146
+ initTests(testModules, <TWDSidebar open={true} position="left" />, createRoot);
146
147
  // Optionally initialize request mocking
147
148
  twd.initRequestMocking()
148
149
  .then(() => {
@@ -169,8 +170,9 @@ pnpm add twd-js
169
170
  './app.twd.test.ts': () => import('./app.twd.test'),
170
171
  './another-test-file.twd.test.ts': () => import('./another-test-file.twd.test'),
171
172
  };
172
- const { initViteLoadTests } = await import('twd-js');
173
- initViteLoadTests(testModules);
173
+ const { initTests, TWDSidebar } = await import('twd-js');
174
+ const { createRoot } = await import('react-dom/client');
175
+ initTests(testModules, <TWDSidebar open={true} position="left" />, createRoot);
174
176
  }
175
177
  ```
176
178
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './twd';
2
- export { initViteLoadTests } from './initializers/viteLoadTests';
2
+ export { TWDSidebar } from './ui/TWDSidebar';
3
+ export { initTests } from './initializers/initTests';
3
4
  export { expect } from 'chai';
4
5
  export { userEvent } from './proxies/userEvent';
@@ -1,6 +1,8 @@
1
1
  interface Options {
2
- open: boolean;
3
- position?: 'left' | 'right';
2
+ Component: React.ReactNode;
3
+ createRoot: (el: HTMLElement) => {
4
+ render: (el: React.ReactNode) => void;
5
+ };
4
6
  }
5
7
  /**
6
8
  * Initialize the TWD sidebar.
@@ -10,8 +12,11 @@ interface Options {
10
12
  * import { initSidebar } from 'twd-js';
11
13
  *
12
14
  * // Initialize the sidebar (e.g., in your main app file)
13
- * initSidebar({ open: false, position: 'left' });
15
+ * initSidebar({
16
+ * Component: <TWDSidebar open={true} position="left" />,
17
+ * createRoot,
18
+ * });
14
19
  * ```
15
20
  */
16
- export declare const initSidebar: (options: Options) => Promise<void>;
21
+ export declare const initSidebar: (options: Options) => void;
17
22
  export {};
@@ -1,7 +1,3 @@
1
- interface Options {
2
- open: boolean;
3
- position?: 'left' | 'right';
4
- }
5
1
  /**
6
2
  * A record of test module paths to their loader functions.
7
3
  * Each function returns a promise that resolves when the module is loaded.
@@ -18,15 +14,19 @@ type TestModule = Record<string, () => Promise<unknown>>;
18
14
  /**
19
15
  * Initialize Vite test loading.
20
16
  * @param testModules - The test modules to load.
21
- * @param options - Options for initializing the test loader.
17
+ * @param component - The React component to render the sidebar.
18
+ * @param createRoot - Function to create a React root.
22
19
  * @example
23
20
  * ```ts
24
21
  * if (import.meta.env.DEV) {
25
22
  * const testModules = import.meta.glob("./example.twd.test.ts");
26
- * const { initViteLoadTests } = await import('twd-js');
27
- * await initViteLoadTests(testModules, { open: false, position: 'left' });
23
+ * const { initTests, TWDSidebar } = await import('twd-js');
24
+ * const { createRoot } = await import('react-dom/client');
25
+ * await initTests(testModules, <TWDSidebar open={true} position="left" />, createRoot);
28
26
  * }
29
27
  * ```
30
28
  */
31
- export declare const initViteLoadTests: (testModules: TestModule, options: Options) => Promise<void>;
29
+ export declare const initTests: (testModules: TestModule, Component: React.ReactNode, createRoot: (el: HTMLElement) => {
30
+ render: (el: React.ReactNode) => void;
31
+ }) => Promise<void>;
32
32
  export {};