1
- import test from 'ava' ;
2
- import nock from 'nock' ;
3
- import getStream from 'get-stream' ;
4
- import ghGot from '.' ;
1
+ const test = require ( 'ava' ) ;
2
+ const nock = require ( 'nock' ) ;
3
+ const getStream = require ( 'get-stream' ) ;
4
+ const ghGot = require ( '.' ) ;
5
5
6
6
const token = process . env . GITHUB_TOKEN ;
7
7
@@ -10,43 +10,54 @@ test('default', async t => {
10
10
} ) ;
11
11
12
12
test ( 'full path' , async t => {
13
- t . is ( ( await ghGot ( 'https://api.github.com/users/sindresorhus' ) ) . body . login , 'sindresorhus' ) ;
13
+ t . is ( ( await ghGot ( 'https://api.github.com/users/sindresorhus' , { prefixUrl : '' } ) ) . body . login , 'sindresorhus' ) ;
14
14
} ) ;
15
15
16
16
test ( 'accepts options' , async t => {
17
17
t . is ( ( await ghGot ( 'users/sindresorhus' , { } ) ) . body . login , 'sindresorhus' ) ;
18
18
} ) ;
19
19
20
- test ( 'accepts options.endpoint without trailing slash' , async t => {
21
- t . is ( ( await ghGot ( 'users/sindresorhus' , { endpoint : 'https://api.github.com' } ) ) . body . login , 'sindresorhus' ) ;
20
+ test ( 'accepts options.prefixUrl without trailing slash' , async t => {
21
+ t . is ( ( await ghGot ( 'users/sindresorhus' , { prefixUrl : 'https://api.github.com' } ) ) . body . login , 'sindresorhus' ) ;
22
22
} ) ;
23
23
24
24
test ( 'dedupes slashes' , async t => {
25
- t . is ( ( await ghGot ( '/users/sindresorhus' , { endpoint : 'https://api.github.com/' } ) ) . body . login , 'sindresorhus' ) ;
25
+ t . is ( ( await ghGot ( '/users/sindresorhus' , { prefixUrl : 'https://api.github.com/' } ) ) . body . login , 'sindresorhus' ) ;
26
26
} ) ;
27
27
28
28
test . serial ( 'global token option' , async t => {
29
29
process . env . GITHUB_TOKEN = 'fail' ;
30
- await t . throwsAsync ( ghGot . recreate ( ) ( 'users/sindresorhus' ) , 'Bad credentials (401)' ) ;
30
+ await t . throwsAsync (
31
+ ghGot . recreate ( ) ( 'users/sindresorhus' ) ,
32
+ {
33
+ message : 'Bad credentials (401)'
34
+ }
35
+ ) ;
31
36
process . env . GITHUB_TOKEN = token ;
32
37
} ) ;
33
38
34
39
test ( 'token option' , async t => {
35
- await t . throwsAsync ( ghGot ( 'users/sindresorhus' , { token : 'fail' } ) , 'Bad credentials (401)' ) ;
40
+ await t . throwsAsync ( ghGot ( 'users/sindresorhus' , { token : 'fail' } ) , {
41
+ message : 'Bad credentials (401)'
42
+ } ) ;
36
43
} ) ;
37
44
38
45
test . serial ( 'global endpoint option' , async t => {
39
46
process . env . GITHUB_ENDPOINT = 'fail' ;
40
- await t . throwsAsync ( ghGot . recreate ( ) ( 'users/sindresorhus' , { retries : 1 } ) , 'Invalid URL: fail/' ) ;
47
+ await t . throwsAsync ( ghGot . recreate ( ) ( 'users/sindresorhus' , { retries : 1 } ) , {
48
+ message : 'Invalid URL: fail/users/sindresorhus'
49
+ } ) ;
41
50
delete process . env . GITHUB_ENDPOINT ;
42
51
} ) ;
43
52
44
53
test . serial ( 'endpoint option' , async t => {
45
54
process . env . GITHUB_ENDPOINT = 'https://api.github.com/' ;
46
55
await t . throwsAsync ( ghGot . recreate ( ) ( 'users/sindresorhus' , {
47
- baseUrl : 'fail' ,
56
+ prefixUrl : 'fail' ,
48
57
retries : 1
49
- } ) , 'Invalid URL: fail/' ) ;
58
+ } ) , {
59
+ message : 'Invalid URL: fail/users/sindresorhus'
60
+ } ) ;
50
61
delete process . env . GITHUB_ENDPOINT ;
51
62
} ) ;
52
63
@@ -56,13 +67,13 @@ test('stream interface', async t => {
56
67
} ) ;
57
68
58
69
test ( 'json body' , async t => {
59
- const baseUrl = 'http://mock-endpoint' ;
70
+ const prefixUrl = 'http://mock-endpoint' ;
60
71
const body = { test : [ 1 , 3 , 3 , 7 ] } ;
61
72
const reply = { ok : true } ;
62
73
63
- const scope = nock ( baseUrl ) . post ( '/test' , body ) . reply ( 200 , reply ) ;
74
+ const scope = nock ( prefixUrl ) . post ( '/test' , body ) . reply ( 200 , reply ) ;
64
75
65
- t . deepEqual ( ( await ghGot ( '/ test', { baseUrl , body} ) ) . body , reply ) ;
76
+ t . deepEqual ( ( await ghGot . post ( ' test', { prefixUrl , body} ) ) . body , reply ) ;
66
77
t . truthy ( scope . isDone ( ) ) ;
67
78
} ) ;
68
79
0 commit comments