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

jute

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jute - npm Package Compare versions

Comparing version 0.0.23 to 0.0.24

examples/output/toolbar/cover.json

4

jute_backend.js

@@ -69,2 +69,5 @@ #!/usr/bin/env node

// Prime cache
eventHub.cache = { browsers: {}, tests_to_run: [], connections: {} };
// Start up base modules

@@ -111,2 +114,3 @@ configure.Create(eventHub);

// Dump the config file for jute_v8 and submit_tests
console.log('DMPING: ' + JSON.stringify(eventHub.config));
fs.writeFile('/tmp/jute.config', JSON.stringify(eventHub.config));

@@ -113,0 +117,0 @@

7

jute/actions.js

@@ -41,4 +41,3 @@ /*

// Javascript is single threaded! We don't have to worry about concurrency!
var cache = { browsers: {}, tests_to_run: [] };
glob = require('glob'),
var glob = require('glob'),
path = require('path'),

@@ -60,7 +59,7 @@ actions = glob.globSync(path.join(__dirname, 'actions/', '*.js'));

// keep party going
hub.emit('action:' + action, req, res, cache);
hub.emit('action:' + action);
}
});
hub.emit('action:prune', action, req, res, cache);
hub.emit('action:prune', action);
});

@@ -67,0 +66,0 @@ }

@@ -44,8 +44,8 @@ /*

function clearResults(req, res, cache) {
function clearResults() {
var exec = require('child_process').exec;
exec("/bin/rm -rf " + hub.config.outputDir + '/*');
res.end('OK');
try {
exec("/bin/rm -rf " + hub.config.outputDir + '/*');
} catch(e) {}
hub.cache.res.end('OK');
}

@@ -52,0 +52,0 @@ }

@@ -44,5 +44,5 @@ /*

function clearTests(req, res, cache) {
cache.tests_to_run = [];
res.end('OK');
function clearTests() {
hub.cache.tests_to_run = [];
hub.cache.res.end('OK');
}

@@ -49,0 +49,0 @@ }

@@ -38,5 +38,7 @@ /*

module.exports = {
Create: function(hub, cache) {
Create: function(hub) {
var cache = hub.cache;
return {
browserName: function(req) {
browserName: function() {
var req = cache.req;
return [req.headers['user-agent'], req.connection.remoteAddress].join('---');

@@ -97,5 +99,7 @@ },

takeSeleniumSnapshot: function(test, filename) {
var b = soda = require('soda'),i
soda.createClient({ host: test.sel_host });
var soda = require('soda'), i
b = soda.createClient({ host: test.sel_host });
if (!test.seleniumID) return;
b.sid = test.seleniumID;

@@ -108,14 +112,21 @@

if (!err) {
b.command('captureScreenshotToString', null, function(err, body, res) {
b.command('captureScreenshotToString', [], function(err, body, res) {
if (!err) {
var bb = new Buffer(body, 'base64');
fs.writeFileSync(filename, bb, 0, bb.length);
this.addTestOutput(test, "Took snapshot: " + filename);
} else {
hub.emit(hub.log, hub.ERROR, 'SNAP ERROR: ' + err);
}
});
} else {
hub.emit(hub.log, hub.ERROR, 'FOCUS ERROR: ' + err);
}
});
} else {
hub.emit(hub.log, hub.ERROR, 'MAX ERROR: ' + err);
}
});
},
addTestOutput: function(cache, test, msg) {
addTestOutput: function(test, msg) {
var lines = msg.split(/\n/),

@@ -132,6 +143,26 @@ now = new Date(),

// do something smart
if (cache[test.browser]) {
cache[test.browser].write(msg);
if (cache.connections[test.browser]) {
cache.connections[test.browser].write(msg);
}
}
},
badUnitTest: function(test) {
// Dump a FAILED XML file
// Use test file name as the NAME of this test (vs. component name from test itself)
var parts = test.url.split('/');
var name = parts.pop();
name = name.replace(/\..*$/, ''); // get rid of suffix
var names = this.makeSaneNames(this.browserName());
var err = '<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="BROWSER" tests="0" failures="1" time="0">Test Timed Out: Most likely a Javascript parsing error - try loading URL in your browser</testsuite></testsuites>',
err = err.replace('BROWSER', names[1]);
err = err.replace('URL', test.url);
var params = { results: err, name: name };
var msg = "Dumped error unit test file " + name + " / " + names[0] + " (from " + test.url + ")";
hub.emit(hub.log, hub.ERROR, msg);
this.addTestOutput(test, msg);
this.dumpFile(params, 'results', names[0] + '-test.xml', name);
this.dumpFile({ output: test.output }, 'output', names[0] + '.txt', name);
}

@@ -138,0 +169,0 @@ };

@@ -40,3 +40,5 @@ /*

// Javascript is single threaded! We don't have to worry about concurrency!
var path = require('path');
var path = require('path'),
cache = hub.cache
;

@@ -46,4 +48,6 @@ // Events I care about

function getTest(req, res, cache) {
var browser = req.session.uuid,
function getTest() {
var req = cache.req,
res = cache.res,
browser = req.session.uuid,
bName = common.browserName(req),

@@ -63,3 +67,3 @@ now = new Date().getTime(),

var test = cache.tests_to_run[i];
if ((test.browser == browser) && test.running) {
if (test.browser == browser && test.running) {
// um you're already running this test!

@@ -69,3 +73,3 @@ // must be something wrong with it - pop it

hub.emit(hub.LOG, hub.ERROR, error);
common.addTestOutput(cache, test, error);
common.badUnitTest(test);
cache.tests_to_run.splice(i, 1);

@@ -76,13 +80,7 @@ i--;

// Check if this is a Selenium test for this Selenium browser
// if so then assign it to this browser
if (test.browser == req.session.seleniumUUID) {
// The Selenium host
test.browser = browser;
}
// This test already running in another browser
// This test is not for us
if (test.browser != browser) continue;
// Otherwise start running this test in capture mode!!
common.addTestOutput(test, "Shipping me off to my browser " + bName);
test.running = now;

@@ -95,3 +93,3 @@ testURL = test.url;

res.end(JSON.stringify({ testLocation: testURL }));
hub.emit(hub.LOG, hub.INFO, "Sending test url: " + testURL);
hub.emit(hub.LOG, hub.INFO, "Sending test url: " + testURL + ' to ' + bName);
} else {

@@ -111,5 +109,5 @@ // find all local tests

// No tests for me - end if we're a Selenium browser
if (req.session.seleniumUUID) {
if (req.session.selenium) {
// Selenium job all done!!
hub.emit('seleniumTestsFinished');
hub.emit('seleniumTestsFinished', browser);
}

@@ -116,0 +114,0 @@

@@ -40,3 +40,3 @@ /*

// Javascript is single threaded! We don't have to worry about concurrency!
var path = require('path');
var path = require('path'), cache = hub.cache;

@@ -46,14 +46,17 @@ // Events I care about

function heartBeat(req, res, cache) {
function heartBeat() {
var req = cache.req, res = cache.res,
id = req.session.uuid;
// Update heartbeat time
if (!cache.browsers[req.session.uuid]) {
cache.browsers[req.session.uuid] = {};
if (!cache.browsers[id]) {
cache.browsers[id] = {};
}
cache.browsers[req.session.uuid].heart_beat = new Date().getTime();
cache.browsers[req.session.uuid].name = common.browserName(req);
cache.browsers[id].heart_beat = new Date().getTime();
cache.browsers[id].name = common.browserName();
hub.once('action:checkedResults', function(results) {
results.current_status = cache;
results.config = hub.config;
results.current_status = { browsers: cache.browsers, tests_to_run: cache.tests_to_run };
results.config = hub.config;
res.end(JSON.stringify(results));

@@ -60,0 +63,0 @@ });

@@ -46,5 +46,5 @@ /*

// Take off top test whatever it is
function pop(req, res, cache) {
cache.tests_to_run.shift();
hub.emit('action:status', req, res, cache);
function pop() {
hub.cache.tests_to_run.shift();
hub.emit('action:status');
}

@@ -51,0 +51,0 @@ }

@@ -38,8 +38,8 @@ /*

module.exports = {
Create: function(hub, common) {
Create: function(hub, common, glob) {
// Javascript is single threaded! We don't have to worry about concurrency!
var TEST_TIME_THRESHOLD = 60000, // 60 seconds to wait before declaring test dead
BROWSER_TIME_THRESHOLD = 20000, // Delete a captured browser after it has been gone for this long - 20 seconds
ERROR = '<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="BROWSER" tests="0" failures="1" time="0">Test Timed Out: Most likely a Javascript parsing error - try loading URL in your browser</testsuite></testsuites>',
path = require('path')
path = require('path'),
cache = hub.cache
;

@@ -50,7 +50,8 @@

function prune(doing_what, req, res, cache) {
function prune(doing_what) {
var redirect;
if (doing_what != 'status') {
prune_browsers(req, cache);
redirect = prune_tests(doing_what, req, res, cache);
prune_browsers();
redirect = prune_tests(doing_what);
hub.emit('pruneDone', redirect);

@@ -60,6 +61,7 @@ }

function prune_tests(doing_what, req, res, cache) {
function prune_tests(doing_what) {
var now = new Date().getTime(),
browser = req.session.uuid, test,
timeStarted;
browser = cache.req.session.uuid, test,
timeStarted
;

@@ -75,25 +77,9 @@ for (var i = 0; i< cache.tests_to_run.length; i++) {

hub.emit(hub.LOG, hub.ERROR, msg);
common.addTestOutput(cache, test, msg);
common.addTestOutput(test, msg);
cache.tests_to_run.splice(i, 1);
common.badUnitTest(test);
// Dump a FAILED XML file
// Use test file name as the NAME of this test (vs. component name from test itself)
var parts = test.url.split('/');
var name = parts.pop();
name = name.replace(/\..*$/, ''); // get rid of suffix
var names = common.makeSaneNames(common.browserName(req));
var err = ERROR;
err = err.replace('BROWSER', names[1]);
err = err.replace('URL', test.url);
var params = { results: err, name: name };
var msg = "Dumped error unit test file " + name + " / " + names[0] + " (from " + test.url + ")";
hub.emit(hub.log, hub.ERROR, msg);
common.addTestOutput(cache, test, msg);
common.dumpFile(params, 'results', names[0] + '-test.xml', name);
common.dumpFile({ output: test.output }, 'output', names[0] + '.txt', name);
/*
if (cache.browsers[browser]) {

@@ -104,4 +90,6 @@ cache.browsers[browser].heart_beat = now;

}
*/
}
} else {
/*
// make sure browser is still requesting tests

@@ -115,2 +103,3 @@ if (cache.browsers[browser]) {

}
*/
}

@@ -120,24 +109,24 @@ }

function prune_browsers(req, cache) {
var now = new Date().getTime(), me = req.session.uuid;
function prune_browsers() {
var now = new Date().getTime(), me = cache.req.session.uuid,
sys = require('sys');
if (typeof cache.browsers == 'object') {
for (browser in cache.browsers) {
if (browser == me) continue;
for (browser in cache.browsers) {
if (browser == me) continue;
var b_time = cache.browsers[browser].heart_beat;
if (now - b_time > BROWSER_TIME_THRESHOLD) {
hub.emit(hub.LOG, hub.ERROR, "We lost browser " + cache.browsers[browser].name);
delete cache.browsers[browser];
// take it out of ay tests it's supposed to be running
for (var i = 0; i < cache.tests_to_run.length; i++) {
var test = cache.tests_to_run[i];
if (test.browser == browser) {
// blow this test out!
hub.emit(hub.LOG, hub.ERROR, "Deleting this test that was part of blow away browser: " + sys.inspect(test));
cache.tests_to_run.splice(i, 1);
i--; // fake a perl 'redo'!! Otherwise we might skip over something!
}
var b_time = cache.browsers[browser].heart_beat;
if (now - b_time > BROWSER_TIME_THRESHOLD) {
hub.emit(hub.LOG, hub.ERROR, "We lost browser " + cache.browsers[browser].name);
delete cache.browsers[browser];
// take it out of ay tests it's supposed to be running
for (var i = 0; i < cache.tests_to_run.length; i++) {
var test = cache.tests_to_run[i];
if (test.browser == browser) {
// blow this test out!
hub.emit(hub.LOG, hub.ERROR, "Deleting this test that was part of lost browser: " + sys.inspect(test));
cache.tests_to_run.splice(i, 1);
i--; // fake a perl 'redo'!! Otherwise we might skip over something!
common.badUnitTest(test);
}
}
}
}

@@ -144,0 +133,0 @@ }

@@ -40,3 +40,4 @@ /*

// Javascript is single threaded! We don't have to worry about concurrency!
var path = require('path');
var path = require('path'),
cache = hub.cache;

@@ -46,7 +47,7 @@ // Events I care about

function runTest(req, res, cache) {
var uuid = require('node-uuid'),
function runTest() {
var uuid = require('node-uuid'),
path = require('path'),
fs = require('fs'),
obj = req.body,
obj = cache.req.body,
sys = require('sys'),

@@ -56,6 +57,7 @@ tests, multipleFromUI = false,

exec = require('child_process').exec,
errors = []
errors = [],
res = cache.res
;
console.log(sys.inspect(obj));
hub.emit(hub.LOG, hub.INFO, sys.inspect(obj));
if (obj.test) {

@@ -108,3 +110,4 @@ // 'run multiple' from UI

url: path.join('/', hub.config.testDirWeb, test),
output: ''
output: '',
sendOutput: obj.send_output
};

@@ -123,3 +126,7 @@

} else if (obj.sel_host) {
// A Selenium Test! - meaning anyone can run it
// A Selenium Test!
// keep this around
test_obj.sel_host = obj.sel_host;
if (obj.send_output) {

@@ -136,3 +143,3 @@ test_obj.sendOutput = 1;

common.addTestOutput(cache, test_obj, 'Selenium test');
common.addTestOutput(test_obj, 'Selenium test');

@@ -144,5 +151,5 @@ cache.tests_to_run.push(test_obj);

// Only run these tests in THIS browser from the UI
test_obj.browser = req.session.uuid;
test_obj.browser = cache.req.session.uuid;
common.addTestOutput(cache, test_obj, 'Multiple in this browser test');
common.addTestOutput(test_obj, 'Multiple in this browser test');

@@ -155,3 +162,3 @@ cache.tests_to_run.push(test_obj);

test_obj.browser = browser;
common.addTestOutput(cache, test_obj, 'Capture test');
common.addTestOutput(test_obj, 'Capture test');
cache.tests_to_run.push(test_obj);

@@ -163,18 +170,12 @@ pushed = true;

common.addTestOutput(cache, test_obj, sys.inspect(test_obj));
common.addTestOutput(test_obj, sys.inspect(test_obj));
}
if (pushed) {
cache[obj.uuid] = res; // our link back to the requesting client for status messages
if (obj.sel_host) {
if (obj.send_output) {
res.write("Opening " + obj.sel_browser + " on Selenium host " + obj.sel_host);
}
// Start up Selenium & Listen for results
// Start up for a Selenium browser & Listen for results
hub.once('action:seleniumDone', function(err) {
delete cache[obj.uuid]; // done with status updates
if (err) {
hub.emit(hub.LOG, hub.ERROR, 'ERROR running Selenium tests: ' + err);
res.end(err);
res.end("" + err);
} else {

@@ -188,3 +189,3 @@ hub.once('action:checkedResults', function(results) {

hub.emit('action:seleniumStart', req, res, obj, tests.length);
hub.emit('action:seleniumStart');
} else {

@@ -209,3 +210,3 @@ // UI wants to run multiple tests - redirect to it!

hub.emit(hub.LOG, hub.ERROR, "No browsers listening!");
response.statusCode = 412; // Ye Olde Failed Precondition
res.statusCode = 412; // Ye Olde Failed Precondition
res.end('No browsers listening!! Test(s) not added!');

@@ -212,0 +213,0 @@ }

@@ -41,3 +41,4 @@ /*

var path = require('path'),
sys = require('sys')
sys = require('sys'),
cache = hub.cache
;

@@ -48,11 +49,12 @@

function startSelenium(req, res, obj, testsLength) {
function startSelenium() {
var soda = require('soda'), cb,
req = cache.req,
res = cache.res,
body = req.body,
browser = soda.createClient({
url: 'http://' + req.headers.host,
host: obj.sel_host,
browser: obj.sel_browser
}),
TIME_TEST_THRESHOLD = 60, // Wait up to 60 seconds/test
maxWaitTime = TIME_TEST_THRESHOLD * (testsLength + 1)
url: 'http://' + (hub.config.host ? hub.config.host + ':' + hub.config.port : req.headers.host),
host: body.sel_host,
browser: body.sel_browser
})
;

@@ -67,7 +69,16 @@

// called when all Selenium tests are complete for this browser
cb = function() {
browser.testComplete(function(err) {
hub.emit('action:seleniumDone', err);
});
};
// && keep track of requesting client for debug messages back...
cache.connections[body.uuid] = res; // our link back to the requesting client for status messages
// Callback for when the Selenium session is done
cb = function(err) {
if (!err) {
browser.chain.testComplete().end(function(err) {
delete cache.connections[body.uuid]; // done with status updates
hub.emit('action:seleniumDone', err);
});
} else {
hub.emit('action:seleniumDone', err);
}
};
cb = hub.once('seleniumTestsFinished', cb);

@@ -78,12 +89,18 @@

session().
open('/?selenium=' + obj.uuid, function(err, body, req) { obj.seleniumID = browser.sid }).
waitForPageToLoad(60000).
open('/?selenium=' + body.uuid, function(err, body, req) { body.seleniumID = browser.sid }).
waitForPageToLoad(10000).
end(function(err) {
if (err) {
var msg = 'Error starting/waiting for Selenium page to load: ' + err;
hub.emit(hub.LOG, hub.ERROR, msg);
res.end(msg);
hub.emit('seleniumTestsFinished', err);
} else {
hub.emit(hub.LOG, hub.INFO, "Selenium a gogo!");
hub.emit(hub.LOG, hub.INFO, "Selenium up and running!");
// If this is one of the tests that are going to run in thie
// Selenium session, tag it with the Selenium token
cache.tests_to_run.forEach(function(test) {
if (test.browser === body.uuid) {
test.seleniumID = body.seleniumID;
}
});
}

@@ -90,0 +107,0 @@ });

@@ -40,3 +40,4 @@ /*

// Javascript is single threaded! We don't have to worry about concurrency!
var path = require('path');
var path = require('path'),
cache = hub.cache;

@@ -46,7 +47,7 @@ // Events I care about

hub.addListener('action:status', function(req, res, cache) {
hub.addListener('action:status', function() {
hub.once('action:checkedResults', function(results) {
results.current_status = cache;
results.current_status = { browsers: cache.browsers, tests_to_run: cache.tests_to_run };
results.config = hub.config;
res.end(JSON.stringify(results));
cache.res.end(JSON.stringify(results));
});

@@ -53,0 +54,0 @@ hub.emit('action:checkResults');

@@ -40,3 +40,4 @@ /*

// Javascript is single threaded! We don't have to worry about concurrency!
var path = require('path');
var path = require('path'),
cache = hub.cache;

@@ -46,5 +47,5 @@ // Events I care about

function testReport(req, res, cache) {
var obj = req.body, succeeded = true,
names = common.makeSaneNames(common.browserName(req)),
function testReport() {
var req = cache.req, obj = req.body, succeeded = true,
names = common.makeSaneNames(common.browserName()),
filename = names[0], pkgname = names[1],

@@ -91,10 +92,11 @@ now = new Date().getTime(), output = '',

var test = cache.tests_to_run[i];
if (test.browser == req.session.uuid) {
common.addTestOutput(cache, test, output);
if (test.snapshot && test.sel_host) {
// This is the test that just finished
common.addTestOutput(test, output);
if (test.snapshot && req.session.selenium) {
common.takeSeleniumSnapshot(test, path.join(names[1], path.basename(names[0], 'xml')) + 'png');
common.addTestOutput(cache, test, "Took snapshot: " + path.join(names[1], path.basename(names[0], 'xml')) + 'png');
}
common.addTestOutput(cache, test, obj.name + " finished - it " + (succeeded ? 'SUCCEEDED' : 'FAILED') + ' - it took ' + (now - test.running) + "ms\n");
common.addTestOutput(test, obj.name + " finished - it " + (succeeded ? 'SUCCEEDED' : 'FAILED') + ' - it took ' + (now - test.running) + "ms\n");
common.dumpFile({ output: test.output }, 'output', path.basename(names[0], 'xml') + 'txt', obj.name);

@@ -111,3 +113,3 @@ cache.tests_to_run.splice(i, 1);

res.end('OK');
cache.res.end('OK');
}

@@ -114,0 +116,0 @@ }

@@ -56,3 +56,4 @@ /*

logFormat: '',
testRegex: '*.htm*'
testRegex: '*.htm*',
host: ''
},

@@ -59,0 +60,0 @@ exec = require('child_process').exec,

@@ -57,3 +57,3 @@ /*

hub.emit(hub.LOG, hub.INFO, "Running as " + process.getuid() + '/' + process.getgid());
hub.emit(hub.LOG, hub.INFO, "Connect at http://" + os.hostname() + ':' + hub.config.port + '/');
hub.emit(hub.LOG, hub.INFO, "Connect at http://" + (hub.config.host || os.hostname()) + ':' + hub.config.port + '/');

@@ -64,19 +64,20 @@ connect(

, connect.query()
, connect.bodyParser()
, function(req, res, next) {
// Make sure we have a session UUID
// maybe even from a selenium host
var sess = req.session;
if (!sess) sess = req.session = {};
if (!sess.uuid) sess.uuid = uuid();
if (!sess.uuid) {
sess.uuid = req.query.selenium || uuid();
sess.selenium = req.query.selenium ? true: false;
}
// stash of req/res
hub.cache.req = req;
hub.cache.res = res;
next();
}
, connect.logger(hub.config.logFormat)
, function(req, res, next) {
// This is a Selenium browser - set that fact in its session so it will
// grab the right test(s)
if (req.query.selenium) {
req.session.seleniumUUID = req.query.selenium;
}
next();
}
, connect.bodyParser()
, connect.router(function(app){

@@ -89,3 +90,3 @@ app.get('/jute_docs/:file', function(req, res, next){

// A JUTE action - GET
hub.emit('action', req.params[0], req, res);
hub.emit('action', req.params[0]);//, req, res);
});

@@ -92,0 +93,0 @@ app.get('/', function(req, res, next){

@@ -5,3 +5,3 @@ {

"keywords": ["selenium", "test", "testing", "unit", "tests"],
"version": "0.0.23",
"version": "0.0.24",
"author": "Mark Ethan Trostler <mark@zzo.com>",

@@ -8,0 +8,0 @@ "preferGlobal": true,

@@ -104,2 +104,7 @@ #!/usr/bin/env node

var options = {
host: args.host,
port: args.port
};
eventHub.on('tests', function(tests) {

@@ -153,3 +158,9 @@ if (tests) {

var req = http.request(options, function(res) {
console.log('Status Response from JUTE: ' + res.statusCode);
if (res.statusCode == 200) {
console.log('JUTE Likey');
} else {
console.log('JUTE Displeased');
}
res.setEncoding('utf8');

@@ -241,7 +252,2 @@ res.on('data', function (chunk) {

var options = {
host: args.host,
port: args.port
};
if (args.clear_results) {

@@ -248,0 +254,0 @@ console.log('Clearing all previous results...');

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