@open-mercato/search 0.4.11-develop.2083.e52e08a1fc → 0.4.11-develop.2084.4ba270ea41
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/package.json +4 -4
- package/src/__tests__/debug.test.ts +113 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/search",
|
|
3
|
-
"version": "0.4.11-develop.
|
|
3
|
+
"version": "0.4.11-develop.2084.4ba270ea41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -126,9 +126,9 @@
|
|
|
126
126
|
"zod": "^4.0.0"
|
|
127
127
|
},
|
|
128
128
|
"peerDependencies": {
|
|
129
|
-
"@open-mercato/core": "0.4.11-develop.
|
|
130
|
-
"@open-mercato/queue": "0.4.11-develop.
|
|
131
|
-
"@open-mercato/shared": "0.4.11-develop.
|
|
129
|
+
"@open-mercato/core": "0.4.11-develop.2084.4ba270ea41",
|
|
130
|
+
"@open-mercato/queue": "0.4.11-develop.2084.4ba270ea41",
|
|
131
|
+
"@open-mercato/shared": "0.4.11-develop.2084.4ba270ea41"
|
|
132
132
|
},
|
|
133
133
|
"devDependencies": {
|
|
134
134
|
"@types/jest": "^30.0.0",
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { isSearchDebugEnabled, searchDebug, searchDebugWarn, searchError } from '../lib/debug'
|
|
2
|
+
|
|
3
|
+
describe('search debug utilities', () => {
|
|
4
|
+
const originalDebugEnv = process.env.OM_SEARCH_DEBUG
|
|
5
|
+
|
|
6
|
+
const restoreDebugEnv = () => {
|
|
7
|
+
if (originalDebugEnv === undefined) {
|
|
8
|
+
delete process.env.OM_SEARCH_DEBUG
|
|
9
|
+
return
|
|
10
|
+
}
|
|
11
|
+
process.env.OM_SEARCH_DEBUG = originalDebugEnv
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
restoreDebugEnv()
|
|
16
|
+
jest.restoreAllMocks()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
restoreDebugEnv()
|
|
21
|
+
jest.restoreAllMocks()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('isSearchDebugEnabled', () => {
|
|
25
|
+
it.each(['1', 'true', 'TRUE', 'Yes', 'on'])('returns true for %s', (value) => {
|
|
26
|
+
process.env.OM_SEARCH_DEBUG = value
|
|
27
|
+
|
|
28
|
+
expect(isSearchDebugEnabled()).toBe(true)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it.each([undefined, '', '0', 'false', 'no', 'off', 'debug'])('returns false for %s', (value) => {
|
|
32
|
+
if (value === undefined) {
|
|
33
|
+
delete process.env.OM_SEARCH_DEBUG
|
|
34
|
+
} else {
|
|
35
|
+
process.env.OM_SEARCH_DEBUG = value
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
expect(isSearchDebugEnabled()).toBe(false)
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('searchDebug', () => {
|
|
43
|
+
it('does not log when debug is disabled', () => {
|
|
44
|
+
delete process.env.OM_SEARCH_DEBUG
|
|
45
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined)
|
|
46
|
+
|
|
47
|
+
searchDebug('search.test', 'suppressed')
|
|
48
|
+
|
|
49
|
+
expect(consoleSpy).not.toHaveBeenCalled()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('logs message and payload when debug is enabled', () => {
|
|
53
|
+
process.env.OM_SEARCH_DEBUG = 'true'
|
|
54
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined)
|
|
55
|
+
const payload = { entityId: 'customers:person', recordId: 'rec-123' }
|
|
56
|
+
|
|
57
|
+
searchDebug('search.test', 'indexed', payload)
|
|
58
|
+
|
|
59
|
+
expect(consoleSpy).toHaveBeenCalledWith('[search.test] indexed', payload)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('logs only the formatted message when payload is omitted', () => {
|
|
63
|
+
process.env.OM_SEARCH_DEBUG = 'true'
|
|
64
|
+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => undefined)
|
|
65
|
+
|
|
66
|
+
searchDebug('search.test', 'indexed')
|
|
67
|
+
|
|
68
|
+
expect(consoleSpy).toHaveBeenCalledWith('[search.test] indexed')
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('searchDebugWarn', () => {
|
|
73
|
+
it('does not warn when debug is disabled', () => {
|
|
74
|
+
process.env.OM_SEARCH_DEBUG = 'false'
|
|
75
|
+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined)
|
|
76
|
+
|
|
77
|
+
searchDebugWarn('search.test', 'suppressed')
|
|
78
|
+
|
|
79
|
+
expect(consoleSpy).not.toHaveBeenCalled()
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('warns with the formatted message and payload when enabled', () => {
|
|
83
|
+
process.env.OM_SEARCH_DEBUG = 'yes'
|
|
84
|
+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined)
|
|
85
|
+
const payload = { queue: 'vector-indexing' }
|
|
86
|
+
|
|
87
|
+
searchDebugWarn('search.test', 'retrying', payload)
|
|
88
|
+
|
|
89
|
+
expect(consoleSpy).toHaveBeenCalledWith('[search.test] retrying', payload)
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('searchError', () => {
|
|
94
|
+
it('always logs errors even when debug is disabled', () => {
|
|
95
|
+
process.env.OM_SEARCH_DEBUG = 'false'
|
|
96
|
+
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => undefined)
|
|
97
|
+
const payload = { error: 'boom' }
|
|
98
|
+
|
|
99
|
+
searchError('search.test', 'failed', payload)
|
|
100
|
+
|
|
101
|
+
expect(consoleSpy).toHaveBeenCalledWith('[search.test] failed', payload)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('logs only the formatted error message when payload is omitted', () => {
|
|
105
|
+
delete process.env.OM_SEARCH_DEBUG
|
|
106
|
+
const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => undefined)
|
|
107
|
+
|
|
108
|
+
searchError('search.test', 'failed')
|
|
109
|
+
|
|
110
|
+
expect(consoleSpy).toHaveBeenCalledWith('[search.test] failed')
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
})
|