forked from geostyler/geostyler-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
81 lines (64 loc) · 2.13 KB
/
test.js
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
const fs = require('fs');
const { spawnSync } = require('child_process');
function checkFileCreated(outputFile) {
try {
fs.accessSync(outputFile, fs.constants.F_OK);
return true;
} catch (err) {
/* eslint-disable no-console */
console.log(`The file: ${outputFile} was not found`);
return false;
}
}
function runTest(args, outputFile) {
const cmd = 'npm';
const result = spawnSync(cmd, args, { shell: true });
/* eslint-disable no-console */
console.log(`Status: ${result.status.toString()}`);
console.log(`Output: ${result.stdout.toString()}`);
console.log(`Error: ${result.stderr.toString()}`);
}
function runAllTests() {
let success = true;
// test sld to qgis
let outputFile = 'output.qml';
let args = ['start', '--', '-s', 'sld', '-t', 'qgis', '-o', outputFile, 'testdata/sld/point_simplepoint.sld'];
runTest(args, outputFile);
if (checkFileCreated(outputFile) === false) {
success = false;
}
// test qgis to sld
outputFile = 'output.sld';
args = ['start', '--', '-s', 'qgis', '-t', 'sld', '-o', outputFile, 'testdata/point_simple.qml'];
runTest(args, outputFile);
if (checkFileCreated(outputFile) === false) {
success = false;
}
// test mapfile to geostyler
outputFile = 'output.geostyler';
args = ['start', '--', '-s', 'mapfile', '-o', outputFile, 'testdata/point_simplepoint.map'];
runTest(args, outputFile);
if (checkFileCreated(outputFile) === false) {
success = false;
}
// test geostyler to mapbox
outputFile = 'output.mapbox';
args = ['start', '--', '-s', 'geostyler', '-o', outputFile, 'testdata/point_simplepoint.geostyler'];
runTest(args, outputFile);
if (checkFileCreated(outputFile) === false) {
success = false;
}
// test folder output
args = ['start', '--', '-s', 'sld', '-t', 'qgis', '-o', './output-bulk', 'testdata/sld'];
runTest(args, outputFile);
if (checkFileCreated('./output-bulk/sld/point_simplepoint.qml') === false) {
success = false;
}
if (checkFileCreated('./output-bulk/sld/point_simpletriangle.qml') === false) {
success = false;
}
return success;
}
if (runAllTests() === false) {
process.exit(1);
}