@olane/o-test 0.7.12

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.
Files changed (60) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +400 -0
  3. package/dist/src/builders/index.d.ts +7 -0
  4. package/dist/src/builders/index.d.ts.map +1 -0
  5. package/dist/src/builders/index.js +6 -0
  6. package/dist/src/builders/leader-child-builder.d.ts +50 -0
  7. package/dist/src/builders/leader-child-builder.d.ts.map +1 -0
  8. package/dist/src/builders/leader-child-builder.js +59 -0
  9. package/dist/src/builders/manager-worker-builder.d.ts +49 -0
  10. package/dist/src/builders/manager-worker-builder.d.ts.map +1 -0
  11. package/dist/src/builders/manager-worker-builder.js +79 -0
  12. package/dist/src/builders/simple-node-builder.d.ts +49 -0
  13. package/dist/src/builders/simple-node-builder.d.ts.map +1 -0
  14. package/dist/src/builders/simple-node-builder.js +66 -0
  15. package/dist/src/example-tool.tool.d.ts +58 -0
  16. package/dist/src/example-tool.tool.d.ts.map +1 -0
  17. package/dist/src/example-tool.tool.js +89 -0
  18. package/dist/src/fixtures/index.d.ts +6 -0
  19. package/dist/src/fixtures/index.d.ts.map +1 -0
  20. package/dist/src/fixtures/index.js +5 -0
  21. package/dist/src/fixtures/mock-data.d.ts +201 -0
  22. package/dist/src/fixtures/mock-data.d.ts.map +1 -0
  23. package/dist/src/fixtures/mock-data.js +180 -0
  24. package/dist/src/fixtures/test-methods.d.ts +33 -0
  25. package/dist/src/fixtures/test-methods.d.ts.map +1 -0
  26. package/dist/src/fixtures/test-methods.js +185 -0
  27. package/dist/src/index.d.ts +18 -0
  28. package/dist/src/index.d.ts.map +1 -0
  29. package/dist/src/index.js +25 -0
  30. package/dist/src/methods/example.methods.d.ts +9 -0
  31. package/dist/src/methods/example.methods.d.ts.map +1 -0
  32. package/dist/src/methods/example.methods.js +50 -0
  33. package/dist/src/test-environment.d.ts +185 -0
  34. package/dist/src/test-environment.d.ts.map +1 -0
  35. package/dist/src/test-environment.js +260 -0
  36. package/dist/src/utils/assertions.d.ts +159 -0
  37. package/dist/src/utils/assertions.d.ts.map +1 -0
  38. package/dist/src/utils/assertions.js +201 -0
  39. package/dist/src/utils/chunk-capture.d.ts +108 -0
  40. package/dist/src/utils/chunk-capture.d.ts.map +1 -0
  41. package/dist/src/utils/chunk-capture.js +156 -0
  42. package/dist/src/utils/index.d.ts +8 -0
  43. package/dist/src/utils/index.d.ts.map +1 -0
  44. package/dist/src/utils/index.js +7 -0
  45. package/dist/src/utils/mock-factories.d.ts +211 -0
  46. package/dist/src/utils/mock-factories.d.ts.map +1 -0
  47. package/dist/src/utils/mock-factories.js +181 -0
  48. package/dist/src/utils/wait-for.d.ts +42 -0
  49. package/dist/src/utils/wait-for.d.ts.map +1 -0
  50. package/dist/src/utils/wait-for.js +59 -0
  51. package/dist/test/example.spec.d.ts +1 -0
  52. package/dist/test/example.spec.d.ts.map +1 -0
  53. package/dist/test/example.spec.js +240 -0
  54. package/dist/test/fixtures/mock-data.d.ts +1 -0
  55. package/dist/test/fixtures/mock-data.d.ts.map +1 -0
  56. package/dist/test/fixtures/mock-data.js +90 -0
  57. package/dist/test/test-environment.spec.d.ts +8 -0
  58. package/dist/test/test-environment.spec.d.ts.map +1 -0
  59. package/dist/test/test-environment.spec.js +393 -0
  60. package/package.json +87 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Wait for a condition to become true
3
+ *
4
+ * @param condition - Function that returns true when condition is met
5
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
6
+ * @param intervalMs - Check interval in milliseconds (default: 100)
7
+ * @returns Promise that resolves when condition is met or rejects on timeout
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * await waitFor(() => tool.isReady, 10000);
12
+ * await waitFor(() => counter > 5, 3000, 50);
13
+ * ```
14
+ */
15
+ export declare function waitFor(condition: () => boolean, timeoutMs?: number, intervalMs?: number): Promise<void>;
16
+ /**
17
+ * Wait for an async condition to become true
18
+ *
19
+ * @param condition - Async function that returns true when condition is met
20
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
21
+ * @param intervalMs - Check interval in milliseconds (default: 100)
22
+ * @returns Promise that resolves when condition is met or rejects on timeout
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * await waitForAsync(async () => await db.isConnected(), 10000);
27
+ * ```
28
+ */
29
+ export declare function waitForAsync(condition: () => Promise<boolean>, timeoutMs?: number, intervalMs?: number): Promise<void>;
30
+ /**
31
+ * Sleep for specified milliseconds
32
+ *
33
+ * @param ms - Milliseconds to sleep
34
+ * @returns Promise that resolves after delay
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * await sleep(1000); // Wait 1 second
39
+ * ```
40
+ */
41
+ export declare function sleep(ms: number): Promise<void>;
42
+ //# sourceMappingURL=wait-for.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait-for.d.ts","sourceRoot":"","sources":["../../../src/utils/wait-for.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,OAAO,EACxB,SAAS,GAAE,MAAa,EACxB,UAAU,GAAE,MAAY,GACvB,OAAO,CAAC,IAAI,CAAC,CAWf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EACjC,SAAS,GAAE,MAAa,EACxB,UAAU,GAAE,MAAY,GACvB,OAAO,CAAC,IAAI,CAAC,CAWf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Wait for a condition to become true
3
+ *
4
+ * @param condition - Function that returns true when condition is met
5
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
6
+ * @param intervalMs - Check interval in milliseconds (default: 100)
7
+ * @returns Promise that resolves when condition is met or rejects on timeout
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * await waitFor(() => tool.isReady, 10000);
12
+ * await waitFor(() => counter > 5, 3000, 50);
13
+ * ```
14
+ */
15
+ export async function waitFor(condition, timeoutMs = 5000, intervalMs = 100) {
16
+ const startTime = Date.now();
17
+ while (!condition()) {
18
+ if (Date.now() - startTime > timeoutMs) {
19
+ throw new Error(`Timeout: Condition not met after ${timeoutMs}ms`);
20
+ }
21
+ await new Promise(resolve => setTimeout(resolve, intervalMs));
22
+ }
23
+ }
24
+ /**
25
+ * Wait for an async condition to become true
26
+ *
27
+ * @param condition - Async function that returns true when condition is met
28
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
29
+ * @param intervalMs - Check interval in milliseconds (default: 100)
30
+ * @returns Promise that resolves when condition is met or rejects on timeout
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * await waitForAsync(async () => await db.isConnected(), 10000);
35
+ * ```
36
+ */
37
+ export async function waitForAsync(condition, timeoutMs = 5000, intervalMs = 100) {
38
+ const startTime = Date.now();
39
+ while (!(await condition())) {
40
+ if (Date.now() - startTime > timeoutMs) {
41
+ throw new Error(`Timeout: Async condition not met after ${timeoutMs}ms`);
42
+ }
43
+ await new Promise(resolve => setTimeout(resolve, intervalMs));
44
+ }
45
+ }
46
+ /**
47
+ * Sleep for specified milliseconds
48
+ *
49
+ * @param ms - Milliseconds to sleep
50
+ * @returns Promise that resolves after delay
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * await sleep(1000); // Wait 1 second
55
+ * ```
56
+ */
57
+ export async function sleep(ms) {
58
+ return new Promise(resolve => setTimeout(resolve, ms));
59
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=example.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.spec.d.ts","sourceRoot":"","sources":["../../test/example.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ // import { expect } from 'chai';
3
+ // import { ExampleTool } from '../src/example-tool.tool.js';
4
+ // import { oRequest } from '@olane/o-core';
5
+ // import { NodeState } from '@olane/o-node';
6
+ // import { mockData } from './fixtures/mock-data.js';
7
+ // /**
8
+ // * Example tests for the ExampleTool
9
+ // *
10
+ // * These tests demonstrate:
11
+ // * - Tool initialization and lifecycle
12
+ // * - Method testing
13
+ // * - Success and error cases
14
+ // * - Using test fixtures
15
+ // *
16
+ // * Run with: npm test
17
+ // */
18
+ // describe('ExampleTool', () => {
19
+ // let tool: ExampleTool;
20
+ // beforeEach(() => {
21
+ // // Initialize a new tool instance before each test
22
+ // tool = new ExampleTool({
23
+ // debugMode: false,
24
+ // timeout: 5000,
25
+ // });
26
+ // });
27
+ // afterEach(async () => {
28
+ // // Clean up after each test
29
+ // if (tool && tool.state === NodeState.RUNNING) {
30
+ // await tool.stop();
31
+ // }
32
+ // });
33
+ // describe('Initialization', () => {
34
+ // it('should initialize the tool successfully', async () => {
35
+ // await tool.start();
36
+ // expect(tool.state).to.equal(NodeState.RUNNING);
37
+ // });
38
+ // it('should initialize with custom configuration', () => {
39
+ // const customTool = new ExampleTool({
40
+ // debugMode: true,
41
+ // timeout: 10000,
42
+ // customOption: 'test-value',
43
+ // });
44
+ // expect(customTool).to.exist;
45
+ // });
46
+ // it('should stop the tool successfully', async () => {
47
+ // await tool.start();
48
+ // expect(tool.state).to.equal(NodeState.RUNNING);
49
+ // await tool.stop();
50
+ // expect(tool.state).to.equal(NodeState.STOPPED);
51
+ // });
52
+ // });
53
+ // describe('example_method', () => {
54
+ // beforeEach(async () => {
55
+ // await tool.start();
56
+ // });
57
+ // it('should process a message successfully', async () => {
58
+ // const request = new oRequest({
59
+ // method: 'example_method',
60
+ // params: { message: 'Hello, oLane!' },
61
+ // });
62
+ // const result = await tool.callMyTool(request);
63
+ // expect(result.success).to.be.true;
64
+ // expect(result.result).to.include('Hello, oLane!');
65
+ // expect(result.result).to.include('Processed:');
66
+ // expect(result.timestamp).to.be.a('number');
67
+ // });
68
+ // it('should process a message with metadata', async () => {
69
+ // const request = new oRequest({
70
+ // method: 'example_method',
71
+ // params: {
72
+ // message: 'Test message',
73
+ // metadata: { userId: '123', source: 'test' },
74
+ // },
75
+ // });
76
+ // const result = await tool.callMyTool(request);
77
+ // expect(result.success).to.be.true;
78
+ // expect(result.result).to.include('Test message');
79
+ // });
80
+ // it('should return error when message parameter is missing', async () => {
81
+ // const request = new oRequest({
82
+ // method: 'example_method',
83
+ // params: {},
84
+ // });
85
+ // const result = await tool.callMyTool(request);
86
+ // expect(result.success).to.be.false;
87
+ // expect(result.error).to.include('required');
88
+ // });
89
+ // it('should use mock data from fixtures', async () => {
90
+ // const request = new oRequest({
91
+ // method: 'example_method',
92
+ // params: { message: mockData.sampleMessage },
93
+ // });
94
+ // const result = await tool.callMyTool(request);
95
+ // expect(result.success).to.be.true;
96
+ // expect(result.result).to.include(mockData.sampleMessage);
97
+ // });
98
+ // });
99
+ // describe('process_data', () => {
100
+ // beforeEach(async () => {
101
+ // await tool.start();
102
+ // });
103
+ // it('should process data in JSON format', async () => {
104
+ // const testData = { name: 'John', age: 30 };
105
+ // const request = new oRequest({
106
+ // method: 'process_data',
107
+ // params: {
108
+ // data: testData,
109
+ // options: { format: 'json' },
110
+ // },
111
+ // });
112
+ // const result = await tool.callMyTool(request);
113
+ // expect(result.success).to.be.true;
114
+ // expect(result.data).to.deep.equal(testData);
115
+ // });
116
+ // it('should process data in text format', async () => {
117
+ // const testData = { name: 'John', age: 30 };
118
+ // const request = new oRequest({
119
+ // method: 'process_data',
120
+ // params: {
121
+ // data: testData,
122
+ // options: { format: 'text' },
123
+ // },
124
+ // });
125
+ // const result = await tool.callMyTool(request);
126
+ // expect(result.success).to.be.true;
127
+ // expect(result.data).to.be.a('string');
128
+ // expect(result.data).to.include('John');
129
+ // });
130
+ // it('should process data in HTML format', async () => {
131
+ // const testData = { name: 'John', age: 30 };
132
+ // const request = new oRequest({
133
+ // method: 'process_data',
134
+ // params: {
135
+ // data: testData,
136
+ // options: { format: 'html' },
137
+ // },
138
+ // });
139
+ // const result = await tool.callMyTool(request);
140
+ // expect(result.success).to.be.true;
141
+ // expect(result.data).to.include('<pre>');
142
+ // expect(result.data).to.include('John');
143
+ // });
144
+ // it('should return error when data parameter is missing', async () => {
145
+ // const request = new oRequest({
146
+ // method: 'process_data',
147
+ // params: {},
148
+ // });
149
+ // const result = await tool.callMyTool(request);
150
+ // expect(result.success).to.be.false;
151
+ // expect(result.error).to.include('required');
152
+ // });
153
+ // it('should return error for unsupported format', async () => {
154
+ // const request = new oRequest({
155
+ // method: 'process_data',
156
+ // params: {
157
+ // data: { test: 'data' },
158
+ // options: { format: 'invalid' as any },
159
+ // },
160
+ // });
161
+ // const result = await tool.callMyTool(request);
162
+ // expect(result.success).to.be.false;
163
+ // expect(result.error).to.include('Unsupported format');
164
+ // });
165
+ // it('should validate data when requested', async () => {
166
+ // const invalidData = { value: 'test' }; // No name or id field
167
+ // const request = new oRequest({
168
+ // method: 'process_data',
169
+ // params: {
170
+ // data: invalidData,
171
+ // options: { validate: true },
172
+ // },
173
+ // });
174
+ // const result = await tool.callMyTool(request);
175
+ // expect(result.success).to.be.false;
176
+ // expect(result.error).to.include('Validation failed');
177
+ // expect(result.validationErrors).to.be.an('array');
178
+ // });
179
+ // it('should pass validation with valid data', async () => {
180
+ // const validData = { name: 'John', age: 30 };
181
+ // const request = new oRequest({
182
+ // method: 'process_data',
183
+ // params: {
184
+ // data: validData,
185
+ // options: { validate: true },
186
+ // },
187
+ // });
188
+ // const result = await tool.callMyTool(request);
189
+ // expect(result.success).to.be.true;
190
+ // expect(result.data).to.deep.equal(validData);
191
+ // });
192
+ // });
193
+ // describe('get_status', () => {
194
+ // beforeEach(async () => {
195
+ // await tool.start();
196
+ // });
197
+ // it('should return tool status', async () => {
198
+ // const request = new oRequest({
199
+ // method: 'get_status',
200
+ // params: {},
201
+ // });
202
+ // const result = await tool.callMyTool(request);
203
+ // expect(result.success).to.be.true;
204
+ // expect(result.status).to.exist;
205
+ // expect(result.status.state).to.equal(NodeState.RUNNING);
206
+ // expect(result.status.address).to.include('o://example');
207
+ // expect(result.status.methods).to.be.an('array');
208
+ // expect(result.status.methods).to.include('example_method');
209
+ // expect(result.status.methods).to.include('process_data');
210
+ // expect(result.status.methods).to.include('get_status');
211
+ // });
212
+ // it('should include configuration in status', async () => {
213
+ // const request = new oRequest({
214
+ // method: 'get_status',
215
+ // params: {},
216
+ // });
217
+ // const result = await tool.callMyTool(request);
218
+ // expect(result.success).to.be.true;
219
+ // expect(result.status.debugMode).to.be.a('boolean');
220
+ // expect(result.status.timeout).to.be.a('number');
221
+ // });
222
+ // });
223
+ // describe('Error Handling', () => {
224
+ // beforeEach(async () => {
225
+ // await tool.start();
226
+ // });
227
+ // it('should handle invalid method gracefully', async () => {
228
+ // const request = new oRequest({
229
+ // method: 'invalid_method',
230
+ // params: {},
231
+ // });
232
+ // try {
233
+ // await tool.callMyTool(request);
234
+ // // Should throw or return error
235
+ // } catch (error) {
236
+ // expect(error).to.exist;
237
+ // }
238
+ // });
239
+ // });
240
+ // });
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=mock-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-data.d.ts","sourceRoot":"","sources":["../../../test/fixtures/mock-data.ts"],"names":[],"mappings":""}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ // /**
3
+ // * Mock data for testing
4
+ // *
5
+ // * This file contains sample data used in tests.
6
+ // * Organize your test fixtures here to keep tests clean and maintainable.
7
+ // */
8
+ // export const mockData = {
9
+ // /**
10
+ // * Sample message for testing example_method
11
+ // */
12
+ // sampleMessage: 'This is a test message from mock data',
13
+ // /**
14
+ // * Sample data object for testing process_data
15
+ // */
16
+ // sampleData: {
17
+ // id: 'test-123',
18
+ // name: 'Test User',
19
+ // email: 'test@example.com',
20
+ // metadata: {
21
+ // created: '2025-01-01T00:00:00Z',
22
+ // source: 'test-fixture',
23
+ // },
24
+ // },
25
+ // /**
26
+ // * Sample data for validation testing
27
+ // */
28
+ // validData: {
29
+ // name: 'Valid User',
30
+ // id: 'valid-123',
31
+ // email: 'valid@example.com',
32
+ // },
33
+ // /**
34
+ // * Invalid data for testing validation errors
35
+ // */
36
+ // invalidData: {
37
+ // value: 'missing required fields',
38
+ // // Missing name and id
39
+ // },
40
+ // /**
41
+ // * Sample metadata for testing
42
+ // */
43
+ // sampleMetadata: {
44
+ // userId: 'user-123',
45
+ // sessionId: 'session-456',
46
+ // timestamp: 1704067200000,
47
+ // source: 'test',
48
+ // },
49
+ // /**
50
+ // * Sample complex nested data
51
+ // */
52
+ // complexData: {
53
+ // users: [
54
+ // { id: 1, name: 'Alice', role: 'admin' },
55
+ // { id: 2, name: 'Bob', role: 'user' },
56
+ // { id: 3, name: 'Charlie', role: 'user' },
57
+ // ],
58
+ // settings: {
59
+ // theme: 'dark',
60
+ // notifications: true,
61
+ // language: 'en',
62
+ // },
63
+ // stats: {
64
+ // totalUsers: 3,
65
+ // activeUsers: 2,
66
+ // lastUpdate: '2025-01-01T12:00:00Z',
67
+ // },
68
+ // },
69
+ // };
70
+ // /**
71
+ // * Helper function to create mock requests
72
+ // */
73
+ // export function createMockRequest(method: string, params: any = {}) {
74
+ // return {
75
+ // method,
76
+ // params,
77
+ // timestamp: Date.now(),
78
+ // };
79
+ // }
80
+ // /**
81
+ // * Helper function to create mock configuration
82
+ // */
83
+ // export function createMockConfig(overrides: any = {}) {
84
+ // return {
85
+ // debugMode: false,
86
+ // timeout: 5000,
87
+ // customOption: 'test-value',
88
+ // ...overrides,
89
+ // };
90
+ // }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Tests for TestEnvironment class
3
+ *
4
+ * Validates the TestEnvironment utilities and serves as
5
+ * documentation/examples for usage patterns.
6
+ */
7
+ import 'dotenv/config';
8
+ //# sourceMappingURL=test-environment.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-environment.spec.d.ts","sourceRoot":"","sources":["../../test/test-environment.spec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,eAAe,CAAC"}