Skip to content

Commit

Permalink
fix: ensure extension output populates ObjectIds in stream (#657)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pulkitkalra-mdb authored Jan 15, 2024
1 parent 00a875e commit ac1a000
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/language/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
WorkerEvaluate,
MongoClientOptions,
} from '../types/playgroundType';
import util from 'util';

interface EvaluationResult {
printable: any;
Expand Down Expand Up @@ -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);
}),
});
},
});
Expand Down
12 changes: 10 additions & 2 deletions src/test/suite/language/mongoDBService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit ac1a000

Please sign in to comment.