spiegel-keyman/developer/src/kmc-package/test/versioning.tests.ts
Marc Durdin 529a49431e maint(developer): make TestCompilerCallbacks usage more consistent and simplify
Simplify usage of `TestCompilerCallbacks` by making it responsible for
the `beforeEach` and `afterEach` incantations itself. There are a couple
of more complex usages of `TestCompilerCallbacks` which have been
excluded from this change on purpose.

Renamed `testCallbacks` to `callbacks` in the one place where it was
different.

Hoist @types/node and @types/mocha because inconsistent versions of
@types/mocha were causing compiler errors with this change.

Also added a cast to `fs.readFileSync` to `Uint8Array` to eliminate
compiler warnings/errors in test files.

Fixes: #15654
Test-bot: skip
2026-03-03 16:44:06 +01:00

75 lines
2.5 KiB
TypeScript

import 'mocha';
import { assert } from 'chai';
import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
import { KmpJsonFile } from '@keymanapp/common-types';
import { KmpCompiler } from '../src/compiler/kmp-compiler.js';
import { unitTestEndpoints } from '../src/compiler/package-version-validator.js';
import { makePathToFixture } from './helpers/index.js';
// This unit test was translated from a Delphi test
// Keyman.Test.System.CompilePackageVersioningTest, but note the difference in
// test results documented below.
describe('package versioning', function () {
const callbacks = new TestCompilerCallbacks(this);
const cases: [string,string][] = [
['test-single-version-1-package', 'test1.kps'],
['test-single-version-2-package', 'test2.kps'],
// The test result for the following two packages has changed in Keyman 17,
// in commit 92c8c6497e987a0583c62c91515884e6e36ece23, to 'shouldPass':
//
// `WARN_KeyboardVersionsDoNotMatchPackageVersion` has been removed, because
// it did not really make sense; if 'FollowKeyboardVersion' is set, it could
// not be raised, and otherwise, the author may wish to have separate
// keyboard + package versions anyway.
['test-version-2-1-mismatch', 'test2-1.kps'],
['test-version-1-2-mismatch', 'test1-2.kps'],
['test-keyboard-1-package-2', 'test-keyboard-1-vs-package-2.kps'],
['test-package-1-keyboard-2', 'test-package-1-vs-keyboard-2.kps'],
];
for(const [ caseTitle, filename ] of cases) {
it(caseTitle, async function () {
const kmpCompiler = new KmpCompiler();
assert.isTrue(await kmpCompiler.init(callbacks, null));
const kpsPath = makePathToFixture('versioning', filename);
const kmpJson: KmpJsonFile.KmpJsonFile = kmpCompiler.transformKpsToKmpObject(kpsPath);
assert.isTrue(kmpJson !== null);
});
}
it('should validate recognized version numbers', function() {
const goodVersions = [
'1.0',
'1',
'1.0.2',
'2.2.3',
'9',
'0',
], badVersions = [
'0001',
'0.1m',
'2.3.4.5',
'1.03.4',
'test',
'1.0-beta',
'',
null,
undefined,
'xxx',
];
for(const v of goodVersions) {
assert.isTrue(unitTestEndpoints.isValidVersionNumber(v), `'${v}' should be recognized as a valid version number`);
}
for(const v of badVersions) {
assert.isFalse(unitTestEndpoints.isValidVersionNumber(v), `'${v}' should be recognized as an invalid version number`);
}
});
});