Select Git revision
core_test.go
index.spec.ts 3.90 KiB
import { getOptions } from '../config/options';
import { loadModules } from '../util/modules';
import { isVersioningApiConstructor } from './common';
import { GenericVersion, GenericVersioningApi } from './loose/generic';
import * as semverVersioning from './semver';
import type { VersioningApi, VersioningApiConstructor } from './types';
import * as allVersioning from '.';
const supportedSchemes = getOptions().find(
(option) => option.name === 'versioning'
).allowedValues;
describe('versioning/index', () => {
it('has api', () => {
// FIXME: explicit assert condition
expect(Object.keys(allVersioning.get('semver')).sort()).toMatchSnapshot();
});
it('validates', () => {
function validate(
module: VersioningApi | VersioningApiConstructor,
name: string
): boolean {
// eslint-disable-next-line new-cap
const mod = isVersioningApiConstructor(module) ? new module() : module;
// TODO: test required api (#9715)
if (!mod.isValid || !mod.isVersion) {
throw Error(`Missing api on ${name}`);
}
return true;
}
const vers = allVersioning.getVersionings();
const loadedVers = loadModules(__dirname);
expect(Array.from(vers.keys())).toEqual(Object.keys(loadedVers));
for (const name of vers.keys()) {
const ver = vers.get(name);
expect(validate(ver, name)).toBe(true);
}
});
it('should fallback to semver', () => {
expect(allVersioning.get(undefined)).toBe(
allVersioning.get(semverVersioning.id)
);
expect(allVersioning.get('unknown')).toBe(
allVersioning.get(semverVersioning.id)
);
});
it('should accept config', () => {
expect(allVersioning.get('semver:test')).toBeDefined();
});
describe('should return the same interface', () => {
const optionalFunctions = [
'isLessThanRange',
'valueToVersion',
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'should',
'toLocaleString',
'toString',
'valueOf',
];
const npmApi = Object.keys(allVersioning.get(semverVersioning.id))