@travetto/test
Advanced tools
Comparing version 0.0.31 to 0.0.32
@@ -31,3 +31,3 @@ { | ||
}, | ||
"version": "0.0.31" | ||
"version": "0.0.32" | ||
} |
@@ -20,4 +20,9 @@ import * as fs from 'fs'; | ||
static asyncTimeout(duration?: number) { | ||
return new Promise((_, reject) => setTimeout(() => reject(TIMEOUT), duration || this.timeout).unref()); | ||
static asyncTimeout(duration?: number): [Promise<any>, Function] { | ||
let id: NodeJS.Timer; | ||
const prom = new Promise((_, reject) => { | ||
id = setTimeout(() => reject(TIMEOUT), duration || this.timeout); | ||
id.unref() | ||
}); | ||
return [prom, () => clearTimeout(id)]; | ||
} | ||
@@ -69,3 +74,5 @@ | ||
for (const fn of suite[phase]) { | ||
await Promise.race([this.asyncTimeout(), fn.call(suite.instance)]); | ||
const [timeout, clear] = this.asyncTimeout(); | ||
await Promise.race([timeout, fn.call(suite.instance)]); | ||
clear(); | ||
} | ||
@@ -76,3 +83,3 @@ } catch (error) { | ||
} | ||
const res = await this.generateSuiteError(consumer, suite, phase, error); | ||
const res = await this.generateSuiteError(consumer, suite, `[[${phase}]]`, error); | ||
result.tests.push(res); | ||
@@ -153,5 +160,6 @@ result.fail++; | ||
const timeout = this.asyncTimeout(test.timeout); | ||
const [timeout, clear] = this.asyncTimeout(test.timeout); | ||
const res = await Promise.race([suite.instance[test.methodName](), timeout]); | ||
result.status = 'success'; | ||
clear(); | ||
} catch (err) { | ||
@@ -158,0 +166,0 @@ if (err === TIMEOUT) { |
46450
1330