Skip to content

Commit

Permalink
refactor(MongoMemoryReplSet): change "_state" to be "protected"
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Oct 12, 2020
1 parent 138e21d commit 415fc8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class MongoMemoryReplSet extends EventEmitter {
replSet: Required<ReplSetOpts>;
};

_state: MongoMemoryReplSetStateEnum = MongoMemoryReplSetStateEnum.stopped;
protected _state: MongoMemoryReplSetStateEnum = MongoMemoryReplSetStateEnum.stopped;

constructor(opts: Partial<MongoMemoryReplSetOptsT> = {}) {
super();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import MongoMemoryReplSet, { MongoMemoryReplSetStateEnum } from '../MongoMemoryReplSet';
import { MongoClient } from 'mongodb';

Expand Down Expand Up @@ -88,8 +89,10 @@ describe('single server replset', () => {
const replSet = new MongoMemoryReplSet();
const spy = jest.spyOn(replSet, 'waitUntilRunning');
// this case can normally happen if "start" is called without await, and "getUri" directly after and that is awaited
// @ts-expect-error
replSet._state = MongoMemoryReplSetStateEnum.init; // artificially set this to init
const promise = replSet.getUri();
// @ts-expect-error
replSet._state = MongoMemoryReplSetStateEnum.stopped; // set it back for "start"
await replSet.start();

Expand All @@ -107,6 +110,7 @@ describe('single server replset', () => {
}, 100);

// this case can normally happen if "start" is called again, without either an error or "stop" happened
// @ts-expect-error
replSet._state = MongoMemoryReplSetStateEnum.running; // artificially set this to running

try {
Expand All @@ -133,6 +137,7 @@ describe('single server replset', () => {
it('"waitUntilRunning" should return if state is "running"', async () => {
const replSet = new MongoMemoryReplSet();
const spy = jest.spyOn(replSet, 'once');
// @ts-expect-error
replSet._state = MongoMemoryReplSetStateEnum.running; // artificially set this to running to not actually have to start an server (test-speedup)

await replSet.waitUntilRunning();
Expand All @@ -147,6 +152,7 @@ describe('single server replset', () => {
}, 100);

// this case can normally happen if "start" is called again, without either an error or "stop" happened
// @ts-expect-error
replSet._state = MongoMemoryReplSetStateEnum.running; // artificially set this to running

try {
Expand All @@ -164,6 +170,7 @@ describe('single server replset', () => {
fail('Timeout - Expected "_initReplSet" to throw');
}, 100);

// @ts-expect-error
replSet._state = MongoMemoryReplSetStateEnum.init; // artificially set this to init

try {
Expand Down

0 comments on commit 415fc8f

Please sign in to comment.