Skip to content

Commit 558f2db

Browse files
odinrCopilot
andcommitted
revert(module-event): remove event mock entry point
The recording/interception mock added in d1a8b58 broke the framework's configurator/provider lifecycle contract: unlike msal's configurator (a disposable builder resolved once during configure), the event module's onDispatch hook is installed directly into the long-lived FrameworkEventDispatcher, so the "configurator" was secretly a permanent runtime component exposed through a pre-init-only accessor (.event) - architecturally inconsistent with every other FrameworkMockConfigurator accessor. Reworking it into a MockEventModuleProvider reached through fusion.modules.event surfaced a simpler question: the real provider already exposes event$ and addEventListener, which is sufficient for "check that expected events are dispatched" with zero test doubles. Recording/interception isn't a gap worth a mock module for - a test subscribes to event$ or registers its own addEventListener the same way application code would. Reverts all files to their state at 340a72f, keeping nothing from the mock feature. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d1a8b58 commit 558f2db

11 files changed

Lines changed: 6 additions & 594 deletions

File tree

.changeset/module-event_mock-entry-point.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/framework/src/__tests__/mock/mock-framework.test.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
22

33
import type { Module } from '@equinor/fusion-framework-module';
44
import { enableMsalMock } from '@equinor/fusion-framework-module-msal/mock';
@@ -171,31 +171,6 @@ describe('FrameworkMockConfigurator', () => {
171171
expect(fusion.modules.http.createClient('my-api')).toBeDefined();
172172
});
173173

174-
it('records every event dispatched through the framework, including onModulesLoaded', async () => {
175-
const configurator = new FrameworkMockConfigurator();
176-
177-
const fusion = await init(configurator);
178-
await fusion.modules.event.dispatchEvent('myFeature', { detail: { id: 1 } });
179-
180-
expect(configurator.event.getEvents('onModulesLoaded')).toHaveLength(1);
181-
expect(configurator.event.lastEvent('myFeature')?.detail).toEqual({ id: 1 });
182-
});
183-
184-
it('lets a test cancel an event before its listeners run', async () => {
185-
const configurator = new FrameworkMockConfigurator();
186-
configurator.event.intercept('myFeature', (event) => event.preventDefault());
187-
188-
const fusion = await init(configurator);
189-
const listener = vi.fn();
190-
fusion.modules.event.addEventListener('myFeature', listener);
191-
await fusion.modules.event.dispatchEvent('myFeature', {
192-
detail: null,
193-
cancelable: true,
194-
});
195-
196-
expect(listener).not.toHaveBeenCalled();
197-
});
198-
199174
it('exposes the same services configurator the services module is built from', () => {
200175
const configurator = new FrameworkMockConfigurator();
201176

packages/framework/src/mock/FrameworkMockConfigurator.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import type { AnyModule } from '@equinor/fusion-framework-module';
33
import contextModule, {
44
type ContextModuleConfigurator,
55
} from '@equinor/fusion-framework-module-context';
6-
import { eventModuleKey } from '@equinor/fusion-framework-module-event';
7-
import {
8-
createEventMockModule,
9-
type EventMockConfigurator,
10-
} from '@equinor/fusion-framework-module-event/mock';
116
import {
127
httpMockModule,
138
type HttpMockConfigurator,
@@ -48,13 +43,10 @@ import { FrameworkConfigurator } from '../FrameworkConfigurator.js';
4843
* are reachable the same way `.msal` is, since their `configure` factories
4944
* take no `ref` and so lose nothing by being pinned early.
5045
*
51-
* `event` is pinned through {@link createEventMockModule} rather than
52-
* {@link _pin}: its `configure` factory reads `ref` to wire bubbling to a
53-
* parent event provider when this configurator is hoisted inside a host
54-
* framework, a decision `_pin` would freeze before any `ref` could be known.
55-
* `.event` still records every dispatched event and lets a test intercept or
56-
* cancel one, so a test never subscribes to `event$` or races
57-
* `addEventListener` against dispatch order just to observe what fired.
46+
* `event` is deliberately not pinned: its `configure` factory reads `ref` to
47+
* wire bubbling to a parent event provider when this configurator is hoisted
48+
* inside a host framework, and pinning would freeze that decision before a
49+
* `ref` could ever be known.
5850
*
5951
* Because this *is* a `FrameworkConfigurator`, every `enableX` helper an
6052
* application already uses accepts it unchanged — including the ones an
@@ -98,12 +90,6 @@ export class FrameworkMockConfigurator<
9890
this._pin(servicesModule);
9991
this._pin(contextModule);
10092
this._pin(telemetryModule);
101-
102-
// `event`'s configure factory needs `ref` at configure time to wire
103-
// bubbling, so it is pinned by hand instead of through `_pin`.
104-
const { configurator: eventConfigurator, module: eventMockModule } = createEventMockModule();
105-
this.#configurators.set(eventMockModule.name, eventConfigurator);
106-
this.addConfig({ module: eventMockModule });
10793
}
10894

10995
/**
@@ -189,20 +175,6 @@ export class FrameworkMockConfigurator<
189175
return this._getConfig<MsalMockConfigurator>(msalMockModule.name);
190176
}
191177

192-
/**
193-
* Records and intercepts every event dispatched through the framework.
194-
*
195-
* @remarks
196-
* The same {@link EventMockConfigurator} the event module is configured
197-
* from, so a change made here — such as canceling an event through
198-
* {@link EventMockConfigurator.intercept} — is what the module sees.
199-
*
200-
* @returns The event mock configurator.
201-
*/
202-
public get event(): EventMockConfigurator {
203-
return this._getConfig<EventMockConfigurator>(eventModuleKey);
204-
}
205-
206178
/**
207179
* Configures the registry services are resolved from.
208180
*

packages/modules/event/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,4 @@ await modules.event.dispatchEvent('myEvent', {
193193
detail: data,
194194
canBubble: false,
195195
});
196-
```
197-
198-
## Testing
199-
200-
Import from `@equinor/fusion-framework-module-event/mock` to record every event dispatched through the framework and intercept or cancel one before its listeners run, instead of subscribing to `event$` or racing `addEventListener` against dispatch order.
201-
202-
See [Testing](docs/testing.md) for `enableEventMock`, `EventMockConfigurator`, and `FrameworkMockConfigurator.event`.
196+
```

packages/modules/event/docs/testing.md

Lines changed: 0 additions & 97 deletions
This file was deleted.

packages/modules/event/package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,12 @@
99
".": {
1010
"import": "./dist/esm/index.js",
1111
"types": "./dist/types/index.d.ts"
12-
},
13-
"./mock": {
14-
"import": "./dist/esm/mock/index.js",
15-
"types": "./dist/types/mock/index.d.ts"
1612
}
1713
},
1814
"typesVersions": {
1915
"*": {
2016
".": [
2117
"dist/types/index.d.ts"
22-
],
23-
"mock": [
24-
"dist/types/mock/index.d.ts"
2518
]
2619
}
2720
},

packages/modules/event/src/__tests__/mock/event-mock.test.ts

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)