Skip to content

Commit bb5d3e9

Browse files
committed
Add failing test
1 parent fe76a28 commit bb5d3e9

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

packages/cloudflare/test/durableobject.test.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,43 @@ describe('instrumentDurableObjectWithSentry', () => {
88
afterEach(() => {
99
vi.restoreAllMocks();
1010
});
11+
1112
it('Generic functionality', () => {
1213
const options = vi.fn();
1314
const instrumented = instrumentDurableObjectWithSentry(options, vi.fn());
1415
expect(instrumented).toBeTypeOf('function');
1516
expect(() => Reflect.construct(instrumented, [])).not.toThrow();
1617
expect(options).toHaveBeenCalledOnce();
1718
});
18-
it('Instruments prototype methods and defines implementation in the object', () => {
19+
20+
it('Instruments sync prototype methods and defines implementation in the object', () => {
1921
const testClass = class {
20-
method() {}
22+
method() {
23+
return 'sync-result';
24+
}
2125
};
2226
const obj = Reflect.construct(instrumentDurableObjectWithSentry(vi.fn(), testClass as any), []) as any;
2327
expect(obj.method).toBe(obj.method);
28+
29+
const result = obj.method();
30+
expect(result).not.toBeInstanceOf(Promise);
31+
expect(result).toEqual('sync-result');
2432
});
33+
34+
it('Instruments async prototype methods and returns a promise', async () => {
35+
const testClass = class {
36+
async asyncMethod() {
37+
return 'async-result';
38+
}
39+
};
40+
const obj = Reflect.construct(instrumentDurableObjectWithSentry(vi.fn(), testClass as any), []) as any;
41+
expect(obj.asyncMethod).toBe(obj.asyncMethod);
42+
43+
const result = obj.asyncMethod();
44+
expect(result).toBeInstanceOf(Promise);
45+
expect(await result).toBe('async-result');
46+
});
47+
2548
it('Instruments prototype methods without "sticking" to the options', () => {
2649
const initCore = vi.spyOn(SentryCore, 'initAndBind');
2750
vi.spyOn(SentryCore, 'getClient').mockReturnValue(undefined);
@@ -41,6 +64,7 @@ describe('instrumentDurableObjectWithSentry', () => {
4164
expect(initCore).nthCalledWith(1, expect.any(Function), expect.objectContaining({ orgId: 1 }));
4265
expect(initCore).nthCalledWith(2, expect.any(Function), expect.objectContaining({ orgId: 2 }));
4366
});
67+
4468
it('All available durable object methods are instrumented', () => {
4569
const testClass = class {
4670
propertyFunction = vi.fn();
@@ -72,6 +96,7 @@ describe('instrumentDurableObjectWithSentry', () => {
7296
expect(isInstrumented((obj as any)[method_name]), `Method ${method_name} is instrumented`).toBeTruthy();
7397
}
7498
});
99+
75100
it('flush performs after all waitUntil promises are finished', async () => {
76101
vi.useFakeTimers();
77102
onTestFinished(() => {

0 commit comments

Comments
 (0)