File: rendering.test.js

package info (click to toggle)
node-carto 0.9.5-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, sid, stretch
  • size: 2,272 kB
  • ctags: 329
  • sloc: xml: 189; makefile: 22
file content (71 lines) | stat: -rw-r--r-- 2,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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('Rendering', function() {
helper.files('rendering', 'mml', function(file) {
    it('should render ' + path.basename(file) + ' correctly', function(done) {
        var completed = false;
        var renderResult;
        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 {
                    throw err;
                }
            } else {
                var result = helper.resultFile(file);
                renderResult = output;
                helper.compareToXMLFile(result, output, function(err,expected_json,actual_json) {
                    completed = true;
                    var actual = file.replace(path.extname(file),'') + '-actual.json';
                    var expected = file.replace(path.extname(file),'') + '-expected.json';
                    if (err) {
                        // disabled since it can break on large diffs
                        /*
                        console.warn(
                            helper.stylize("Failure", 'red') + ': ' +
                            helper.stylize(file, 'underline') +
                            ' differs from expected result.');
                        helper.showDifferences(err);
                        throw '';
                        */
                        fs.writeFileSync(actual,JSON.stringify(actual_json,null,4));
                        fs.writeFileSync(expected,JSON.stringify(expected_json,null,4));
                        throw new Error('failed: xml ' + result + ' in json form does not match expected result:\n' + actual + ' (actual)\n' + expected + ' (expected)');
                    } else {
                        // cleanup any actual renders that no longer fail
                        try {
                          fs.unlinkSync(actual);
                          fs.unlinkSync(expected);
                        } catch (err) {}
                    }
                    done();
                }, [
                    helper.removeAbsoluteImages,
                    helper.removeAbsoluteDatasources
                ]);
            }
        });

        // beforeExit(function() {
        //     if (!completed && renderResult) {
        //         console.warn(helper.stylize('renderer produced:', 'bold'));
        //         console.warn(renderResult);
        //     }
        //     assert.ok(completed, 'Rendering finished.');
        // });
    });
});
});