Skip to content

Commit

Permalink
Add tests for failed event typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Grondin committed Jun 8, 2019
1 parent 3166fec commit 712db2f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bottleneck.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ declare module "bottleneck" {
on(name: "queued", fn: (info: Bottleneck.EventInfoQueued) => void): void;
on(name: "scheduled", fn: (info: Bottleneck.EventInfo) => void): void;
on(name: "executing", fn: (info: Bottleneck.EventInfoRetryable) => void): void;
on(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number | void> | number | void): void;
on(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number | void | null> | number | void | null): void;
on(name: "retry", fn: (message: string, info: Bottleneck.EventInfoRetryable) => void): void;
on(name: "done", fn: (info: Bottleneck.EventInfoRetryable) => void): void;

Expand All @@ -511,7 +511,7 @@ declare module "bottleneck" {
once(name: "queued", fn: (info: Bottleneck.EventInfoQueued) => void): void;
once(name: "scheduled", fn: (info: Bottleneck.EventInfo) => void): void;
once(name: "executing", fn: (info: Bottleneck.EventInfoRetryable) => void): void;
once(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number | void> | number | void): void;
once(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number | void | null> | number | void | null): void;
once(name: "retry", fn: (message: string, info: Bottleneck.EventInfoRetryable) => void): void;
once(name: "done", fn: (info: Bottleneck.EventInfoRetryable) => void): void;

Expand Down
4 changes: 2 additions & 2 deletions bottleneck.d.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ declare module "bottleneck" {
on(name: "queued", fn: (info: Bottleneck.EventInfoQueued) => void): void;
on(name: "scheduled", fn: (info: Bottleneck.EventInfo) => void): void;
on(name: "executing", fn: (info: Bottleneck.EventInfoRetryable) => void): void;
on(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number> | void): void;
on(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number | void | null> | number | void | null): void;
on(name: "retry", fn: (message: string, info: Bottleneck.EventInfoRetryable) => void): void;
on(name: "done", fn: (info: Bottleneck.EventInfoRetryable) => void): void;

Expand All @@ -511,7 +511,7 @@ declare module "bottleneck" {
once(name: "queued", fn: (info: Bottleneck.EventInfoQueued) => void): void;
once(name: "scheduled", fn: (info: Bottleneck.EventInfo) => void): void;
once(name: "executing", fn: (info: Bottleneck.EventInfoRetryable) => void): void;
once(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number> | void): void;
once(name: "failed", fn: (error: any, info: Bottleneck.EventInfoRetryable) => Promise<number | void | null> | number | void | null): void;
once(name: "retry", fn: (message: string, info: Bottleneck.EventInfoRetryable) => void): void;
once(name: "done", fn: (info: Bottleneck.EventInfoRetryable) => void): void;

Expand Down
34 changes: 34 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@ limiter.on('failed', (error, info) => {
return Promise.resolve(10)
})

limiter.on('failed', (error, info) => {
checkEventInfo(info)
const message: string = error.message;
const count: number = info.retryCount;
return Promise.resolve(null)
})

limiter.on('failed', (error, info) => {
checkEventInfo(info)
const message: string = error.message;
const count: number = info.retryCount;
return Promise.resolve()
})

limiter.on('failed', (error, info) => {
checkEventInfo(info)
const message: string = error.message;
const count: number = info.retryCount;
return 10
})

limiter.on('failed', (error, info) => {
checkEventInfo(info)
const message: string = error.message;
const count: number = info.retryCount;
return null
})

limiter.on('failed', (error, info) => {
checkEventInfo(info)
const message: string = error.message;
const count: number = info.retryCount;
})

limiter.on('retry', (message: string, info) => {
checkEventInfo(info)
const count: number = info.retryCount;
Expand Down

0 comments on commit 712db2f

Please sign in to comment.