(testInfo: TestInfoEntry, recursiveIndex: number, testTimeout?: number)
| 84 | const defaultTimeout = 5000; |
| 85 | |
| 86 | function runAsync(testInfo: TestInfoEntry, recursiveIndex: number, testTimeout?: number) { |
| 87 | let error; |
| 88 | let isDone = false; |
| 89 | let handle; |
| 90 | const testStartTime = time(); |
| 91 | //write("--- [" + testInfo.testName + "] Started at: " + testStartTime, Trace.messageType.info); |
| 92 | const doneCallback = (e: Error) => { |
| 93 | if (e) { |
| 94 | error = e; |
| 95 | } else { |
| 96 | isDone = true; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | const timeout = testTimeout || testInfo.testTimeout || defaultTimeout; |
| 101 | |
| 102 | let duration; |
| 103 | const checkFinished = () => { |
| 104 | duration = time() - testStartTime; |
| 105 | testInfo.duration = duration; |
| 106 | if (isDone) { |
| 107 | write(`--- [${testInfo.testName}] OK, duration: ${duration.toFixed(2)}`, Trace.messageType.info); |
| 108 | testInfo.isPassed = true; |
| 109 | runTests(testsQueue, recursiveIndex + 1); |
| 110 | } else if (error) { |
| 111 | write(`--- [${testInfo.testName}] FAILED: ${error.message}, duration: ${duration.toFixed(2)}`, Trace.messageType.error); |
| 112 | testInfo.errorMessage = error.message; |
| 113 | runTests(testsQueue, recursiveIndex + 1); |
| 114 | } else { |
| 115 | const testEndTime = time(); |
| 116 | if (testEndTime - testStartTime > timeout) { |
| 117 | write(`--- [${testInfo.testName}] TIMEOUT, duration: ${duration.toFixed(2)}`, Trace.messageType.error); |
| 118 | testInfo.errorMessage = 'Test timeout.'; |
| 119 | runTests(testsQueue, recursiveIndex + 1); |
| 120 | } else { |
| 121 | setTimeout(checkFinished, 20); |
| 122 | } |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | try { |
| 127 | if (testInfo.instance) { |
| 128 | testInfo.testFunc.apply(testInfo.instance, [doneCallback]); |
| 129 | } else { |
| 130 | const func: any = testInfo.testFunc; |
| 131 | func(doneCallback); |
| 132 | } |
| 133 | } catch (e) { |
| 134 | doneCallback(e); |
| 135 | } |
| 136 | |
| 137 | setTimeout(checkFinished, 20); |
| 138 | } |
| 139 | |
| 140 | export function runTests(tests: Array<TestInfoEntry>, recursiveIndex) { |
| 141 | testsQueue = tests; |
no test coverage detected