Splitted the node server in modules
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Yellow Lab Tools main file
|
||||
*/
|
||||
|
||||
var q = require ('q');
|
||||
var phantomas = require('phantomas');
|
||||
|
||||
var PhantomasWrapper = function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This is the phantomas launcher. It merges user chosen options into the default options
|
||||
* Available options :
|
||||
*
|
||||
* - timeout : in seconds (default 60)
|
||||
* - jsDeepAnalysis : should we inspect subrequests in the javascript execution tree (reported durations of main tasks will be slower than usual)
|
||||
*
|
||||
*/
|
||||
this.execute = function(task, callback) {
|
||||
|
||||
var options = {
|
||||
// Cusomizable options
|
||||
timeout: task.options.timeout || 60,
|
||||
'js-deep-analysis': task.options.jsDeepAnalysis || false,
|
||||
|
||||
// Mandatory
|
||||
reporter: 'json:pretty',
|
||||
'skip-modules': [
|
||||
'ajaxRequests',
|
||||
'alerts',
|
||||
'cacheHits',
|
||||
'caching',
|
||||
'console',
|
||||
'cookies',
|
||||
'documentHeight',
|
||||
'domains',
|
||||
'domComplexity',
|
||||
'domMutations',
|
||||
'domQueries',
|
||||
'filmStrip',
|
||||
'jQuery',
|
||||
'jserrors',
|
||||
'har',
|
||||
'headers',
|
||||
'localStorage',
|
||||
'mainRequest',
|
||||
'pageSource',
|
||||
'redirects',
|
||||
'requestsStats',
|
||||
'screenshot',
|
||||
'staticAssets',
|
||||
'timeToFirst',
|
||||
'waitForSelector'
|
||||
].join(','),
|
||||
'include-dirs': [
|
||||
'phantomas_custom/core',
|
||||
'phantomas_custom/modules'
|
||||
].join(',')
|
||||
};
|
||||
|
||||
// It's time to launch the test!!!
|
||||
phantomas(task.url, options, callback);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = new PhantomasWrapper();
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Creation of a queue and it's worker function
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var async = require('async');
|
||||
var phantomasWrapper = require('./phantomasWrapper');
|
||||
|
||||
|
||||
var testQueue = function() {
|
||||
'use strict';
|
||||
|
||||
var currentTask = null;
|
||||
var self = this;
|
||||
|
||||
var queue = async.queue(function(task, callback) {
|
||||
currentTask = task;
|
||||
|
||||
console.log('Starting test ' + task.testId);
|
||||
|
||||
phantomasWrapper.execute(task, function(err, json, results) {
|
||||
console.log('Test ' + task.testId + ' complete');
|
||||
currentTask = null;
|
||||
callback(err, json, results);
|
||||
self.emit('queueMoving');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Use this method to add a test to the queue
|
||||
this.push = queue.push;
|
||||
|
||||
|
||||
// Gives the position of a task in the queue
|
||||
// Returns 0 if it is the current running task
|
||||
// Returns -1 if not found
|
||||
this.indexOf = function(testId) {
|
||||
if (currentTask && currentTask.testId === testId) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var position = -1;
|
||||
if (queue.length() > 0) {
|
||||
queue.tasks.forEach(function(task, index) {
|
||||
if (task.data.testId === testId) {
|
||||
position = index + 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
return position;
|
||||
};
|
||||
|
||||
// Forward testComplete
|
||||
this.testComplete = function(testId) {
|
||||
self.emit('testComplete', testId);
|
||||
};
|
||||
};
|
||||
|
||||
// extend the EventEmitter class using our Radio class
|
||||
util.inherits(testQueue, EventEmitter);
|
||||
|
||||
module.exports = new testQueue();
|
||||
Reference in New Issue
Block a user