From 0f00111373d65be8a17ee2569aa91a5b934aa603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Thu, 15 Jan 2015 12:34:47 +0100 Subject: [PATCH] Fix #39 Error 1001 when using the Node module --- Gruntfile.js | 5 +- .../custom_modules/modules/domQYLT/domQYLT.js | 2 +- .../custom_modules/modules/jQYLT/jQYLT.js | 2 +- .../modules/jsFileLoadYLT/jsFileLoadYLT.js | 29 ---------- .../custom_modules/util/collection.js | 54 +++++++++++++++++++ 5 files changed, 59 insertions(+), 33 deletions(-) delete mode 100644 lib/tools/phantomas/custom_modules/modules/jsFileLoadYLT/jsFileLoadYLT.js create mode 100644 lib/tools/phantomas/custom_modules/util/collection.js diff --git a/Gruntfile.js b/Gruntfile.js index 197fe33..475359a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -93,7 +93,9 @@ module.exports = function(grunt) { coverage: { files: [ {src: ['test/**'], dest: 'coverage/'}, - {src: ['lib/metadata/**'], dest: 'coverage/'} + {src: ['lib/metadata/**'], dest: 'coverage/'}, + {src: ['node_modules/phantomas/**'], dest: 'coverage/'}, + {src: ['lib/tools/phantomas/custom_modules/**'], dest: 'coverage/'} ] }, build: { @@ -336,7 +338,6 @@ module.exports = function(grunt) { ]); grunt.registerTask('test-current-work', [ - 'build', 'jshint', 'express:testSuite', 'clean:coverage', diff --git a/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js b/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js index 81985f4..fe19cdc 100644 --- a/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js +++ b/lib/tools/phantomas/custom_modules/modules/domQYLT/domQYLT.js @@ -289,7 +289,7 @@ exports.module = function(phantomas) { // count DOM queries by either ID, tag name, class name and selector query // @see https://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-document-doctype - var Collection = require('../../../../../../node_modules/phantomas/lib/collection'), + var Collection = require('../../util/collection'), DOMqueries = new Collection(); phantomas.on('domQuery', function(type, query, fnName, context) { diff --git a/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js b/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js index a850312..d76db71 100644 --- a/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js +++ b/lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js @@ -276,7 +276,7 @@ exports.module = function(phantomas) { // count Sizzle calls to detect duplicated queries - var Collection = require('../../../../../../node_modules/phantomas/lib/collection'), + var Collection = require('../../util/collection'), sizzleCalls = new Collection(), jQueryLoading = new Collection(); diff --git a/lib/tools/phantomas/custom_modules/modules/jsFileLoadYLT/jsFileLoadYLT.js b/lib/tools/phantomas/custom_modules/modules/jsFileLoadYLT/jsFileLoadYLT.js deleted file mode 100644 index 4aa6c7d..0000000 --- a/lib/tools/phantomas/custom_modules/modules/jsFileLoadYLT/jsFileLoadYLT.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Meters the number of page errors, and provides traces as offenders for "jsErrors" metric - */ - -exports.version = '0.0'; - -exports.module = function(phantomas) { - 'use strict'; - - /*phantomas.on('recv', function(entry, res) { - if (!entry.isJS) { - return; - } - - // Yeah, this is weird, i'm sending the information back to the browser... - phantomas.evaluate(function(url) { - (function(phantomas) { - - phantomas.pushContext({ - type: 'script loaded', - callDetails: { - arguments: [url] - } - }); - - })(window.__phantomas); - }, entry.url); - });*/ -}; diff --git a/lib/tools/phantomas/custom_modules/util/collection.js b/lib/tools/phantomas/custom_modules/util/collection.js new file mode 100644 index 0000000..db1ca7f --- /dev/null +++ b/lib/tools/phantomas/custom_modules/util/collection.js @@ -0,0 +1,54 @@ +/** + * Push items and count them + */ + +function collection() { + /* jshint validthis: true */ + this.items = {}; +} + +collection.prototype = { + push: function(item) { + if (typeof this.items[item] === 'undefined') { + this.items[item] = { + cnt: 1 + }; + } else { + this.items[item].cnt++; + } + }, + + sort: function() { + var newItems = {}, + sortedKeys; + + // sort in descending order (by cnt) + sortedKeys = Object.keys(this.items).sort((function(a, b) { + return this.items[b].cnt - this.items[a].cnt; + }).bind(this)); + + // build new items dictionary + sortedKeys.forEach(function(key) { + newItems[key] = this.items[key]; + }, this); + + this.items = newItems; + return this; + }, + + forEach: function(callback) { + Object.keys(this.items).forEach(function(key) { + callback(key, this.items[key].cnt); + }, this); + }, + + has: function(item) { + return (typeof this.items[item] !== 'undefined'); + }, + + getLength: function() { + return Object.keys(this.items).length; + } +}; + +module.exports = collection;