2011-01-25 06:23:18 +08:00
|
|
|
var path = require('path'),
|
|
|
|
assert = require('assert'),
|
2011-01-27 06:56:16 +08:00
|
|
|
fs = require('fs');
|
2011-01-25 06:23:18 +08:00
|
|
|
|
2011-07-23 01:48:52 +08:00
|
|
|
var carto = require('../lib/carto');
|
|
|
|
var tree = require('../lib/carto/tree');
|
2011-01-25 06:23:18 +08:00
|
|
|
var helper = require('./support/helper');
|
|
|
|
|
2012-05-03 00:56:38 +08:00
|
|
|
describe('Rendering', function() {
|
2011-01-25 06:23:18 +08:00
|
|
|
helper.files('rendering', 'mml', function(file) {
|
2012-05-03 00:56:38 +08:00
|
|
|
it('should render ' + path.basename(file) + ' correctly', function(done) {
|
2011-01-25 07:50:27 +08:00
|
|
|
var completed = false;
|
2011-01-26 06:12:45 +08:00
|
|
|
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);
|
2011-01-25 06:23:18 +08:00
|
|
|
} else {
|
2011-07-23 01:48:52 +08:00
|
|
|
throw err;
|
2011-01-25 06:23:18 +08:00
|
|
|
}
|
2011-07-23 01:48:52 +08:00
|
|
|
} else {
|
|
|
|
var result = helper.resultFile(file);
|
2012-12-22 07:05:17 +08:00
|
|
|
renderResult = output;
|
2012-12-22 08:12:02 +08:00
|
|
|
helper.compareToXMLFile(result, output, function(err,expected_json,actual_json) {
|
2011-07-23 01:48:52 +08:00
|
|
|
completed = true;
|
2012-12-22 08:12:02 +08:00
|
|
|
var actual = file.replace(path.extname(file),'') + '-actual.json';
|
|
|
|
var expected = file.replace(path.extname(file),'') + '-expected.json';
|
2011-07-23 01:48:52 +08:00
|
|
|
if (err) {
|
2012-12-22 07:05:17 +08:00
|
|
|
// disabled since it can break on large diffs
|
|
|
|
/*
|
2011-07-23 01:48:52 +08:00
|
|
|
console.warn(
|
2012-05-03 00:56:38 +08:00
|
|
|
helper.stylize("Failure", 'red') + ': ' +
|
|
|
|
helper.stylize(file, 'underline') +
|
|
|
|
' differs from expected result.');
|
2011-07-23 01:48:52 +08:00
|
|
|
helper.showDifferences(err);
|
|
|
|
throw '';
|
2012-12-22 07:05:17 +08:00
|
|
|
*/
|
2012-12-22 08:12:02 +08:00
|
|
|
fs.writeFileSync(actual,JSON.stringify(actual_json,null,4));
|
|
|
|
fs.writeFileSync(expected,JSON.stringify(expected_json,null,4));
|
2013-03-02 04:08:29 +08:00
|
|
|
throw new Error('failed: xml ' + result + ' in json form does not match expected result:\n' + actual + ' (actual)\n' + expected + ' (expected)');
|
2012-12-22 07:14:36 +08:00
|
|
|
} else {
|
|
|
|
// cleanup any actual renders that no longer fail
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(actual);
|
2012-12-22 08:12:02 +08:00
|
|
|
fs.unlinkSync(expected);
|
2012-12-22 07:14:36 +08:00
|
|
|
} catch (err) {}
|
2011-07-23 01:48:52 +08:00
|
|
|
}
|
2012-12-22 07:05:17 +08:00
|
|
|
done();
|
2011-07-23 01:48:52 +08:00
|
|
|
}, [
|
|
|
|
helper.removeAbsoluteImages,
|
|
|
|
helper.removeAbsoluteDatasources
|
|
|
|
]);
|
|
|
|
}
|
2011-01-25 06:23:18 +08:00
|
|
|
});
|
|
|
|
|
2012-05-03 00:56:38 +08:00
|
|
|
// beforeExit(function() {
|
|
|
|
// if (!completed && renderResult) {
|
|
|
|
// console.warn(helper.stylize('renderer produced:', 'bold'));
|
|
|
|
// console.warn(renderResult);
|
|
|
|
// }
|
|
|
|
// assert.ok(completed, 'Rendering finished.');
|
|
|
|
// });
|
|
|
|
});
|
|
|
|
});
|
2011-01-25 06:23:18 +08:00
|
|
|
});
|