diff --git a/test/errorhandling.test.js b/test/errorhandling.test.js index 7a962ff..d264d79 100644 --- a/test/errorhandling.test.js +++ b/test/errorhandling.test.js @@ -6,7 +6,7 @@ var carto = require('../lib/carto'); var tree = require('../lib/carto/tree'); var helper = require('./support/helper'); -describe('Error handling', function() { +describe('Error handling mml+mss', function() { helper.files('errorhandling', 'mml', function(file) { it('should handle errors in ' + path.basename(file), function(done) { var completed = false; @@ -45,3 +45,43 @@ helper.files('errorhandling', 'mml', function(file) { }); }); }); + +describe('Error handling mss', function() { +helper.files('errorhandling', 'mss', function(file) { + it('should handle errors in ' + path.basename(file), function(done) { + var completed = false; + var renderResult; + console.log(file) + var mss = helper.mss(file); + try { + new carto.Renderer({ + paths: [ path.dirname(file) ], + data_dir: path.join(__dirname, '../data'), + local_data_dir: path.join(__dirname, 'rendering'), + filename: file + }).renderMSS(mss, function (err) { + if (!err) { + console.warn("*** <--- WARNING invalid error handling test found (" + file + "): all error handling tests should throw errors!"); + } else { + var result = helper.resultFile(file); + var output = err.message; + // @TODO for some reason, fs.readFile includes an additional \n + // at the end of read files. Determine why. + fs.readFile(helper.resultFile(file), 'utf8', function(err, data) { + if (!err) assert.deepEqual(output, data.substr(0, data.length - 1)); + }); + } + }); + } catch(err) { + var result = helper.resultFile(file); + var output = err.message; + // @TODO for some reason, fs.readFile includes an additional \n + // at the end of read files. Determine why. + fs.readFile(helper.resultFile(file), 'utf8', function(err, data) { + if (!err) assert.deepEqual(output, data.substr(0, data.length - 1)); + }); + } + done(); + }); +}); +}); diff --git a/test/support/helper.js b/test/support/helper.js index 6507dc3..7118773 100644 --- a/test/support/helper.js +++ b/test/support/helper.js @@ -46,6 +46,10 @@ exports.mml = function(file) { return mml; }; +exports.mss = function(file) { + return fs.readFileSync(file, 'utf-8'); +}; + exports.showDifferences = function(e, format) { var changes = diff( (format || JSON.stringify)(e.actual),