-
Notifications
You must be signed in to change notification settings - Fork 578
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { fakeServer } from '../../acceptance/fake-server'; | ||
import { createProject } from '../util/createProject'; | ||
import { | ||
createProjectFromFixture, | ||
createProjectFromWorkspace, | ||
} from '../util/createProject'; | ||
import { runSnykCLI } from '../util/runSnykCLI'; | ||
import * as request from '../../../src/lib/request'; | ||
import * as fs from 'fs'; | ||
|
||
jest.setTimeout(1000 * 30); | ||
|
||
describe('analytics module', () => { | ||
let server; | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}); | ||
|
||
afterAll((done) => { | ||
|
@@ -37,7 +40,7 @@ describe('analytics module', () => { | |
}); | ||
|
||
it('sends analytics for `snyk test` with no vulns found', async () => { | ||
const project = await createProject('../acceptance/workspaces/npm-package'); | ||
const project = await createProjectFromWorkspace('npm-package'); | ||
const { code } = await runSnykCLI('test', { | ||
cwd: project.path(), | ||
env, | ||
|
@@ -101,14 +104,11 @@ describe('analytics module', () => { | |
}); | ||
|
||
it('sends analytics for `snyk test` with vulns found', async () => { | ||
const testDepGraphResult = JSON.parse( | ||
fs.readFileSync( | ||
'test/fixtures/npm/with-vulnerable-lodash-dep/test-dep-graph-result.json', | ||
'utf-8', | ||
), | ||
const project = await createProjectFromFixture( | ||
'npm/with-vulnerable-lodash-dep', | ||
); | ||
server.setNextResponse(testDepGraphResult); | ||
const project = await createProject('npm/with-vulnerable-lodash-dep'); | ||
|
||
server.setNextResponse(await project.read('test-dep-graph-result.json')); | ||
|
||
const { code } = await runSnykCLI('test', { | ||
cwd: project.path(), | ||
|
@@ -183,7 +183,7 @@ describe('analytics module', () => { | |
}); | ||
|
||
it('sends correct analytics data a bad command', async () => { | ||
const project = await createProject('../acceptance/workspaces/npm-package'); | ||
const project = await createProjectFromWorkspace('npm-package'); | ||
const { code } = await runSnykCLI('random-nonsense-command --some-option', { | ||
cwd: project.path(), | ||
env, | ||
|
@@ -246,7 +246,7 @@ describe('analytics module', () => { | |
}); | ||
|
||
it('sends analytics data a bad command', async () => { | ||
const project = await createProject('../acceptance/workspaces/npm-package'); | ||
const project = await createProjectFromWorkspace('npm-package'); | ||
const { code } = await runSnykCLI('', { | ||
cwd: project.path(), | ||
env, | ||
|
@@ -301,14 +301,15 @@ describe('analytics module', () => { | |
}); | ||
|
||
it("won't send analytics if disable analytics is set", async () => { | ||
const requestSpy = jest.spyOn(request, 'makeRequest'); | ||
const { code } = await runSnykCLI(`version`, { | ||
env: { | ||
...env, | ||
SNYK_DISABLE_ANALYTICS: '1', | ||
}, | ||
}); | ||
expect(code).toBe(0); | ||
expect(requestSpy).not.toBeCalled(); | ||
|
||
const lastRequest = server.popRequest(); | ||
expect(lastRequest).toBeUndefined(); | ||
Comment on lines
+311
to
+313
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. 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.
This is the main thing to avoid test timeouts.