forked from eurodatacube/public-collections
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stac-json.test.js
44 lines (36 loc) · 900 Bytes
/
stac-json.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
require('jest')
const fs = require('fs');
const path = require('path');
const jsonDir = './_output/stac/';
let files;
if (isExistingDirectory(jsonDir)) {
files = fs.readdirSync(jsonDir);
} else {
files = []
}
files.forEach((file) => {
test(`Should parse ${file} in STAC folder as JSON.`, () => {
const buffer = fs.readFileSync(path.join(jsonDir, file));
expect(isValidJSON(buffer)).toBe(true)
})
})
test.skip("Workaround to have at least one test available at all times", () => true)
function isExistingDirectory(directory) {
try {
fs.readdirSync(directory);
} catch (error) {
return false
}
return true
}
function isValidJSON(buffer) {
try {
const json = JSON.parse(buffer)
if (typeof json !== 'object') {
return false
}
} catch (error) {
return false
}
return true
}