@relaycorp/ws-mock
Advanced tools
Comparing version 2.5.1 to 2.5.2
@@ -5,3 +5,2 @@ "use strict"; | ||
exports.EmitClientErrorAction = exports.ReceiveMessageAction = exports.SendMessageAction = exports.CloseConnectionAction = exports.AcceptConnectionAction = exports.MockServerAction = void 0; | ||
const events_1 = require("events"); | ||
class MockServerAction { | ||
@@ -18,10 +17,4 @@ constructor() { | ||
this._wasRun = true; | ||
// Allow enough time for the client to process any event emitted by the action. We would | ||
// normally use setImmediate(), but we can't rely on timer functions because they may be | ||
// mocked (e.g., `jest.useFakeTimers()`). | ||
await new Promise((resolve) => { | ||
const events = new events_1.EventEmitter(); | ||
events.once('done', resolve); | ||
events.emit('done'); | ||
}); | ||
// Allow enough time for the client to process any event emitted by the action | ||
await waitForSetImmediate(); | ||
} | ||
@@ -83,5 +76,9 @@ } | ||
await mockServer.abort(this.error); | ||
await super.run(mockServer); | ||
} | ||
} | ||
exports.EmitClientErrorAction = EmitClientErrorAction; | ||
function waitForSetImmediate() { | ||
return new Promise((resolve) => setImmediate(resolve)); | ||
} | ||
//# sourceMappingURL=MockServerAction.js.map |
// tslint:disable:max-classes-per-file | ||
import { EventEmitter } from 'events'; | ||
export class MockServerAction { | ||
@@ -12,10 +11,4 @@ // tslint:disable-next-line:readonly-keyword | ||
this._wasRun = true; | ||
// Allow enough time for the client to process any event emitted by the action. We would | ||
// normally use setImmediate(), but we can't rely on timer functions because they may be | ||
// mocked (e.g., `jest.useFakeTimers()`). | ||
await new Promise((resolve) => { | ||
const events = new EventEmitter(); | ||
events.once('done', resolve); | ||
events.emit('done'); | ||
}); | ||
// Allow enough time for the client to process any event emitted by the action | ||
await waitForSetImmediate(); | ||
} | ||
@@ -73,4 +66,8 @@ } | ||
await mockServer.abort(this.error); | ||
await super.run(mockServer); | ||
} | ||
} | ||
function waitForSetImmediate() { | ||
return new Promise((resolve) => setImmediate(resolve)); | ||
} | ||
//# sourceMappingURL=MockServerAction.js.map |
{ | ||
"name": "@relaycorp/ws-mock", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "email": "no-reply@relaycorp.tech", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63393
1091