@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afixt/test-utils",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Various utilities for accessibility testing",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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 = m => console.log(m), ...tesseractOptions } = options;
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 accept null logger to disable logging', async () => {
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
- expect(recognizeSpy).toHaveBeenCalledWith(
130
- 'image.jpg',
131
- 'eng',
132
- expect.objectContaining({ logger: null })
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 () => {