Skip to content

Commit 6f30993

Browse files
committed
fix: wrap the bus for hookLogger and tests
Wrapping the bus can allow us to inject onBus onto the logger which can help us prevent logs being created from there. That said, we still have the problem of having to either re-register those hooks each time, so we may want to instead update hookLogger to take function for getting the latest log rather than just a variable.
1 parent c0dd05a commit 6f30993

File tree

2 files changed

+218
-134
lines changed

2 files changed

+218
-134
lines changed

packages/logging/src/logging-and-telemetry.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,29 @@ describe('MongoshLoggingAndTelemetry', function () {
221221
expect(analyticsOutput).to.have.lengthOf(1);
222222
});
223223

224+
it('detaching logger applies to devtools-connect events', function () {
225+
loggingAndTelemetry.setup();
226+
loggingAndTelemetry.attachLogger(logger);
227+
228+
bus.emit('devtools-connect:connect-fail-early');
229+
bus.emit('devtools-connect:connect-fail-early');
230+
231+
expect(logOutput).to.have.lengthOf(2);
232+
// No analytics event attached to this
233+
expect(analyticsOutput).to.have.lengthOf(0);
234+
235+
loggingAndTelemetry.detachLogger();
236+
bus.emit('devtools-connect:connect-fail-early');
237+
238+
expect(logOutput).to.have.lengthOf(2);
239+
expect(analyticsOutput).to.have.lengthOf(0);
240+
241+
loggingAndTelemetry.attachLogger(logger);
242+
243+
bus.emit('devtools-connect:connect-fail-early');
244+
expect(logOutput).to.have.lengthOf(3);
245+
});
246+
224247
it('detaching logger mid-way leads to no logging but persists analytics', function () {
225248
loggingAndTelemetry.setup();
226249
loggingAndTelemetry.attachLogger(logger);

0 commit comments

Comments
 (0)