Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b265f49
commit 1fc6d02
Showing
5 changed files
with
34 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
import test from 'ava'; | ||
import getStream from 'get-stream'; | ||
import fn from './'; | ||
|
||
global.Promise = Promise; | ||
import m from './'; | ||
|
||
const token = process.env.GITHUB_TOKEN; | ||
|
||
test('default', async t => { | ||
t.is((await fn('users/sindresorhus')).body.login, 'sindresorhus'); | ||
t.is((await m('users/sindresorhus')).body.login, 'sindresorhus'); | ||
}); | ||
|
||
test('full path', async t => { | ||
t.is((await fn('https://api.github.com/users/sindresorhus')).body.login, 'sindresorhus'); | ||
t.is((await m('https://api.github.com/users/sindresorhus')).body.login, 'sindresorhus'); | ||
}); | ||
|
||
test('should accept options', async t => { | ||
t.is((await fn('users/sindresorhus', {})).body.login, 'sindresorhus'); | ||
test('accepts options', async t => { | ||
t.is((await m('users/sindresorhus', {})).body.login, 'sindresorhus'); | ||
}); | ||
|
||
test.serial('token option', async t => { | ||
process.env.GITHUB_TOKEN = 'fail'; | ||
await t.throws(fn('users/sindresorhus'), 'Response code 401 (Unauthorized)'); | ||
await t.throws(m('users/sindresorhus'), 'Response code 401 (Unauthorized)'); | ||
process.env.GITHUB_TOKEN = token; | ||
}); | ||
|
||
test('endpoint option', async t => { | ||
await t.throws(fn('users/sindresorhus', {endpoint: 'fail', retries: 1}), /ENOTFOUND/); | ||
await t.throws(m('users/sindresorhus', {endpoint: 'fail', retries: 1}), /ENOTFOUND/); | ||
}); | ||
|
||
test('stream interface', async t => { | ||
t.is(JSON.parse(await getStream(fn.stream('users/sindresorhus'))).login, 'sindresorhus'); | ||
t.is(JSON.parse(await getStream(fn.stream.get('users/sindresorhus'))).login, 'sindresorhus'); | ||
t.is(JSON.parse(await getStream(m.stream('users/sindresorhus'))).login, 'sindresorhus'); | ||
t.is(JSON.parse(await getStream(m.stream.get('users/sindresorhus'))).login, 'sindresorhus'); | ||
}); |
I was writing a tiny cli to fetch current github rate limits for a user (given a token as an argument) but with the environment variable defined, I can't override it unless I clear it first. In other words, wouldn't this be preferable?