-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmake-error.js
31 lines (24 loc) · 1.24 KB
/
make-error.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
const _makeError = require('../lib/make-error.js')
const errors = require('../lib/errors.js')
const t = require('tap')
const makeError = (message) =>
// Create the error with properties like it came from promise-spawn
_makeError(Object.assign(new Error(), { stderr: message }))
t.test('throw matching error for missing pathspec', (t) => {
const missingPathspec =
makeError('error: pathspec \'foo\' did not match any file(s) known to git')
t.ok(missingPathspec instanceof errors.GitPathspecError, 'error is a pathspec error')
t.end()
})
t.test('only transient connection errors are retried', (t) => {
const sslError = makeError('SSL_ERROR_SYSCALL')
t.ok(sslError.shouldRetry(1), 'transient error, not beyond max')
t.ok(sslError instanceof errors.GitConnectionError, 'error is a connection error')
const unknownError = makeError('asdf')
t.notOk(unknownError.shouldRetry(1), 'unknown error, do not retry')
t.ok(unknownError instanceof errors.GitUnknownError, 'error is an unknown error')
const connectError = makeError('Failed to connect to fooblz Timed out')
t.notOk(connectError.shouldRetry(69), 'beyond max retries, do not retry')
t.ok(connectError instanceof errors.GitConnectionError, 'error is a connection error')
t.end()
})