Skip to content

Commit 7159a97

Browse files
Fix webworker loading and Jest test failures (#75)
* fix: correct webworker loading in Next.js Update check.ts to use proper URL constructor for loading TypeScript webworker file. This resolves NS_ERROR_CORRUPTED_CONTENT error when browser attempts to load non-existent check_webworker.js. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: resolve Jest test failure with webworker import.meta.url - Add fallback to regular fetch when webworker is not available (e.g., in test environment) - Create manual mock for check module to properly handle Jest imports - Prevents 'Cannot use import.meta outside a module' error in tests - Fix async promise executor lint error 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6fd6cb0 commit 7159a97

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

app/_api/horde/__mocks__/check.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { CheckSuccessResponse, CheckErrorResponse } from '../check';
2+
3+
const checkImage = jest.fn<Promise<CheckSuccessResponse | CheckErrorResponse>, [string]>();
4+
5+
export default checkImage;
6+
export type { CheckSuccessResponse, CheckErrorResponse };

app/_api/horde/check.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ let worker: Worker | null = null;
2222

2323
function getWorker() {
2424
if (!worker && typeof Worker !== 'undefined') {
25-
worker = new Worker('./check_webworker.js');
25+
// Check if we're in a test environment
26+
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'test') {
27+
// Return null in test environment to avoid import.meta.url error
28+
return null;
29+
}
30+
worker = new Worker(new URL('./check_webworker.ts', import.meta.url));
2631
}
2732
return worker;
2833
}
@@ -39,7 +44,29 @@ const performCheckUsingWorker = (
3944

4045
const workerInstance = getWorker();
4146
if (!workerInstance) {
42-
reject(new Error('Worker not available'));
47+
// Fallback to regular fetch in test environment
48+
fetch(url, { headers })
49+
.then(response => {
50+
return response.json().then(result => ({
51+
ok: response.ok,
52+
status: response.status,
53+
result
54+
}));
55+
})
56+
.then(({ ok, status, result }) => {
57+
if (ok) {
58+
resolve({ ...result, success: true });
59+
} else {
60+
resolve({
61+
success: false,
62+
statusCode: status,
63+
message: result.message || 'Unknown error'
64+
});
65+
}
66+
})
67+
.catch(error => {
68+
reject(error);
69+
});
4370
return;
4471
}
4572

buildId.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"buildId": "20250702_04.42.10"
2+
"buildId": "20250704_14.21.57"
33
}

0 commit comments

Comments
 (0)