carto/test/rendering.test.js

58 lines
2.0 KiB
JavaScript
Raw Normal View History

var path = require('path'),
assert = require('assert'),
2011-01-27 06:56:16 +08:00
fs = require('fs');
2011-07-23 01:48:52 +08:00
var carto = require('../lib/carto');
var tree = require('../lib/carto/tree');
var helper = require('./support/helper');
describe('Rendering', function() {
helper.files('rendering', 'mml', function(file) {
it('should render ' + path.basename(file) + ' correctly', function(done) {
2011-01-25 07:50:27 +08:00
var completed = false;
var renderResult;
2011-07-23 01:48:52 +08:00
var mml = helper.mml(file);
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 {
2011-07-23 01:48:52 +08:00
throw err;
}
2011-07-23 01:48:52 +08:00
} 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.');
2011-07-23 01:48:52 +08:00
helper.showDifferences(err);
throw '';
}
}, [
helper.removeAbsoluteImages,
helper.removeAbsoluteDatasources
]);
}
done();
});
// beforeExit(function() {
// if (!completed && renderResult) {
// console.warn(helper.stylize('renderer produced:', 'bold'));
// console.warn(renderResult);
// }
// assert.ok(completed, 'Rendering finished.');
// });
});
});
});