-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fetch: Add tests for AbortSignal's abort reason #35374
Merged
nidhijaju
merged 11 commits into
web-platform-tests:master
from
nidhijaju:fetch-abortreason-tests
Oct 6, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d4a347a
add abort reason tests
nidhijaju 75174a9
fix test
nidhijaju f2f12d1
fix promise rejection
nidhijaju be63549
add test
nidhijaju 7a3d345
removing logging
nidhijaju 4759700
fix typo
nidhijaju d02270b
update test
nidhijaju c52030b
remove waitUntil()
nidhijaju e26ec20
Merge branch 'web-platform-tests:master' into fetch-abortreason-tests
nidhijaju acb5c9c
add serialization test
nidhijaju 52f8b23
mutate error
nidhijaju 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
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,19 @@ | ||
async function messageClient(clientId, message) { | ||
const client = await clients.get(clientId); | ||
client.postMessage(message); | ||
} | ||
|
||
addEventListener('fetch', event => { | ||
let resolve; | ||
const promise = new Promise(r => resolve = r); | ||
|
||
function onAborted() { | ||
messageClient(event.clientId, event.request.signal.reason); | ||
resolve(); | ||
} | ||
|
||
messageClient(event.clientId, 'fetch event has arrived'); | ||
|
||
event.respondWith(promise.then(() => new Response('hello'))); | ||
event.request.signal.addEventListener('abort', onAborted); | ||
}); |
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.
The test does not produce the required failure messages in the tests
I think the await here should be removed.
The above code will return a response object and not the promise which we need to pass it to promise_rejects_exactly.
The following code should solve the problem:
Kindly check, I am not a JS expert :)
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.
That seems correct @MayyaSunil. Could you create a PR?
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.
Sure @annevk. I will submit the fix in mozilla's repo and let the sync bot do the job? Is it acceptable to you?
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.
Yeah that works. It might be worth having another test like this whereby we do wait for the response and then check that
response.body
was errored with the correct exception if that doesn't exist already.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.
Bug 1798921 is created to track this
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.
If the below patch is fine, I will submit it to our repo.
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.
That looks correct, yeah. Thanks @MayyaSunil!