Skip to content

ref(nextjs): Split up config code and add tests #3693

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

Merged
merged 2 commits into from
Jun 17, 2021

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Jun 16, 2021

No behavior changes here, but withSentryConfig (and its side effects) have been giving us fits, so this:

  • refactors the code, both changing a number of names for clarity and splitting it up into smaller functions in multiple files
  • adds tests for the overall next config, the webpack config, and the entry config within the webpack config

Not yet tested is any of the code configuring the SentryWebpackPlugin. This will likely have to wait for a later PR.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 16, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 21.01 KB (0%)
@sentry/browser - Webpack 21.89 KB (0%)
@sentry/react - Webpack 21.92 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.4 KB (-0.01% 🔽)

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Nice! I'll do a more in-depth pass once you got tests in.

webpack?: WebpackConfigFunction;
} & {
// other `next.config.js` options
[key: string]: unknown;
Copy link
Member

Choose a reason for hiding this comment

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

We might have to type as any, I'm scared of stuff breaking 😅. Maybe we'll be fine?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you mean.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly probably not a problem, ignore me

if (!options.dev) {
// TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see
// https://webpack.js.org/plugins/source-map-dev-tool-plugin/)
// TODO Give user option to use `hidden-source-map` ?
Copy link
Member

Choose a reason for hiding this comment

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

lets make sure each of these todos have tickets - we can then discuss with the team and anyone can pick them up.

Maybe even open a GH issue and make it open for contribution? Could be a good way to get the community involved.

checkWebpackPluginOverrides(userSentryWebpackPluginOptions);
newConfig.plugins = newConfig.plugins || [];
newConfig.plugins.push(
// @ts-ignore Our types for the plugin are messed up somehow - TS wants this to be `SentryWebpackPlugin.default`,
Copy link
Member

Choose a reason for hiding this comment

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

Is this a @sentry/webpack-plugin issue? We should open a GH issue then and make sure we document that in that repo.

@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-handle-other-config-scenarios branch from c30db27 to 61316be Compare June 17, 2021 05:48
@lobsterkatie lobsterkatie force-pushed the kmclb-nextjs-handle-other-config-scenarios branch from 61316be to 748ea46 Compare June 17, 2021 05:49
@lobsterkatie lobsterkatie marked this pull request as ready for review June 17, 2021 06:01
Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

I would like to see more integration style tests that use some some example plugins and check. Referencing issues we've hit before:

We can wait on these though, feel free to open a todo ticket in the meantime.

Also, I think we can skip writing the Sentry webpack plugin config tests, feel free to place a TODO there as there are more pressing things to get to.


/** mocks of the arguments passed to `nextConfig.webpack` */
const serverWebpackConfig = {
entry: () => Promise.resolve({ 'pages/api/dogs/[name]': 'private-next-pages/api/dogs/[name].js' }),
Copy link
Member

@AbhiPrasad AbhiPrasad Jun 17, 2021

Choose a reason for hiding this comment

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

Can we have a config for a sample webpack 5 entry as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I might have been being overcautious when I included handling for entry point objects - even under webpack 5, next doesn't actually use them for main, which is the only one we care about on the browser side. (On the server side we're not adding to an existing entry point, we're making our own, so the format of the others doesn't matter.)

Comment on lines +65 to +67
const finalConfigValues = withSentryConfig(userNextConfig, userSentryWebpackPluginConfig);

return finalConfigValues;
Copy link
Member

Choose a reason for hiding this comment

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

Derive the final values of all next config options, by first applying withSentryConfig and then running the resulting function

This doesn't seem to be running a resulting function? Just returning the value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh. This is what I get for making changes A and B together, then backing out B to stick it into another PR. I missed that docstring on my first pass and by the time I noticed it, I'd already pushed everything. As soon as this merges I'm going to PR that other change (which makes this docstring correct).


it('includes expected properties', async () => {
const finalWebpackConfig = await materializeFinalWebpackConfig({
userNextConfig,
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we should table test both the includes expected properties and injects correct code when building client bundle tests. We can create various different server/client configs and buildContexts and check to make sure we get a sane finalWebpackConfig.

See my table tests for sessions as an example: https://github.com/getsentry/sentry-javascript/blob/master/packages/hub/test/session.test.ts#L32-L90.

We can also come back to this once we update the require server init flow, feel free to slap a TODO somewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, a table test isn't a bad idea. We can cross that bridge once we have enough different scenarios to warrant it.

@lobsterkatie
Copy link
Member Author

I would like to see more integration style tests that use some some example plugins and check. Referencing issues we've hit before:

We can wait on these though, feel free to open a todo ticket in the meantime.

Yeah, going to wait on that, because it would take a whole different set up. In the meantime, as we fix bugs we can add unit tests for the specific problems we encounter.

Also, I think we can skip writing the Sentry webpack plugin config tests, feel free to place a TODO there as there are more pressing things to get to.

Yeah, was not planning to do them in this PR.

Going to merge this and we can add anything we like once the new structure is in place.

@lobsterkatie lobsterkatie merged commit db1edce into master Jun 17, 2021
@lobsterkatie lobsterkatie deleted the kmclb-nextjs-handle-other-config-scenarios branch June 17, 2021 17:30
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