Skip to content

Commit

Permalink
Add support for breaking on summary conditions with specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeekens committed Dec 16, 2014
1 parent 4cac4f3 commit 3b3e25c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ Or add it to an existing task: `grunt.registerTask('test', ['clean', 'weightwatc
* },
* groups: {
* text: 20000
* },
* summary: {
* text: 50000
* }
* }
*/
break: <{
file: {},
aggregations: {}
aggregations: {},
summary: {}
}>
}
```
Expand All @@ -78,3 +82,4 @@ Developing on the task alone is fairly easy just `git clone https://github.com/t
- 0.0.1 Initial release
- 0.0.2 Add conditional breaking of build
- 0.0.3 Clean up and refactoring
- 0.0.4 Add support for breaking on summary conditions
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grunt-weightwatchsy",
"version": "0.0.3",
"version": "0.0.4",
"description": "A grunt plugin to gather a project's assets' file sizes.",
"scripts": {
"test": "grunt ci-test"
Expand Down
10 changes: 9 additions & 1 deletion tasks/modules/breaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Breaker.prototype.breakOn = function(conditions, sizes) {
reasons: []
},
fileConditions = conditions.files || {},
aggregationConditions = conditions.aggregations || {};
aggregationConditions = conditions.aggregations || {},
summaryConditions = conditions.summary || {};;

Object.keys(fileConditions).forEach(function(file) {
if (sizes.files[file] > conditions.files[file]) {
Expand All @@ -27,6 +28,13 @@ Breaker.prototype.breakOn = function(conditions, sizes) {
}
});

Object.keys(summaryConditions).forEach(function(summary) {
if (sizes.summary[summary] > conditions.summary[summary]) {
analysis.reasons.push(summary);
analysis.broken = true;
}
});

return analysis;
};

Expand Down
3 changes: 2 additions & 1 deletion tasks/weightwatchsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = function(grunt) {
groups: {},
break: {
files: {},
aggregations: {}
aggregations: {},
summary: {}
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/coverage.html

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions test/modules/breaker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,26 @@ describe('Breaker specification', function() {
breakerResult.reasons.indexOf('.txt') >= 0
).to.be.true;
});

it('intendens to break when a summary condition is truethy', function() {
var files = [
'./test/fixtures/my.txt',
'./test/fixtures/five.txt',
'./test/fixtures/cents.txt'
];
var sizes = sizeDeterminer.determine(files);
var breakerResult = breaker.breakOn({
summary: {
size: 0
}
}, sizes);

expect(
breakerResult.broken
).to.be.true;

expect(
breakerResult.reasons.indexOf('size') >= 0
).to.be.true;
});
});

0 comments on commit 3b3e25c

Please sign in to comment.