spiegel-keyman/common/models/templates/test/helpers.js
2022-09-06 09:48:52 +07:00

47 lines
1 KiB
JavaScript

const path = require('path');
const assert = require('assert');
var _ = global;
// TODO: move this to its own package; e.g., @keymanapp/models-test-helpers
// TODO: then mocha invocation is as follows:
// TODO: mocha -r @keymanapp/models-test-helpers test/
// Ensure that we can successfully load the module & apply kmwLength, as it's
// needed for some of the unit tests.
require('../build/index.bundled.js');
assert.ok('💩'.kmwLength);
/**
* Load JSON fixtures from a well-known place.
*/
_.jsonFixture = function (name) {
return require(path.join(__dirname, 'fixtures', `${name}.json`));
}
/**
* 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,
};
}