Skip to content

Commit

Permalink
fix: wrap the bus for hookLogger and tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gagik committed Jan 30, 2025
1 parent c0dd05a commit 6f30993
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 134 deletions.
23 changes: 23 additions & 0 deletions packages/logging/src/logging-and-telemetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,29 @@ describe('MongoshLoggingAndTelemetry', function () {
expect(analyticsOutput).to.have.lengthOf(1);
});

it('detaching logger applies to devtools-connect events', function () {
loggingAndTelemetry.setup();
loggingAndTelemetry.attachLogger(logger);

bus.emit('devtools-connect:connect-fail-early');
bus.emit('devtools-connect:connect-fail-early');

expect(logOutput).to.have.lengthOf(2);
// No analytics event attached to this
expect(analyticsOutput).to.have.lengthOf(0);

loggingAndTelemetry.detachLogger();
bus.emit('devtools-connect:connect-fail-early');

expect(logOutput).to.have.lengthOf(2);
expect(analyticsOutput).to.have.lengthOf(0);

loggingAndTelemetry.attachLogger(logger);

bus.emit('devtools-connect:connect-fail-early');
expect(logOutput).to.have.lengthOf(3);
});

it('detaching logger mid-way leads to no logging but persists analytics', function () {
loggingAndTelemetry.setup();
loggingAndTelemetry.attachLogger(logger);
Expand Down
Loading

0 comments on commit 6f30993

Please sign in to comment.