Skip to content

Commit

Permalink
fix: events duplication
Browse files Browse the repository at this point in the history
Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 committed Jun 12, 2024
1 parent 4d699f1 commit 700f084
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/shared/src/messages/MessageProxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ beforeAll(() => {
} as unknown as PodmanDesktopApi;
});

test('init logic should be executing once', () => {
vi.spyOn(webview, 'onDidReceiveMessage');
const rpcExtension = new RpcExtension(webview);
rpcExtension.init();

expect(webview.onDidReceiveMessage).toHaveBeenCalledOnce();
});

test('Test register channel no argument', async () => {
const rpcExtension = new RpcExtension(webview);
rpcExtension.init();
const rpcBrowser = new RpcBrowser(window, api);

rpcExtension.register('ping', () => {
Expand All @@ -65,6 +74,7 @@ test('Test register channel no argument', async () => {

test('Test register channel one argument', async () => {
const rpcExtension = new RpcExtension(webview);
rpcExtension.init();
const rpcBrowser = new RpcBrowser(window, api);

rpcExtension.register('double', (value: number) => {
Expand All @@ -76,6 +86,7 @@ test('Test register channel one argument', async () => {

test('Test register channel multiple arguments', async () => {
const rpcExtension = new RpcExtension(webview);
rpcExtension.init();
const rpcBrowser = new RpcBrowser(window, api);

rpcExtension.register('sum', (...args: number[]) => {
Expand All @@ -93,6 +104,7 @@ test('Test register instance with async', async () => {
}

const rpcExtension = new RpcExtension(webview);
rpcExtension.init();
const rpcBrowser = new RpcBrowser(window, api);

rpcExtension.registerInstance(Dummy, new Dummy());
Expand All @@ -103,6 +115,7 @@ test('Test register instance with async', async () => {

test('Test raising exception', async () => {
const rpcExtension = new RpcExtension(webview);
rpcExtension.init();
const rpcBrowser = new RpcBrowser(window, api);

rpcExtension.register('raiseError', () => {
Expand All @@ -114,6 +127,7 @@ test('Test raising exception', async () => {

test('A noTimeoutChannel should not call the setTimeout', async () => {
const rpcExtension = new RpcExtension(webview);
rpcExtension.init();
const rpcBrowser = new RpcBrowser(window, api);

rpcExtension.register('openDialog', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/shared/src/messages/MessageProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export class RpcExtension implements Disposable {
#webviewDisposable: Disposable | undefined;
methods: Map<string, (...args: unknown[]) => Promise<unknown>> = new Map();

constructor(private webview: Webview) {
this.init();
}
constructor(private webview: Webview) {}

dispose(): void {
this.#webviewDisposable?.dispose();
Expand Down

0 comments on commit 700f084

Please sign in to comment.