Skip to content

Commit 67cd19f

Browse files
committed
test(): cover with different arguments case
1 parent 1baf710 commit 67cd19f

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

workers/javascript/tests/index.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,72 @@ describe('JavaScript event worker', () => {
374374

375375
await worker.finish();
376376
});
377+
378+
it('should not memoize beautifyBacktrace within several calls with different arguments', async () => {
379+
// Arrange
380+
const worker = new JavascriptEventWorker();
381+
382+
await worker.start();
383+
384+
// Create event with two frames mapping to the same origin file
385+
const workerEvent = {
386+
...createEventMock({ withBacktrace: true }),
387+
} as JavaScriptEventWorkerTask;
388+
389+
workerEvent.payload.backtrace = [
390+
{
391+
file: 'file:///main.js',
392+
line: 1,
393+
column: 100,
394+
},
395+
] as any;
396+
397+
/**
398+
* Worker event with different backtrace
399+
*/
400+
const anotherWorkerEvent = {
401+
...createEventMock({ withBacktrace: true }),
402+
} as JavaScriptEventWorkerTask;
403+
404+
anotherWorkerEvent.payload.backtrace = [
405+
{
406+
file: 'file:///main.js',
407+
line: 10,
408+
column: 14,
409+
},
410+
] as any;
411+
412+
// Create a release with a single map file used by both frames
413+
const singleMapRelease = {
414+
...createReleaseMock({
415+
projectId: workerEvent.projectId,
416+
release: workerEvent.payload.release,
417+
}),
418+
} as any;
419+
const firstFileId = singleMapRelease.files[0]._id;
420+
421+
singleMapRelease.files = [
422+
{
423+
mapFileName: 'main.js.map',
424+
originFileName: 'main.js',
425+
_id: firstFileId,
426+
},
427+
];
428+
429+
await db.collection('releases').insertOne(singleMapRelease);
430+
431+
/**
432+
* Cast prototype to any because getReleaseRecord is ts private
433+
*/
434+
const getReleaseRecordSpy = jest.spyOn(JavascriptEventWorker.prototype as any, 'getReleaseRecord');
435+
436+
// Act
437+
await worker.handle(workerEvent);
438+
await worker.handle(anotherWorkerEvent);
439+
440+
// Assert: Since beautifyBacktrace is now memoized, the entire method should only be called once
441+
expect(getReleaseRecordSpy).toHaveBeenCalledTimes(2);
442+
443+
await worker.finish();
444+
});
377445
});

0 commit comments

Comments
 (0)