Debian Codegraph @

topojson/test/geojson-command-test.js

raw
1 var fs = require("fs"),
2 os = require("os"),
3 path = require("path"),
4 child = require("child_process"),
5 tape = require("tape");
6
7 require("./inDelta");
8
9 var tmpprefix = "geojson-command-test-" + process.pid + "-",
10 testId = Math.random() * 0xffff | 0;
11
12 testConversion(
13 "Polygons",
14 {
15 polygon: "polygon-feature"
16 },
17 "-- test/topojson/polygon.json"
18 );
19
20 testConversion(
21 "Non-quantized Polygons",
22 {
23 polygon: "polygon-feature"
24 },
25 "-- test/topojson/polygon-no-quantization.json"
26 );
27
28 testConversion(
29 "Projected polygons",
30 {
31 clockwise: "polygon-feature-mercator",
32 counterclockwise: "polygon-feature-mercator"
33 },
34 "-- test/topojson/polygon-mercator.json"
35 );
36
37 testConversion(
38 "Rounded polygons",
39 {
40 clockwise: "polygon-feature-rounded",
41 counterclockwise: "polygon-feature-rounded"
42 },
43 "--precision 2"
44 + " -- test/topojson/polygon-mercator.json"
45 );
46
47 function testConversion(name, output, options) {
48 if (!options) options = "";
49 var tmpdir = path.join(os.tmpdir(), tmpprefix + (++testId).toString(16));
50 fs.mkdirSync(tmpdir);
51 tape(name, function(test) {
52 child.exec("bin/topojson-geojson -o " + tmpdir + " " + options, function(error) {
53 if (error) throw error;
54 var actual = {};
55 fs.readdirSync(tmpdir).forEach(function(file) {
56 actual[path.basename(file, ".json")] = JSON.parse(fs.readFileSync(tmpdir + "/" + file), "utf-8");
57 fs.unlinkSync(tmpdir + "/" + file);
58 });
59 fs.rmdir(tmpdir);
60 for (var file in output) {
61 test.inDelta(actual[file], JSON.parse(fs.readFileSync("test/geojson/" + output[file] + ".json", "utf-8")));
62 }
63 test.end();
64 });
65 });
66 }