123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- var should = require('chai').should();
- var rulesChecker = require('../../lib/rulesChecker');
- describe('customPolicies', function() {
-
- var policies = require('../../lib/metadata/policies.js');
- var results;
-
- it('should transform DOMelementMaxDepth offenders', function() {
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "DOMelementMaxDepth": 3
- },
- "offenders": {
- "DOMelementMaxDepth": [
- "body > div#foo > span.bar"
- ]
- }
- }
- }
- }, policies);
- results.should.have.a.property('DOMelementMaxDepth');
- results.DOMelementMaxDepth.should.have.a.property('offendersObj').that.deep.equals({
- "count": 1,
- "tree": {
- "body": {
- "div#foo": {
- "span.bar": 1
- }
- }
- }
- });
- });
- it('should transform DOMidDuplicated offenders', function() {
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "DOMidDuplicated": 2
- },
- "offenders": {
- "DOMidDuplicated": [
- {
- "id": "colorswitch-30883-30865",
- "occurrences": 4
- }, {
- "id": "foo",
- "occurrences": 1
- }
- ]
- }
- }
- }
- }, policies);
- results.should.have.a.property('DOMidDuplicated');
- results.DOMidDuplicated.should.have.a.property('offendersObj').that.deep.equals({
- "count": 2,
- "list": [
- {
- "id": "colorswitch-30883-30865",
- "occurrences": 4
- },
- {
- "id": "foo",
- "occurrences": 1
- }
- ]
- });
- });
- it('should transform DOMqueriesAvoidable offenders', function() {
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "DOMqueriesAvoidable": 2
- },
- "offenders": {
- "DOMqueriesDuplicated": [
- "id \"#j2t-top-cart\" with getElementById (in context #document): 4 queries",
- "class \".listingResult\" with getElementsByClassName (in context body > div#Global > div#Listing): 4 queries"
- ]
- }
- }
- }
- }, policies);
- results.should.have.a.property('DOMqueriesAvoidable');
- results.DOMqueriesAvoidable.should.have.a.property('offendersObj').that.deep.equals({
- "count": 2,
- "list": [
- {
- "query": "#j2t-top-cart",
- "context": {
- "type": "document"
- },
- "fn": "getElementById ",
- "count": 4
- },
- {
- "query": ".listingResult",
- "context": {
- "type": "domElement",
- "element": "div#Listing",
- "tree": {
- "body": {
- "div#Global": {
- "div#Listing": 1
- }
- }
- }
- },
- "fn": "getElementsByClassName ",
- "count": 4
- }
- ]
- });
- });
- it('should transform jsErrors offenders', function() {
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "jsErrors": 2
- },
- "offenders": {
- "jsErrors": [
- "TypeError: 'undefined' is not a function (evaluating 'this.successfullyCollected.bind(this)') - http://asset.easydmp.net/js/collect.js:1160 / callCollecte http://asset.easydmp.net/js/collect.js:1203 / callbackUpdateParams http://asset.easydmp.net/js/collect.js:1135 / http://asset.easydmp.net/js/collect.js:1191",
- "TypeError: 'undefined' is not an object (evaluating 'd.readyState') - http://me.hunkal.com/p/:3"
- ]
- }
- }
- }
- }, policies);
- results.should.have.a.property('jsErrors');
- results.jsErrors.should.have.a.property('offendersObj').that.deep.equals({
- "count": 2,
- "list": [
- {
- "error": "TypeError: 'undefined' is not a function (evaluating 'this.successfullyCollected.bind(this)')",
- "backtrace": [
- {
- "file": "http://asset.easydmp.net/js/collect.js",
- "line": 1160
- },
- {
- "file": "http://asset.easydmp.net/js/collect.js",
- "line": 1203,
- "functionName": "callCollecte"
- },
- {
- "file": "http://asset.easydmp.net/js/collect.js",
- "line": 1135,
- "functionName": "callbackUpdateParams"
- },
- {
- "file": "http://asset.easydmp.net/js/collect.js",
- "line": 1191
- }
- ]
- },
- {
- "error": "TypeError: 'undefined' is not an object (evaluating 'd.readyState')",
- "backtrace": [
- {
- "file": "http://me.hunkal.com/p/",
- "line": 3
- }
- ]
- }
- ]
- });
- });
- it('should grade correctly jQuery versions', function() {
- var versions = {
- '1.7.0': 0,
- '1.10.1': 20,
- '1.10.3a': 20,
- '2.0.0-rc1': 20,
- '1.11.1': 30,
- '2.1.1-beta1': 30,
- '1.12.1': 40,
- '2.2.1': 40,
- '3.0.1': 50,
- '3.1.0': 70,
- '3.2.1': 90,
- '3.3.1': 100,
- '3.5.0': 100
- };
- for (var version in versions) {
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "jQueryVersion": version
- }
- }
- }
- }, policies);
- results.jQueryVersion.score.should.equal(versions[version]);
- }
- // Unknown jQuery version
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "jQueryVersion": "wooot"
- }
- }
- }
- }, policies);
- results.should.deep.equals({});
- // If jQueryVersionsLoaded is 0
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "jQueryVersion": "1.6.0",
- "jQueryVersionsLoaded": 0
- }
- }
- }
- }, policies);
- results.should.not.have.a.property('jQueryVersion');
- results.should.have.a.property('jQueryVersionsLoaded');
- results.jQueryVersionsLoaded.should.have.a.property('score').that.equals(100);
- // If there are more than 1 jQuery version
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "jQueryVersion": "1.6.0",
- "jQueryVersionsLoaded": 2
- }
- }
- }
- }, policies);
- results.should.not.have.a.property('jQueryVersion');
- results.should.have.a.property('jQueryVersionsLoaded');
- results.jQueryVersionsLoaded.should.have.a.property('score').that.equals(0);
- results.jQueryVersionsLoaded.should.have.a.property('abnormal').that.equals(true);
- });
- it('should transform cssParsingErrors offenders', function() {
- results = rulesChecker.check({
- "toolsResults": {
- "phantomas": {
- "metrics": {
- "cssParsingErrors": 2
- },
- "offenders": {
- "cssParsingErrors": [
- {
- "url": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/styles.css",
- "value": {
- "message": "Error: CSS parsing failed: missing '}'",
- "position": {
- "start": {
- "line": 4,
- "column": 1
- },
- "end": {
- "line": 4,
- "column": 72
- }
- }
- }
- },
- {
- "url": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/reset.css",
- "value": {
- "message": "Empty CSS was provided"
- }
- },
- "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/another.css"
- ]
- }
- }
- }
- }, policies);
- results.should.have.a.property('cssParsingErrors');
- results.cssParsingErrors.should.have.a.property('offendersObj').that.deep.equals({
- "count": 3,
- "list": [
- {
- "error": "Error: CSS parsing failed: missing '}'",
- "file": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/styles.css",
- "line": 4,
- "column": 1
- },
- {
- "error": "Empty CSS was provided",
- "file": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/reset.css",
- "line": null,
- "column": null
- },
- {
- "error": "Unknown parsing error. The entire file was ignored. As a result, the other CSS metrics and scores are miscalculated.",
- "file": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/another.css",
- "line": null,
- "column": null
- }
- ]
- });
- });
-
- // Enough for the moment, to be complete...
- });
|