-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
38 lines (34 loc) · 949 Bytes
/
index.ts
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
/*
* @japa/api-client
*
* (c) Japa.dev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import type { PluginFn } from '@japa/runner/types'
import { ApiClient } from './src/client.js'
import { TestContext } from '@japa/runner/core'
export { ApiClient }
export { ApiRequest } from './src/request.js'
export { ApiResponse } from './src/response.js'
/**
* API client plugin registers an HTTP request client that
* can be used for testing API endpoints.
*/
export function apiClient(options?: string | { baseURL?: string }): PluginFn {
return function () {
TestContext.getter(
'client',
function (this: TestContext) {
return new ApiClient(typeof options === 'string' ? options : options?.baseURL, this.assert)
},
true
)
}
}
declare module '@japa/runner/core' {
interface TestContext {
client: ApiClient
}
}