Unverified Commit 826ef8c7 authored by Dima Voytenko's avatar Dima Voytenko Committed by GitHub

Allow any number of onFetch handlers for a single test (#54846)

Recent usability testing indicated that it's convenient to register multiple `onFetch` handlers and iterate them until one of them response a result.
parent 7b54e954
......@@ -9,7 +9,7 @@ export interface NextFixture {
}
class NextFixtureImpl implements NextFixture {
private fetchHandler: FetchHandler | null = null
private fetchHandlers: FetchHandler[] = []
constructor(
public testId: string,
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment