-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
utils.spec.ts
76 lines (67 loc) · 2 KB
/
utils.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import {
GenericVersioningApi,
GenericVersion,
} from '../../../lib/versioning/loose/generic';
describe('loose/utils', () => {
const optionalFunctions = [
'isLessThanRange',
'valueToVersion',
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'should',
'toLocaleString',
'toString',
'valueOf',
];
function getAllPropertyNames(obj: any): string[] {
const props = [];
let o = obj;
do {
Object.getOwnPropertyNames(o).forEach(prop => {
if (props.indexOf(prop) === -1) {
props.push(prop);
}
});
// eslint-disable-next-line no-cond-assign
} while ((o = Object.getPrototypeOf(o)));
return props;
}
describe('GenericVersioningApi', () => {
class DummyScheme extends GenericVersioningApi {
// eslint-disable-next-line class-methods-use-this
protected _compare(_version: string, _other: string): number {
return _version ? _version.localeCompare(_other) : 0;
}
// eslint-disable-next-line class-methods-use-this
protected _parse(_version: string): GenericVersion {
return _version === 'test' ? null : { release: [1, 0, 0] };
}
}
const api = new DummyScheme();
const schemeKeys = getAllPropertyNames(api)
.filter(val => !optionalFunctions.includes(val) && !val.startsWith('_'))
.filter(
val => !['minSatisfyingVersion', 'maxSatisfyingVersion'].includes(val)
)
.sort();
for (const key of schemeKeys) {
it(`${key}`, () => {
expect(api[key]()).toMatchSnapshot();
});
}
it('getMajor is null', () => {
expect(api.getMajor('test')).toBeNull();
});
it('isLessThanRange', () => {
expect(api.isLessThanRange('', '')).toBeFalsy();
});
it('minSatisfyingVersion', () => {
expect(api.minSatisfyingVersion([''], '')).toBeNull();
});
it('maxSatisfyingVersion', () => {
expect(api.maxSatisfyingVersion([''], '')).toBeNull();
});
});
});