carto/test/errorhandling.test.js

71 lines
2.6 KiB
JavaScript
Raw Normal View History

2011-07-25 14:26:20 +08:00
var path = require('path'),
assert = require('assert'),
fs = require('fs');
var carto = require('../lib/carto');
var tree = require('../lib/carto/tree');
var helper = require('./support/helper');
describe('Error handling mml+mss', function() {
2011-07-25 14:26:20 +08:00
helper.files('errorhandling', 'mml', function(file) {
var basename = path.basename(file);
it('should handle errors in ' + basename, function(done) {
2011-07-25 14:26:20 +08:00
var completed = false;
var renderResult;
var mml = helper.mml(file);
try {
new carto.Renderer({
paths: [ path.dirname(file) ],
data_dir: path.join(__dirname, '../data'),
local_data_dir: path.join(__dirname, 'rendering'),
filename: file
2014-05-21 04:10:31 +08:00
}).render(mml);
} catch(err) {
if (err.message.indexOf('***') > -1) throw err;
2011-07-25 14:26:20 +08:00
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.
2014-05-21 04:10:31 +08:00
// fs.writeFileSync(helper.resultFile(file), output);
var data = fs.readFileSync(helper.resultFile(file), 'utf8');
assert.deepEqual(output, data);
done();
}
});
});
2011-07-25 14:26:20 +08:00
});
describe('Error handling mss', function() {
helper.files('errorhandling', 'mss', function(file) {
2012-12-19 08:40:11 +08:00
var basename = path.basename(file);
if (basename == 'multi_stylesheets_a.mss') {
return;
}
it('should handle errors in ' + basename, function(done) {
var completed = false;
var renderResult;
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'),
2012-12-19 08:40:11 +08:00
// note: we use the basename here so that the expected error result
// will match if the style was loaded from mml
2012-12-19 08:40:11 +08:00
filename: basename
2014-05-21 04:10:31 +08:00
}).renderMSS(mss);
} catch(err) {
if (err.message.indexOf('***') > -1) throw 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.
2014-05-21 04:10:31 +08:00
// fs.writeFileSync(helper.resultFile(file), output);
var data = fs.readFileSync(helper.resultFile(file), 'utf8');
assert.deepEqual(output, data);
done();
}
});
});
});