-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve typings, avoid returning response if unnecessary and add uni…
…t tests (#138) * Cleanup response returns * Improve typings and avoid returning response if unnecessary * More tests * Go * Go * Do not fail-fast * Prettier :) * ... * ..
- Loading branch information
Showing
10 changed files
with
518 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { CustomEvent } from '@whatwg-node/events'; | ||
import { Request, Response } from '@whatwg-node/fetch'; | ||
import { createServerAdapter } from '../src'; | ||
|
||
describe('FetchEvent listener', () => { | ||
it('should not return a promise to event listener', () => { | ||
const response = new Response(); | ||
const response$ = Promise.resolve(response); | ||
const adapter = createServerAdapter(() => response$); | ||
const respondWith = jest.fn(); | ||
const waitUntil = jest.fn(); | ||
const fetchEvent = Object.assign(new CustomEvent('fetch'), { | ||
request: new Request('http://localhost:8080'), | ||
respondWith, | ||
waitUntil, | ||
}); | ||
const returnValue = adapter(fetchEvent); | ||
expect(returnValue).toBeUndefined(); | ||
expect(respondWith).toHaveBeenCalledWith(response$); | ||
}); | ||
it('should expose FetchEvent as server context', () => { | ||
const handleRequest = jest.fn(); | ||
const adapter = createServerAdapter(handleRequest); | ||
const respondWith = jest.fn(); | ||
const waitUntil = jest.fn(); | ||
const fetchEvent = Object.assign(new CustomEvent('fetch'), { | ||
request: new Request('http://localhost:8080'), | ||
respondWith, | ||
waitUntil, | ||
}); | ||
adapter(fetchEvent); | ||
expect(handleRequest).toHaveBeenCalledWith(fetchEvent.request, fetchEvent); | ||
}); | ||
it('should accept additional parameters as server context', () => { | ||
const handleRequest = jest.fn(); | ||
const adapter = createServerAdapter<{ | ||
foo: string; | ||
}>(handleRequest); | ||
const respondWith = jest.fn(); | ||
const waitUntil = jest.fn(); | ||
const fetchEvent = Object.assign(new CustomEvent('fetch'), { | ||
request: new Request('http://localhost:8080'), | ||
respondWith, | ||
waitUntil, | ||
}); | ||
const additionalCtx = { foo: 'bar' }; | ||
adapter(fetchEvent, additionalCtx); | ||
expect(handleRequest).toHaveBeenCalledWith(fetchEvent.request, expect.objectContaining(additionalCtx)); | ||
}); | ||
}); |
Oops, something went wrong.