-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathWorkerError.test.js
More file actions
52 lines (40 loc) · 1.81 KB
/
WorkerError.test.js
File metadata and controls
52 lines (40 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import WorkerError from '../src/WorkerError.js';
describe('WorkerError', () => {
it('should create a WorkerError with merged stack trace', () => {
const originalError = new Error('Something went wrong');
originalError.stack = `Error: Something went wrong
at doSomething (worker.js:10:5)
at runWorker (thread.js:20:10)`;
const workerError = new WorkerError(originalError, 3);
expect(workerError).toBeInstanceOf(Error);
expect(workerError.name).toBe('Error');
expect(workerError.message).toBe('Something went wrong');
expect(workerError.stack).toContain('Thread Loader (Worker 3)');
expect(workerError.stack).toContain('doSomething');
});
it('should handle missing err.stack gracefully', () => {
const err = { message: 'No stack here' };
const workerError = new WorkerError(err, 1);
expect(workerError.stack).toContain('Thread Loader (Worker 1)');
expect(workerError.message).toBe('No stack here');
});
it('should handle undefined workerId safely', () => {
const err = new Error('Worker ID missing');
const workerError = new WorkerError(err);
expect(workerError.stack).toContain('Thread Loader (Worker unknown)');
expect(workerError.message).toBe('Worker ID missing');
});
it('should preserve originalError reference', () => {
const err = new Error('Check original');
const workerError = new WorkerError(err, 2);
expect(workerError.originalError).toBe(err);
});
it('should include both worker and origin stack traces when available', () => {
const err = new Error('Test merge');
err.stack = `Error: Test merge
at originFunction (origin.js:5:3)`;
const workerError = new WorkerError(err, 4);
expect(workerError.stack).toMatch(/Thread Loader \(Worker 4\)/);
expect(workerError.stack).toMatch(/originFunction/);
});
});