Skip to content

Commit 5760b85

Browse files
author
Peter Bengtsson
authored
make FailBot unit tests independent of env (#22871)
Part of #1229
1 parent cb76d78 commit 5760b85

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/failbot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async function retryingGot(url, args) {
3131
)
3232
}
3333

34-
export function report(error, metadata) {
34+
export async function report(error, metadata) {
3535
// If there's no HAYSTACK_URL set, bail early
3636
if (!process.env.HAYSTACK_URL) return
3737

tests/unit/failbot.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ describe('FailBot', () => {
55
const requestBodiesSent = []
66

77
beforeEach(() => {
8+
delete process.env.HAYSTACK_URL
9+
10+
// Always reset the array to an empty one between tests
11+
// so it doesn't intefere across tests.
12+
requestBodiesSent.length = 0
13+
814
nock('https://haystack.example.com')
915
.post('/')
1016
.reply(200, (uri, requestBody) => {
@@ -15,15 +21,13 @@ describe('FailBot', () => {
1521

1622
afterEach(() => {
1723
delete process.env.HAYSTACK_URL
18-
// Reset the array to an empty one between tests
19-
// so it doesn't intefere across tests.
20-
requestBodiesSent.length = 0
2124
})
2225

2326
describe('.report', () => {
2427
it('returns early if `HAYSTACK_URL` is not set', async () => {
2528
const result = await FailBot.report()
2629
expect(result).toBeUndefined()
30+
expect(requestBodiesSent.length).toBe(0)
2731
})
2832

2933
it('sends the expected report', async () => {

0 commit comments

Comments
 (0)