Repository navigation
fix: add production build of the websocket plugin to playground #1355
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
Merged
asyncapi-bot
merged 14 commits into
asyncapi:master
from
AceTheCreator:extend-plugin-context
Sep 17, 2026
+940
−1,916
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a8706bd
feat(plugins): extend slot context and lifecycle
AceTheCreator 3e8dcba
fix(plugins): prevent mutations during teardown
AceTheCreator 9fc70d6
fix(plugins): serialize teardown and replacement registration
AceTheCreator 8cb7ec8
Merge branch 'master' of https://github.com/AceTheCreator/asyncapi-re…
AceTheCreator c7a7e57
feat(plugins): add awaitable teardown and cancellation signal
AceTheCreator bb02391
fix: add cancellation feeback from review
AceTheCreator 49197e2
fix: preserve event listener until plugin teardown completes
AceTheCreator aea6d28
fix: wait for uninstalls already in progress before teardown
AceTheCreator 321461f
feat: add ws plugin to playground
AceTheCreator 9e37241
Merge branch 'master' of https://github.com/AceTheCreator/asyncapi-re…
AceTheCreator 0bd10d1
feat: use production build of ws plugin for playground
AceTheCreator a9a5893
fix(playground): address plugin lifecycle and schema feedback
AceTheCreator e615aa7
fix: reset WebSocket plugin when server configuration changes
AceTheCreator 4c2799d
fix: Preserves top-level server declaration order.
AceTheCreator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,146 @@ | ||
| /** | ||
| * @jest-environment jsdom | ||
| */ | ||
|
|
||
| import React, { StrictMode } from 'react'; | ||
| import { render, waitFor } from '@testing-library/react'; | ||
| import AsyncApiComponent from '..'; | ||
| import { AsyncApiPlugin, PluginAPI, PluginSlot } from '../types'; | ||
|
|
||
| jest.mock('use-resize-observer', () => ({ | ||
| __esModule: true, | ||
| useResizeObserver: jest.fn().mockImplementation(() => ({ | ||
| observe: jest.fn(), | ||
| unobserve: jest.fn(), | ||
| disconnect: jest.fn(), | ||
| })), | ||
| })); | ||
| jest.setTimeout(20000); | ||
|
|
||
| const schema = { | ||
| asyncapi: '3.0.0', | ||
| info: { title: 'Strict Mode API', version: '1.0.0' }, | ||
| channels: { | ||
| userSignedUp: { | ||
| address: 'user/signedup', | ||
| messages: { UserSignedUp: { payload: { type: 'string' } } }, | ||
| }, | ||
| }, | ||
| operations: { | ||
| onUserSignedUp: { | ||
| action: 'receive', | ||
| channel: { $ref: '#/channels/userSignedUp' }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const PluginPanel = () => <div data-testid="plugin-panel">panel</div>; | ||
|
|
||
| test('keeps plugins registered when StrictMode remounts the component', async () => { | ||
| const finishUninstalls: (() => void)[] = []; | ||
| let resourceActive = false; | ||
| let lifecycleOverlapped = false; | ||
| const install = jest.fn((api: PluginAPI) => { | ||
| if (resourceActive) lifecycleOverlapped = true; | ||
| resourceActive = true; | ||
| api.registerComponent(PluginSlot.OPERATION, PluginPanel); | ||
| }); | ||
| const uninstall = jest.fn( | ||
| () => | ||
| new Promise<void>((resolve) => { | ||
| finishUninstalls.push(() => { | ||
| resourceActive = false; | ||
| resolve(); | ||
| }); | ||
| }), | ||
| ); | ||
| const plugin: AsyncApiPlugin = { | ||
| name: 'strict-mode-plugin', | ||
| version: '1.0.0', | ||
| install, | ||
| uninstall, | ||
| }; | ||
|
|
||
| const result = render( | ||
| <StrictMode> | ||
| <AsyncApiComponent schema={schema} plugins={[plugin]} /> | ||
| </StrictMode>, | ||
| ); | ||
|
|
||
| await waitFor(() => expect(uninstall).toHaveBeenCalledTimes(1)); | ||
| expect(install).toHaveBeenCalledTimes(1); | ||
|
|
||
| finishUninstalls[0](); | ||
|
|
||
| await waitFor( | ||
| () => { | ||
| expect( | ||
| result.container.querySelector('[data-testid="plugin-panel"]'), | ||
| ).toBeTruthy(); | ||
| }, | ||
| { timeout: 15000 }, | ||
| ); | ||
| expect(install).toHaveBeenCalledTimes(2); | ||
| expect(lifecycleOverlapped).toBe(false); | ||
|
|
||
| result.rerender( | ||
| <StrictMode> | ||
| <AsyncApiComponent schema={schema} plugins={[]} /> | ||
| </StrictMode>, | ||
| ); | ||
| await waitFor(() => expect(uninstall).toHaveBeenCalledTimes(2)); | ||
|
|
||
| result.rerender( | ||
| <StrictMode> | ||
| <AsyncApiComponent schema={schema} plugins={[plugin]} /> | ||
| </StrictMode>, | ||
| ); | ||
| expect(install).toHaveBeenCalledTimes(2); | ||
|
|
||
| finishUninstalls[1](); | ||
| await waitFor(() => expect(install).toHaveBeenCalledTimes(3)); | ||
| expect(lifecycleOverlapped).toBe(false); | ||
|
|
||
| result.unmount(); | ||
| await waitFor(() => expect(uninstall).toHaveBeenCalledTimes(3)); | ||
| finishUninstalls[2](); | ||
| }); | ||
|
|
||
| test('waits for a same-name plugin to uninstall before installing its replacement', async () => { | ||
| let finishUninstall: (() => void) | undefined; | ||
| const firstInstall = jest.fn(); | ||
| const firstUninstall = jest.fn( | ||
| () => | ||
| new Promise<void>((resolve) => { | ||
| finishUninstall = resolve; | ||
| }), | ||
| ); | ||
| const replacementInstall = jest.fn(); | ||
| const firstPlugin: AsyncApiPlugin = { | ||
| name: 'replaceable-plugin', | ||
| version: '1.0.0', | ||
| install: firstInstall, | ||
| uninstall: firstUninstall, | ||
| }; | ||
| const replacementPlugin: AsyncApiPlugin = { | ||
| name: 'replaceable-plugin', | ||
| version: '2.0.0', | ||
| install: replacementInstall, | ||
| }; | ||
|
|
||
| const result = render( | ||
| <AsyncApiComponent schema={schema} plugins={[firstPlugin]} />, | ||
| ); | ||
| await waitFor(() => expect(firstInstall).toHaveBeenCalledTimes(1)); | ||
|
|
||
| result.rerender( | ||
| <AsyncApiComponent schema={schema} plugins={[replacementPlugin]} />, | ||
| ); | ||
| await waitFor(() => expect(firstUninstall).toHaveBeenCalledTimes(1)); | ||
| expect(replacementInstall).not.toHaveBeenCalled(); | ||
|
|
||
| finishUninstall?.(); | ||
| await waitFor(() => expect(replacementInstall).toHaveBeenCalledTimes(1)); | ||
|
|
||
| result.unmount(); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.