Fixes with tests

This commit is contained in:
Don Jayamanne 2021-08-24 17:17:48 -07:00
parent 31abc3784e
commit 7bbd66c2d2
2 changed files with 48 additions and 1 deletions

View file

@ -227,7 +227,7 @@ function convertStreamOutput(output: NotebookCellOutput): JupyterOutput {
const outputs: string[] = [];
output.items
.filter((opit) => opit.mime === CellOutputMimeTypes.stderr || opit.mime === CellOutputMimeTypes.stdout)
.map((opit) => convertOutputMimeToJupyterOutput(opit.mime, opit.data as Uint8Array) as string)
.map((opit) => textDecoder.decode(opit.data))
.forEach(value => {
// Ensure each line is a seprate entry in an array (ending with \n).
const lines = value.split('\n');
@ -240,6 +240,11 @@ function convertStreamOutput(output: NotebookCellOutput): JupyterOutput {
outputs.push(line);
}
});
for (let index = 0; index < (outputs.length - 1); index++) {
outputs[index] = `${outputs[index]}\n`;
}
// Skip last one if empty (it's the only one that could be length 0)
if (outputs.length && outputs[outputs.length - 1].length === 0) {
outputs.pop();

View file

@ -106,6 +106,48 @@ suite('ipynb serializer', () => {
]
);
});
test('Stream output and line endings', () => {
validateCellOutputTranslation(
[
{
output_type: 'stream',
name: 'stdout',
text: [
'Line1\n',
'\n',
'Line3\n',
'Line4'
]
}
],
[
new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.stdout('Line1\n\nLine3\nLine4')], {
outputType: 'stream'
})
]
);
validateCellOutputTranslation(
[
{
output_type: 'stream',
name: 'stdout',
text: [
'Hello\n',
'Hello\n',
'Hello\n',
'Hello\n',
'Hello\n',
'Hello\n'
]
}
],
[
new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.stdout('Hello\nHello\nHello\nHello\nHello\nHello\n')], {
outputType: 'stream'
})
]
);
});
test('Multi-line Stream output', () => {
validateCellOutputTranslation(
[