From 981dc42441977b9587f4f5b5b8291f30dcde0181 Mon Sep 17 00:00:00 2001 From: pulkitkalra-mdb Date: Fri, 12 Jan 2024 15:50:52 +1100 Subject: [PATCH 1/3] fix: ensure extension output populates ObjectIds in stream --- src/language/worker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/language/worker.ts b/src/language/worker.ts index 31ee97049..e524b0d50 100644 --- a/src/language/worker.ts +++ b/src/language/worker.ts @@ -57,7 +57,7 @@ const execute = async ( onPrint(values: EvaluationResult[]) { parentPort?.postMessage({ name: ServerCommands.SHOW_CONSOLE_OUTPUT, - payload: values.map((v) => v.printable), + payload: values.map((v) => JSON.parse(EJSON.stringify(v.printable))), }); }, }); From 9469f446c4d3d3df078776bc773355852eb6c380 Mon Sep 17 00:00:00 2001 From: Pulkit Kalra Date: Mon, 15 Jan 2024 10:59:54 +1100 Subject: [PATCH 2/3] fix: use util.inspect to get string representation as message payload within the worker --- src/language/worker.ts | 7 ++++++- src/test/suite/language/mongoDBService.test.ts | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/language/worker.ts b/src/language/worker.ts index e524b0d50..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) => JSON.parse(EJSON.stringify(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..1b1aabfb2 100644 --- a/src/test/suite/language/mongoDBService.test.ts +++ b/src/test/suite/language/mongoDBService.test.ts @@ -2981,12 +2981,13 @@ suite('MongoDBService Test Suite', () => { 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); 42', }, source.token ); - const expectedConsoleOutputs = ['Hello', 1, 2, 3]; + const expectedConsoleOutputs = ['Hello', '1', '2', '3', 'true']; expect(consoleOutputs).to.deep.equal(expectedConsoleOutputs); const expectedResult = { From 3e0046eb9330c7ad0881ba85529716fab5f6415d Mon Sep 17 00:00:00 2001 From: Pulkit Kalra Date: Mon, 15 Jan 2024 12:16:30 +1100 Subject: [PATCH 3/3] Update mongoDBService.test.ts task: add assertion for objectId to unit test --- src/test/suite/language/mongoDBService.test.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/suite/language/mongoDBService.test.ts b/src/test/suite/language/mongoDBService.test.ts index 1b1aabfb2..1b2f06ec4 100644 --- a/src/test/suite/language/mongoDBService.test.ts +++ b/src/test/suite/language/mongoDBService.test.ts @@ -2977,17 +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); console.log(true); 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', 'true']; + const expectedConsoleOutputs = [ + 'Hello', + '1', + '2', + '3', + 'true', + `ObjectId(\'${hexString}\')`, + ]; expect(consoleOutputs).to.deep.equal(expectedConsoleOutputs); const expectedResult = {