-
Notifications
You must be signed in to change notification settings - Fork 574
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: increase analytics test timeout #2157
Conversation
This spy is never called as we're executing code outside the process.
Launching process alone takes 5 seconds which is the default timeout.
cb97952
to
2735bce
Compare
2735bce
to
8e296a6
Compare
@@ -27,7 +30,7 @@ describe('analytics module', () => { | |||
}); | |||
|
|||
afterEach(() => { | |||
jest.restoreAllMocks(); | |||
server.clearRequests(); |
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.
Added this as we should typically clear state between tests so we aren't asserting on invalid state.
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.
👍
import * as request from '../../../src/lib/request'; | ||
import * as fs from 'fs'; | ||
|
||
jest.setTimeout(1000 * 30); |
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.
This is the main thing to avoid test timeouts.
|
||
const lastRequest = server.popRequest(); | ||
expect(lastRequest).toBeUndefined(); |
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.
Spying won't work as spies are bound to the current Node context; which is Jest. We are launching Snyk CLI in its own process where the spy does not exist.
To test this correctly, we can ensure fakeServer didn't receive a request.
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.
Nice
Launching process alone takes 5 seconds which is the default timeout. Causes unreliable tests.
https://app.circleci.com/pipelines/github/snyk/snyk/6706/workflows/1ae30a6e-a106-4d71-a337-dffd58512a09/jobs/44733
Also made some small fixes (see commits).