Refactor: move global test helpers to unit_tests/helpers.js.

This commit is contained in:
Eddie Antonio Santos 2019-01-10 14:58:00 -07:00
parent f2b1335c97
commit bf60ea5e6d
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87
5 changed files with 70 additions and 100 deletions

View file

@ -114,33 +114,16 @@ describe('LMLayerWorker', function() {
});
});
/**
* Creates a MessageEvent (for inter-worker communication), with the given data payload.
* @param {*} data
*/
function createMessageEventWithData(data) {
return { data };
}
/**
* Deprecation warning: Soon, models will not be required to be passed as source code;
* when this happens, tests should refrain from sending source code for the model
* parameter.
*/
// TODO: Use dummyModel defined in unit_tests/helpers.js
function dummyModel() {
return 'return {model: {}, configuration: {}}';
}
/**
* Returns reasonable defaults for the default capabilities
* to initialize the LMLayer.
*/
function defaultCapabilities() {
return {
maxLeftContextCodeUnits: 64
};
}
/**
* Returns the last message received in a pretty string format.
* @param {sinon.SinonFake} fakePostMessage

View file

@ -206,41 +206,4 @@ describe('LMLayerWorker dummy model', function() {
futureSuggestions[3]);
});
});
/**
* Capabilities of a keyboard that will ONLY send left-sided capabilities.
* The keyboard does not support deleting to the right.
*
* @returns Capabilities
*/
function defaultCapabilities() {
return {
maxLeftContextCodeUnits: 64,
};
}
/**
* Returns a transform that does nothing.
*
* @returns Transform
*/
function zeroTransform() {
return {
insert: '',
deleteLeft: 0,
};
}
/**
* Returns a context of an empty buffer.
*
* @returns Context
*/
function emptyContext() {
return {
left: '',
startOfBuffer: true,
endOfBuffer: true
};
}
});

View file

@ -48,47 +48,4 @@ describe('LMLayerWorker', function () {
sinon.restore();
});
});
// Helpers (TODO: factor out!)
/**
* Creates a MessageEvent (for inter-worker communication), with the given data payload.
* @param {*} data
*/
function createMessageEventWithData(data) {
return { data };
}
/**
* A valid model that suggests exactly what you want it to suggest.
*/
function dummyModel(futureSuggestions) {
return {
type: 'dummy',
futureSuggestions: futureSuggestions || []
};
}
/**
* Returns reasonable defaults for the default capabilities
* to initialize the LMLayer.
*/
function defaultCapabilities() {
return {
maxLeftContextCodeUnits: 64
};
}
/**
* Context of an empty buffer; no text, at both the start and end of the buffer.
*/
function emptyContext() {
return { left: '', startOfBuffer: true, endOfBuffer: true };
}
/**
* This transform, when applied, makes no changes to the buffer.
*/
function zeroTransform() {
return { insert: '', deleteLeft: 0 };
}
});

View file

@ -0,0 +1,67 @@
/**
* @file helpers
*
* Globally-defined helper functions for use in in Mocha tests.
*/
// Choose the appropriate global object. Either `global` in
// Node, or `window` in browsers.
var _ = global || window;
/**
* Creates a MessageEvent (for inter-worker communication), with the given data payload.
*
* @param {*} data
*/
_.createMessageEventWithData = function createMessageEventWithData(data) {
return { data };
}
/**
* A valid model that suggests exactly what you want it to suggest.
*
* @returns {ModelDescription}
*/
_.dummyModel = function dummyModel(futureSuggestions) {
return {
type: 'dummy',
futureSuggestions: futureSuggestions || []
};
}
/**
* Capabilities of a keyboard that will ONLY send left-sided capabilities.
* The keyboard does not support deleting to the right.
*
* @returns {Capabilities}
*/
_.defaultCapabilities = function defaultCapabilities() {
return {
maxLeftContextCodeUnits: 64
};
}
/**
* Returns the Context of an empty buffer; no text, at both the start and
* end of the buffer.
*
* @returns {Context}
*/
_.emptyContext = function emptyContext() {
return {
left: '',
startOfBuffer: true,
endOfBuffer: true
};
}
/**
* Returns a Transform that, when applied, makes no changes to the buffer.
*
* @returns {Transform}
*/
_.zeroTransform = function zeroTransform() {
return {
insert: '',
deleteLeft: 0,
};
}

View file

@ -45,7 +45,7 @@ test-browsers ( ) {
# Defaults
get_builder_OS # return: os_id="linux"|"mac"|"win"
FLAGS=
FLAGS="--require ./unit_tests/helpers"
CI_REPORTING=0
RUN_HEADLESS=1
RUN_BROWSERS=1
@ -80,4 +80,4 @@ fi
# Run browser-based tests.
if (( RUN_BROWSERS )); then
test-browsers || fail "Browser-based tests failed!"
fi
fi