mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-04 12:07:33 +00:00
Merge pull request #1136 from hedgedoc/fix/getServerVersion
Utils: Fix getServerVersionFromPackageJson
This commit is contained in:
commit
ff27e988a6
2 changed files with 28 additions and 1 deletions
27
src/utils/serverVersion.spec.ts
Normal file
27
src/utils/serverVersion.spec.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import { getServerVersionFromPackageJson } from './serverVersion';
|
||||
|
||||
it('getServerVersionFromPackageJson works', async () => {
|
||||
const major = 2;
|
||||
const minor = 0;
|
||||
const patch = 0;
|
||||
const preRelease = 'dev';
|
||||
/* eslint-disable @typescript-eslint/require-await*/
|
||||
jest.spyOn(fs, 'readFile').mockImplementationOnce(async (_) => {
|
||||
return `{
|
||||
"version": "${major}.${minor}.${patch}"
|
||||
}
|
||||
`;
|
||||
});
|
||||
const serverVersion = await getServerVersionFromPackageJson();
|
||||
expect(serverVersion.major).toEqual(major);
|
||||
expect(serverVersion.minor).toEqual(minor);
|
||||
expect(serverVersion.patch).toEqual(patch);
|
||||
expect(serverVersion.preRelease).toEqual(preRelease);
|
||||
});
|
|
@ -11,7 +11,7 @@ import { join as joinPath } from 'path';
|
|||
let versionCache: ServerVersion;
|
||||
|
||||
export async function getServerVersionFromPackageJson(): Promise<ServerVersion> {
|
||||
if (versionCache === null) {
|
||||
if (versionCache === undefined) {
|
||||
const rawFileContent: string = await fs.readFile(
|
||||
joinPath(__dirname, '../../package.json'),
|
||||
{ encoding: 'utf8' },
|
||||
|
|
Loading…
Reference in a new issue