valenceai 0.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/.env.example +0 -0
- package/CHANGELOG.md +154 -0
- package/README.dev.md +7 -0
- package/README.md +240 -0
- package/examples/uploadLong.js +10 -0
- package/examples/uploadShort.js +7 -0
- package/jest.config.js +27 -0
- package/package.json +30 -0
- package/src/asyncAudio.js +168 -0
- package/src/client.js +18 -0
- package/src/config.js +36 -0
- package/src/discreteAudio.js +61 -0
- package/src/index.js +2 -0
- package/src/utils/logger.js +16 -0
- package/src/utils/upload.js +0 -0
- package/src/valenceClient.js +256 -0
- package/tests/asyncAudio.test.js +331 -0
- package/tests/client.test.js +42 -0
- package/tests/config.test.js +90 -0
- package/tests/discreteAudio.test.js +168 -0
- package/tests/index.test.js +33 -0
- package/tests/logger.test.js +121 -0
- package/tests/setup.js +5 -0
- package/tests/valenceClient.test.js +21 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, test, expect, beforeEach, afterEach, jest } from '@jest/globals';
|
|
2
|
+
import { log } from '../src/utils/logger.js';
|
|
3
|
+
|
|
4
|
+
describe('Logger', () => {
|
|
5
|
+
const originalEnv = process.env;
|
|
6
|
+
let consoleSpy;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
process.env = { ...originalEnv };
|
|
10
|
+
delete process.env.VALENCE_LOG_LEVEL;
|
|
11
|
+
consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
process.env = originalEnv;
|
|
16
|
+
consoleSpy.mockRestore();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('log function', () => {
|
|
20
|
+
test('should log info messages by default', () => {
|
|
21
|
+
process.env.VALENCE_LOG_LEVEL = 'info';
|
|
22
|
+
|
|
23
|
+
log('test message');
|
|
24
|
+
|
|
25
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
26
|
+
expect.stringMatching(/^\[.*\] \[INFO\] test message$/)
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should log with specified level', () => {
|
|
31
|
+
process.env.VALENCE_LOG_LEVEL = 'debug';
|
|
32
|
+
|
|
33
|
+
log('test message', 'error');
|
|
34
|
+
|
|
35
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
36
|
+
expect.stringMatching(/^\[.*\] \[ERROR\] test message$/)
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should respect log level hierarchy - debug shows all', () => {
|
|
41
|
+
process.env.VALENCE_LOG_LEVEL = 'debug';
|
|
42
|
+
|
|
43
|
+
log('debug msg', 'debug');
|
|
44
|
+
log('info msg', 'info');
|
|
45
|
+
log('warn msg', 'warn');
|
|
46
|
+
log('error msg', 'error');
|
|
47
|
+
|
|
48
|
+
expect(consoleSpy).toHaveBeenCalledTimes(4);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should respect log level hierarchy - info shows info, warn, error', () => {
|
|
52
|
+
process.env.VALENCE_LOG_LEVEL = 'info';
|
|
53
|
+
|
|
54
|
+
log('debug msg', 'debug');
|
|
55
|
+
log('info msg', 'info');
|
|
56
|
+
log('warn msg', 'warn');
|
|
57
|
+
log('error msg', 'error');
|
|
58
|
+
|
|
59
|
+
expect(consoleSpy).toHaveBeenCalledTimes(3);
|
|
60
|
+
expect(consoleSpy).not.toHaveBeenCalledWith(
|
|
61
|
+
expect.stringMatching(/DEBUG.*debug msg/)
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('should respect log level hierarchy - warn shows warn, error', () => {
|
|
66
|
+
process.env.VALENCE_LOG_LEVEL = 'warn';
|
|
67
|
+
|
|
68
|
+
log('debug msg', 'debug');
|
|
69
|
+
log('info msg', 'info');
|
|
70
|
+
log('warn msg', 'warn');
|
|
71
|
+
log('error msg', 'error');
|
|
72
|
+
|
|
73
|
+
expect(consoleSpy).toHaveBeenCalledTimes(2);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('should respect log level hierarchy - error shows only error', () => {
|
|
77
|
+
process.env.VALENCE_LOG_LEVEL = 'error';
|
|
78
|
+
|
|
79
|
+
log('debug msg', 'debug');
|
|
80
|
+
log('info msg', 'info');
|
|
81
|
+
log('warn msg', 'warn');
|
|
82
|
+
log('error msg', 'error');
|
|
83
|
+
|
|
84
|
+
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
86
|
+
expect.stringMatching(/ERROR.*error msg/)
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('should default to info level when invalid level set', async () => {
|
|
91
|
+
process.env.VALENCE_LOG_LEVEL = 'invalid';
|
|
92
|
+
|
|
93
|
+
// Re-import logger to pick up env change
|
|
94
|
+
const { log: freshLog } = await import('../src/utils/logger.js?' + Math.random());
|
|
95
|
+
freshLog('info msg', 'info');
|
|
96
|
+
freshLog('debug msg', 'debug');
|
|
97
|
+
|
|
98
|
+
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('should include timestamp in log output', () => {
|
|
102
|
+
process.env.VALENCE_LOG_LEVEL = 'info';
|
|
103
|
+
|
|
104
|
+
log('test message');
|
|
105
|
+
|
|
106
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
107
|
+
expect.stringMatching(/^\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\] \[INFO\] test message$/)
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('should handle invalid message level gracefully', () => {
|
|
112
|
+
process.env.VALENCE_LOG_LEVEL = 'info';
|
|
113
|
+
|
|
114
|
+
log('test message', 'invalid');
|
|
115
|
+
|
|
116
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
117
|
+
expect.stringMatching(/^\[.*\] \[INVALID\] test message$/)
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
package/tests/setup.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, test, expect } from '@jest/globals';
|
|
2
|
+
import { ValenceClient } from '../src/valenceClient.js';
|
|
3
|
+
|
|
4
|
+
describe('ValenceClient', () => {
|
|
5
|
+
test('should create client with nested discrete and asynch properties', () => {
|
|
6
|
+
const client = new ValenceClient();
|
|
7
|
+
|
|
8
|
+
expect(client).toHaveProperty('discrete');
|
|
9
|
+
expect(client).toHaveProperty('asynch');
|
|
10
|
+
expect(typeof client.discrete.emotions).toBe('function');
|
|
11
|
+
expect(typeof client.asynch.upload).toBe('function');
|
|
12
|
+
expect(typeof client.asynch.emotions).toBe('function');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('should pass constructor parameters to AsyncClient', () => {
|
|
16
|
+
const client = new ValenceClient(1024, 5);
|
|
17
|
+
|
|
18
|
+
expect(client.asynch.partSize).toBe(1024);
|
|
19
|
+
expect(client.asynch.maxRetries).toBe(5);
|
|
20
|
+
});
|
|
21
|
+
});
|