Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(developer): keyboard info compiler messages unit tests 2 #11253

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ beforeEach(function() {
callbacks.clear();
});

const KHMER_ANGKOR_JS = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js');
const KHMER_ANGKOR_KPS = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const KHMER_ANGKOR_KMP = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');

const KHMER_ANGKOR_SOURCES = {
kmpFilename: KHMER_ANGKOR_KMP,
sourcePath: 'release/k/khmer_angkor',
kpsFilename: KHMER_ANGKOR_KPS,
jsFilename: KHMER_ANGKOR_JS,
forPublishing: true,
};

describe('KeyboardInfoCompilerMessages', function () {
it('should have a valid KeyboardInfoCompilerMessages object', function() {
return verifyCompilerMessagesObject(KeyboardInfoCompilerMessages, CompilerErrorNamespace.KeyboardInfoCompiler);
Expand All @@ -22,14 +34,14 @@ describe('KeyboardInfoCompilerMessages', function () {

it('should generate ERROR_FileDoesNotExist error if .js file does not exist', async function() {
const jsFilename = makePathToFixture('khmer_angkor', 'build', 'xxx.js');
const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');
const kpsFilename = KHMER_ANGKOR_KPS;
const kmpFilename = KHMER_ANGKOR_KMP;

const sources = {
kmpFilename,
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
jsFilename,
forPublishing: true,
};

Expand Down Expand Up @@ -61,7 +73,7 @@ describe('KeyboardInfoCompilerMessages', function () {
kmpFilename,
sourcePath: 'release/k/no-kmp',
kpsFilename,
jsFilename: jsFilename,
jsFilename,
forPublishing: true,
};

Expand All @@ -87,27 +99,15 @@ describe('KeyboardInfoCompilerMessages', function () {
// ERROR_FileDoesNotExist (font file not in package)

it('should generate ERROR_FileDoesNotExist error if font file is missing from package', async function() {
const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js');
const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');

const sources = {
kmpFilename,
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
};

const sources = KHMER_ANGKOR_SOURCES;
const compiler = new KeyboardInfoCompiler();
assert.isTrue(await compiler.init(callbacks, {sources}));
const kmpJsonData: KmpJsonFile.KmpJsonFile = {system: {fileVersion: "7.0", keymanDeveloperVersion: "17.0.204"},
options: {},
files: []}
const source = ["Mondulkiri-R.ttf"]
const result = await compiler['fontSourceToKeyboardInfoFont'](kpsFilename, kmpJsonData, source)
const result = await compiler['fontSourceToKeyboardInfoFont'](KHMER_ANGKOR_KPS, kmpJsonData, source)
assert.isNull(result);

assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist),
`ERROR_FileDoesNotExist not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist).includes(source[0]),
Expand All @@ -117,27 +117,15 @@ describe('KeyboardInfoCompilerMessages', function () {
// ERROR_FileDoesNotExist (font file not on disk)

it('should generate ERROR_FileDoesNotExist error if font file is missing from disk', async function() {
const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js');
const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');

const sources = {
kmpFilename,
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
};

const sources = KHMER_ANGKOR_SOURCES;
const compiler = new KeyboardInfoCompiler();
assert.isTrue(await compiler.init(callbacks, {sources}));
const kmpJsonData: KmpJsonFile.KmpJsonFile = {system: {fileVersion: "7.0", keymanDeveloperVersion: "17.0.204"},
options: {},
files: [{name: "../shared/fonts/khmer/mondulkiri/xxx.ttf", description: "Font not on disk"}]}
const source = ["xxx.ttf"]
const result = await compiler['fontSourceToKeyboardInfoFont'](kpsFilename, kmpJsonData, source)
const result = await compiler['fontSourceToKeyboardInfoFont'](KHMER_ANGKOR_KPS, kmpJsonData, source)
assert.isNull(result);

assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist),
`ERROR_FileDoesNotExist not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_FileDoesNotExist).includes(kmpJsonData.files[0].name),
Expand All @@ -147,24 +135,12 @@ describe('KeyboardInfoCompilerMessages', function () {
// ERROR_LicenseFileIsMissing

it('should generate ERROR_LicenseFileIsMissing error if license file is missing from disk', async function() {
const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js');
const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');

const sources = {
kmpFilename,
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
};

const sources = KHMER_ANGKOR_SOURCES;
const compiler = new KeyboardInfoCompiler();
assert.isTrue(await compiler.init(callbacks, {sources}));
const licenseFilename = makePathToFixture('khmer_angkor', 'xxx.md');
const result = compiler['isLicenseMIT'](licenseFilename)
assert.isFalse(result);

assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_LicenseFileIsMissing),
`ERROR_LicenseFileIsMissing not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_LicenseFileIsMissing).includes(licenseFilename),
Expand All @@ -174,18 +150,7 @@ describe('KeyboardInfoCompilerMessages', function () {
// ERROR_LicenseFileIsDamaged (error on decode)

it('should generate ERROR_LicenseFileIsDamaged error if license file throws error on decode', async function() {
const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js');
const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');

const sources = {
kmpFilename,
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
};

const sources = KHMER_ANGKOR_SOURCES;
const compiler = new KeyboardInfoCompiler();
assert.isTrue(await compiler.init(callbacks, {sources}));
const licenseFilename = makePathToFixture('khmer_angkor', 'LICENSE.md');
Expand All @@ -194,7 +159,6 @@ describe('KeyboardInfoCompilerMessages', function () {
const result = compiler['isLicenseMIT'](licenseFilename)
TextDecoder.prototype.decode = originalDecode
assert.isFalse(result);

assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged),
`ERROR_LicenseFileIsDamaged not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged).includes(licenseFilename),
Expand All @@ -204,27 +168,15 @@ describe('KeyboardInfoCompilerMessages', function () {
// ERROR_LicenseFileIsDamaged (null on decode)

it('should generate ERROR_LicenseFileIsDamaged error if license file returns null on decode', async function() {
const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js');
const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');

const sources = {
kmpFilename,
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
};

const sources = KHMER_ANGKOR_SOURCES;
const compiler = new KeyboardInfoCompiler();
assert.isTrue(await compiler.init(callbacks, {sources}));
const licenseFilename = makePathToFixture('khmer_angkor', 'LICENSE.md');
const originalDecode = TextDecoder.prototype.decode
TextDecoder.prototype.decode = () => { return null }
TextDecoder.prototype.decode = () => null;
const result = compiler['isLicenseMIT'](licenseFilename)
TextDecoder.prototype.decode = originalDecode
assert.isFalse(result);

assert.isTrue(callbacks.hasMessage(KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged),
`ERROR_LicenseFileIsDamaged not generated, instead got: `+JSON.stringify(callbacks.messages,null,2));
assert.isTrue(nodeCompilerMessage(callbacks, KeyboardInfoCompilerMessages.ERROR_LicenseFileIsDamaged).includes(licenseFilename),
Expand All @@ -234,9 +186,9 @@ describe('KeyboardInfoCompilerMessages', function () {
// ERROR_LicenseIsNotValid

it('should generate ERROR_LicenseIsNotValid error if license file is invalid', async function() {
const jsFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.js');
const kpsFilename = makePathToFixture('khmer_angkor', 'source', 'khmer_angkor.kps');
const kmpFilename = makePathToFixture('khmer_angkor', 'build', 'khmer_angkor.kmp');
const jsFilename = KHMER_ANGKOR_JS;
const kpsFilename = KHMER_ANGKOR_KPS;
const kmpFilename = KHMER_ANGKOR_KMP;

const sources = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do this as:

const sources = {
  ...KHMER_ANGKOR_SOURCES,
  sourcePath: 'release/k/invalid-license',
};

here, and above, and that way eliminate a bunch of repeated constants. 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found only a couple of places I could do this; can you spot any more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't spot any more!

kmpFilename,
Expand Down
Loading