Skip to content

Commit

Permalink
Merge pull request #221 from awto/master
Browse files Browse the repository at this point in the history
clearing timeouts in testSupport
  • Loading branch information
roblourens authored Nov 11, 2019
2 parents 01fa3d9 + 3bbc6d2 commit 4eb2ef5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions testSupport/src/debugClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,15 @@ export class DebugClient extends ProtocolClient {
public waitForEvent(eventType: string, timeout?: number): Promise<DebugProtocol.Event> {

timeout = timeout || this.defaultTimeout;
let timeoutHandler: any;

return new Promise((resolve, reject) => {
this.once(eventType, event => {
clearTimeout(timeoutHandler);
resolve(event);
});
if (!this._socket) { // no timeouts if debugging the tests
setTimeout(() => {
timeoutHandler = setTimeout(() => {
reject(new Error(`no event '${eventType}' received after ${timeout} ms`));
}, timeout);
}
Expand Down Expand Up @@ -393,11 +395,13 @@ export class DebugClient extends ProtocolClient {

return new Promise((resolve, reject) => {
let output = '';
let timeoutHandler: any;
this.on('output', event => {
const e = <DebugProtocol.OutputEvent> event;
if (e.body.category === category) {
output += e.body.output;
if (output.indexOf(expected) === 0) {
clearTimeout(timeoutHandler);
resolve(event);
} else if (expected.indexOf(output) !== 0) {
const sanitize = (s: string) => s.toString().replace(/\r/mg, '\\r').replace(/\n/mg, '\\n');
Expand All @@ -406,7 +410,7 @@ export class DebugClient extends ProtocolClient {
}
});
if (!this._socket) { // no timeouts if debugging the tests
setTimeout(() => {
timeoutHandler = setTimeout(() => {
reject(new Error(`not enough output data received after ${timeout} ms`));
}, timeout);
}
Expand Down

0 comments on commit 4eb2ef5

Please sign in to comment.