@afixt/test-utils 2.1.0 → 2.1.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/package.json +1 -1
- package/src/getImageText.js +2 -1
- package/test/getImageText.test.js +18 -6
package/package.json
CHANGED
package/src/getImageText.js
CHANGED
|
@@ -20,7 +20,8 @@ const _internal = {
|
|
|
20
20
|
* @returns {Promise<string|false>} Extracted text if found, otherwise false.
|
|
21
21
|
*/
|
|
22
22
|
async function getImageText(imagePath, options = {}) {
|
|
23
|
-
const { lang = 'eng', logger
|
|
23
|
+
const { lang = 'eng', logger: _logger, ...tesseractOptions } = options;
|
|
24
|
+
const logger = _logger === null ? () => {} : (_logger ?? (m => console.log(m)));
|
|
24
25
|
|
|
25
26
|
try {
|
|
26
27
|
const {
|
|
@@ -121,16 +121,28 @@ describe('getImageText', () => {
|
|
|
121
121
|
);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
it('should
|
|
124
|
+
it('should convert null logger to a no-op function instead of passing null to Tesseract', async () => {
|
|
125
125
|
recognizeSpy.mockResolvedValueOnce({ data: { text: 'hello' } });
|
|
126
126
|
|
|
127
127
|
await getImageText('image.jpg', { logger: null });
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
const callArgs = recognizeSpy.mock.calls[0][2];
|
|
130
|
+
expect(typeof callArgs.logger).toBe('function');
|
|
131
|
+
// Verify it's a no-op (doesn't throw, returns undefined)
|
|
132
|
+
expect(callArgs.logger('test')).toBeUndefined();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should not crash when logger is null', async () => {
|
|
136
|
+
recognizeSpy.mockImplementation((path, lang, opts) => {
|
|
137
|
+
// Simulate Tesseract calling the logger
|
|
138
|
+
if (opts.logger) {
|
|
139
|
+
opts.logger({ status: 'recognizing text' });
|
|
140
|
+
}
|
|
141
|
+
return Promise.resolve({ data: { text: 'hello' } });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const result = await getImageText('image.jpg', { logger: null });
|
|
145
|
+
expect(result).toBe('hello');
|
|
134
146
|
});
|
|
135
147
|
|
|
136
148
|
it('should pass through additional Tesseract options', async () => {
|