Skip to content

Commit

Permalink
Merge pull request #11253 from keymanapp/test/developer/keyboard-info…
Browse files Browse the repository at this point in the history
…-compiler-messages-unit-tests-2

test(developer): keyboard info compiler messages unit tests 2
  • Loading branch information
markcsinclair authored Apr 25, 2024
2 parents 32a8632 + 343a45c commit 4ae7418
Showing 1 changed file with 26 additions and 86 deletions.
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,22 +34,17 @@ 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 sources = {
kmpFilename,
sourcePath: 'release/k/khmer_angkor',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
...KHMER_ANGKOR_SOURCES,
jsFilename,
};

const compiler = new KeyboardInfoCompiler();
assert.isTrue(await compiler.init(callbacks, {sources}));
let result: KeyboardInfoCompilerResult = null;
try {
result = await compiler.run(kmpFilename, null);
result = await compiler.run(KHMER_ANGKOR_KMP, null);
} catch(e) {
callbacks.printMessages();
throw e;
Expand All @@ -61,7 +68,7 @@ describe('KeyboardInfoCompilerMessages', function () {
kmpFilename,
sourcePath: 'release/k/no-kmp',
kpsFilename,
jsFilename: jsFilename,
jsFilename,
forPublishing: true,
};

Expand All @@ -87,27 +94,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 +112,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 +130,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 +145,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 +154,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 +163,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,16 +181,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 sources = {
kmpFilename,
...KHMER_ANGKOR_SOURCES,
sourcePath: 'release/k/invalid-license',
kpsFilename,
jsFilename: jsFilename,
forPublishing: true,
};

const compiler = new KeyboardInfoCompiler();
Expand Down Expand Up @@ -329,7 +269,7 @@ describe('KeyboardInfoCompilerMessages', function () {
kmpFilename,
sourcePath: 'release/k/font-meta-data-is-invalid',
kpsFilename,
jsFilename: jsFilename,
jsFilename,
forPublishing: true,
};

Expand Down

0 comments on commit 4ae7418

Please sign in to comment.