-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
test-helpers.js
33 lines (29 loc) · 918 Bytes
/
test-helpers.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
import nock from 'nock'
import config from 'config'
import { fetch } from '../core/base-service/got.js'
const runnerConfig = config.util.toObject()
function cleanUpNockAfterEach() {
afterEach(function () {
nock.cleanAll()
nock.enableNetConnect()
})
}
function noToken(serviceClass) {
let hasLogged = false
return () => {
const userKey = serviceClass.auth.userKey
const passKey = serviceClass.auth.passKey
const noToken =
(userKey && !runnerConfig.private[userKey]) ||
(passKey && !runnerConfig.private[passKey])
if (noToken && !hasLogged) {
console.warn(
`${serviceClass.name}: no credentials configured, tests for this service will be skipped. Add credentials in local.yml to run them.`
)
hasLogged = true
}
return noToken
}
}
const defaultContext = { requestFetcher: fetch }
export { cleanUpNockAfterEach, noToken, defaultContext }