Skip to content

Commit 72c9c15

Browse files
committed
chore(app-registry): use scoped globalAppRegistry in withMockedServices helper
1 parent 20f2bf6 commit 72c9c15

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

packages/compass-home/src/components/home.spec.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const createDataService = () => ({
3939
setName: 'foo',
4040
};
4141
},
42+
configuredKMSProviders() {
43+
return [];
44+
},
4245
on() {},
4346
off() {},
4447
});

packages/databases-collections/src/stores/create-namespace.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import userEvent from '@testing-library/user-event';
1212
import { expect } from 'chai';
1313

14-
describe('DropNamespacePlugin', function () {
14+
describe('CreateNamespacePlugin', function () {
1515
const sandbox = Sinon.createSandbox();
1616
const appRegistry = sandbox.spy(new AppRegistry());
1717
const dataService = {

packages/hadron-app-registry/src/app-registry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ export class AppRegistry {
282282
}
283283

284284
deactivate() {
285-
for (const plugin of Object.values(this.plugins)) {
285+
for (const [name, plugin] of Object.entries(this.plugins)) {
286286
plugin.deactivate?.();
287+
this.deregisterPlugin(name);
287288
}
288289
for (const event of this.eventNames()) {
289290
this.removeAllListeners(event);

packages/hadron-app-registry/src/react-context.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ const debug = createDebug('hadron-app-registry:react');
1414
*/
1515
export const GlobalAppRegistryContext = createContext(globalAppRegistry);
1616

17-
/**
18-
* @internal exported for the mock plugin helper implementation
19-
*/
20-
export const LocalAppRegistryContext = createContext<AppRegistry | null>(null);
17+
const LocalAppRegistryContext = createContext<AppRegistry | null>(null);
2118

2219
type AppRegistryProviderProps =
2320
| {

packages/hadron-app-registry/src/register-plugin.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ import React, { useRef, useState } from 'react';
22
import type { Store as RefluxStore } from 'reflux';
33
import { Provider as ReduxStoreProvider } from 'react-redux';
44
import type { Actions } from './actions';
5-
import {
6-
type Store,
7-
AppRegistry,
8-
isReduxStore,
9-
globalAppRegistry,
10-
} from './app-registry';
5+
import { type Store, AppRegistry, isReduxStore } from './app-registry';
116
import {
127
GlobalAppRegistryContext,
13-
LocalAppRegistryContext,
8+
AppRegistryProvider,
149
useGlobalAppRegistry,
1510
useLocalAppRegistry,
1611
} from './react-context';
@@ -229,8 +224,13 @@ export function registerHadronPlugin<
229224
mocks: Partial<Registries & Services<S>>
230225
): React.FunctionComponent<T> {
231226
const {
232-
globalAppRegistry: _globalAppRegistry,
233-
localAppRegistry: _localAppRegistry,
227+
// In case globalAppRegistry mock is not provided, we use the one
228+
// created in scope so that plugins don't leak their events and
229+
// registered metadata on the globalAppRegistry
230+
globalAppRegistry = new AppRegistry(),
231+
// If localAppRegistry is not explicitly provided, use the passed mock
232+
// for global app registry instead
233+
localAppRegistry = globalAppRegistry,
234234
...mockServices
235235
} = mocks;
236236
const mockServiceLocators = Object.fromEntries(
@@ -241,16 +241,10 @@ export function registerHadronPlugin<
241241
const MockPlugin = registerHadronPlugin(config, mockServiceLocators);
242242
return function MockPluginWithContext(props: T) {
243243
return (
244-
<GlobalAppRegistryContext.Provider
245-
value={_globalAppRegistry ?? globalAppRegistry}
246-
>
247-
<LocalAppRegistryContext.Provider
248-
value={
249-
_localAppRegistry ?? _globalAppRegistry ?? new AppRegistry()
250-
}
251-
>
244+
<GlobalAppRegistryContext.Provider value={globalAppRegistry}>
245+
<AppRegistryProvider localAppRegistry={localAppRegistry}>
252246
<MockPlugin {...(props as any)}></MockPlugin>
253-
</LocalAppRegistryContext.Provider>
247+
</AppRegistryProvider>
254248
</GlobalAppRegistryContext.Provider>
255249
);
256250
};

0 commit comments

Comments
 (0)