Skip to content

Commit 2472ad1

Browse files
test: add unit tests for pusher-js CJS export compat shim
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 7f792e9 commit 2472ad1

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// eslint-disable-next-line node/no-extraneous-import,n/no-extraneous-import
2+
import { describe, expect, it } from '@jest/globals';
3+
4+
/**
5+
* Tests for the pusher-js CJS export compat shim in client-channel-service.
6+
*
7+
* pusher-js@8.5.0 changed its webpack build so the CJS export shape became:
8+
* module.exports.Pusher = PusherClass (8.5.0+)
9+
* instead of the previous:
10+
* module.exports = PusherClass (< 8.5.0)
11+
*
12+
* The shim: `(pusherLib as { Pusher?: T }).Pusher ?? pusherLib`
13+
* must resolve to the constructor in both cases.
14+
*/
15+
describe('Pusher import compat shim', () => {
16+
it('resolves to the constructor when pusher-js exports it directly (< 8.5.0)', () => {
17+
class FakePusher {}
18+
19+
type PusherConstructor = typeof FakePusher;
20+
const pusherLib = FakePusher as unknown as PusherConstructor;
21+
const Pusher = (pusherLib as unknown as { Pusher?: PusherConstructor }).Pusher ?? pusherLib;
22+
23+
expect(Pusher).toBe(FakePusher);
24+
expect(new Pusher()).toBeInstanceOf(FakePusher);
25+
});
26+
27+
it('resolves to the constructor when pusher-js wraps it in an object (>= 8.5.0)', () => {
28+
class FakePusher {}
29+
30+
type PusherConstructor = typeof FakePusher;
31+
const pusherLib = { Pusher: FakePusher } as unknown as PusherConstructor;
32+
const Pusher = (pusherLib as unknown as { Pusher?: PusherConstructor }).Pusher ?? pusherLib;
33+
34+
expect(Pusher).toBe(FakePusher);
35+
expect(new Pusher()).toBeInstanceOf(FakePusher);
36+
});
37+
});

0 commit comments

Comments
 (0)