-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: fix jest usage and add retry #2838
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,9 @@ describe('options', () => { | |
|
||
afterAll((done) => { | ||
if (server) { | ||
server.close(() => { | ||
done(); | ||
}); | ||
server.close(done); | ||
} else { | ||
done(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,7 @@ describe('https option', () => { | |
req.get('/').expect(200, /Heyo/, done); | ||
}); | ||
|
||
afterAll(() => { | ||
testServer.close(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
afterAll(testServer.close); | ||
}); | ||
|
||
describe('as an object when ca, pfx, key and cert are buffer', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,34 +9,29 @@ jest.mock('os', () => { | |
}); | ||
|
||
describe('runBonjour', () => { | ||
let mock; | ||
let publish = jest.fn(); | ||
let unpublishAll = jest.fn(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variables referenced outside of |
||
const mockPublish = jest.fn(); | ||
const mockUnpublishAll = jest.fn(); | ||
|
||
beforeAll(() => { | ||
mock = jest.mock('bonjour', () => () => { | ||
jest.mock('bonjour', () => () => { | ||
return { | ||
publish, | ||
unpublishAll, | ||
publish: mockPublish, | ||
unpublishAll: mockUnpublishAll, | ||
}; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
publish = jest.fn(); | ||
unpublishAll = jest.fn(); | ||
}); | ||
|
||
afterAll(() => { | ||
mock.mockRestore(); | ||
mockPublish.mockClear(); | ||
mockUnpublishAll.mockClear(); | ||
}); | ||
|
||
it('should call bonjour.publish', () => { | ||
runBonjour({ | ||
port: 1111, | ||
}); | ||
|
||
expect(publish.mock.calls[0][0]).toMatchSnapshot(); | ||
expect(mockPublish.mock.calls[0][0]).toMatchSnapshot(); | ||
}); | ||
|
||
it('should call bonjour.publish with different name for different ports', () => { | ||
|
@@ -47,7 +42,7 @@ describe('runBonjour', () => { | |
port: 2222, | ||
}); | ||
|
||
const calls = publish.mock.calls; | ||
const calls = mockPublish.mock.calls; | ||
|
||
expect(calls[0][0].name).not.toEqual(calls[1][0].name); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.