version.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { SemVersion, isVersionGtOrEq } from 'app/core/utils/version';
  2. describe('SemVersion', () => {
  3. let version = '1.0.0-alpha.1';
  4. describe('parsing', () => {
  5. it('should parse version properly', () => {
  6. const semver = new SemVersion(version);
  7. expect(semver.major).toBe(1);
  8. expect(semver.minor).toBe(0);
  9. expect(semver.patch).toBe(0);
  10. expect(semver.meta).toBe('alpha.1');
  11. });
  12. });
  13. describe('comparing', () => {
  14. beforeEach(() => {
  15. version = '3.4.5';
  16. });
  17. it('should detect greater version properly', () => {
  18. const semver = new SemVersion(version);
  19. const cases = [
  20. { value: '3.4.5', expected: true },
  21. { value: '3.4.4', expected: true },
  22. { value: '3.4.6', expected: false },
  23. { value: '4', expected: false },
  24. { value: '3.5', expected: false },
  25. ];
  26. cases.forEach((testCase) => {
  27. expect(semver.isGtOrEq(testCase.value)).toBe(testCase.expected);
  28. });
  29. });
  30. });
  31. describe('isVersionGtOrEq', () => {
  32. it('should compare versions properly (a >= b)', () => {
  33. const cases = [
  34. { values: ['3.4.5', '3.4.5'], expected: true },
  35. { values: ['3.4.5', '3.4.4'], expected: true },
  36. { values: ['3.4.5', '3.4.6'], expected: false },
  37. { values: ['3.4', '3.4.0'], expected: true },
  38. { values: ['3', '3.0.0'], expected: true },
  39. { values: ['3.1.1-beta1', '3.1'], expected: true },
  40. { values: ['3.4.5', '4'], expected: false },
  41. { values: ['3.4.5', '3.5'], expected: false },
  42. { values: ['6.0.0', '5.2.0'], expected: true },
  43. ];
  44. cases.forEach((testCase) => {
  45. expect(isVersionGtOrEq(testCase.values[0], testCase.values[1])).toBe(testCase.expected);
  46. });
  47. });
  48. });
  49. });