Skip to content

Commit

Permalink
filter console logs based on app uuid (#204)
Browse files Browse the repository at this point in the history
filter console logs based on app uuid
Signed-off-by: Oana Pleșu <oanaplesu@google.com>
  • Loading branch information
plesuoana committed Aug 25, 2022
1 parent 5396fba commit 68a08d3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/sdk-cli/src/models/LogConsumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ describe('LogConsumer', () => {
companion: componentSourceMaps,
settings: componentSourceMaps,
},
uuid: 'fakeUUID',
} as any;

sourceMapConsumers = {
Expand Down Expand Up @@ -233,6 +234,32 @@ describe('LogConsumer', () => {
});
});

it('processes the log message because uuids match', async () => {
await logConsumer.registerHost(registerAppHostObject);
const testMessage = {
emittedBy: {
uuid: 'fakeUUID',
component: 'app' as ComponentType,
},
};

appHost.emit('consoleMessage', testMessage);
expect(messageFormatter).toBeCalledWith(testMessage);
});

it('discards the log message because uuids do not match', async () => {
await logConsumer.registerHost(registerAppHostObject);
const testMessage = {
emittedBy: {
uuid: 'fakeUUID2',
component: 'app' as ComponentType,
},
};

appHost.emit('consoleMessage', testMessage);
expect(messageFormatter).not.toBeCalledWith(testMessage);
});

it('does not register source maps if an appPackage does not exist', async () => {
appContext.appPackage = undefined;
await logConsumer.registerSourceMaps();
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk-cli/src/models/LogConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export default class LogConsumer {
};

private handleLog = (message: ConsoleMessage) => {
if (
this.componentSourceMapConsumers[message.emittedBy.component] &&
this.appContext.appPackage &&
message.emittedBy.uuid !== this.appContext.appPackage.uuid
) {
return;
}

this.messageFormatter(
sourceMapMessage(message, this.componentSourceMapConsumers),
);
Expand Down

0 comments on commit 68a08d3

Please sign in to comment.