mirror of
https://github.com/n8n-io/n8n
synced 2026-04-19 13:05:54 +02:00
test: Fix flaky unit tests across three packages (no-changelog) (#28336)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -215,22 +215,21 @@ describe('ExecutionPersistence', () => {
|
||||
const target = { workflowId: 'wf-1', executionId: 'exec-1', storedAt: 'db' as const };
|
||||
|
||||
it('should soft-delete with backdated `deletedAt` when pruning is enabled', async () => {
|
||||
jest.useFakeTimers();
|
||||
const now = Date.now();
|
||||
|
||||
executionsConfig.pruneData = true;
|
||||
executionsConfig.pruneDataHardDeleteBuffer = 1;
|
||||
const executionPersistence = createPersistenceService('db');
|
||||
|
||||
await executionPersistence.deleteInFlightExecution(target);
|
||||
const after = Date.now();
|
||||
|
||||
expect(executionRepository.update).toHaveBeenCalledWith('exec-1', {
|
||||
deletedAt: expect.any(Date),
|
||||
deletedAt: new Date(now - 3600_000),
|
||||
});
|
||||
|
||||
const { deletedAt } = executionRepository.update.mock.calls[0][1] as { deletedAt: Date };
|
||||
// deletedAt should be backdated by ~1 hour (the buffer)
|
||||
// Use `after` to tolerate clock progression between before/after snapshots
|
||||
expect(deletedAt.getTime()).toBeLessThanOrEqual(after - 3600_000);
|
||||
expect(executionRepository.deleteByIds).not.toHaveBeenCalled();
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('should hard-delete immediately when pruning is disabled', async () => {
|
||||
|
||||
@@ -5,6 +5,15 @@ import { mock } from 'vitest-mock-extended';
|
||||
import type { WorkerInitOptions } from '../types';
|
||||
import { worker } from './typescript.worker';
|
||||
|
||||
vi.mock('@/app/plugins/cache', () => ({
|
||||
indexedDbCache: async () => ({
|
||||
getItem: () => '{}',
|
||||
setItem: () => {},
|
||||
removeItem: () => {},
|
||||
clear: () => {},
|
||||
getAllWithPrefix: async () => ({}),
|
||||
}),
|
||||
}));
|
||||
vi.mock('@typescript/vfs');
|
||||
vi.mock('typescript', async (importOriginal) => {
|
||||
return await importOriginal();
|
||||
|
||||
@@ -8,6 +8,18 @@ import { GoogleSheetsTrigger } from '../GoogleSheetsTrigger.node';
|
||||
describe('GoogleSheetsTrigger', () => {
|
||||
const baseUrl = 'https://sheets.googleapis.com';
|
||||
|
||||
beforeAll(() => {
|
||||
nock.disableNetConnect();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
nock.enableNetConnect();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
describe('rowAdded event', () => {
|
||||
it('should return rows without header', async () => {
|
||||
const scope = nock(baseUrl);
|
||||
|
||||
Reference in New Issue
Block a user