diff --git a/common/predictive-text/unit_tests/headless/worker-dummy-integration.js b/common/predictive-text/unit_tests/headless/worker-dummy-integration.js index bea5941d0e..6f6c34d860 100644 --- a/common/predictive-text/unit_tests/headless/worker-dummy-integration.js +++ b/common/predictive-text/unit_tests/headless/worker-dummy-integration.js @@ -14,6 +14,12 @@ describe('LMLayer using dummy model', function () { it('will predict future suggestions', function () { var lmLayer = new LMLayer(capabilities()); + var stripIDs = function(suggestions) { + suggestions.forEach(function(suggestion) { + delete suggestion.id; + }); + } + // We're testing many as asynchronous messages in a row. // this would be cleaner using async/await syntax. // Not done yet, as this test case is a slightly-edited copy of the in-browser version. @@ -25,15 +31,19 @@ describe('LMLayer using dummy model', function () { }).then(function () { return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[0]); return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[1]); return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[2]); return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[3]); lmLayer.shutdown(); return Promise.resolve(); diff --git a/common/predictive-text/unit_tests/headless/worker-predict.js b/common/predictive-text/unit_tests/headless/worker-predict.js index 8f935c7804..c9d7eb42d7 100644 --- a/common/predictive-text/unit_tests/headless/worker-predict.js +++ b/common/predictive-text/unit_tests/headless/worker-predict.js @@ -17,8 +17,20 @@ describe('LMLayerWorker', function () { // Initialize the worker with a model that will produce one suggestion. var fakePostMessage = sinon.fake(); + var filteredFakePostMessage = function(event) { + if(event.message == 'suggestions') { + let suggestions = event.suggestions; + + // Strip any IDs set by the model compositor. + suggestions.forEach(function(suggestion) { + delete suggestion.id; + }); + } + + fakePostMessage(event); + } var context = { - postMessage: fakePostMessage + postMessage: filteredFakePostMessage }; context.importScripts = importScriptsWith(context); diff --git a/common/predictive-text/unit_tests/in_browser/cases/worker-dummy-integration.js b/common/predictive-text/unit_tests/in_browser/cases/worker-dummy-integration.js index 4702709d03..80f0f095f5 100644 --- a/common/predictive-text/unit_tests/in_browser/cases/worker-dummy-integration.js +++ b/common/predictive-text/unit_tests/in_browser/cases/worker-dummy-integration.js @@ -18,6 +18,12 @@ describe('LMLayer using dummy model', function () { // the WebWorker boundary, so we should be generous here. var lmLayer = new LMLayer(helpers.defaultCapabilities); + var stripIDs = function(suggestions) { + suggestions.forEach(function(suggestion) { + delete suggestion.id; + }); + } + // We're testing many as asynchronous messages in a row. // this would be cleaner using async/await syntax, but // alas some of our browsers don't support it. @@ -29,15 +35,19 @@ describe('LMLayer using dummy model', function () { }).then(function () { return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[0]); return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[1]); return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[2]); return lmLayer.predict(zeroTransform(), emptyContext()); }).then(function (suggestions) { + stripIDs(suggestions); assert.deepEqual(suggestions, iGotDistractedByHazel()[3]); lmLayer.shutdown(); return Promise.resolve();