浏览代码

Fix #39 Error 1001 when using the Node module

Gaël Métais 10 年之前
父节点
当前提交
0f00111373

+ 3 - 2
Gruntfile.js

@@ -93,7 +93,9 @@ module.exports = function(grunt) {
             coverage: {
             coverage: {
                 files: [
                 files: [
                     {src: ['test/**'], dest: 'coverage/'},
                     {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: {
             build: {
@@ -336,7 +338,6 @@ module.exports = function(grunt) {
     ]);
     ]);
 
 
     grunt.registerTask('test-current-work', [
     grunt.registerTask('test-current-work', [
-        'build',
         'jshint',
         'jshint',
         'express:testSuite',
         'express:testSuite',
         'clean:coverage',
         'clean:coverage',

+ 1 - 1
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
     // 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
     // @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();
         DOMqueries = new Collection();
 
 
     phantomas.on('domQuery', function(type, query, fnName, context) {
     phantomas.on('domQuery', function(type, query, fnName, context) {

+ 1 - 1
lib/tools/phantomas/custom_modules/modules/jQYLT/jQYLT.js

@@ -276,7 +276,7 @@ exports.module = function(phantomas) {
 
 
 
 
     // count Sizzle calls to detect duplicated queries
     // count Sizzle calls to detect duplicated queries
-    var Collection = require('../../../../../../node_modules/phantomas/lib/collection'),
+    var Collection = require('../../util/collection'),
         sizzleCalls = new Collection(),
         sizzleCalls = new Collection(),
         jQueryLoading = new Collection();
         jQueryLoading = new Collection();
 
 

+ 0 - 29
lib/tools/phantomas/custom_modules/modules/jsFileLoadYLT/jsFileLoadYLT.js

@@ -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);
-    });*/
-};

+ 54 - 0
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;