fix(common/models): adjusts affected unit tests

This commit is contained in:
jahorton 2020-10-02 15:46:27 +07:00
parent 2ce4d3ba87
commit 07f48bdc19
3 changed files with 33 additions and 1 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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();