Skip to content

Commit

Permalink
fix: replace "get-port" usage with "getport" module
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Jul 14, 2023
1 parent 4d139a2 commit 9bffeea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/mongodb-memory-server-core/src/MongoMemoryServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SpawnOptions } from 'child_process';
import getPort from 'get-port';
import { getFreePort } from './util/getport';
import {
assertion,
generateDbName,
Expand Down Expand Up @@ -343,7 +343,7 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {
* @param port A User defined default port
*/
protected async getNewPort(port?: number): Promise<number> {
const newPort = await getPort({ port });
const newPort = await getFreePort(port);

// only log this message if a custom port was provided
if (port != newPort && typeof port === 'number') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as dbUtil from '../utils';
import MongodbInstance, { MongoInstanceEvents } from '../MongoInstance';
import resolveConfig, { ResolveConfigVariables } from '../resolveConfig';
import getPort from 'get-port';
import { getFreePort } from '../getport';
import {
GenericMMSError,
StartBinaryFailedError,
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('MongodbInstance', () => {
});

it('should start instance on port specific port', async () => {
const gotPort = await getPort({ port: 27333 });
const gotPort = await getFreePort(27333);
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version },
Expand All @@ -167,7 +167,7 @@ describe('MongodbInstance', () => {
});

it('should throw error if port is busy', async () => {
const gotPort = await getPort({ port: 27444 });
const gotPort = await getFreePort(27444);
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version },
Expand All @@ -190,7 +190,7 @@ describe('MongodbInstance', () => {
});

it('should wait until childprocess and killerprocess are killed', async () => {
const gotPort = await getPort({ port: 27445 });
const gotPort = await getFreePort(27445);
const mongod: MongodbInstance = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version },
Expand All @@ -209,7 +209,7 @@ describe('MongodbInstance', () => {

describe('should work with mongodb LTS releases', () => {
it('should work with mongodb 4.0', async () => {
const gotPort = await getPort({ port: 27445 });
const gotPort = await getFreePort(27445);
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version: '4.0.28' }, // explicit version instead of default to not mess it up later
Expand All @@ -219,7 +219,7 @@ describe('MongodbInstance', () => {
});

it('should work with mongodb 4.2', async () => {
const gotPort = await getPort({ port: 27445 });
const gotPort = await getFreePort(27445);
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version: '4.2.23' },
Expand All @@ -229,7 +229,7 @@ describe('MongodbInstance', () => {
});

it('should work with mongodb 4.4', async () => {
const gotPort = await getPort({ port: 27445 });
const gotPort = await getFreePort(27445);
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version: '4.4.22' },
Expand All @@ -239,7 +239,7 @@ describe('MongodbInstance', () => {
});

it('should work with mongodb 5.0', async () => {
const gotPort = await getPort({ port: 27445 });
const gotPort = await getFreePort(27445);
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version: '5.0.18' },
Expand All @@ -249,7 +249,7 @@ describe('MongodbInstance', () => {
});

it('should work with mongodb 6.0', async () => {
const gotPort = await getPort({ port: 27445 });
const gotPort = await getFreePort(27445);
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version: '6.0.6' },
Expand Down Expand Up @@ -682,7 +682,7 @@ describe('MongodbInstance', () => {
});

it('should throw error if instance is already started (#662)', async () => {
const gotPort = await getPort();
const gotPort = await getFreePort();
const mongod = await MongodbInstance.create({
instance: { port: gotPort, dbPath: tmpDir },
binary: { version },
Expand Down

0 comments on commit 9bffeea

Please sign in to comment.