From 6e06694fd6acab185432bccf57bd5c9c3b68f218 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Jan 2023 13:53:24 +0100 Subject: Fix semver comparison --- server/tests/helpers/index.ts | 1 + server/tests/helpers/version.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 server/tests/helpers/version.ts (limited to 'server') diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts index 1b5c6d15b..073ae6455 100644 --- a/server/tests/helpers/index.ts +++ b/server/tests/helpers/index.ts @@ -6,3 +6,4 @@ import './image' import './markdown' import './request' import './validator' +import './version' diff --git a/server/tests/helpers/version.ts b/server/tests/helpers/version.ts new file mode 100644 index 000000000..7d5600715 --- /dev/null +++ b/server/tests/helpers/version.ts @@ -0,0 +1,31 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { compareSemVer } from '@shared/core-utils' + +describe('Version', function () { + + it('Should correctly compare two stable versions', async function () { + expect(compareSemVer('3.4.0', '3.5.0')).to.be.below(0) + expect(compareSemVer('3.5.0', '3.4.0')).to.be.above(0) + + expect(compareSemVer('3.4.0', '4.1.0')).to.be.below(0) + expect(compareSemVer('4.1.0', '3.4.0')).to.be.above(0) + + expect(compareSemVer('3.4.0', '3.4.1')).to.be.below(0) + expect(compareSemVer('3.4.1', '3.4.0')).to.be.above(0) + }) + + it('Should correctly compare two unstable version', async function () { + expect(compareSemVer('3.4.0-alpha', '3.4.0-beta.1')).to.be.below(0) + expect(compareSemVer('3.4.0-alpha.1', '3.4.0-beta.1')).to.be.below(0) + expect(compareSemVer('3.4.0-beta.1', '3.4.0-beta.2')).to.be.below(0) + expect(compareSemVer('3.4.0-beta.1', '3.5.0-alpha.1')).to.be.below(0) + }) + + it('Should correctly compare a stable and unstable versions', async function () { + expect(compareSemVer('3.4.0', '3.4.1-beta.1')).to.be.below(0) + expect(compareSemVer('3.4.0-beta.1', '3.4.0-beta.2')).to.be.below(0) + expect(compareSemVer('3.4.0-beta.1', '3.4.0')).to.be.below(0) + }) +}) -- cgit v1.2.3