File: specificity.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 (55 lines) | stat: -rw-r--r-- 2,070 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
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');

function cleanupItem(key, value) {
    if (key === 'rules') return;
    else if (key === 'ruleIndex') return;
    else if (key === 'elements') return value.map(function(item) { return item.value; });
    else if (key === 'filters') {
        var arr = [];
        for (var id in value.filters) arr.push(id + value.filters[id].val);
        if (arr.length) return arr;
    }
    else if (key === 'attachment' && value === '__default__') return;
    else if (key === 'zoom') {
        if (value != tree.Zoom.all) return (new tree.Zoom()).setZoom(value).toString();
    }
    else return value;
}

describe('Specificity', function() {
helper.files('specificity', 'mss', function(file) {
    it('should handle spec correctly in ' + file, function(done) {
        helper.file(file, function(content) {
            var tree = (new carto.Parser({
                paths: [ path.dirname(file) ],
                filename: file
            })).parse(content);

            var mss = tree.toList({});
            mss = helper.makePlain(mss, cleanupItem);
            var json = JSON.parse(fs.readFileSync(helper.resultFile(file)));
            var actual = file.replace(path.extname(file),'') + '-actual.json';
            var expected = file.replace(path.extname(file),'') + '-expected.json';
            try {
              assert.deepEqual(mss, json);
              // cleanup any actual renders that no longer fail
              try {
                fs.unlinkSync(actual);
                fs.unlinkSync(expected);
              } catch (err) {}
            } catch (err) {
                fs.writeFileSync(actual,JSON.stringify(mss,null,4));
                fs.writeFileSync(expected,JSON.stringify(json,null,4));
                throw new Error('failed: ' + actual + ' not equal to expected: ' + expected);
            }
            done();
        });
    });
});
});