Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ describe('electing an implementation', () => {
expect(loaded).toEqual(['2.2.0'])
})

it('announces the winner', async () => {
const debug = vi.spyOn(logger, 'debug')
registerImplementation({ version: '2.1.0', load: async () => {} })
registerImplementation({ version: '2.2.0', load: async () => {} })

await loadImplementation()

expect(debug).toHaveBeenCalledWith(
'🗳️ The votes are in: 2.2.0 is elected viewer of this page (2 running: 2.1.0, 2.2.0)',
{ versions: ['2.1.0', '2.2.0'] },
)
debug.mockRestore()
})

it('loads once however many callers ask', async () => {
const load = vi.fn().mockResolvedValue(undefined)
registerImplementation({ version: '2.0.0', load })
Expand Down
2 changes: 2 additions & 0 deletions lib/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export function loadImplementation(): Promise<unknown> {
if (best === undefined) {
throw new Error('No viewer implementation is available on this page')
}
const versions = scope.candidates.map((candidate) => candidate.version)
logger.debug(`🗳️ The votes are in: ${best.version} is elected viewer of this page (${versions.length} running: ${versions.join(', ')})`, { versions })
return best.load()
})().catch((error) => {
// A load that failed is not the answer for the rest of the page's
Expand Down
Loading