Skip to content

Commit

Permalink
refacto: last cleanup of todos and some types
Browse files Browse the repository at this point in the history
  • Loading branch information
AJRdev committed Mar 9, 2019
1 parent 14dc24e commit 74ad96a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 20 deletions.
8 changes: 1 addition & 7 deletions src/MongoMemoryServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChildProcess } from 'child_process';
import tmp from 'tmp';
import getPort from 'get-port';
// import Debug from 'debug'; // TODO : Do we really need this package ?
import { generateDbName } from './util/db_util';
import MongoInstance from './util/MongoInstance';
import { MongoBinaryOpts } from './util/MongoBinary';
Expand Down Expand Up @@ -39,7 +38,6 @@ export interface MongoInstanceDataT {
replSet?: string;
}

// TODO: do we need to keep this function async ?
const generateConnectionString = async (port: number, dbName: string): Promise<string> => {
return `mongodb://127.0.0.1:${port}/${dbName}`;
};
Expand Down Expand Up @@ -101,10 +99,6 @@ export default class MongoMemoryServer {

const instOpts = this.opts.instance;
data.port = await getPort({ port: (instOpts && instOpts.port) || undefined });
/*
this.debug = Debug(`Mongo[${data.port}]`); // TODO: Why do we dont just use this.debug here ?
this.debug.enabled = !!this.opts.debug; // Useful ?
*/
data.dbName = generateDbName(instOpts && instOpts.dbName);
data.uri = await generateConnectionString(data.port, data.dbName);
data.storageEngine = (instOpts && instOpts.storageEngine) || 'ephemeralForTest';
Expand All @@ -119,6 +113,7 @@ export default class MongoMemoryServer {
unsafeCleanup: true,
});
data.dbPath = tmpDir.name;
data.tmpDir = tmpDir;
}

this.debug(`Starting MongoDB instance with following options: ${JSON.stringify(data)}`);
Expand All @@ -142,7 +137,6 @@ export default class MongoMemoryServer {
});
data.instance = instance;
data.childProcess = instance.childProcess;
// data.tmpDir = tmpDir;

return data;
}
Expand Down
4 changes: 0 additions & 4 deletions src/__tests__/replset-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ describe('single server replset', () => {
expect(dbName).toEqual('static');
});

// TODO: This test provoke an unfinished async operation if MongoMemoryReplSet
// starts regardless of the autostart option
// Maybe should we re think how this functionality is tested by just mocking
// MongoMemoryReplSet.start function
it('should not autostart if autostart: false', async () => {
replSet = new MongoMemoryReplSet({ autoStart: false });
await new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/MongoBinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class MongoBinary {
cwd: new RegExp(`node_modules${path.sep}mongodb-memory-server$`).test(process.cwd())
? path.resolve(process.cwd(), '..', '..')
: process.cwd(),
}) || '', // TODO : path resolve doesnt accept string | null
}) || '',
'mongodb-binaries'
)),
platform: process.env.MONGOMS_PLATFORM || os.platform(),
Expand Down
10 changes: 6 additions & 4 deletions src/util/MongoBinaryDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface HttpDownloadOptions {
port: string;
path: string;
method: 'GET' | 'POST';
agent: any | undefined; // TODO: fix type by adding declaration file for http-proxy module
agent: HttpsProxyAgent | undefined;
}

export default class MongoBinaryDownload {
Expand Down Expand Up @@ -106,9 +106,12 @@ export default class MongoBinaryDownload {
return mongoDBArchive;
}

async makeMD5check(urlForReferenceMD5: string, mongoDBArchive: string): Promise<boolean> {
async makeMD5check(
urlForReferenceMD5: string,
mongoDBArchive: string
): Promise<boolean | undefined> {
if (!this.checkMD5) {
return false; // TODO : why was it return undefined; ?
return undefined;
}
const mongoDBArchiveMd5 = await this.download(urlForReferenceMD5);
const signatureContent = fs.readFileSync(mongoDBArchiveMd5).toString('UTF-8');
Expand Down Expand Up @@ -246,7 +249,6 @@ export default class MongoBinaryDownload {
}

printDownloadProgress(chunk: any): void {
// TODO : chunk type ?
this.dlProgress.current += chunk.length;

const now = Date.now();
Expand Down
2 changes: 1 addition & 1 deletion src/util/__tests__/MongoBinary-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('MongoBinary', () => {
expect(accessSpy).toHaveBeenCalledWith('/usr/local/bin/mongod', expect.any(Function));

accessSpy.mockClear();
delete process.env.MONGOMS_SYSTEM_BINARY; // TODO : needed to add this because it was affecting the rest of the tests
delete process.env.MONGOMS_SYSTEM_BINARY;
});
});

Expand Down
3 changes: 1 addition & 2 deletions src/util/__tests__/MongoBinaryDownload-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('MongoBinaryDownload', () => {
});

it('checkMD5 attribute can be set via constructor parameter', () => {
// TODO: need to add all these as MongoBinaryDownloadOpts becausing the type is only defined with mandatory fields
expect(new MongoBinaryDownload({ checkMD5: true }).checkMD5).toBe(true);
expect(new MongoBinaryDownload({ checkMD5: false }).checkMD5).toBe(false);
});
Expand Down Expand Up @@ -93,6 +92,6 @@ the same as in the reference result`, () => {
const du = new MongoBinaryDownload({});
du.checkMD5 = false;
const result = await du.makeMD5check('', '');
expect(result).toBe(false); // TODO: changed to false
expect(result).toBe(undefined);
});
});
2 changes: 1 addition & 1 deletion src/util/__tests__/MongoInstance-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('MongodbInstance', () => {
binary: { version: LATEST_VERSION },
});
const pid: any = mongod.getPid();
const killerPid: any = mongod.killerProcess && mongod.killerProcess.pid; // TODO: need to type this var but has a problem of null value in the class
const killerPid: any = mongod.killerProcess && mongod.killerProcess.pid;
expect(pid).toBeGreaterThan(0);
expect(killerPid).toBeGreaterThan(0);

Expand Down

0 comments on commit 74ad96a

Please sign in to comment.