Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there is one critical functional issue that violates the requirements, plus some test reliability problems that could cause failures in CI. The main blocker is in src/createServer.js: when you build the URL with new URL(req.url || '/', 'http://localhost'), a path starting with // (for example //hello/world/123) is treated as a protocol‑relative URL, so hello becomes the hostname instead of the first path segment; this breaks the requirement that parts must be ['hello','world','123'] for doubled leading slashes [CHECKLIST ITEM #9]. To fix this, normalize req.url before passing it to new URL, e.g. collapse multiple leading slashes to a single / so that //hello/world/123 is parsed as a normal pathname. In tests/paramsServer.test.js, your beforeEach starts the server and afterEach closes it, but neither waits for those asynchronous operations to complete; this can lead to flaky tests where requests hit before listen is ready, or the next test tries to bind the port before close finishes. Make beforeEach and afterEach async and await server.listen/server.close (using a small new Promise wrapper around the callback) to ensure reliable test setup and teardown. As a small polish, fix the typo in the test name (shouold → should) to keep your test descriptions clear. Overall the core idea is solid and most requirements are met; once you address the URL normalization and test lifecycle handling, your solution will be in great shape.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| /* Write your code here */ | ||
| // Return instance of http.Server class | ||
| return http.createServer((req, res) => { | ||
| const url = new URL(req.url || '/', 'http://localhost'); |
There was a problem hiding this comment.
Using new URL(req.url || '/', 'http://localhost') will treat a value that starts with // as a protocol-relative URL (host + path) rather than a pathname, so a request like //hello/world/123 becomes hostname: 'hello' and pathname: '/world/123', which breaks checklist item #9. Consider normalizing the raw request URL first, e.g.: const raw = (req.url || '/').replace(/^\/+/,'/'); const url = new URL(raw, 'http://localhost'); This preserves leading segments and ensures //hello/world/123 yields ['hello','world','123']. (Relates to checklist item #9)
| beforeEach(() => { | ||
| server = createServer(); | ||
| server.listen(PORT); |
There was a problem hiding this comment.
The beforeEach hook starts the server but does not wait for it to finish listening. Starting the server is asynchronous — consider making beforeEach async and awaiting server.listen (for example: await new Promise(resolve => server.listen(PORT, resolve))) so tests won't issue requests before the server is ready.
| afterEach(() => { | ||
| server.close(); |
There was a problem hiding this comment.
The afterEach hook closes the server but does not wait for the close to complete. server.close() is asynchronous — consider awaiting it (for example: await new Promise(resolve => server.close(resolve))) or using the callback form so the next test doesn't try to bind the same port before the previous server has fully closed.
| expect(response.status).toEqual(200); | ||
| }); | ||
| it('shouold handle requests with multiple query parameters', async () => { |
There was a problem hiding this comment.
Small typo in the test title: shouold -> should (fix the test description to avoid confusion).
No description provided.