-
-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement a RequestController
class
#595
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d2c6b64
feat: implement RequestController class
kettanaito 073e3f2
feat(fetch): use RequestController
kettanaito d3a41fe
chore: implement "handleRequest" pipeline
kettanaito 566ad8e
fix(fetch): use new "handleRequest" function
kettanaito 04b5f82
fix(xhr): use "handleRequest" function
kettanaito 3bb58bb
fix(ClientRequest): use "handleRequest" function
kettanaito b4d4b5f
fix(remote): use "handleRequest" function
kettanaito e9d9a5a
chore: adjust "request.respondWith" assertions
kettanaito 84a54b7
test(ClientRequest): use controller in tests
kettanaito aee5229
Merge branch 'main' into feat/request-controller
kettanaito c897655
test(ClientRequest): remove multiple "respondWith" test case
kettanaito dda17f8
test(RequestController): add unit tests
kettanaito 05e929d
test: fix wrong request.respondWith() usage
kettanaito 0728cfa
chore: polish
kettanaito 08ec0a0
fix(xhr): treat "onAborted" as error
kettanaito e62dba8
fix(handleRequest): rename "onAborted" to "onError"
kettanaito 49db30c
docs: document net "RequestController" api
kettanaito a53ab06
Merge branch 'main' into feat/request-controller
kettanaito 3470de4
Merge branch 'main' into feat/request-controller
kettanaito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
export class InterceptorError extends Error { | ||
constructor(message?: string) { | ||
super(message) | ||
this.name = 'InterceptorError' | ||
Object.setPrototypeOf(this, InterceptorError.prototype) | ||
} | ||
} |
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,49 @@ | ||
import { it, expect } from 'vitest' | ||
import { kResponsePromise, RequestController } from './RequestController' | ||
|
||
it('creates a pending response promise on construction', () => { | ||
const controller = new RequestController(new Request('http://localhost')) | ||
expect(controller[kResponsePromise]).toBeInstanceOf(Promise) | ||
expect(controller[kResponsePromise].state).toBe('pending') | ||
}) | ||
|
||
it('resolves the response promise with the response provided to "respondWith"', async () => { | ||
const controller = new RequestController(new Request('http://localhost')) | ||
controller.respondWith(new Response('hello world')) | ||
|
||
const response = (await controller[kResponsePromise]) as Response | ||
|
||
expect(response).toBeInstanceOf(Response) | ||
expect(response.status).toBe(200) | ||
expect(await response.text()).toBe('hello world') | ||
}) | ||
|
||
it('resolves the response promise with the error provided to "errorWith"', async () => { | ||
const controller = new RequestController(new Request('http://localhost')) | ||
const error = new Error('Oops!') | ||
controller.errorWith(error) | ||
|
||
await expect(controller[kResponsePromise]).resolves.toEqual(error) | ||
}) | ||
|
||
it('throws when calling "respondWith" multiple times', () => { | ||
const controller = new RequestController(new Request('http://localhost')) | ||
controller.respondWith(new Response('hello world')) | ||
|
||
expect(() => { | ||
controller.respondWith(new Response('second response')) | ||
}).toThrow( | ||
'Failed to respond to the "GET http://localhost/" request: the "request" event has already been handled.' | ||
) | ||
}) | ||
|
||
it('throws when calling "errorWith" multiple times', () => { | ||
const controller = new RequestController(new Request('http://localhost')) | ||
controller.errorWith(new Error('Oops!')) | ||
|
||
expect(() => { | ||
controller.errorWith(new Error('second error')) | ||
}).toThrow( | ||
'Failed to error the "GET http://localhost/" request: the "request" event has already been handled.' | ||
) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outvariant
had issues with polymorphic errors and multiple positionals. Fixed it and updated the dependency.