Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

testable-utils

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testable-utils - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

lib/events-watcher.js

26

lib/main.js

@@ -9,5 +9,6 @@

const wdio = require('./wdio-commands');
const eventsWatcher = require('./events-watcher');
const EventEmitter = require('events');
var LocalInfo = {
const LocalInfo = {
iteration: 0,

@@ -63,9 +64,9 @@ client: 0,

var writeStream = isLocal ? null : fs.createWriteStream(process.env.TESTABLE_RESULT_FILE, { flags: 'a' });
var log = createLog(writeStream);
var results = createResults(writeStream);
const writeStream = isLocal ? null : fs.createWriteStream(process.env.TESTABLE_RESULT_FILE, { flags: 'a' });
const log = createLog(writeStream);
const results = createResults(writeStream);
results.current = results('dummy','http://dummy.com');
results.toResourceName = function(url) { return url; };
var stopwatch = function(code, metricName, resource) {
const stopwatch = function(code, metricName, resource) {
const start = Date.now();

@@ -89,3 +90,3 @@ const options = _.isObject(metricName) ? metricName : { name: metricName, resource: resource };

// stub functionality. no tracking needed outside of sandbox
var execute = function(codeToExecute) {
const execute = function(codeToExecute) {
return new Promise(function(resolve, reject) {

@@ -99,5 +100,10 @@ if (codeToExecute)

var csv = isLocal ? csvLocal.initialize() : csvRemote.initialize(info, log);
var registerCommands = typeof browser !== 'undefined' && _.isUndefined(browser.testableLogInfo);
const csv = isLocal ? csvLocal.initialize() : csvRemote.initialize(info, log);
const registerCommands = typeof browser !== 'undefined' && _.isUndefined(browser.testableLogInfo);
const events = new EventEmitter();
if (process.env.TESTABLE_EVENTS_FILE) {
eventsWatcher(process.env.TESTABLE_EVENTS_FILE, events, log);
}
if (registerCommands) {

@@ -109,5 +115,7 @@ wdio.registerLogCommands(browser, log);

wdio.registerStopwatchCommands(browser, stopwatch);
wdio.registerEventsCommands(browser, events);
}
module.exports.isLocal = isLocal;
module.exports.isSmokeTest = Number(process.env.TESTABLE_CHUNK_ID) < 0;
module.exports.info = info;

@@ -118,3 +126,3 @@ module.exports.log = log;

module.exports.execute = execute;
module.exports.events = new EventEmitter();
module.exports.events = events;
module.exports.dataTable = csv;

@@ -82,2 +82,27 @@ var _ = require('lodash');

function registerEventsCommands(browser, events, log) {
if (isWdioContext(browser)) {
browser.addCommand('testableWaitForEvent', function async(eventName, timeout) {
var resolved = false;
return new Promise(function(resolve, reject) {
var timeoutHandle;
const listener = function(contents) {
resolved = true;
if (timeoutHandle)
clearTimeout(timeoutHandle);
resolve(contents);
};
if (timeout && timeout > 0) {
timeoutHandle = setTimeout(function() {
if (!resolved) {
events.off(eventName, listener);
reject(`Timeout waiting for event ${eventName}`);
}
}, timeout);
}
events.once(eventName, listener);
});
});
}
}

@@ -88,2 +113,3 @@ module.exports.registerLogCommands = registerLogCommands;

module.exports.registerInfoCommands = registerInfoCommands;
module.exports.registerStopwatchCommands = registerStopwatchCommands;
module.exports.registerStopwatchCommands = registerStopwatchCommands;
module.exports.registerEventsCommands = registerEventsCommands;
{
"name": "testable-utils",
"version": "0.2.5",
"version": "0.2.6",
"description": "Utilities for Testable scripts",

@@ -20,2 +20,3 @@ "author": "Avi Stramer",

"dependencies": {
"always-tail": "^0.2.0",
"babyparse": "^0.4.6",

@@ -22,0 +23,0 @@ "lodash": "^4.17.2",

@@ -226,4 +226,2 @@ # Testable Script Utilities

**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.

@@ -233,3 +231,3 @@

Example:
Example (Node.js):

@@ -256,2 +254,19 @@ ```javascript

Example (Webdriver.io):
```javascript
const testableUtils = require('testable-utils');
const fireNow = testableUtils.isLocal || testableUtils.isSmokeTest;
describe('Load Url Requested in Event', function() {
it('should load url', function() {
var url = 'http://google.com'; // default for local or smoke test
if (!fireNow)
url = browser.testableWaitForEvent('go-time');
browser.url(url);
browser.testableScreenshot('Requested Url');
});
});
```
## Webdriver.io Commands

@@ -358,2 +373,6 @@

<tr>
<td><pre>browser.testableWaitForEvent(eventName[, timeout]);</pre></td>
<td><a href="#manual-live-events"><pre>events.on(eventName);</pre></a></td>
</tr>
<tr>
<td><pre>// blocks until done() is called

@@ -360,0 +379,0 @@ browser.testableStopwatch(function(done) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc