Ind.ie is now Small Technology Foundation.
Commit 40e88d53 authored by Aral Balkan's avatar Aral Balkan

Added a timeout for HAR generation.

parent 943f5a78
Pipeline #301 skipped
......@@ -15,7 +15,10 @@ var spawn = require('cross-spawn-async');
* @param {function(err, json)} callback callback (NOTE: if err != null err.code will be the exit code (e.g. 3 - wrong usage,
* 4 - timeout, below zero - http://src.chromium.org/svn/trunk/src/net/base/net_error_list.h))
*/
module.exports = function electronHAR(url, options, callback) {
module.exports = function electronHAR(url, options, timeout, callback) {
if (timeout == undefined) { timeout = 0; }
typeof options === 'function' && (callback = options, options = {});
// Using temporary file to prevent messages like "Xlib: extension ...",
......@@ -54,6 +57,9 @@ module.exports = function electronHAR(url, options, callback) {
// The callback for the spawned process.
var processCallback = function (err, stdout, stderr) {
if (timeoutID != null) { clearTimeout(timeoutID); }
if (err) {
if (stderr) {
err.message = stderr.trim();
......@@ -77,11 +83,19 @@ module.exports = function electronHAR(url, options, callback) {
// Initialise the electron-har process using spawn
// as cross-exec-file (exec-file) results in stdout maxBuffer exceeded errors.
var command = spawn(__dirname + '/../bin/electron-har', args)
var command = spawn(__dirname + '/../bin/electron-har', args, {detached: true})
var result = ''
command.stdout.on('data', function(data){
result += data.toString();
})
command.on('close', processCallback)
var timeoutID = null
if (timeout > 0) {
timeoutID = setTimeout(function () {
process.kill(-command.pid, 'SIGINT')
}, timeout * 1000);
}
});
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment