Skip to content

Commit

Permalink
Add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
t32k committed Apr 5, 2014
1 parent d4dea67 commit 48b34ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/parser.js
Expand Up @@ -36,6 +36,7 @@ function requestSync(options) {
* @constructor
*/
function Parser(urls, files, styles, options) {

this.urls = urls;
this.files = files;
this.styles = styles;
Expand Down Expand Up @@ -198,12 +199,7 @@ Parser.prototype.parse = function(callback) {

// parse css string
var rawRules = [];

try {
rawRules = cssParse(parsedData.cssString).stylesheet.rules;
} catch (error) {
throw error;
}
rawRules = cssParse(parsedData.cssString).stylesheet.rules;

// add rules into result
rawRules.forEach(function(rule) {
Expand Down
4 changes: 4 additions & 0 deletions lib/stylestats.js
Expand Up @@ -77,6 +77,10 @@ function StyleStats(args, config) {
}

this.options = _.extend({}, defaultOptions, customOptions);

if (_.isEmpty(this.urls) && _.isEmpty(this.files) && _.isEmpty(this.styles)) {
throw new Error('Invalid argument: [' + args + ']');
}
this.parser = new Parser(this.urls, this.files, this.styles, this.options);
}

Expand Down
12 changes: 12 additions & 0 deletions test/stats-test.js
Expand Up @@ -82,6 +82,18 @@ describe('Customize with configuration file', function() {
});
});

describe('Invalid argument', function() {
it('should throw erroe', function(done) {
assert.throws(
function() {
new StyleStats('xxxxxxxxxxxxxxxx');
},
Error
);
done();
});
});

describe('Customize with option', function() {
it('should return gzipped size', function(done) {
var customObjectStats = new StyleStats('test/fixture/test.css', {
Expand Down

0 comments on commit 48b34ac

Please sign in to comment.