diff --git a/packages/@n8n_io/eslint-config/local-rules.js b/packages/@n8n_io/eslint-config/local-rules.js index 152415e14c8d0..09a9c00f0f852 100644 --- a/packages/@n8n_io/eslint-config/local-rules.js +++ b/packages/@n8n_io/eslint-config/local-rules.js @@ -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'), + }); + } + }, }; }, }, diff --git a/packages/cli/src/telemetry/__tests__/telemetry.test.ts b/packages/cli/src/telemetry/__tests__/telemetry.test.ts index a0441519eaf6f..e701301d58802 100644 --- a/packages/cli/src/telemetry/__tests__/telemetry.test.ts +++ b/packages/cli/src/telemetry/__tests__/telemetry.test.ts @@ -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 => { diff --git a/packages/cli/test/shared/flushPromises.ts b/packages/cli/test/shared/flushPromises.ts deleted file mode 100644 index 405b9e98dca26..0000000000000 --- a/packages/cli/test/shared/flushPromises.ts +++ /dev/null @@ -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);