Skip to content

Commit ac1a000

Browse files
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
1 parent 00a875e commit ac1a000

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/language/worker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
WorkerEvaluate,
1010
MongoClientOptions,
1111
} from '../types/playgroundType';
12+
import util from 'util';
1213

1314
interface EvaluationResult {
1415
printable: any;
@@ -57,7 +58,11 @@ const execute = async (
5758
onPrint(values: EvaluationResult[]) {
5859
parentPort?.postMessage({
5960
name: ServerCommands.SHOW_CONSOLE_OUTPUT,
60-
payload: values.map((v) => v.printable),
61+
payload: values.map((v) => {
62+
return typeof v.printable === 'string'
63+
? v.printable
64+
: util.inspect(v.printable);
65+
}),
6166
});
6267
},
6368
});

src/test/suite/language/mongoDBService.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2977,16 +2977,24 @@ suite('MongoDBService Test Suite', () => {
29772977

29782978
test('sends print() and console.log() output continuously', async () => {
29792979
const source = new CancellationTokenSource();
2980+
const hexString = '65a482edbf4fc24c5255a8fa';
29802981

29812982
const result = await testMongoDBService.evaluate(
29822983
{
29832984
connectionId: 'pineapple',
2984-
codeToEvaluate: 'print("Hello"); console.log(1,2,3); 42',
2985+
codeToEvaluate: `print("Hello"); console.log(1,2,3); console.log(true); console.log(ObjectId(\'${hexString}\')); 42`,
29852986
},
29862987
source.token
29872988
);
29882989

2989-
const expectedConsoleOutputs = ['Hello', 1, 2, 3];
2990+
const expectedConsoleOutputs = [
2991+
'Hello',
2992+
'1',
2993+
'2',
2994+
'3',
2995+
'true',
2996+
`ObjectId(\'${hexString}\')`,
2997+
];
29902998
expect(consoleOutputs).to.deep.equal(expectedConsoleOutputs);
29912999

29923000
const expectedResult = {

0 commit comments

Comments
 (0)