Skip to content

Commit 74ad96a

Browse files
committed
refacto: last cleanup of todos and some types
1 parent 14dc24e commit 74ad96a

File tree

7 files changed

+11
-20
lines changed

7 files changed

+11
-20
lines changed

src/MongoMemoryServer.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ChildProcess } from 'child_process';
22
import tmp from 'tmp';
33
import getPort from 'get-port';
4-
// import Debug from 'debug'; // TODO : Do we really need this package ?
54
import { generateDbName } from './util/db_util';
65
import MongoInstance from './util/MongoInstance';
76
import { MongoBinaryOpts } from './util/MongoBinary';
@@ -39,7 +38,6 @@ export interface MongoInstanceDataT {
3938
replSet?: string;
4039
}
4140

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

102100
const instOpts = this.opts.instance;
103101
data.port = await getPort({ port: (instOpts && instOpts.port) || undefined });
104-
/*
105-
this.debug = Debug(`Mongo[${data.port}]`); // TODO: Why do we dont just use this.debug here ?
106-
this.debug.enabled = !!this.opts.debug; // Useful ?
107-
*/
108102
data.dbName = generateDbName(instOpts && instOpts.dbName);
109103
data.uri = await generateConnectionString(data.port, data.dbName);
110104
data.storageEngine = (instOpts && instOpts.storageEngine) || 'ephemeralForTest';
@@ -119,6 +113,7 @@ export default class MongoMemoryServer {
119113
unsafeCleanup: true,
120114
});
121115
data.dbPath = tmpDir.name;
116+
data.tmpDir = tmpDir;
122117
}
123118

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

147141
return data;
148142
}

src/__tests__/replset-test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ describe('single server replset', () => {
3333
expect(dbName).toEqual('static');
3434
});
3535

36-
// TODO: This test provoke an unfinished async operation if MongoMemoryReplSet
37-
// starts regardless of the autostart option
38-
// Maybe should we re think how this functionality is tested by just mocking
39-
// MongoMemoryReplSet.start function
4036
it('should not autostart if autostart: false', async () => {
4137
replSet = new MongoMemoryReplSet({ autoStart: false });
4238
await new Promise((resolve, reject) => {

src/util/MongoBinary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default class MongoBinary {
115115
cwd: new RegExp(`node_modules${path.sep}mongodb-memory-server$`).test(process.cwd())
116116
? path.resolve(process.cwd(), '..', '..')
117117
: process.cwd(),
118-
}) || '', // TODO : path resolve doesnt accept string | null
118+
}) || '',
119119
'mongodb-binaries'
120120
)),
121121
platform: process.env.MONGOMS_PLATFORM || os.platform(),

src/util/MongoBinaryDownload.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface HttpDownloadOptions {
2424
port: string;
2525
path: string;
2626
method: 'GET' | 'POST';
27-
agent: any | undefined; // TODO: fix type by adding declaration file for http-proxy module
27+
agent: HttpsProxyAgent | undefined;
2828
}
2929

3030
export default class MongoBinaryDownload {
@@ -106,9 +106,12 @@ export default class MongoBinaryDownload {
106106
return mongoDBArchive;
107107
}
108108

109-
async makeMD5check(urlForReferenceMD5: string, mongoDBArchive: string): Promise<boolean> {
109+
async makeMD5check(
110+
urlForReferenceMD5: string,
111+
mongoDBArchive: string
112+
): Promise<boolean | undefined> {
110113
if (!this.checkMD5) {
111-
return false; // TODO : why was it return undefined; ?
114+
return undefined;
112115
}
113116
const mongoDBArchiveMd5 = await this.download(urlForReferenceMD5);
114117
const signatureContent = fs.readFileSync(mongoDBArchiveMd5).toString('UTF-8');
@@ -246,7 +249,6 @@ export default class MongoBinaryDownload {
246249
}
247250

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

252254
const now = Date.now();

src/util/__tests__/MongoBinary-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('MongoBinary', () => {
3939
expect(accessSpy).toHaveBeenCalledWith('/usr/local/bin/mongod', expect.any(Function));
4040

4141
accessSpy.mockClear();
42-
delete process.env.MONGOMS_SYSTEM_BINARY; // TODO : needed to add this because it was affecting the rest of the tests
42+
delete process.env.MONGOMS_SYSTEM_BINARY;
4343
});
4444
});
4545

src/util/__tests__/MongoBinaryDownload-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ describe('MongoBinaryDownload', () => {
1111
});
1212

1313
it('checkMD5 attribute can be set via constructor parameter', () => {
14-
// TODO: need to add all these as MongoBinaryDownloadOpts becausing the type is only defined with mandatory fields
1514
expect(new MongoBinaryDownload({ checkMD5: true }).checkMD5).toBe(true);
1615
expect(new MongoBinaryDownload({ checkMD5: false }).checkMD5).toBe(false);
1716
});
@@ -93,6 +92,6 @@ the same as in the reference result`, () => {
9392
const du = new MongoBinaryDownload({});
9493
du.checkMD5 = false;
9594
const result = await du.makeMD5check('', '');
96-
expect(result).toBe(false); // TODO: changed to false
95+
expect(result).toBe(undefined);
9796
});
9897
});

src/util/__tests__/MongoInstance-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('MongodbInstance', () => {
123123
binary: { version: LATEST_VERSION },
124124
});
125125
const pid: any = mongod.getPid();
126-
const killerPid: any = mongod.killerProcess && mongod.killerProcess.pid; // TODO: need to type this var but has a problem of null value in the class
126+
const killerPid: any = mongod.killerProcess && mongod.killerProcess.pid;
127127
expect(pid).toBeGreaterThan(0);
128128
expect(killerPid).toBeGreaterThan(0);
129129

0 commit comments

Comments
 (0)