mongodb-memory-server 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -156,9 +156,7 @@ class MongoMemoryReplSet extends _events.default.EventEmitter {
156
156
  throw new Error(`Already in 'init' or 'running' state. Use opts.debug = true for more info.`);
157
157
  }
158
158
 
159
- _this4._state = 'init';
160
-
161
- _this4.emit('state', 'init');
159
+ _this4.emit(_this4._state = 'init');
162
160
 
163
161
  _this4.debug('init'); // Any servers defined within `opts.instanceOpts` should be started first as
164
162
  // the user could have specified a `dbPath` in which case we would want to perform
@@ -197,10 +195,15 @@ class MongoMemoryReplSet extends _events.default.EventEmitter {
197
195
  if (_this5._state === 'stopped') return false;
198
196
  const servers = _this5.servers;
199
197
  _this5.servers = [];
200
- _this5._state = 'stopped';
201
- return Promise.all(servers.map(s => s.stop())).then(() => true).catch(err => {
198
+ return Promise.all(servers.map(s => s.stop())).then(() => {
199
+ _this5.emit(_this5._state = 'stopped');
200
+
201
+ return true;
202
+ }).catch(err => {
202
203
  _this5.debug(err);
203
204
 
205
+ _this5.emit(_this5._state = 'stopped', err);
206
+
204
207
  return false;
205
208
  });
206
209
  })();
@@ -211,7 +214,7 @@ class MongoMemoryReplSet extends _events.default.EventEmitter {
211
214
 
212
215
  return _asyncToGenerator(function* () {
213
216
  if (_this6._state === 'running') return;
214
- yield new Promise(resolve => _this6.on('state', state => state === 'running' && resolve()));
217
+ yield new Promise(resolve => _this6.once('running', () => resolve()));
215
218
  })();
216
219
  }
217
220
  /**
@@ -257,9 +260,8 @@ class MongoMemoryReplSet extends _events.default.EventEmitter {
257
260
  _this7.debug('Waiting for replica set to have a PRIMARY member.');
258
261
 
259
262
  yield _this7._waitForPrimary(admin);
260
- _this7._state = 'running';
261
263
 
262
- _this7.emit('state', 'running');
264
+ _this7.emit(_this7._state = 'running');
263
265
 
264
266
  _this7.debug('running');
265
267
  } finally {
@@ -148,8 +148,7 @@ export default class MongoMemoryReplSet extends events.EventEmitter {
148
148
  if (this._state !== 'stopped') {
149
149
  throw new Error(`Already in 'init' or 'running' state. Use opts.debug = true for more info.`);
150
150
  }
151
- this._state = 'init';
152
- this.emit('state', 'init');
151
+ this.emit((this._state = 'init'));
153
152
  this.debug('init');
154
153
  // Any servers defined within `opts.instanceOpts` should be started first as
155
154
  // the user could have specified a `dbPath` in which case we would want to perform
@@ -176,18 +175,21 @@ export default class MongoMemoryReplSet extends events.EventEmitter {
176
175
  if (this._state === 'stopped') return false;
177
176
  const servers = this.servers;
178
177
  this.servers = [];
179
- this._state = 'stopped';
180
178
  return Promise.all(servers.map(s => s.stop()))
181
- .then(() => true)
179
+ .then(() => {
180
+ this.emit((this._state = 'stopped'));
181
+ return true;
182
+ })
182
183
  .catch(err => {
183
184
  this.debug(err);
185
+ this.emit((this._state = 'stopped'), err);
184
186
  return false;
185
187
  });
186
188
  }
187
189
 
188
190
  async waitUntilRunning() {
189
191
  if (this._state === 'running') return;
190
- await new Promise(resolve => this.on('state', state => state === 'running' && resolve()));
192
+ await new Promise(resolve => this.once('running', () => resolve()));
191
193
  }
192
194
 
193
195
  /**
@@ -218,8 +220,7 @@ export default class MongoMemoryReplSet extends events.EventEmitter {
218
220
  await admin.command({ replSetInitiate: rsConfig });
219
221
  this.debug('Waiting for replica set to have a PRIMARY member.');
220
222
  await this._waitForPrimary(admin);
221
- this._state = 'running';
222
- this.emit('state', 'running');
223
+ this.emit((this._state = 'running'));
223
224
  this.debug('running');
224
225
  } finally {
225
226
  await conn.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb-memory-server",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "In-memory MongoDB Server. Designed with testing in mind, the server will allow you to connect your favourite ODM or client library to the MongoDB Server and run integration tests isolated from each other.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",