Skip to content

add task solution#453

Open
lublubuterbrodi wants to merge 1 commit intomate-academy:masterfrom
lublubuterbrodi:develop
Open

add task solution#453
lublubuterbrodi wants to merge 1 commit intomate-academy:masterfrom
lublubuterbrodi:develop

Conversation

@lublubuterbrodi
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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 (shouoldshould) 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

/* Write your code here */
// Return instance of http.Server class
return http.createServer((req, res) => {
const url = new URL(req.url || '/', 'http://localhost');

Choose a reason for hiding this comment

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

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)

Comment on lines +29 to +31
beforeEach(() => {
server = createServer();
server.listen(PORT);

Choose a reason for hiding this comment

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

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.

Comment on lines +33 to +35
afterEach(() => {
server.close();

Choose a reason for hiding this comment

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

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 () => {

Choose a reason for hiding this comment

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

Small typo in the test title: shouold -> should (fix the test description to avoid confusion).

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.

2 participants