Skip to content
Snippets Groups Projects
Commit eab9b74f authored by Karishma Chadha's avatar Karishma Chadha
Browse files

Fix issue where regular cloud variable messages were throwing uncaught Json...

Fix issue where regular cloud variable messages were throwing uncaught Json parse errors because of a newline being at the end of the message. Add test that fails without the bugfix.
parent b0808743
Branches
Tags
No related merge requests found
......@@ -51,8 +51,10 @@ class CloudProvider {
log.info(`Received websocket message: ${messageString}`);
// Multiple commands can be received, newline separated
messageString.split('\n').forEach(message => {
const parsedData = this.parseMessage(JSON.parse(message));
this.vm.postIOData('cloud', parsedData);
if (message) { // .split can also contain '' in the array it returns
const parsedData = this.parseMessage(JSON.parse(message));
this.vm.postIOData('cloud', parsedData);
}
});
}
......
......@@ -70,6 +70,16 @@ describe('CloudProvider', () => {
expect(vmIOData[0].varUpdate.value).toEqual('value');
});
test('onMessage with newline at the end', () => {
const msg1 = JSON.stringify({
method: 'set',
name: 'name1',
value: 'value'
});
cloudProvider.onMessage({data: `${msg1}\n`});
expect(vmIOData[0].varUpdate.name).toEqual('name1');
});
test('onMessage with multiple commands', () => {
const msg1 = JSON.stringify({
method: 'set',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment