File: errorhandling.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 (94 lines) | stat: -rw-r--r-- 3,988 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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() {
helper.files('errorhandling', 'mml', function(file) {
    var basename = path.basename(file);
    it('should handle errors in ' + basename, function(done) {
        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
            }).render(mml, function (err) {
                if (!err) {
                    throw new Error("*** invalid error handling test found: " + basename + ": all error handling tests should throw!");
                }
                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.
                fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
                    if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
                    done();
                });
            });
        } 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.
            fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
                if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
                done();
            });
        }
    });
});
});

describe('Error handling mss', function() {
helper.files('errorhandling', 'mss', function(file) {
    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'),
                // note: we use the basename here so that the expected error result
                // will match if the style was loaded from mml
                filename: basename
            }).renderMSS(mss, function (err) {
                if (!err) {
                    throw new Error("*** invalid error handling test found: " + basename + ": all error handling tests should throw!");
                }
                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.
                fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
                    if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
                    done();
                });
            });
        } 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.
            fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
                if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
                done();
            });
        }
    });
});
});