testable-utils
Advanced tools
Comparing version 0.1.7 to 0.2.0
@@ -9,2 +9,3 @@ | ||
const wdio = require('./wdio-commands'); | ||
const EventEmitter = require('events'); | ||
@@ -87,14 +88,10 @@ var LocalInfo = { | ||
// stub functionality. no tracking needed outside of sandbox | ||
var testable = { | ||
start: function() { }, | ||
finish: function() { }, | ||
execute: function(codeToExecute) { | ||
return new Promise(function(resolve, reject) { | ||
if (codeToExecute) | ||
codeToExecute(resolve); | ||
else | ||
resolve(); | ||
}); | ||
} | ||
}; | ||
var execute = function(codeToExecute) { | ||
return new Promise(function(resolve, reject) { | ||
if (codeToExecute) | ||
codeToExecute(resolve); | ||
else | ||
resolve(); | ||
}); | ||
} | ||
@@ -117,3 +114,4 @@ var csv = isLocal ? csvLocal.initialize() : csvRemote.initialize(info, log); | ||
module.exports.stopwatch = stopwatch; | ||
module.exports.testable = testable; | ||
module.exports.execute = execute; | ||
module.exports.events = new EventEmitter(); | ||
module.exports.dataTable = csv; |
@@ -45,3 +45,3 @@ var _ = require('lodash'); | ||
return results(resource, url); | ||
}) | ||
}); | ||
browser.addCommand('testableTiming', function async(result) { | ||
@@ -48,0 +48,0 @@ const args = Array.prototype.slice.call(arguments, 1); |
{ | ||
"name": "testable-utils", | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"description": "Utilities for Testable scripts", | ||
@@ -5,0 +5,0 @@ "author": "Avi Stramer", |
@@ -8,4 +8,6 @@ # Testable Script Utilities | ||
* [Logging](#logging) | ||
* [Execution Info](#execution-info) | ||
* [CSV](#csv) | ||
* [Execution Info](#execution-info) | ||
* [Async Code](#async-code) | ||
* [Manual Live Event](#manual-live-event) | ||
* [Webdriver.io Custom Commands](#webdriverio-commands) | ||
@@ -206,2 +208,48 @@ * [Screenshots](#screenshots) | ||
### Async Code | ||
**Node.js Only** | ||
When running a Node.js script on Testable and use a 3rd party module that performs async actions you might need to tell Testable when the action is finished. Testable automatically instruments many modules so you don't need to do this including async, http, https, request, net, ws, socketio, engineio, tls, setTimeout, setInterval. | ||
For other async code use the below. | ||
```javascript | ||
var execute = require('testable-utils').execute; | ||
execute(function(finished) { | ||
// my async code here, call finished() when done | ||
// ... | ||
finished(); | ||
}); | ||
``` | ||
### Manual Live Event | ||
**Node.js Only** | ||
You can manually trigger an event while a test is running from the test results page (action menu => Send Live Event) or our API. Your script can listen for this event and perform an action in response. This is useful if you want to have all the virtual users perform an action at the exact same time for example. The event name/contents can be whatever you want. | ||
For local testing, you can also trigger the event in your script by checking the `isLocal` boolean variable. | ||
Example: | ||
```javascript | ||
const isLocal = require('testable-utils').isLocal; | ||
const request = require('request'); | ||
const events = require('testable-utils').events; | ||
const execute = require('testable-utils').execute; | ||
execute(function(finished) { | ||
events.on('my-event', function(symbol) { | ||
request.get('http://sample.testable.io/stocks/' + symbol); | ||
finished(); | ||
}); | ||
}); | ||
if (isLocal) { | ||
// trigger the event when run locally for testing | ||
events.emit('my-event', 'MSFT'); | ||
} | ||
``` | ||
## Webdriver.io Commands | ||
@@ -208,0 +256,0 @@ |
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
28922
366
478