Skip to content

Commit

Permalink
Allow any number of onFetch handlers for a single test (#54846)
Browse files Browse the repository at this point in the history
Recent usability testing indicated that it's convenient to register multiple `onFetch` handlers and iterate them until one of them response a result.
  • Loading branch information
dvoytenko committed Aug 31, 2023
1 parent 7b54e95 commit 826ef8c
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface NextFixture {
}

class NextFixtureImpl implements NextFixture {
private fetchHandler: FetchHandler | null = null
private fetchHandlers: FetchHandler[] = []

constructor(
public testId: string,
Expand All @@ -27,12 +27,11 @@ class NextFixtureImpl implements NextFixture {
}

onFetch(handler: FetchHandler): void {
this.fetchHandler = handler
this.fetchHandlers.push(handler)
}

private async handleFetch(request: Request): Promise<FetchHandlerResult> {
const handler = this.fetchHandler
if (handler) {
for (const handler of this.fetchHandlers.slice().reverse()) {
const result = handler(request)
if (result) {
return result
Expand Down

0 comments on commit 826ef8c

Please sign in to comment.