Skip to content

Commit 8829f74

Browse files
committed
refactor: add LATEST_VERSION constant in code for global changing latest version on some value.
Change `latest` version on `4.0.3` 😂 cause latest version download with 403 status code. Related #131
1 parent 72445b8 commit 8829f74

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/util/MongoBinary.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import dedent from 'dedent';
1111
import { promisify } from 'util';
1212
import MongoBinaryDownload from './MongoBinaryDownload';
1313

14+
// TODO: return back `latest` version when it will be fixed in MongoDB distro (for now use 4.0.3 😂)
15+
// More details in https://github.com/nodkz/mongodb-memory-server/issues/131
16+
// export const LATEST_VERSION = 'latest';
17+
export const LATEST_VERSION = '4.0.3';
18+
1419
export type MongoBinaryCache = {
1520
[version: string]: string,
1621
};
@@ -122,7 +127,7 @@ export default class MongoBinary {
122127
)),
123128
platform: process.env?.MONGOMS_PLATFORM || os.platform(),
124129
arch: process.env?.MONGOMS_ARCH || os.arch(),
125-
version: process.env?.MONGOMS_VERSION || 'latest',
130+
version: process.env?.MONGOMS_VERSION || LATEST_VERSION,
126131
systemBinary: process.env?.MONGOMS_SYSTEM_BINARY,
127132
debug:
128133
typeof process.env.MONGOMS_DEBUG === 'string'
@@ -155,7 +160,7 @@ export default class MongoBinary {
155160
.split('\n')[0]
156161
.split(' ')[2];
157162

158-
if (version !== 'latest' && version !== binaryVersion) {
163+
if (version !== LATEST_VERSION && version !== binaryVersion) {
159164
// we will log the version number of the system binary and the version requested so the user can see the difference
160165
this.debug(dedent`
161166
MongoMemoryServer: Possible version conflict

src/util/MongoBinaryDownload.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import HttpsProxyAgent from 'https-proxy-agent';
1111
import decompress from 'decompress'; // 💩💩💩 this package does not work with Node@11+Jest+Babel
1212
import MongoBinaryDownloadUrl from './MongoBinaryDownloadUrl';
1313
import type { DebugFn, DebugPropT, DownloadProgressT } from '../types';
14+
import { LATEST_VERSION } from './MongoBinary';
1415

1516
export type MongoBinaryDownloadOpts = {
1617
version: string,
@@ -42,7 +43,7 @@ export default class MongoBinaryDownload {
4243
}: $Shape<MongoBinaryDownloadOpts>) {
4344
this.platform = platform || os.platform();
4445
this.arch = arch || os.arch();
45-
this.version = version || 'latest';
46+
this.version = version || LATEST_VERSION;
4647
this.downloadDir = path.resolve(downloadDir || 'mongodb-download');
4748
if (checkMD5 === undefined) {
4849
this.checkMD5 =

src/util/__tests__/MongoBinary-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import tmp from 'tmp';
44
import fs from 'fs';
55
import os from 'os';
6-
import MongoBinary from '../MongoBinary';
6+
import MongoBinary, { LATEST_VERSION } from '../MongoBinary';
77

88
const MongoBinaryDownload: any = require('../MongoBinaryDownload');
99

@@ -48,7 +48,7 @@ describe('MongoBinary', () => {
4848
describe('getDownloadPath', () => {
4949
it('should download binary and keep it in cache', async () => {
5050
// download
51-
const version = 'latest';
51+
const version = LATEST_VERSION;
5252
const binPath = await MongoBinary.getPath({
5353
downloadDir: tmpDir.name,
5454
version,

src/util/__tests__/MongoInstance-test.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
import tmp from 'tmp';
44
import MongoInstance from '../MongoInstance';
5+
import { LATEST_VERSION } from '../MongoBinary';
56

67
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
78

8-
// TODO: return back `latest` version when it will be fixed in MongoDB distro (for now use 4.0.3 😂)
9-
// more details in https://github.com/nodkz/mongodb-memory-server/issues/131
10-
// const latestVersion = 'latest';
11-
const latestVersion = '4.0.3';
12-
139
let tmpDir;
1410
beforeEach(() => {
1511
tmp.setGracefulCleanup();
@@ -99,7 +95,7 @@ describe('MongoInstance', () => {
9995
it('should start instance on port 27333', async () => {
10096
const mongod = await MongoInstance.run({
10197
instance: { port: 27333, dbPath: tmpDir.name },
102-
binary: { version: latestVersion },
98+
binary: { version: LATEST_VERSION },
10399
});
104100

105101
expect(mongod.getPid()).toBeGreaterThan(0);
@@ -110,13 +106,13 @@ describe('MongoInstance', () => {
110106
it('should throw error if port is busy', async () => {
111107
const mongod = await MongoInstance.run({
112108
instance: { port: 27444, dbPath: tmpDir.name },
113-
binary: { version: latestVersion },
109+
binary: { version: LATEST_VERSION },
114110
});
115111

116112
await expect(
117113
MongoInstance.run({
118114
instance: { port: 27444, dbPath: tmpDir.name },
119-
binary: { version: latestVersion },
115+
binary: { version: LATEST_VERSION },
120116
})
121117
).rejects.toBeDefined();
122118

@@ -126,7 +122,7 @@ describe('MongoInstance', () => {
126122
it('should await while mongo is killed', async () => {
127123
const mongod = await MongoInstance.run({
128124
instance: { port: 27445, dbPath: tmpDir.name },
129-
binary: { version: latestVersion },
125+
binary: { version: LATEST_VERSION },
130126
});
131127
const pid: any = mongod.getPid();
132128
const killerPid: any = mongod.killerProcess.pid;

0 commit comments

Comments
 (0)