This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
forked from cambecc/grib2json
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.test.js
121 lines (114 loc) · 3.39 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
let fs = require('fs-extra')
let path = require('path')
let chai = require('chai')
let chailint = require('chai-lint')
let grib2json = require('..')
describe('weacast-grib2json', () => {
const header = {
discipline: 0,
gribEdition: 2,
gribLength: 48676,
center: 7,
subcenter: 0,
refTime: '2017-06-20T00:00:00.000Z',
significanceOfRT: 1,
productStatus: 0,
productType: 1,
productDefinitionTemplate: 0,
parameterCategory: 0,
parameterNumber: 0,
parameterUnit: 'K',
genProcessType: 2,
forecastTime: 0,
surface1Type: 1,
surface1Value: 0,
surface2Type: 255,
surface2Value: 0,
gridDefinitionTemplate: 0,
numberPoints: 65160,
shape: 6,
gridUnits: 'degrees',
resolution: 48,
winds: 'true',
scanMode: 0,
nx: 360,
ny: 181,
basicAngle: 0,
subDivisions: 0,
lo1: 0,
la1: 90,
lo2: 359,
la2: -90,
dx: 1,
dy: 1
}
const output = path.join(__dirname, 'data', 'output.json')
let jsonArray
before(() => {
chailint(chai, chai.util)
})
it('is CommonJS compatible', () => {
chai.expect(typeof grib2json).to.equal('function')
})
it('generates valid json in memory', () => {
jsonArray = JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'gfs.json')))
return grib2json(path.join(__dirname, 'data', 'gfs.grib'), {
data: true, verbose: true
}).then(function (json) {
// We extract a single variable
chai.expect(json.length).to.equal(1)
// Check for header
chai.expect(json[0].header).to.deep.equal(header)
// Check for data
chai.expect(json[0].data.length).to.equal(jsonArray.length)
chai.expect(json[0].data).to.deep.equal(jsonArray)
})
})
// Let enough time to process data
.timeout(10000)
it('generates valid json in file', () => {
jsonArray = JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'gfs.json')))
return grib2json(path.join(__dirname, 'data', 'gfs.grib'), {
data: true,
output, verbose: true
}).then(function (json) {
// We extract a single variable
chai.expect(json.length).to.equal(1)
// Check for header
chai.expect(json[0].header).to.deep.equal(header)
// Check for data
chai.expect(json[0].data.length).to.equal(jsonArray.length)
chai.expect(json[0].data).to.deep.equal(jsonArray)
// Check for output
let jsonOutput = JSON.parse(fs.readFileSync(output))
chai.expect(json).to.deep.equal(jsonOutput)
})
})
// Let enough time to process data
.timeout(10000)
it('generates valid json with limited precision in file', () => {
jsonArray = jsonArray.map(value => Number(value.toFixed(2)))
return grib2json(path.join(__dirname, 'data', 'gfs.grib'), {
data: true,
output, verbose: true,
precision: 2
}).then(function (json) {
// We extract a single variable
chai.expect(json.length).to.equal(1)
// Check for header
chai.expect(json[0].header).to.deep.equal(header)
// Check for data
chai.expect(json[0].data.length).to.equal(jsonArray.length)
chai.expect(json[0].data).to.deep.equal(jsonArray)
// Check for output
let jsonOutput = JSON.parse(fs.readFileSync(output))
chai.expect(json).to.deep.equal(jsonOutput)
})
})
// Let enough time to process data
.timeout(10000)
// Cleanup
after(() => {
fs.removeSync(output)
})
})