diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts index 610aa82133a..8a9c2652ba0 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler-messages.ts @@ -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); @@ -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; @@ -61,7 +68,7 @@ describe('KeyboardInfoCompilerMessages', function () { kmpFilename, sourcePath: 'release/k/no-kmp', kpsFilename, - jsFilename: jsFilename, + jsFilename, forPublishing: true, }; @@ -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]), @@ -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), @@ -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), @@ -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'); @@ -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), @@ -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), @@ -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(); @@ -329,7 +269,7 @@ describe('KeyboardInfoCompilerMessages', function () { kmpFilename, sourcePath: 'release/k/font-meta-data-is-invalid', kpsFilename, - jsFilename: jsFilename, + jsFilename, forPublishing: true, };