Skip to content

Commit

Permalink
Better test failure information
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbasta committed Dec 10, 2016
1 parent ed66ab4 commit 746739b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ function Engine (name, fn) {

exports.bench = function (css, precise) {
var start = process.hrtime();
return new Promise(function (resolve) {
return Promise.resolve(fn(css)).then(function () {
return new Promise(function (resolve, reject) {
Promise.resolve(fn(css)).then(function () {
resolve(pretty(process.hrtime(start), {precise: precise}));
}, function (err) {
reject(err);
});
});
};
Expand Down
12 changes: 8 additions & 4 deletions engines/more-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ var more = require('more-css');

module.exports = new Engine('more-css', function (css) {
return new Promise(function (resolve, reject) {
var minified = more.compress(css, true);
if (minified.indexOf('Error: ') === 0) {
return reject(new Error(minified));
try {
var minified = more.compress(css, true);
if (minified.indexOf('Error: ') === 0) {
return reject(new Error(minified));
}
return resolve(minified);
} catch (e) {
reject(e);
}
return resolve(minified);
});
});
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ test('integration tests', function (t) {
Object.keys(minifiers).forEach(function (minifier) {
Promise.resolve(minifiers[minifier](css)).then(function (css) {
t.equal(css, expected, 'should minify css with ' + minifier);
}, function (err) {
t.fail('Failure from engine "' + minifier + '": ' + String(err));
});
});
});
Expand All @@ -23,6 +25,8 @@ test('benchmark tests', function (t) {
var minifier = minifiers[m];
Promise.resolve(minifier.bench(css)).then(function (time) {
t.ok(time, minifier + ' took ' + time);
}, function (err) {
t.fail('Failure from engine "' + minifier + '": ' + String(err));
});
});
});
Expand Down

0 comments on commit 746739b

Please sign in to comment.