carto/test/rendering.test.js
2011-05-17 13:54:44 -04:00

58 lines
2.0 KiB
JavaScript

var path = require('path'),
sys = require('sys'),
assert = require('assert'),
fs = require('fs');
var carto = require('carto');
var tree = require('carto/tree');
var helper = require('./support/helper');
helper.files('rendering', 'mml', function(file) {
exports['test rendering ' + file] = function(beforeExit) {
var completed = false;
var renderResult;
helper.file(file, function(mml) {
new carto.Renderer({
paths: [ path.dirname(file) ],
data_dir: path.join(__dirname, '../data'),
local_data_dir: path.join(__dirname, 'rendering'),
filename: file
}).render(mml, function (err, output) {
if (err) {
if (Array.isArray(err)){
err.forEach(carto.writeError);
} else {
throw err;
}
} else {
renderResult = output;
var result = helper.resultFile(file);
helper.compareToXMLFile(result, output, function(err) {
completed = true;
if (err) {
console.warn(
helper.stylize("Failure", 'red') + ': '
+ helper.stylize(file, 'underline')
+ ' differs from expected result.');
helper.showDifferences(err);
throw '';
}
}, [
helper.removeAbsoluteImages,
helper.removeAbsoluteDatasources
]);
}
});
});
beforeExit(function() {
if (!completed && renderResult) {
console.warn(helper.stylize('renderer produced:', 'bold'));
console.warn(renderResult);
}
assert.ok(completed, 'Rendering finished.');
});
}
});