Skip to content
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

Ignore style.loadURL abort error when style is removed #4425

Merged
merged 8 commits into from
Jul 29, 2024

Conversation

madoci
Copy link
Contributor

@madoci madoci commented Jul 18, 2024

Fixes #4400

Ignore the abort error raised by style.loadURL when the style is removed.

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.40%. Comparing base (adc0495) to head (fc3cc98).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4425      +/-   ##
==========================================
- Coverage   87.94%   87.40%   -0.54%     
==========================================
  Files         246      246              
  Lines       33396    33397       +1     
  Branches     2173     2208      +35     
==========================================
- Hits        29371    29192     -179     
- Misses       3033     3191     +158     
- Partials      992     1014      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@madoci madoci marked this pull request as ready for review July 18, 2024 10:06
@HarelM
Copy link
Collaborator

HarelM commented Jul 18, 2024

Thanks for taking the time to open this PR!
Looks like a good and clean solution, thanks!

@madoci
Copy link
Contributor Author

madoci commented Jul 18, 2024

Thank you @HarelM for the review. Should I open a new PR to add a test of the error firing in case it isn't an abort error, to ensure coverage of the if condition ? Or maybe do it here ?

@HarelM
Copy link
Collaborator

HarelM commented Jul 18, 2024

Here would be better. THANKS!

src/style/style.test.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Jul 18, 2024

Besides the test nit-picking this looks good.

1 similar comment
@HarelM

This comment was marked as duplicate.

Copy link
Collaborator

@HarelM HarelM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@HarelM HarelM enabled auto-merge (squash) July 20, 2024 07:25
@HarelM HarelM disabled auto-merge July 20, 2024 07:31

style.on('error', spy);
style.loadURL('style.json');
const promise = new Promise((_, reject) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see other places are using a simpler method:
expect((server.lastRequest as any).aborted).toBe(true);
I think it can be used here as well.
I'll open a PR to update the types so we can remove these "as any".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect((server.lastRequest as any).aborted).toBe(true); is used to test if the request has been aborted, which the test above does ('cancels pending requests if removed'). In our case, we want to test that, when the request is aborted, no error are fired.

Removing these "as any" would be nice, thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using expect((server.lastRequest as any).aborted).toBe(true); would remove the need to use this promise, and wait for it rejection. I find it more elegant. You might still need a sleep(0) though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the nise types, now you can use it without the "as any":
#4446

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the nise types, now you can use it without the "as any"

Thanks !

Using expect((server.lastRequest as any).aborted).toBe(true); would remove the need to use this promise, and wait for it rejection. I find it more elegant. You might still need a sleep(0) though.

We would still need a sleep(0) since the rejection is asynchronous. Without it, the test succeed even if the Style fires the abort error. The promise is just a way to wait for the rejection we want to test rather than just wait for a bit with the sleep(0), but I agree it's not very elegant and it might be too bound to implementation. Should I revert to sleep(0) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please.

@HarelM HarelM merged commit fc0012e into maplibre:main Jul 29, 2024
15 checks passed
@madoci madoci deleted the ignore-aborts branch July 29, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

style.loadURL prints an error when the request is aborted
3 participants