Skip to content

Commit 4dfa0af

Browse files
committed
test(core): Add tests for isolateTrace functionality
Add unit tests for the new isolateTrace option in withMonitor: - Test isolateTrace: true option acceptance - Test isolateTrace: false maintains default behavior - Test isolateTrace works with async operations
1 parent 382fdc6 commit 4dfa0af

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/core/test/lib/client.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,43 @@ describe('Client', () => {
26002600
const promise = await withMonitor('test-monitor', callback);
26012601
await expect(promise).rejects.toThrowError(error);
26022602
});
2603+
2604+
test('accepts isolateTrace option without error', () => {
2605+
const result = 'foo';
2606+
const callback = vi.fn().mockReturnValue(result);
2607+
2608+
const returnedResult = withMonitor('test-monitor', callback, {
2609+
schedule: { type: 'crontab', value: '* * * * *' },
2610+
isolateTrace: true
2611+
});
2612+
2613+
expect(returnedResult).toBe(result);
2614+
expect(callback).toHaveBeenCalledTimes(1);
2615+
});
2616+
2617+
test('works with isolateTrace set to false', () => {
2618+
const result = 'foo';
2619+
const callback = vi.fn().mockReturnValue(result);
2620+
2621+
const returnedResult = withMonitor('test-monitor', callback, {
2622+
schedule: { type: 'crontab', value: '* * * * *' },
2623+
isolateTrace: false
2624+
});
2625+
2626+
expect(returnedResult).toBe(result);
2627+
expect(callback).toHaveBeenCalledTimes(1);
2628+
});
2629+
2630+
test('handles isolateTrace with asynchronous operations', async () => {
2631+
const result = 'foo';
2632+
const callback = vi.fn().mockResolvedValue(result);
2633+
2634+
const promise = withMonitor('test-monitor', callback, {
2635+
schedule: { type: 'crontab', value: '* * * * *' },
2636+
isolateTrace: true
2637+
});
2638+
await expect(promise).resolves.toEqual(result);
2639+
});
26032640
});
26042641

26052642
describe('log weight-based flushing', () => {

0 commit comments

Comments
 (0)