-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add eventemitter3 #6823
add eventemitter3 #6823
Changes from all commits
6b95286
97255b3
79a25f2
fb28b3b
334ea0b
0aa37ec
007104e
111bcfb
bb5ac86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,23 +97,6 @@ describe('IPCProvider', () => { | |
expect(end).toHaveBeenCalled(); | ||
}); | ||
|
||
it('connection error', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed connection error test, mock implementation doesn't seem to emit error for this one unit test so i added an integration test to substitute it |
||
const ipc = new IpcProvider(socketPath); | ||
// @ts-expect-error mock method | ||
ipc._socketConnection.connecting = false; | ||
// @ts-expect-error mock method | ||
ipc._connectionStatus = 'disconnected'; | ||
ipc.connect = jest.fn(); | ||
|
||
await expect( | ||
ipc.request({ | ||
jsonrpc: '2.0', | ||
id: 42, | ||
method: 'eth_getBalance', | ||
params: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'], | ||
}), | ||
).rejects.toThrow('Connection not open'); | ||
}); | ||
it('_onCloseHandler autoReconnect=false', () => { | ||
const ipc = new IpcProvider(socketPath, {}, { autoReconnect: false }); | ||
const _clearQueues = jest.fn(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,28 +85,14 @@ describe('WebSocketProvider', () => { | |
ws.disconnect(code, data); | ||
expect(close).toHaveBeenCalledWith(code, data); | ||
}); | ||
it('connection error', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed connection error test, mock implementation doesn't seem to emit error for this one unit test so i added an integration test to substitute it |
||
const ws = new WebSocketProvider('ws://localhost:8545'); | ||
// @ts-expect-error mock method | ||
ws._socketConnection.readyState = 2; | ||
ws.connect = jest.fn(); | ||
|
||
await expect( | ||
ws.request({ | ||
jsonrpc: '2.0', | ||
id: 42, | ||
method: 'eth_getBalance', | ||
params: ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest'], | ||
}), | ||
).rejects.toThrow('Connection not open'); | ||
}); | ||
it('onCloseEvent autoReconnect=false', () => { | ||
const ws = new WebSocketProvider('ws://localhost:8545', {}, { autoReconnect: false }); | ||
const _clearQueues = jest.fn(); | ||
const _removeSocketListeners = jest.fn(); | ||
const _onDisconnect = jest.fn(); | ||
// @ts-expect-error mock method | ||
ws._socketConnection.close = jest.fn(); | ||
|
||
// @ts-expect-error mock method | ||
ws._clearQueues = _clearQueues; | ||
// @ts-expect-error mock method | ||
|
@@ -140,7 +126,7 @@ describe('WebSocketProvider', () => { | |
const ws = new WebSocketProvider('ws://localhost:8545'); | ||
// @ts-expect-error mock method | ||
ws._socketConnection.listeners = () => { | ||
throw new Error('error'); | ||
throw new Error('error'); | ||
}; | ||
const addEventListener = jest.fn(); | ||
// @ts-expect-error mock method | ||
|
@@ -161,6 +147,6 @@ describe('WebSocketProvider', () => { | |
expect(removeEventListener).toHaveBeenCalledWith('open', ws._onOpenHandler); | ||
// @ts-expect-error mock method | ||
expect(removeEventListener).toHaveBeenCalledWith('close', ws._onCloseHandler); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventemitter3 has a circular structure so we use stringify library to parse properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats error for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.