1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/tests/unit/failbot.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

48 lines
1.3 KiB
JavaScript

import FailBot from '../../lib/failbot.js'
import nock from 'nock'
describe('FailBot', () => {
beforeEach(() => {
nock('https://haystack.com')
.post('/')
.reply(200, (uri, requestBody) => {
return requestBody
})
})
afterEach(() => {
delete process.env.HAYSTACK_URL
})
describe('.report', () => {
it('returns early if `HAYSTACK_URL` is not set', async () => {
const result = await FailBot.report()
expect(result).toBeUndefined()
})
it('sends the expected report', async () => {
process.env.HAYSTACK_URL = 'https://haystack.com'
const err = new Error('Kaboom')
const result = await FailBot.report(err)
// Check that we made a request
expect(result.status).toBe(200)
// Verify the basic fetch params
expect(result.headers.get('content-type')).toBe('application/json')
// Check that we send the expected body
const body = await result.json()
expect(body).toMatchObject({
app: 'docs',
backtrace: expect.stringContaining('Error: Kaboom'),
class: 'Error',
created_at: expect.any(String),
js_environment: expect.stringMatching(/^Node\.js\sv[\d.]+/),
message: 'Kaboom',
rollup: expect.any(String),
})
})
})
})