spiegel-keyman/developer/src/kmc/test/generateLexicalModel.tests.ts
Marc Durdin 724a8ea0f5 maint(developer): cleanup additional TestCompilerCallbacks references
Address a review comment from #15665 and cleanup additional references
that I missed the first time around, along with the `fs.readFileSync`
`Uint8Array` cast.

Follows: #15665
Test-bot: skip
2026-03-05 13:15:43 +01:00

68 lines
2.1 KiB
TypeScript

/*
* Keyman is copyright (C) SIL Global. MIT License.
*/
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import 'mocha';
import { assert } from 'chai';
import { GeneratorOptions, LexicalModelGenerator } from '@keymanapp/kmc-generate';
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
import { unitTestEndpoints } from '../src/commands/generate.js';
import { KeymanTargets } from '@keymanapp/common-types';
describe('generateLexicalModel', function() {
const modelOptions: GeneratorOptions = {
// icon: true,
// id is written by generate functions
id: '',
languageTags: ['en'],
name: 'Sample Model',
outPath: '.',
targets: [KeymanTargets.KeymanTarget.any],
version: '1.0',
author: 'Keyman',
copyright: 'Keyman',
logLevel: 'info',
description: 'Sample Model Test',
};
const callbacks: TestCompilerCallbacks = new TestCompilerCallbacks(this);
let outPath: string = null;
this.beforeEach(function() {
outPath = fs.mkdtempSync(path.join(os.tmpdir(), 'kmc-'));
});
this.afterEach(function() {
if(this.currentTest.isFailed()) {
console.error(`Output kept at ${outPath}`);
} else {
if(outPath) fs.rmSync(outPath, {recursive: true, force: true});
}
outPath = null;
});
it('should generate a lexical model project', async function() {
assert.isTrue(await unitTestEndpoints.doGenerate(
callbacks,
new LexicalModelGenerator(),
{ ...modelOptions, id: 'sample.en.sample', outPath }
));
// Note: we won't test contents of files as this is tested in kmc-generate directly
const files = [
'HISTORY.md', 'LICENSE.md', 'README.md', 'sample.en.sample.kpj',
'source/readme.htm', 'source/sample.en.sample.model.kps', 'source/sample.en.sample.model.ts', 'source/welcome.htm', 'source/wordlist.tsv'
];
for(const file of files) {
const fullPath = path.join(outPath, 'sample.en.sample', file);
assert.isTrue(fs.existsSync(fullPath), `Expected file '${fullPath}' to exist`);
}
});
});