Skip to content

Commit

Permalink
Merge branch 'main' into fix-needs-manual-og-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere authored Sep 11, 2024
2 parents 1f8ff51 + 30346e2 commit 5190001
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 144 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@types/node": "^18.11.8",
"@types/node-fetch": "^2.5.4",
"@types/pino-std-serializers": "^4.0.0",
"@types/sinon": "^10.0.15",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"eslint": "^8.0.1",
"eslint-config-standard-with-typescript": "^36.0.0",
Expand All @@ -45,7 +44,6 @@
"lint-staged": "^10.4.2",
"nock": "^13.2.9",
"prettier": "^3.0.0",
"sinon": "^15.2.0",
"smee-client": "^2.0.1",
"ts-jest": "^29.0.0",
"typescript": "*"
Expand Down
33 changes: 16 additions & 17 deletions spec/queue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EventEmitter } from 'events';
import * as sinon from 'sinon';

import { ExecutionQueue } from '../src/Queue';

Expand All @@ -22,8 +21,8 @@ const delayedEvent = async (
const fakeTask = (name: string) => {
const namedArgs = {
name,
taskRunner: sinon.stub().returns(Promise.resolve()),
errorHandler: sinon.stub().returns(Promise.resolve()),
taskRunner: jest.fn().mockResolvedValue(undefined),
errorHandler: jest.fn().mockResolvedValue(undefined),
args: () =>
[name, namedArgs.taskRunner, namedArgs.errorHandler] as [
string,
Expand All @@ -40,18 +39,18 @@ describe('ExecutionQueue', () => {

const task = fakeTask('test');
await delayedEvent(q, 'empty', async () => q.enterQueue(...task.args()));
expect(task.taskRunner.callCount).toBe(1);
expect(task.taskRunner).toHaveBeenCalledTimes(1);
});

it('should run the tasks error handler if the task throws', async () => {
const q = new ExecutionQueue();

const task = fakeTask('test');
task.taskRunner.returns(Promise.reject('err'));
task.taskRunner.mockRejectedValue('err');
await delayedEvent(q, 'empty', async () => q.enterQueue(...task.args()));
expect(task.taskRunner.callCount).toBe(1);
expect(task.errorHandler.callCount).toBe(1);
expect(task.errorHandler.firstCall.args[0]).toBe('err');
expect(task.taskRunner).toHaveBeenCalledTimes(1);
expect(task.errorHandler).toHaveBeenCalledTimes(1);
expect(task.errorHandler).toHaveBeenNthCalledWith(1, 'err');
});

it('should run the next task if the current task succeeds', async () => {
Expand All @@ -63,36 +62,36 @@ describe('ExecutionQueue', () => {
q.enterQueue(...task.args());
q.enterQueue(...task2.args());
});
expect(task.taskRunner.callCount).toBe(1);
expect(task2.taskRunner.callCount).toBe(1);
expect(task.taskRunner).toHaveBeenCalledTimes(1);
expect(task2.taskRunner).toHaveBeenCalledTimes(1);
});

it('should run the next task if the current task fails', async () => {
const q = new ExecutionQueue();

const task = fakeTask('test');
task.taskRunner.returns(Promise.reject('err'));
task.taskRunner.mockRejectedValue('err');
const task2 = fakeTask('test2');
await delayedEvent(q, 'empty', async () => {
q.enterQueue(...task.args());
q.enterQueue(...task2.args());
});
expect(task.taskRunner.callCount).toBe(1);
expect(task2.taskRunner.callCount).toBe(1);
expect(task.taskRunner).toHaveBeenCalledTimes(1);
expect(task2.taskRunner).toHaveBeenCalledTimes(1);
});

it("should run the next task if the current task fails and it's error handler fails", async () => {
const q = new ExecutionQueue();

const task = fakeTask('test');
task.taskRunner.returns(Promise.reject('err'));
task.errorHandler.returns(Promise.reject('bad error'));
task.taskRunner.mockRejectedValue('err');
task.errorHandler.mockRejectedValue('bad error');
const task2 = fakeTask('test2');
await delayedEvent(q, 'empty', async () => {
q.enterQueue(...task.args());
q.enterQueue(...task2.args());
});
expect(task.taskRunner.callCount).toBe(1);
expect(task2.taskRunner.callCount).toBe(1);
expect(task.taskRunner).toHaveBeenCalledTimes(1);
expect(task2.taskRunner).toHaveBeenCalledTimes(1);
});
});
Loading

0 comments on commit 5190001

Please sign in to comment.