-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from leny/feature/declarations-per-rule-metric
Feature/declarations per rule metric
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/*! Parker v0.0.0 - MIT license */ | ||
|
||
'use strict'; | ||
|
||
var CssRule = require( "../lib/CssRule.js" ); | ||
|
||
module.exports = { | ||
id: 'declarations-per-rule', | ||
name: 'Declarations Per Rule', | ||
type: 'rule', | ||
aggregate: 'mean', | ||
format: 'number', | ||
measure: function (rule) { | ||
return (new CssRule(rule)).getDeclarations().length; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*! Parker v0.0.0 - MIT license */ | ||
|
||
var expect = require('chai').expect, | ||
Parker = require('../lib/Parker.js'), | ||
metric = require('../metrics/DeclarationsPerRule.js'); | ||
|
||
|
||
describe('The declarations-per-rule metric', function () { | ||
it('should provide a string identifier for the metric', function() { | ||
expect(metric.id).to.be.a('string'); | ||
}); | ||
|
||
it('should provide a metric type', function() { | ||
expect(metric.aggregate).to.match(/sum|mean/g); | ||
}); | ||
|
||
it('should return 0 for an empty string', function () { | ||
expect(metric.measure('')).to.equal(0); | ||
}); | ||
|
||
it('should return 1 for the selector "body {color:blue;}"', function() { | ||
expect(metric.measure('body {color:blue;}')).to.equal(1); | ||
}); | ||
|
||
it('should return 2 for the selector "body section {color:blue;background:yellow;}"', function() { | ||
expect(metric.measure('body section {color:blue;background:yellow;}')).to.equal(2); | ||
}); | ||
|
||
it('should return 2 for the selector "body section {color:blue;background:yellow;} body article h3 {text-align:center;color:red;}"', function() { | ||
var parker = new Parker([metric]), | ||
report = parker.run('body section {color:blue;background:yellow;} body article h3 {text-align:center;color:red;}'); | ||
|
||
expect(report).to.have.property('declarations-per-rule'); | ||
expect(report['declarations-per-rule']).to.equal(2); | ||
}); | ||
|
||
it('should return 1.5 for the selector "body section {color:blue;background:yellow;} body article h3 {text-align:center;}"', function() { | ||
var parker = new Parker([metric]), | ||
report = parker.run('body section {color:blue;background:yellow;} body article h3 {text-align:center;}'); | ||
|
||
expect(report).to.have.property('declarations-per-rule'); | ||
expect(report['declarations-per-rule']).to.equal(1.5); | ||
}); | ||
|
||
it('should return 2 for the selector "body section {-webkit-something:blue;-moz-anything:yellow;} body article h3 {text-align:center;color:red;}"', function() { | ||
var parker = new Parker([metric]), | ||
report = parker.run('body section {-webkit-something:blue;-moz-anything:yellow;} body article h3 {text-align:center;color:red;}'); | ||
|
||
expect(report).to.have.property('declarations-per-rule'); | ||
expect(report['declarations-per-rule']).to.equal(2); | ||
}); | ||
}); |