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

Merge url query with exportPathMap #4678

Merged
merged 4 commits into from
Jun 28, 2018
Merged

Merge url query with exportPathMap #4678

merged 4 commits into from
Jun 28, 2018

Conversation

lucleray
Copy link
Member

@lucleray lucleray commented Jun 26, 2018

This PR fixes #4615

From the issue :

One thing we might consider is merging and showing a warning for keys not defined in exportPathMap

The behaviour after this PR is the following :

// next.config.js
module.exports = {
  exportPathMap: () => ({
    '/': { page: '/', query: { a: 'blue' } }
  })
}
url called ctx.query warning ?
/ { a: 'blue' }
/?a=red { a: 'blue' }
/?b=green { a: 'blue', b: 'green' } ... parameter 'b' missing in exportPathMap

Is that the expected behaviour ? If not, I'll update the PR to shape the expected behavior.

server/index.js Outdated
.filter(key => query[key] === undefined)
.forEach(key => console.warn(`Url defines a query parameter '${key}' that is missing in exportPathMap`))

const mergedQuery = Object.assign({}, urlQuery, query)
Copy link
Member

Choose a reason for hiding this comment

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

Let's do {...urlQuery, ...query} instead of Object.assign

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

Let's add a test for this new behavior 👍 can be added in test/integration/export

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

My review was actually a request changes

@timneutkens
Copy link
Member

timneutkens commented Jun 27, 2018

I actually gave the wrong directory, static already has tests for next export. It also has a test for the query I believe 🤔 So you can add the extra tests there. Sorry for the confusion 🙏

@lucleray
Copy link
Member Author

@timneutkens I added the tests for the 3 scenario in the PR's description.

I ran into the following problems while writing the tests :

1. launchApp / killApp

If I used launchApp from the next-test-utils, it was harder to catch console.warn call and the app wouldn't shut down properly.

killApp does kill the PID of the spawned process, here :
https://github.com/zeit/next.js/blob/7fcfb8bde91af096af6905ec8c426934f667f0b6/test/lib/next-test-utils.js#L102-L104

But it does not kill the PID of the "subprocess" spawned by the spawned process 💣
Basically, launchApp spawn a new process : next, which spawns another new process : next-dev
They get PID and PID+1 (for example 44013 and 44014).
killApp only kills PID, but not PID+1. They would need to be both killed for killApp to work properly.

2. startApp / stopApp

There is a bug in stopApp, I think.

More precisely here :

https://github.com/zeit/next.js/blob/7fcfb8bde91af096af6905ec8c426934f667f0b6/test/lib/next-test-utils.js#L116-L121

app is never touched.

What I did

So I ended up simply using start and stop from server/next. Not sure it's the best thing to do for integration test. Let me know 🙂

@lucleray
Copy link
Member Author

lucleray commented Jun 27, 2018

@timneutkens
Ok, I can move the tests to static

Oh, but static runs tests with a static server. These tests need to be run with a dev server.
EDIT : my bad, it has both, I'll move it there 👍

@timneutkens
Copy link
Member

You actually don't have to test the console.log calls, just check loading the page with a querystring and query defined and see if it works. We don't test console.log side effects as they will most likely change in the future and can't break anything.

@lucleray
Copy link
Member Author

I fixed the tests, I removed the test for console.log.

Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@timneutkens timneutkens merged commit e98a877 into vercel:canary Jun 28, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jun 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ctx.query undefined during dev and using exportPathMap
2 participants