Skip to content

Commit 803750a

Browse files
committed
fix(MongoInstance): displaying debug logs only if they were requested
1 parent a5eeeea commit 803750a

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/util/MongoInstance.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface MongodOps {
2828
debug?: DebugPropT;
2929
}
3030

31-
export default class MongodbInstance {
31+
export default class MongoInstance {
3232
static childProcessList: ChildProcess[] = [];
3333
opts: MongodOps;
3434
debug: Function;
@@ -54,13 +54,7 @@ export default class MongodbInstance {
5454
this.opts.binary.debug = this.opts.debug;
5555
}
5656

57-
this.debug = (msg: string): void => {
58-
if (this.opts.instance && this.opts.instance.debug) {
59-
console.log(`Mongo[${this.opts.instance && this.opts.instance.port}]: ${msg}`);
60-
}
61-
};
62-
63-
/*if (this.opts.instance && this.opts.instance.debug) {
57+
if (this.opts.instance && this.opts.instance.debug) {
6458
if (
6559
typeof this.opts.instance.debug === 'function' &&
6660
this.opts.instance.debug.apply &&
@@ -72,10 +66,17 @@ export default class MongodbInstance {
7266
}
7367
} else {
7468
this.debug = () => {};
75-
}*/
69+
}
70+
71+
// add instance's port to debug output
72+
const debugFn = this.debug;
73+
const port = this.opts.instance && this.opts.instance.port;
74+
this.debug = (msg: string): void => {
75+
debugFn(`Mongo[${port}]: ${msg}`);
76+
};
7677
}
7778

78-
static run(opts: MongodOps): Promise<MongodbInstance> {
79+
static run(opts: MongodOps): Promise<MongoInstance> {
7980
const instance = new this(opts);
8081
return instance.run();
8182
}
@@ -95,7 +96,7 @@ export default class MongodbInstance {
9596
return result.concat(args || []);
9697
}
9798

98-
async run(): Promise<MongodbInstance> {
99+
async run(): Promise<MongoInstance> {
99100
const launch = new Promise((resolve, reject) => {
100101
this.instanceReady = () => {
101102
this.isInstanceReady = true;
@@ -117,7 +118,7 @@ export default class MongodbInstance {
117118
return this;
118119
}
119120

120-
async kill(): Promise<MongodbInstance> {
121+
async kill(): Promise<MongoInstance> {
121122
if (this.childProcess && !this.childProcess.killed) {
122123
await new Promise((resolve) => {
123124
if (this.childProcess) {

0 commit comments

Comments
 (0)