diff --git a/developer/src/kmc-keyboard-info/test/fixtures/invalid-js-file/build/invalid_js_file.js b/developer/src/kmc-keyboard-info/test/fixtures/invalid-js-file/build/invalid_js_file.js new file mode 100644 index 0000000000..816f909dfa --- /dev/null +++ b/developer/src/kmc-keyboard-info/test/fixtures/invalid-js-file/build/invalid_js_file.js @@ -0,0 +1 @@ +// This is a file used to test the loadJsFile throws error if .js file is invalid error (see keyboard-info-compiler.ts) \ No newline at end of file diff --git a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts index 7cd1ea7a8e..99f860d5b5 100644 --- a/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts +++ b/developer/src/kmc-keyboard-info/test/test-keyboard-info-compiler.ts @@ -319,9 +319,9 @@ describe('keyboard-info-compiler', function () { }); it('check loadKmxFiles can handle two .kmx files', async function() { - const jsFilename = makePathToFixture('two-kmx', 'build', 'two-kmx.js'); - const kpsFilename = makePathToFixture('two-kmx', 'source', 'two-kmx.kps'); - const kmpFilename = makePathToFixture('two-kmx', 'build', 'two-kmx.kmp'); + const jsFilename = makePathToFixture('two-kmx', 'build', 'two_kmx.js'); + const kpsFilename = makePathToFixture('two-kmx', 'source', 'two_kmx.kps'); + const kmpFilename = makePathToFixture('two-kmx', 'build', 'two_kmx.kmp'); const sources = { kmpFilename, @@ -354,4 +354,25 @@ describe('keyboard-info-compiler', function () { assert.isNotNull(kmxFiles[0].data); assert.isNotNull(kmxFiles[1].data); }); + + it('check loadJsFile throws error if .js file is invalid', async function() { + const jsFilename = makePathToFixture('invalid-js-file', 'build', 'invalid_js_file.js'); + const kpsFilename = makePathToFixture('invalid-js-file', 'source', 'invalid_js_file.kps'); + const kmpFilename = makePathToFixture('invalid-js-file', 'build', 'invalid_js_file.kmp'); + + const sources = { + kmpFilename, + sourcePath: 'release/k/invalid-js-file', + kpsFilename, + jsFilename: jsFilename, + forPublishing: true, + }; + + const compiler = new KeyboardInfoCompiler(); + assert.isTrue(await compiler.init(callbacks, {sources})); + const origTextDecoderDecode = TextDecoder.prototype.decode; + TextDecoder.prototype.decode = () => { throw new TypeError(); } + assert.throws(() => compiler['loadJsFile'](jsFilename)); + TextDecoder.prototype.decode = origTextDecoderDecode; + }); });