From ac1a00014377b042ddc4d6a4dfcfd58f7d4faaa9 Mon Sep 17 00:00:00 2001 From: pulkitkalra-mdb <156152710+pulkitkalra-mdb@users.noreply.github.com> Date: Mon, 15 Jan 2024 13:39:57 +1100 Subject: [PATCH] fix: ensure extension output populates ObjectIds in stream (#657) * fix: ensure extension output populates ObjectIds in stream * fix: use util.inspect to get string representation as message payload within the worker * Update mongoDBService.test.ts task: add assertion for objectId to unit test --- src/language/worker.ts | 7 ++++++- src/test/suite/language/mongoDBService.test.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/language/worker.ts b/src/language/worker.ts index 31ee97049..c1c73854a 100644 --- a/src/language/worker.ts +++ b/src/language/worker.ts @@ -9,6 +9,7 @@ import type { WorkerEvaluate, MongoClientOptions, } from '../types/playgroundType'; +import util from 'util'; interface EvaluationResult { printable: any; @@ -57,7 +58,11 @@ const execute = async ( onPrint(values: EvaluationResult[]) { parentPort?.postMessage({ name: ServerCommands.SHOW_CONSOLE_OUTPUT, - payload: values.map((v) => v.printable), + payload: values.map((v) => { + return typeof v.printable === 'string' + ? v.printable + : util.inspect(v.printable); + }), }); }, }); diff --git a/src/test/suite/language/mongoDBService.test.ts b/src/test/suite/language/mongoDBService.test.ts index 9ce0ad064..1b2f06ec4 100644 --- a/src/test/suite/language/mongoDBService.test.ts +++ b/src/test/suite/language/mongoDBService.test.ts @@ -2977,16 +2977,24 @@ suite('MongoDBService Test Suite', () => { test('sends print() and console.log() output continuously', async () => { const source = new CancellationTokenSource(); + const hexString = '65a482edbf4fc24c5255a8fa'; const result = await testMongoDBService.evaluate( { connectionId: 'pineapple', - codeToEvaluate: 'print("Hello"); console.log(1,2,3); 42', + codeToEvaluate: `print("Hello"); console.log(1,2,3); console.log(true); console.log(ObjectId(\'${hexString}\')); 42`, }, source.token ); - const expectedConsoleOutputs = ['Hello', 1, 2, 3]; + const expectedConsoleOutputs = [ + 'Hello', + '1', + '2', + '3', + 'true', + `ObjectId(\'${hexString}\')`, + ]; expect(consoleOutputs).to.deep.equal(expectedConsoleOutputs); const expectedResult = {