-
-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathtest-errors.js
114 lines (112 loc) · 3.04 KB
/
test-errors.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
'use strict'
const t = require('tap')
const { codes: errors } = require('../../lib/ours/errors')
function checkError(err, Base, name, code, message) {
t.ok(err instanceof Base)
t.equal(err.name, name)
t.equal(err.code, code)
t.equal(err.message, message)
}
// Update this numbers based on the number of checkError below multiplied by the assertions within checkError
t.plan(17 * 4)
checkError(
new errors.ERR_INVALID_ARG_VALUE('name', 0),
TypeError,
'TypeError',
'ERR_INVALID_ARG_VALUE',
"The argument 'name' is invalid. Received 0"
)
checkError(
new errors.ERR_INVALID_ARG_VALUE('name', undefined),
TypeError,
'TypeError',
'ERR_INVALID_ARG_VALUE',
"The argument 'name' is invalid. Received undefined"
)
checkError(
new errors.ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], 0),
TypeError,
'TypeError',
'ERR_INVALID_ARG_TYPE',
'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received type number (0)'
)
checkError(
new errors.ERR_INVALID_ARG_TYPE('first argument', 'not string', 'foo'),
TypeError,
'TypeError',
'ERR_INVALID_ARG_TYPE',
"The first argument must be not string. Received type string ('foo')"
)
checkError(
new errors.ERR_INVALID_ARG_TYPE('obj.prop', 'string', undefined),
TypeError,
'TypeError',
'ERR_INVALID_ARG_TYPE',
'The "obj.prop" property must be of type string. Received undefined'
)
checkError(
new errors.ERR_STREAM_PUSH_AFTER_EOF(),
Error,
'Error',
'ERR_STREAM_PUSH_AFTER_EOF',
'stream.push() after EOF'
)
checkError(
new errors.ERR_METHOD_NOT_IMPLEMENTED('_read()'),
Error,
'Error',
'ERR_METHOD_NOT_IMPLEMENTED',
'The _read() method is not implemented'
)
checkError(
new errors.ERR_METHOD_NOT_IMPLEMENTED('_write()'),
Error,
'Error',
'ERR_METHOD_NOT_IMPLEMENTED',
'The _write() method is not implemented'
)
checkError(new errors.ERR_STREAM_PREMATURE_CLOSE(), Error, 'Error', 'ERR_STREAM_PREMATURE_CLOSE', 'Premature close')
checkError(
new errors.ERR_STREAM_DESTROYED('pipe'),
Error,
'Error',
'ERR_STREAM_DESTROYED',
'Cannot call pipe after a stream was destroyed'
)
checkError(
new errors.ERR_STREAM_DESTROYED('write'),
Error,
'Error',
'ERR_STREAM_DESTROYED',
'Cannot call write after a stream was destroyed'
)
checkError(
new errors.ERR_MULTIPLE_CALLBACK(),
Error,
'Error',
'ERR_MULTIPLE_CALLBACK',
'Callback called multiple times'
)
checkError(new errors.ERR_STREAM_CANNOT_PIPE(), Error, 'Error', 'ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable')
checkError(new errors.ERR_STREAM_WRITE_AFTER_END(), Error, 'Error', 'ERR_STREAM_WRITE_AFTER_END', 'write after end')
checkError(
new errors.ERR_STREAM_NULL_VALUES(),
TypeError,
'TypeError',
'ERR_STREAM_NULL_VALUES',
'May not write null values to stream'
)
checkError(
new errors.ERR_UNKNOWN_ENCODING('foo'),
TypeError,
'TypeError',
'ERR_UNKNOWN_ENCODING',
'Unknown encoding: foo'
)
checkError(
new errors.ERR_STREAM_UNSHIFT_AFTER_END_EVENT(),
Error,
'Error',
'ERR_STREAM_UNSHIFT_AFTER_END_EVENT',
'stream.unshift() after end event'
)