-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace require-dir to get jest test working require-dir is not compatible with jest, but require-directory seems to work aseemk/requireDir#53 (comment)
- Loading branch information
1 parent
8c4db67
commit 10e4242
Showing
11 changed files
with
2,639 additions
and
587 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
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,68 +1,56 @@ | ||
|
||
|
||
const assert = require('assert'); | ||
const sinon = require('sinon'); | ||
require('sinon-as-promised'); | ||
const got = require('got'); | ||
const hapi = require('hapi'); | ||
const plugin = require('../src/plugins/ping.js'); | ||
|
||
jest.mock('got'); | ||
|
||
describe('ping', () => { | ||
let server; | ||
|
||
before(async () => { | ||
beforeAll(async () => { | ||
server = new hapi.Server(); | ||
|
||
await server.register(plugin); | ||
return server.start(); | ||
}); | ||
|
||
after(() => server.stop()); | ||
|
||
beforeEach(() => { | ||
this.sandbox = sinon.sandbox.create(); | ||
this.gotStub = this.sandbox.stub(got, 'get'); | ||
}); | ||
|
||
afterEach(() => { | ||
this.sandbox.restore(); | ||
}); | ||
afterAll(() => server.stop()); | ||
|
||
it('performs an HTTP HEAD request', async () => { | ||
this.gotStub.resolves(); | ||
got.get.mockResolvedValue(); | ||
|
||
const options = { | ||
url: '/ping?url=http://awesomefooland.com', | ||
}; | ||
|
||
await server.inject(options); | ||
assert.equal(this.gotStub.callCount, 1); | ||
assert.equal(this.gotStub.args[0][0], 'http://awesomefooland.com'); | ||
expect(got.get.mock.calls).toHaveLength(1); | ||
expect(got.get.mock.calls[0][0]).toBe('http://awesomefooland.com'); | ||
}); | ||
|
||
it('returns 404 response if package can not be found', async () => { | ||
const err = new Error('Some error'); | ||
err.code = 404; | ||
this.gotStub.rejects(err); | ||
got.get.mockRejectedValue(err); | ||
|
||
const options = { | ||
method: 'GET', | ||
url: '/ping?url=http://awesomefooland.com', | ||
}; | ||
|
||
const response = await server.inject(options); | ||
assert.equal(response.statusCode, 404); | ||
expect(response.statusCode).toBe(404); | ||
}); | ||
|
||
it('returns project url', async () => { | ||
this.gotStub.resolves(); | ||
got.get.mockResolvedValue(); | ||
|
||
const options = { | ||
method: 'GET', | ||
url: '/ping?url=http://awesomefooland.com', | ||
}; | ||
|
||
const response = await server.inject(options); | ||
assert.equal(response.statusCode, 200); | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
}); |
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
Oops, something went wrong.