Skip to content

Commit

Permalink
test: remove spy from acceptance test
Browse files Browse the repository at this point in the history
This spy is never called as we're executing code outside the process.
  • Loading branch information
Jahed Ahmed committed Aug 11, 2021
1 parent 104b07d commit 6573d1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions test/acceptance/fake-server.ts
Expand Up @@ -8,6 +8,7 @@ interface FakeServer extends restify.Server {
popRequests: (num: number) => restify.Request[];
setNextResponse: (r: any) => void;
setNextStatusCodeAndResponse: (c: number, r: any) => void;
clearRequests: () => void;
}

export function fakeServer(root, apikey) {
Expand All @@ -23,6 +24,9 @@ export function fakeServer(root, apikey) {
server.popRequests = (num: number) => {
return server._reqLog.splice(server._reqLog.length - num, num);
};
server.clearRequests = () => {
server._reqLog = [];
};
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser({ mapParams: true }));
server.use(restify.plugins.bodyParser({ mapParams: true }));
Expand Down
8 changes: 4 additions & 4 deletions test/jest/acceptance/analytics.spec.ts
@@ -1,7 +1,6 @@
import { fakeServer } from '../../acceptance/fake-server';
import { createProject } from '../util/createProject';
import { runSnykCLI } from '../util/runSnykCLI';
import * as request from '../../../src/lib/request';
import * as fs from 'fs';

describe('analytics module', () => {
Expand All @@ -27,7 +26,7 @@ describe('analytics module', () => {
});

afterEach(() => {
jest.restoreAllMocks();
server.clearRequests();
});

afterAll((done) => {
Expand Down Expand Up @@ -301,14 +300,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();
});
});

0 comments on commit 6573d1b

Please sign in to comment.