-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display workerName and processInfoId in the console status bar (#…
…1173) Get optional workerName and processInfoId along with the login options response from the DHE host, display in the console status bar.
- Loading branch information
Showing
9 changed files
with
247 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { | ||
makeMessage, | ||
makeResponse, | ||
Message, | ||
requestParentResponse, | ||
} from './MessageUtils'; | ||
|
||
it('Throws an exception if called on a window without parent', async () => { | ||
await expect(requestParentResponse('request')).rejects.toThrow( | ||
'window.opener is null, unable to send request.' | ||
); | ||
}); | ||
|
||
describe('requestParentResponse', () => { | ||
let addListenerSpy: jest.SpyInstance; | ||
let removeListenerSpy: jest.SpyInstance; | ||
let listenerCallback; | ||
let messageId; | ||
const mockPostMessage = jest.fn((data: Message<unknown>) => { | ||
messageId = data.id; | ||
}); | ||
const originalWindowOpener = window.opener; | ||
beforeEach(() => { | ||
addListenerSpy = jest | ||
.spyOn(window, 'addEventListener') | ||
.mockImplementation((event, cb) => { | ||
listenerCallback = cb; | ||
}); | ||
removeListenerSpy = jest.spyOn(window, 'removeEventListener'); | ||
window.opener = { postMessage: mockPostMessage }; | ||
}); | ||
afterEach(() => { | ||
addListenerSpy.mockRestore(); | ||
removeListenerSpy.mockRestore(); | ||
mockPostMessage.mockClear(); | ||
window.opener = originalWindowOpener; | ||
messageId = undefined; | ||
}); | ||
|
||
it('Posts message to parent and subscribes to response', async () => { | ||
requestParentResponse('request'); | ||
expect(mockPostMessage).toHaveBeenCalledWith( | ||
expect.objectContaining(makeMessage('request', messageId)), | ||
'*' | ||
); | ||
expect(addListenerSpy).toHaveBeenCalledWith( | ||
'message', | ||
expect.any(Function) | ||
); | ||
}); | ||
|
||
it('Resolves with the payload from the parent window response and unsubscribes', async () => { | ||
const PAYLOAD = 'PAYLOAD'; | ||
const promise = requestParentResponse('request'); | ||
listenerCallback({ | ||
data: makeResponse(messageId, PAYLOAD), | ||
}); | ||
const result = await promise; | ||
expect(result).toBe(PAYLOAD); | ||
expect(removeListenerSpy).toHaveBeenCalledWith('message', listenerCallback); | ||
}); | ||
|
||
it('Ignores unrelated response, rejects on timeout', async () => { | ||
jest.useFakeTimers(); | ||
const promise = requestParentResponse('request'); | ||
listenerCallback({ | ||
data: makeMessage('wrong-id'), | ||
}); | ||
jest.runOnlyPendingTimers(); | ||
await expect(promise).rejects.toThrow('Request timed out'); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('Times out if no response', async () => { | ||
jest.useFakeTimers(); | ||
const promise = requestParentResponse('request'); | ||
jest.runOnlyPendingTimers(); | ||
expect(removeListenerSpy).toHaveBeenCalled(); | ||
await expect(promise).rejects.toThrow('Request timed out'); | ||
jest.useRealTimers(); | ||
}); | ||
}); |
Oops, something went wrong.