-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle attempt to send response when port is disconnected
- Loading branch information
Showing
3 changed files
with
144 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,83 @@ | ||
import { ChunkedChannel } from './../src/Channels/ChunkedChannel' | ||
import { GenericChannel } from './../src/Channels/GenericChannel' | ||
import { TransportMessage } from './../src/Message' | ||
import { DEFAULT_PARAM } from './../src/Constants' | ||
import { ChunkedChannel } from "./../src/Channels/ChunkedChannel"; | ||
import { GenericChannel } from "./../src/Channels/GenericChannel"; | ||
import { TransportMessage } from "./../src/Message"; | ||
import { DEFAULT_PARAM } from "./../src/Constants"; | ||
|
||
export class TestChannel extends GenericChannel { | ||
public sendSpy = jest.fn(); | ||
|
||
public sendSpy = jest.fn() | ||
public autoReconnectSpy = jest.fn(); | ||
|
||
public autoReconnectSpy = jest.fn() | ||
constructor( | ||
options: { withAutoReconnect: boolean } = { withAutoReconnect: true } | ||
) { | ||
super(); | ||
|
||
constructor() { | ||
super() | ||
if (options.withAutoReconnect) { | ||
this.autoReconnect = () => { | ||
this.callConnected(); | ||
|
||
this.autoReconnectSpy(); | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Allows to inspect calls to Channel.send() by a transport | ||
*/ | ||
|
||
public callConnected() { | ||
this._connected() | ||
this._connected(); | ||
} | ||
|
||
public callDisconnected() { | ||
this._disconnected() | ||
this._disconnected(); | ||
} | ||
|
||
public callMessageReceived() { | ||
this._messageReceived({ | ||
type: 'error', | ||
slotName: 'test', | ||
type: "error", | ||
slotName: "test", | ||
param: DEFAULT_PARAM, | ||
id: '1', | ||
message: 'error' | ||
}) | ||
id: "1", | ||
message: "error", | ||
}); | ||
} | ||
|
||
public callError() { | ||
this._error(new Error('LOLOL')) | ||
this._error(new Error("LOLOL")); | ||
} | ||
|
||
public autoReconnect() { | ||
this.callConnected() | ||
|
||
this.autoReconnectSpy() | ||
} | ||
public autoReconnect?: () => void; | ||
|
||
public send(message: TransportMessage) { | ||
this.sendSpy(message) | ||
this.sendSpy(message); | ||
} | ||
|
||
/** | ||
* Allows to fake reception of messages from the far end | ||
*/ | ||
public fakeReceive(message: TransportMessage) { | ||
this._messageReceived(message) | ||
this._messageReceived(message); | ||
} | ||
|
||
} | ||
|
||
export class TestChunkedChannel extends ChunkedChannel { | ||
public sendSpy = jest.fn() | ||
public dataSpy = jest.fn() | ||
public sendSpy = jest.fn(); | ||
public dataSpy = jest.fn(); | ||
|
||
constructor(chunkSize: number, stringAlloc = -1) { | ||
super({ | ||
chunkSize, | ||
sender: null as any, | ||
maxStringAlloc: stringAlloc | ||
}) | ||
this._sender = m => { | ||
this.sendSpy(m) | ||
this._messageReceived(m) | ||
} | ||
|
||
this.onData(this.dataSpy) | ||
this._connected() | ||
maxStringAlloc: stringAlloc, | ||
}); | ||
this._sender = (m) => { | ||
this.sendSpy(m); | ||
this._messageReceived(m); | ||
}; | ||
|
||
this.onData(this.dataSpy); | ||
this._connected(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters