Skip to content

Conversation

@Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Feb 5, 2024

replaces chai and mocha with native test runner of node.

found a bug in Fetch Request.

@KhafraDev
Copy link
Member

What is the issue in fetch? Why is the webidl stuff needed?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Feb 5, 2024

@KhafraDev

webidl.converters.BodyInit is not defined in request.js but we are using it in this line

webidl.converters.BodyInit

The unit test 'should throw error with GET/HEAD requests with body' was before just checking if a error is thrown. When i changed it to also check the message, it showed 'converter not defined'(or something similar). This was because BodyInit was not defined.
Now it throws the correct error.

@KhafraDev
Copy link
Member

I'm assuming you imported lib/fetch/request.js and not index.js?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Feb 5, 2024

@KhafraDev Yes you are right. If I import it from index.js it will work as expected. But would this not mean, that we have the risk of breaking something if we import directly from fetch/request.js and not from index.js?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Feb 5, 2024

@KhafraDev

Done, but feels error prone as the hoisting order is important.

@KhafraDev
Copy link
Member

It's either that or circular imports... I opted for this way. After all, you can't have Request by itself.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Feb 5, 2024

How about adding a simple

if (webidl.converters.BodyInit === undefined) {
throw new Error('should have required correctly')
}

Or in webidl.nullableConverter it should check if the coverter is a function, and throw accordingly.

This should result in no runtime overhead but improves the chance of finding a wrong require/import

@KhafraDev
Copy link
Member

Meh, realistically it shouldn't happen and tests should just require index.js. I don't see it being useful.

@Uzlopak Uzlopak changed the title chore: remove mocha and chai, fix bug in fetch request chore: remove mocha and chai Feb 5, 2024
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Feb 5, 2024

@KhafraDev

But overall you like the changes?

@KhafraDev
Copy link
Member

yeah, I just have no time to do a full review on it

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Feb 5, 2024

@KhafraDev
No worries. I just want to make sure, that there is no big reason for rejection or something i can fix now as long as it is still "warm" in my head.

@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.28%. Comparing base (e39a632) to head (5cb116e).
Report is 1161 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2696      +/-   ##
==========================================
- Coverage   85.54%   85.28%   -0.27%     
==========================================
  Files          76       84       +8     
  Lines        6858     7593     +735     
==========================================
+ Hits         5867     6476     +609     
- Misses        991     1117     +126     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 0a069ab into nodejs:main Feb 8, 2024
@Uzlopak Uzlopak deleted the remove-mocha-chai branch February 8, 2024 16:04
@renovate renovate bot mentioned this pull request Mar 12, 2024
1 task
return assert.rejects(fetch(url), new TypeError('Failed to parse URL from /some/path'))
})

// TODO: This seems odd
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why this seems odd?

I am seeing the following:

TypeError: fetch failed
    at node:internal/deps/undici/undici:12502:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  [cause]: Error: unknown scheme

Perhaps this test should check for unknown scheme instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think this is what made it odd to me.

Copy link
Member

Choose a reason for hiding this comment

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

fetch should always reject with "fetch failed" and the cause should be the error. Basically, it's working properly.

Copy link
Member

Choose a reason for hiding this comment

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

I see. In that case we should remove the comment?

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 think are lacking the test that error.cause.message should be "unknown scheme".

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.

6 participants