chore(test): Convert github tests to TypeScript (#625)

This commit is contained in:
Kentaro Matsushita
2018-07-18 13:02:07 +09:00
committed by Brandon Keepers
parent 59046bb7d8
commit eb6cea4e63
3 changed files with 21 additions and 19 deletions

View File

@@ -23,7 +23,7 @@ export function GitHubAPI (options: Options = {} as any) {
}
export interface Options extends Octokit.Options {
debug: boolean
debug?: boolean
logger: Logger
limiter?: any
}

View File

@@ -1,25 +1,26 @@
const {GitHubAPI} = require('../src/github')
const nock = require('nock')
const Bottleneck = require('bottleneck')
import Bottleneck from 'bottleneck'
import nock from 'nock'
import { GitHubAPI, Options } from '../src/github'
import { logger } from '../src/logger'
describe('GitHubAPI', () => {
let github
let github: GitHubAPI
beforeEach(() => {
const logger = {
debug: jest.fn(),
trace: jest.fn()
}
// Set a shorter limiter, otherwise tests are _slow_
const limiter = new Bottleneck()
github = new GitHubAPI({ logger, limiter })
const options: Options = {
limiter,
logger
}
github = GitHubAPI(options)
})
test('works without options', async () => {
github = new GitHubAPI()
const user = {login: 'ohai'}
github = GitHubAPI()
const user = { login: 'ohai' }
nock('https://api.github.com').get('/user').reply(200, user)
expect((await github.users.get({})).data).toEqual(user)
@@ -28,11 +29,11 @@ describe('GitHubAPI', () => {
describe('paginate', () => {
beforeEach(() => {
// Prepare an array of issue objects
const issues = new Array(5).fill().map((_, i, arr) => {
const issues = new Array(5).fill(0).map((_, i, arr) => {
return {
title: `Issue number ${i}`,
id: i,
number: i
number: i,
title: `Issue number ${i}`
}
})
@@ -63,8 +64,8 @@ describe('GitHubAPI', () => {
})
it('stops iterating if the done() function is called in the callback', async () => {
const spy = jest.fn((res, done) => {
if (res.data.id === 2) done()
const spy = jest.fn((response, done) => {
if (response.data.id === 2) done()
})
const res = await github.paginate(github.issues.getForRepo({ owner: 'JasonEtco', repo: 'pizza', per_page: 1 }), spy)
expect(res.length).toBe(3)

View File

@@ -6,6 +6,7 @@
],
"rules": {
"interface-name": [true, "never-prefix"],
"prefer-object-spread": false
"prefer-object-spread": false,
"no-implicit-dependencies": [true, "dev"]
}
}