refactor(core): Remove skipped telemetry tests (no-changelog) (#10319)

This commit is contained in:
Iván Ovejero 2024-08-07 15:11:22 +02:00 committed by GitHub
parent 171173c7e8
commit b232831f18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 163 deletions

View file

@ -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 {
@ -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'),
});
}
},
};
},
},

View file

@ -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';
@ -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 => {

View file

@ -1,6 +0,0 @@
/**
* Ensure all pending promises settle. The promise's `resolve` is placed in
* the macrotask queue and so called at the next iteration of the event loop
* after all promises in the microtask queue have settled first.
*/
export const flushPromises = async () => await new Promise(setImmediate);