Skip to content

Commit

Permalink
refactor(core): Remove skipped telemetry tests (no-changelog) (#10319)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Aug 7, 2024
1 parent 171173c commit b232831
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 163 deletions.
14 changes: 14 additions & 0 deletions packages/@n8n_io/eslint-config/local-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,14 @@ module.exports = {
messages: {
removeSkip: 'Remove `.skip()` call',
removeOnly: 'Remove `.only()` call',
removeXPrefix: 'Remove `x` prefix',
},
fixable: 'code',
},
create(context) {
const TESTING_FUNCTIONS = new Set(['test', 'it', 'describe']);
const SKIPPING_METHODS = new Set(['skip', 'only']);
const PREFIXED_TESTING_FUNCTIONS = new Set(['xtest', 'xit', 'xdescribe']);
const toMessageId = (s) => 'remove' + s.charAt(0).toUpperCase() + s.slice(1);

return {
Expand All @@ -208,6 +210,18 @@ module.exports = {
});
}
},
CallExpression(node) {
if (
node.callee.type === 'Identifier' &&
PREFIXED_TESTING_FUNCTIONS.has(node.callee.name)
) {
context.report({
messageId: 'removeXPrefix',
node,
fix: (fixer) => fixer.replaceText(node.callee, 'test'),
});
}
},
};
},
},
Expand Down
157 changes: 0 additions & 157 deletions packages/cli/src/telemetry/__tests__/telemetry.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type RudderStack from '@rudderstack/rudder-sdk-node';
import { Telemetry } from '@/telemetry';
import config from '@/config';
import { flushPromises } from '@test/flushPromises';
import { PostHogClient } from '@/posthog';
import { mock } from 'jest-mock-extended';
import { InstanceSettings } from 'n8n-core';
Expand Down Expand Up @@ -266,162 +265,6 @@ describe('Telemetry', () => {
expect(execBuffer['2'].prod_success?.first).toEqual(execTime1);
});
});

describe('pulse', () => {
let pulseSpy: jest.SpyInstance;
beforeAll(() => {
startPulseSpy.mockRestore();
});

beforeEach(() => {
fakeJestSystemTime(testDateTime);
pulseSpy = jest.spyOn(Telemetry.prototype as any, 'pulse').mockName('pulseSpy');
});

afterEach(() => {
pulseSpy.mockClear();
});

xtest('should trigger pulse in intervals', async () => {
expect(pulseSpy).toBeCalledTimes(0);

jest.advanceTimersToNextTimer();
await flushPromises();

expect(pulseSpy).toBeCalledTimes(1);
expect(spyTrack).toHaveBeenCalledTimes(1);
expect(spyTrack).toHaveBeenCalledWith('pulse', {
plan_name_current: 'Community',
quota: -1,
usage: 0,
});

jest.advanceTimersToNextTimer();

await flushPromises();

expect(pulseSpy).toBeCalledTimes(2);
expect(spyTrack).toHaveBeenCalledTimes(2);
expect(spyTrack).toHaveBeenCalledWith('pulse', {
plan_name_current: 'Community',
quota: -1,
usage: 0,
});
});

xtest('should track workflow counts correctly', async () => {
expect(pulseSpy).toBeCalledTimes(0);

let execBuffer = telemetry.getCountsBuffer();

// expect clear counters on start
expect(Object.keys(execBuffer).length).toBe(0);

const payload = {
workflow_id: '1',
is_manual: true,
success: true,
error_node_type: 'custom-nodes-base.node-type',
};

telemetry.trackWorkflowExecution(payload);
telemetry.trackWorkflowExecution(payload);

payload.is_manual = false;
payload.success = true;
telemetry.trackWorkflowExecution(payload);
telemetry.trackWorkflowExecution(payload);

payload.is_manual = true;
payload.success = false;
telemetry.trackWorkflowExecution(payload);
telemetry.trackWorkflowExecution(payload);

payload.is_manual = false;
payload.success = false;
telemetry.trackWorkflowExecution(payload);
telemetry.trackWorkflowExecution(payload);

payload.workflow_id = '2';
telemetry.trackWorkflowExecution(payload);
telemetry.trackWorkflowExecution(payload);

expect(spyTrack).toHaveBeenCalledTimes(0);
expect(pulseSpy).toBeCalledTimes(0);

jest.advanceTimersToNextTimer();

execBuffer = telemetry.getCountsBuffer();

await flushPromises();

expect(pulseSpy).toBeCalledTimes(1);
expect(spyTrack).toHaveBeenCalledTimes(3);
expect(spyTrack).toHaveBeenNthCalledWith(
1,
'Workflow execution count',
{
event_version: '2',
workflow_id: '1',
user_id: undefined,
manual_error: {
count: 2,
first: testDateTime,
},
manual_success: {
count: 2,
first: testDateTime,
},
prod_error: {
count: 2,
first: testDateTime,
},
prod_success: {
count: 2,
first: testDateTime,
},
},
{ withPostHog: true },
);
expect(spyTrack).toHaveBeenNthCalledWith(
2,
'Workflow execution count',
{
event_version: '2',
workflow_id: '2',
user_id: undefined,
prod_error: {
count: 2,
first: testDateTime,
},
},
{ withPostHog: true },
);
expect(spyTrack).toHaveBeenNthCalledWith(3, 'pulse', {
plan_name_current: 'Community',
quota: -1,
usage: 0,
});
expect(Object.keys(execBuffer).length).toBe(0);

// Adding a second step here because we believe PostHog may use timers for sending data
// and adding posthog to the above metric was causing the pulseSpy timer to not be ran
jest.advanceTimersToNextTimer();

execBuffer = telemetry.getCountsBuffer();
expect(Object.keys(execBuffer).length).toBe(0);

// @TODO: Flushing promises here is not working

// expect(pulseSpy).toBeCalledTimes(2);
// expect(spyTrack).toHaveBeenCalledTimes(4);
// expect(spyTrack).toHaveBeenNthCalledWith(4, 'pulse', {
// plan_name_current: 'Community',
// quota: -1,
// usage: 0,
// });
});
});
});

const fakeJestSystemTime = (dateTime: string | Date): Date => {
Expand Down
6 changes: 0 additions & 6 deletions packages/cli/test/shared/flushPromises.ts

This file was deleted.

0 comments on commit b232831

Please sign in to comment.