feat(core): Remove all floating promises. Enforce @typescript-eslint/no-floating-promises (#6281)
This commit is contained in:
committed by
GitHub
parent
5d2f4746ea
commit
e046f656fe
@@ -3,7 +3,7 @@ import { ActiveExecutions } from '@/ActiveExecutions';
|
||||
import { mocked } from 'jest-mock';
|
||||
import PCancelable from 'p-cancelable';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import type { IDeferredPromise, IExecuteResponsePromiseData, IRun } from 'n8n-workflow';
|
||||
import type { IExecuteResponsePromiseData, IRun } from 'n8n-workflow';
|
||||
import { createDeferredPromise } from 'n8n-workflow';
|
||||
import type { IWorkflowExecutionDataProcess } from '@/Interfaces';
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('ActiveExecutions', () => {
|
||||
const fakeResponse = { data: { resultData: { runData: {} } } };
|
||||
activeExecutions.resolveResponsePromise(FAKE_EXECUTION_ID, fakeResponse);
|
||||
|
||||
expect(deferredPromise.promise()).resolves.toEqual(fakeResponse);
|
||||
await expect(deferredPromise.promise()).resolves.toEqual(fakeResponse);
|
||||
});
|
||||
|
||||
test('Should remove an existing execution', async () => {
|
||||
@@ -108,11 +108,11 @@ describe('ActiveExecutions', () => {
|
||||
const fakeOutput = mockFullRunData();
|
||||
activeExecutions.remove(executionId, fakeOutput);
|
||||
|
||||
expect(postExecutePromise).resolves.toEqual(fakeOutput);
|
||||
await expect(postExecutePromise).resolves.toEqual(fakeOutput);
|
||||
});
|
||||
|
||||
test('Should throw error when trying to create a promise with invalid execution', async () => {
|
||||
expect(activeExecutions.getPostExecutePromise(FAKE_EXECUTION_ID)).rejects.toThrow();
|
||||
await expect(activeExecutions.getPostExecutePromise(FAKE_EXECUTION_ID)).rejects.toThrow();
|
||||
});
|
||||
|
||||
test('Should call function to cancel execution when asked to stop', async () => {
|
||||
@@ -122,7 +122,7 @@ describe('ActiveExecutions', () => {
|
||||
const cancellablePromise = mockCancelablePromise();
|
||||
cancellablePromise.cancel = cancelExecution;
|
||||
activeExecutions.attachWorkflowExecution(executionId, cancellablePromise);
|
||||
activeExecutions.stopExecution(executionId);
|
||||
void activeExecutions.stopExecution(executionId);
|
||||
|
||||
expect(cancelExecution).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
@@ -156,12 +156,7 @@ function mockFullRunData(): IRun {
|
||||
};
|
||||
}
|
||||
|
||||
async function mockCancelablePromise(): PCancelable<IRun> {
|
||||
return new PCancelable(async (resolve) => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
async function mockDeferredPromise(): Promise<IDeferredPromise<IExecuteResponsePromiseData>> {
|
||||
return createDeferredPromise<IExecuteResponsePromiseData>();
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
||||
const mockCancelablePromise = () => new PCancelable<IRun>((resolve) => resolve());
|
||||
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
||||
const mockDeferredPromise = () => createDeferredPromise<IExecuteResponsePromiseData>();
|
||||
|
||||
Reference in New Issue
Block a user