Splitted the node server in modules

This commit is contained in:
Gaël Métais
2014-08-07 19:26:58 +02:00
parent 9b6b0f39f0
commit 7fcdf2aaa2
17 changed files with 407 additions and 250 deletions
@@ -2,11 +2,11 @@
* Analyzes DOM complexity
*/
/* global document: true, Node: true, window: true */
'use strict';
exports.version = '0.3.a';
exports.module = function(phantomas) {
'use strict';
// total length of HTML comments (including <!-- --> brackets)
phantomas.setMetric('commentsSize'); // @desc the size of HTML comments on the page @offenders
+23 -9
View File
@@ -2,18 +2,19 @@
* Analyzes DOM queries done via native DOM methods
*/
/* global Element: true, Document: true, Node: true, window: true */
'use strict';
exports.version = '0.7.a';
exports.module = function(phantomas) {
phantomas.setMetric('DOMqueries'); // @desc number of all DOM queries @offenders
phantomas.setMetric('DOMqueriesById'); // @desc number of document.getElementById calls
phantomas.setMetric('DOMqueriesByClassName'); // @desc number of document.getElementsByClassName calls
phantomas.setMetric('DOMqueriesByTagName'); // @desc number of document.getElementsByTagName calls
phantomas.setMetric('DOMqueriesByQuerySelectorAll'); // @desc number of document.querySelector(All) calls
phantomas.setMetric('DOMinserts'); // @desc number of DOM nodes inserts
phantomas.setMetric('DOMqueriesDuplicated'); // @desc number of duplicated DOM queries
'use strict';
phantomas.setMetric('DOMqueries'); // @desc number of all DOM queries @offenders
phantomas.setMetric('DOMqueriesById'); // @desc number of document.getElementById calls
phantomas.setMetric('DOMqueriesByClassName'); // @desc number of document.getElementsByClassName calls
phantomas.setMetric('DOMqueriesByTagName'); // @desc number of document.getElementsByTagName calls
phantomas.setMetric('DOMqueriesByQuerySelectorAll'); // @desc number of document.querySelector(All) calls
phantomas.setMetric('DOMinserts'); // @desc number of DOM nodes inserts
phantomas.setMetric('DOMqueriesDuplicated'); // @desc number of duplicated DOM queries
// fake native DOM functions
phantomas.once('init', function() {
@@ -43,6 +44,8 @@ exports.module = function(phantomas) {
// selectors by class name
function selectorClassNameSpyBefore(className) {
/*jshint validthis: true */
phantomas.incrMetric('DOMqueriesByClassName');
phantomas.addOffender('DOMqueriesByClassName', '.' + className);
querySpy('class', '.' + className, 'getElementsByClassName');
@@ -65,6 +68,8 @@ exports.module = function(phantomas) {
// selectors by tag name
function selectorTagNameSpyBefore(tagName) {
/*jshint validthis: true */
phantomas.incrMetric('DOMqueriesByTagName');
phantomas.addOffender('DOMqueriesByTagName', tagName);
querySpy('tag name', tagName, 'getElementsByTagName');
@@ -93,6 +98,8 @@ exports.module = function(phantomas) {
}
function selectorQuerySpyBefore(selector) {
/*jshint validthis: true */
selectorQuerySpy(selector);
phantomas.enterContext({
@@ -109,6 +116,8 @@ exports.module = function(phantomas) {
}
function selectorAllQuerySpyBefore(selector) {
/*jshint validthis: true */
selectorQuerySpy(selector);
phantomas.enterContext({
@@ -132,7 +141,8 @@ exports.module = function(phantomas) {
// count DOM inserts
function appendChild(child) {
/* jshint validthis: true */
/*jshint validthis: true */
// ignore appending to the node that's not yet added to DOM tree
if (!this.parentNode) {
return;
@@ -154,6 +164,8 @@ exports.module = function(phantomas) {
}
function appendChildSpyBefore(child) {
/*jshint validthis: true */
appendChild(child);
phantomas.enterContext({
@@ -170,6 +182,8 @@ exports.module = function(phantomas) {
}
function insertBeforeSpyBefore(child) {
/*jshint validthis: true */
appendChild(child);
phantomas.enterContext({
+10 -8
View File
@@ -5,17 +5,19 @@
* @see http://code.jquery.com/jquery-2.0.3.js
*/
/* global document: true, window: true */
'use strict';
/* jshint -W030 */
exports.version = '0.2.a';
exports.module = function(phantomas) {
phantomas.setMetric('jQueryVersion', ''); // @desc version of jQuery framework (if loaded) [string]
phantomas.setMetric('jQueryOnDOMReadyFunctions'); // @desc number of functions bound to onDOMReady event
phantomas.setMetric('jQuerySizzleCalls'); // @desc number of calls to Sizzle (including those that will be resolved using querySelectorAll)
phantomas.setMetric('jQuerySizzleCallsDuplicated'); // @desc number of calls on the same Sizzle request
phantomas.setMetric('jQueryBindOnMultipleElements'); //@desc number of calls to jQuery bind function on 2 or more elements
phantomas.setMetric('jQueryDifferentVersions'); //@desc number of different jQuery versions loaded on the page (not counting iframes)
'use strict';
phantomas.setMetric('jQueryVersion', ''); // @desc version of jQuery framework (if loaded) [string]
phantomas.setMetric('jQueryOnDOMReadyFunctions'); // @desc number of functions bound to onDOMReady event
phantomas.setMetric('jQuerySizzleCalls'); // @desc number of calls to Sizzle (including those that will be resolved using querySelectorAll)
phantomas.setMetric('jQuerySizzleCallsDuplicated'); // @desc number of calls on the same Sizzle request
phantomas.setMetric('jQueryBindOnMultipleElements'); //@desc number of calls to jQuery bind function on 2 or more elements
phantomas.setMetric('jQueryDifferentVersions'); //@desc number of different jQuery versions loaded on the page (not counting iframes)
var jQueryFunctions = [
// DOM manipulations
@@ -244,7 +246,7 @@ exports.module = function(phantomas) {
arg = 'false';
}
if (arg == null) {
if (arg === null) {
arg = 'null';
}
@@ -1,11 +1,12 @@
/**
* Meters the number of page errors, and provides traces as offenders for "jsErrors" metric
*/
'use strict';
exports.version = '0.3.a';
exports.module = function(phantomas) {
'use strict';
phantomas.setMetric('jsErrors'); // @desc number of JavaScript errors
function formatTrace(trace) {
@@ -1,11 +1,11 @@
/**
* Meters the number of page errors, and provides traces as offenders for "jsErrors" metric
*/
'use strict';
exports.version = '0.0';
exports.module = function(phantomas) {
'use strict';
phantomas.on('recv', function(entry, res) {
if (!entry.isJS) {
@@ -3,11 +3,11 @@
*
* Run phantomas with --js-execution-tree option to use this module
*/
'use strict';
exports.version = '0.1';
exports.module = function(phantomas) {
'use strict';
phantomas.setMetric('javascriptExecutionTree'); // @desc number of duplicated DOM queries