testable-utils
Advanced tools
Comparing version 0.1.3 to 0.1.5
@@ -69,8 +69,12 @@ | ||
const start = Date.now(); | ||
const options = _.isObject(metricName) ? metricName : { name: metricName, resource: resource }; | ||
options.units = 'ms'; | ||
const _this = this; | ||
return new Promise(function(resolve, reject) { | ||
var done = function() { | ||
var result = results(resource); | ||
if (result !== null) | ||
result.timing(metricName, Date.now() - start, 'ms'); | ||
var result = results(options.resource); | ||
if (result !== null) { | ||
options.val = Date.now() - start; | ||
result.timing(options); | ||
} | ||
resolve(result); | ||
@@ -77,0 +81,0 @@ }; |
@@ -0,1 +1,22 @@ | ||
function toMetricOptions(args, hasKey) { | ||
if (args.length === 0) { | ||
return null; | ||
} | ||
var options; | ||
if (args[0] !== null && typeof args[0] === 'object') { | ||
options = args[0]; | ||
} else if (hasKey && args.length < 2) { | ||
return null; | ||
} else { | ||
options = { name: args[0] }; | ||
if (hasKey) | ||
options.key = args[1]; | ||
const valIndex = hasKey ? 2 : 1; | ||
if (args.length > valIndex) | ||
options.val = args[valIndex]; | ||
if (args.length > valIndex + 1) | ||
options.units = args[valIndex + 1]; | ||
} | ||
return options; | ||
} | ||
@@ -9,19 +30,28 @@ function createResults(writeStream) { | ||
}, | ||
timing: function(name, val, units) { | ||
return sendResult(writeStream, { | ||
type: 'Timing', | ||
data: { resource: resource, url: url, name: name, val: val, units: units } | ||
}); | ||
timing: function() { | ||
const options = toMetricOptions(arguments); | ||
if (options) | ||
return sendResult(writeStream, { | ||
type: 'Timing', | ||
data: { resource: resource, url: url, namespace: options.namespace, name: options.name, | ||
val: options.val, units: options.units } | ||
}); | ||
}, | ||
counter: function(name, val, units) { | ||
return sendResult(writeStream, { | ||
type: 'Counter', | ||
data: { resource: resource, url: url, name: name, val: val, units: units } | ||
}); | ||
counter: function() { | ||
const options = toMetricOptions(arguments); | ||
if (options) | ||
return sendResult(writeStream, { | ||
type: 'Counter', | ||
data: { resource: resource, url: url, namespace: options.namespace, name: options.name, | ||
val: options.val, units: options.units } | ||
}); | ||
}, | ||
histogram: function(name, key, val) { | ||
return sendResult(writeStream, { | ||
type: 'Histogram', | ||
data: { resource: resource, url: url, name: name, key: key, val: val } | ||
}); | ||
histogram: function() { | ||
const options = toMetricOptions(arguments, true); | ||
if (options) | ||
return sendResult(writeStream, { | ||
type: 'Histogram', | ||
data: { resource: resource, url: url,namespace: options.namespace, name: options.name, | ||
key: options.key, val: options.val } | ||
}); | ||
} | ||
@@ -28,0 +58,0 @@ }; |
@@ -46,10 +46,13 @@ var _ = require('lodash'); | ||
}) | ||
browser.addCommand('testableTiming', function async(result, name, val, units) { | ||
return result.timing(name, val, units); | ||
browser.addCommand('testableTiming', function async(result) { | ||
const args = Array.prototype.slice.call(arguments, 1); | ||
return result.timing.apply(result, args); | ||
}); | ||
browser.addCommand('testableCounter', function async(result, name, val, units) { | ||
return result.counter(name, val, units); | ||
browser.addCommand('testableCounter', function async(result) { | ||
const args = Array.prototype.slice.call(arguments, 1); | ||
return result.counter.apply(result, args); | ||
}); | ||
browser.addCommand('testableHistogram', function async(result, name, key, val) { | ||
return result.histogram(name, key, val); | ||
browser.addCommand('testableHistogram', function async(result) { | ||
const args = Array.prototype.slice.call(arguments, 1); | ||
return result.histogram.apply(result, args); | ||
}); | ||
@@ -56,0 +59,0 @@ } |
{ | ||
"name": "testable-utils", | ||
"version": "0.1.3", | ||
"version": "0.1.5", | ||
"description": "Utilities for Testable scripts", | ||
@@ -5,0 +5,0 @@ "author": "Avi Stramer", |
@@ -11,2 +11,3 @@ # Testable Script Utilities | ||
* [Webdriver.io Custom Commands](#webdriverio-commands) | ||
* [Screenshots](#screenshots) | ||
@@ -33,5 +34,8 @@ ## Installation | ||
`results([resource], [url]).counter(name, [increment], [units])` | ||
```javscript | ||
results([resource], [url]).counter(name, [increment], [units]) | ||
results([resource], [url]).counter(options) | ||
``` | ||
Keep track of a counter across test execution. Increment defaults to 1. Resource and url default to blank and are included with the "overall results". | ||
Keep track of a counter across test execution. Namespace defaults `User`. Increment defaults to 1. Resource and url default to blank and are included with the "overall results". | ||
@@ -44,2 +48,3 @@ For example: | ||
results().counter('slowRequests', 1, 'requests'); | ||
results().counter({ namespace: 'User', name: 'fastRequests', val: 2, units: 'requests' }); | ||
``` | ||
@@ -49,5 +54,8 @@ | ||
`results([resource], [url]).timing(name, timing, [units])` | ||
```javscript | ||
results([resource], [url]).timing(name, timing, [units]) | ||
results([resource], [url]).timing(options) | ||
``` | ||
Capture a timing. Units defaults to `ms`. Resource and url default to blank and are included with the "overall results". Testable will calculate various aggergations like min, max, average, standard deviation, and the percentiles defined in your test configuration. | ||
Capture a timing. Namespace defaults to `User`. Units defaults to `ms`. Resource and url default to blank and are included with the "overall results". Testable will calculate various aggergations like min, max, average, standard deviation, and the percentiles defined in your test configuration. | ||
@@ -60,2 +68,3 @@ For example: | ||
results('Google Homepage', 'https://www.google.com').timing('pageLoadMs', 1294); | ||
results().timing({ namespace: 'User', name: 'latencyMs', val: 196, units: 'ms' }); | ||
``` | ||
@@ -65,5 +74,8 @@ | ||
`results([resource], [url]).histogram(name, bucket, [increment])` | ||
```javscript | ||
results([resource], [url]).histogram(name, bucket, [increment]) | ||
results([resource], [url]).histogram(options) | ||
``` | ||
Capture a histogram. Increment defaults to 1. Resource and url default to blank and are included with the "overall results". | ||
Capture a histogram. Namespace defaults to `User`. Increment defaults to 1. Resource and url default to blank and are included with the "overall results". | ||
@@ -76,2 +88,3 @@ For example: | ||
results().histogram('httpResponseCodes', 200); | ||
results().histogram({ namespace: 'User', name: 'bandwidthByType', key: 'text/html', val: 1928 }); | ||
``` | ||
@@ -92,3 +105,3 @@ | ||
done(); | ||
}, 'myCustomTimer').then(function() { | ||
}, { namespace: 'User', name: 'myCustomTimer' }).then(function() { | ||
// called after done() is invoked | ||
@@ -181,4 +194,9 @@ }); | ||
Iterate over the CSV file, retrieving 1 or more rows. The iterator is global across the entire test execution. See [Testable documentation](https://testable.io/documentation/scripts/upload-data.html#datatable-module) for full set of options. `next()` return a `Promise`. | ||
Iterate over the CSV file, retrieving 1 or more rows. The iterator is global across the entire test execution. | ||
The `next()` function takes an optional `options` object that supports the following properties: | ||
* `wrap`: By default the iterator will wrap back around to the first row once it reaches the last row during test execution. To prevent this and fail instead, set this option to false. | ||
* `rows`: The number of rows to return. Defaults to 1. | ||
```javascript | ||
@@ -188,3 +206,3 @@ var dataTable = require('testable-utils').dataTable; | ||
.open('data.csv') | ||
.next() | ||
.next({ wrap: true, rows: 1 }) | ||
.then(function(results) { | ||
@@ -191,0 +209,0 @@ // Example: |
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
27305
480
318