@@ -3,15 +3,15 @@ import { NtpPacketParser } from "../src";
3
3
4
4
const assert = require ( "assert" ) ;
5
5
6
- describe ( "NTP packet parser" , function ( ) {
7
- describe ( "Structure" , function ( ) {
6
+ describe ( "NTP packet parser" , function ( ) {
7
+ describe ( "Structure" , function ( ) {
8
8
const validPacket = require ( "./packets.valid" ) [ 0 ] . buffer ;
9
9
10
- it ( "should parse without errors" , function ( ) {
10
+ it ( "should parse without errors" , function ( ) {
11
11
NtpPacketParser . parse ( validPacket ) ;
12
12
} ) ;
13
13
14
- it ( "should return a full struct" , function ( ) {
14
+ it ( "should return a full struct" , function ( ) {
15
15
const struct = NtpPacketParser . parse ( validPacket ) ;
16
16
17
17
assert . ok ( "leapIndicator" in struct ) ;
@@ -29,106 +29,100 @@ describe("NTP packet parser", function() {
29
29
assert . ok ( "transmitTimestamp" in struct ) ;
30
30
} ) ;
31
31
32
- it ( "should return an integer for leapIndicator" , function ( ) {
32
+ it ( "should return an integer for leapIndicator" , function ( ) {
33
33
const struct = NtpPacketParser . parse ( validPacket ) ;
34
34
35
35
assert . ok ( Number . isInteger ( struct . leapIndicator ) ) ;
36
36
} ) ;
37
37
38
- it ( "should return an integer for mode" , function ( ) {
38
+ it ( "should return an integer for mode" , function ( ) {
39
39
const struct = NtpPacketParser . parse ( validPacket ) ;
40
40
41
41
assert . ok ( Number . isInteger ( struct . mode ) ) ;
42
42
} ) ;
43
43
44
- it ( "should return an integer for stratum" , function ( ) {
44
+ it ( "should return an integer for stratum" , function ( ) {
45
45
const struct = NtpPacketParser . parse ( validPacket ) ;
46
46
47
47
assert . ok ( Number . isInteger ( struct . stratum ) ) ;
48
48
} ) ;
49
49
50
- it ( "should return an integer for poll" , function ( ) {
50
+ it ( "should return an integer for poll" , function ( ) {
51
51
const struct = NtpPacketParser . parse ( validPacket ) ;
52
52
53
53
assert . ok ( Number . isInteger ( struct . poll ) ) ;
54
54
} ) ;
55
55
56
- it ( "should return an integer for precision" , function ( ) {
56
+ it ( "should return an integer for precision" , function ( ) {
57
57
const struct = NtpPacketParser . parse ( validPacket ) ;
58
58
59
59
assert . ok ( Number . isInteger ( struct . precision ) ) ;
60
60
} ) ;
61
61
62
- it ( "should return a date for rootDelay" , function ( ) {
62
+ it ( "should return a date for rootDelay" , function ( ) {
63
63
const struct = NtpPacketParser . parse ( validPacket ) ;
64
64
65
65
assert . ok ( struct . rootDelay instanceof Date ) ;
66
66
} ) ;
67
67
68
- it ( "should return a date for rootDispersion" , function ( ) {
68
+ it ( "should return a date for rootDispersion" , function ( ) {
69
69
const struct = NtpPacketParser . parse ( validPacket ) ;
70
70
71
71
assert . ok ( struct . rootDispersion instanceof Date ) ;
72
72
} ) ;
73
73
74
- it ( "should return a string for referenceId" , function ( ) {
74
+ it ( "should return a string for referenceId" , function ( ) {
75
75
const struct = NtpPacketParser . parse ( validPacket ) ;
76
76
77
77
assert . ok ( typeof struct . referenceId === "string" ) ;
78
78
} ) ;
79
79
80
- it ( "should return a date for referenceTimestamp" , function ( ) {
80
+ it ( "should return a date for referenceTimestamp" , function ( ) {
81
81
const struct = NtpPacketParser . parse ( validPacket ) ;
82
82
83
83
assert . ok ( struct . referenceTimestamp instanceof Date ) ;
84
84
} ) ;
85
85
86
- it ( "should return a date for originTimestamp" , function ( ) {
86
+ it ( "should return a date for originTimestamp" , function ( ) {
87
87
const struct = NtpPacketParser . parse ( validPacket ) ;
88
88
89
89
assert . ok ( struct . originTimestamp instanceof Date ) ;
90
90
} ) ;
91
91
92
- it ( "should return a date for receiveTimestamp" , function ( ) {
92
+ it ( "should return a date for receiveTimestamp" , function ( ) {
93
93
const struct = NtpPacketParser . parse ( validPacket ) ;
94
94
95
95
assert . ok ( struct . receiveTimestamp instanceof Date ) ;
96
96
} ) ;
97
97
98
- it ( "should return a date for transmitTimestamp" , function ( ) {
98
+ it ( "should return a date for transmitTimestamp" , function ( ) {
99
99
const struct = NtpPacketParser . parse ( validPacket ) ;
100
100
101
101
assert . ok ( struct . transmitTimestamp instanceof Date ) ;
102
102
} ) ;
103
103
} ) ;
104
104
105
105
const validPackets = require ( "./packets.valid.js" ) ;
106
- validPackets . forEach ( function ( packet ) {
107
- describe ( "Parsing" , function ( ) {
106
+ validPackets . forEach ( function ( packet ) {
107
+ describe ( "Parsing" , function ( ) {
108
108
const struct = NtpPacketParser . parse ( packet . buffer ) ;
109
109
110
110
for ( let key in packet . expected ) {
111
111
if ( ! packet . expected . hasOwnProperty ( key ) ) {
112
112
continue ;
113
113
}
114
114
115
- it ( "should have the property " + key , function ( ) {
115
+ it ( "should have the property " + key , function ( ) {
116
116
assert . ok ( key in struct ) ;
117
117
} ) ;
118
118
119
- it (
120
- "should return " + packet . expected [ key ] + " for property " + key ,
121
- function ( ) {
122
- if ( packet . expected [ key ] instanceof Date ) {
123
- assert . equal (
124
- struct [ key ] . getTime ( ) ,
125
- packet . expected [ key ] . getTime ( )
126
- ) ;
127
- } else {
128
- assert . equal ( struct [ key ] , packet . expected [ key ] ) ;
129
- }
119
+ it ( "should return " + packet . expected [ key ] + " for property " + key , function ( ) {
120
+ if ( packet . expected [ key ] instanceof Date ) {
121
+ assert . equal ( struct [ key ] . getTime ( ) , packet . expected [ key ] . getTime ( ) ) ;
122
+ } else {
123
+ assert . equal ( struct [ key ] , packet . expected [ key ] ) ;
130
124
}
131
- ) ;
125
+ } ) ;
132
126
}
133
127
} ) ;
134
128
} ) ;
0 commit comments