testable-utils
Advanced tools
Comparing version 0.2.9 to 0.2.12
@@ -13,2 +13,3 @@ | ||
const LocalInfo = { | ||
expectedFinishTimestamp: -1, | ||
iteration: 0, | ||
@@ -98,4 +99,14 @@ client: 0, | ||
}); | ||
} | ||
}; | ||
const expectedFinishTimestamp = info.expectedFinishTimestamp; | ||
const waitForFinish = function() { | ||
return new Promise(function(resolve, reject) { | ||
if (expectedFinishTimestamp > 0 && expectedFinishTimestamp - Date.now() > 0) | ||
setTimeout(resolve, expectedFinishTimestamp - Date.now()); | ||
else | ||
resolve(); | ||
}); | ||
}; | ||
const csv = isLocal ? csvLocal.initialize() : csvRemote.initialize(info, log); | ||
@@ -115,3 +126,3 @@ const registerCommands = typeof browser !== 'undefined' && _.isUndefined(browser.testableLogInfo); | ||
wdio.registerStopwatchCommands(browser, stopwatch); | ||
wdio.registerEventsCommands(browser, events, doNotWait); | ||
wdio.registerEventsCommands(browser, events, doNotWait, waitForFinish); | ||
} | ||
@@ -127,2 +138,3 @@ | ||
module.exports.events = events; | ||
module.exports.dataTable = csv; | ||
module.exports.dataTable = csv; | ||
module.exports.waitForFinish = waitForFinish; |
@@ -134,3 +134,3 @@ const _ = require('lodash'); | ||
function registerEventsCommands(browser, events, doNotWait) { | ||
function registerEventsCommands(browser, events, doNotWait, waitForFinish) { | ||
if (isWdioContext(browser)) { | ||
@@ -162,2 +162,5 @@ browser.addCommand('testableWaitForEvent', function async(eventName, timeout, defaultVal) { | ||
}); | ||
browser.addCommand('testableWaitForFinish', function async() { | ||
return waitForFinish(); | ||
}); | ||
} | ||
@@ -164,0 +167,0 @@ } |
{ | ||
"name": "testable-utils", | ||
"version": "0.2.9", | ||
"version": "0.2.12", | ||
"description": "Utilities for Testable scripts", | ||
@@ -5,0 +5,0 @@ "author": "Avi Stramer", |
@@ -12,3 +12,3 @@ # Testable Script Utilities | ||
* [Manual Live Event](#manual-live-event) | ||
* [Coordination Across Virtual Users](#coordination-across-virtual-users) | ||
* [Wait For Finish](#wait-for-finish) | ||
* [Webdriver.io Custom Commands](#webdriverio-commands) | ||
@@ -316,2 +316,15 @@ * [Screenshots](#screenshots) | ||
### Wait For Finish | ||
Use this function to wait for the remainder of the test duration before the script finishes. Returns a Promise so that you can run some cleanup code before the script exits. | ||
For tests configured for a set number of iterations the promise resolved immediately. Otherwise the promise will not resolve until the remaining duration has passed. | ||
``` | ||
const testableUtils = require('testable-utils'); | ||
testableUtils.waitForFinish().then(() => { | ||
console.log('finished!'); | ||
}); | ||
``` | ||
## Webdriver.io Commands | ||
@@ -426,2 +439,6 @@ | ||
<tr> | ||
<td><pre>browser.testableWaitForFinish();</pre></td> | ||
<td><a href="#wait-for-finish"><pre>testableUtils.waitForFinish().then(() => { });</pre></a></td> | ||
</tr> | ||
<tr> | ||
<td><pre>// blocks until done() is called | ||
@@ -428,0 +445,0 @@ browser.testableStopwatch(function(done) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41173
710
453