@@ -7,20 +7,14 @@ import {
7
7
SentryWebpackPluginOptions ,
8
8
WebpackConfigObject ,
9
9
} from '../src/config/types' ;
10
- import { SENTRY_SERVER_CONFIG_FILE , SERVER_SDK_INIT_PATH } from '../src/config/utils' ;
11
- import { constructWebpackConfigFunction , SentryWebpackPlugin } from '../src/config/webpack' ;
12
-
13
- // mock `storeServerConfigFileLocation` in order to make it a no-op when necessary
14
- jest . mock ( '../src/config/utils' , ( ) => {
15
- const original = jest . requireActual ( '../src/config/utils' ) ;
16
- return {
17
- ...original ,
18
- // nuke this so it won't try to look for our dummy paths
19
- storeServerConfigFileLocation : jest . fn ( ) ,
20
- } ;
21
- } ) ;
10
+ import {
11
+ constructWebpackConfigFunction ,
12
+ SentryWebpackPlugin ,
13
+ CLIENT_SDK_CONFIG_FILE ,
14
+ SERVER_SDK_CONFIG_FILE ,
15
+ } from '../src/config/webpack' ;
22
16
23
- /** mocks of the arguments passed to `withSentryConfig` */
17
+ /** Mocks of the arguments passed to `withSentryConfig` */
24
18
const userNextConfig = {
25
19
publicRuntimeConfig : { location : 'dogpark' , activities : [ 'fetch' , 'chasing' , 'digging' ] } ,
26
20
webpack : ( config : WebpackConfigObject , _options : BuildContext ) => ( {
@@ -35,19 +29,36 @@ const userNextConfig = {
35
29
} ;
36
30
const userSentryWebpackPluginConfig = { org : 'squirrelChasers' , project : 'simulator' , include : './thirdPartyMaps' } ;
37
31
38
- /** mocks of the arguments passed to the result of `withSentryConfig` (when it's a function) */
39
- const runtimePhase = 'puppy-phase-chew-everything-in-sight ' ;
32
+ /** Mocks of the arguments passed to the result of `withSentryConfig` (when it's a function). */
33
+ const runtimePhase = 'ball-fetching ' ;
40
34
const defaultNextConfig = { nappingHoursPerDay : 20 , oversizeFeet : true , shouldChaseTail : true } ;
41
35
42
36
/** mocks of the arguments passed to `nextConfig.webpack` */
43
37
const serverWebpackConfig = {
44
- entry : ( ) => Promise . resolve ( { 'pages/api/dogs/[name]' : 'private-next-pages/api/dogs/[name].js' } ) ,
38
+ entry : ( ) =>
39
+ Promise . resolve ( {
40
+ 'pages/api/dogs/[name]' : 'private-next-pages/api/dogs/[name].js' ,
41
+ 'pages/_app' : [ './node_modules/smellOVision/index.js' , 'private-next-pages/_app.js' ] ,
42
+ 'pages/api/simulator/dogStats/[name]' : { import : 'private-next-pages/api/simulator/dogStats/[name].js' } ,
43
+ 'pages/api/simulator/leaderboard' : {
44
+ import : [ './node_modules/dogPoints/converter.js' , 'private-next-pages/api/simulator/leaderboard.js' ] ,
45
+ } ,
46
+ 'pages/api/tricks/[trickName]' : {
47
+ import : 'private-next-pages/api/tricks/[trickName].js' ,
48
+ dependOn : 'treats' ,
49
+ } ,
50
+ treats : './node_modules/dogTreats/treatProvider.js' ,
51
+ } ) ,
45
52
output : { filename : '[name].js' , path : '/Users/Maisey/projects/squirrelChasingSimulator/.next' } ,
46
53
target : 'node' ,
47
54
context : '/Users/Maisey/projects/squirrelChasingSimulator' ,
48
55
} ;
49
56
const clientWebpackConfig = {
50
- entry : ( ) => Promise . resolve ( { main : './src/index.ts' } ) ,
57
+ entry : ( ) =>
58
+ Promise . resolve ( {
59
+ main : './src/index.ts' ,
60
+ 'pages/_app' : 'next-client-pages-loader?page=%2F_app' ,
61
+ } ) ,
51
62
output : { filename : 'static/chunks/[name].js' , path : '/Users/Maisey/projects/squirrelChasingSimulator/.next' } ,
52
63
target : 'web' ,
53
64
context : '/Users/Maisey/projects/squirrelChasingSimulator' ,
@@ -212,7 +223,7 @@ describe('webpack config', () => {
212
223
} ) ;
213
224
214
225
describe ( 'webpack `entry` property config' , ( ) => {
215
- it ( 'injects correct code when building server bundle ' , async ( ) => {
226
+ it ( 'handles various entrypoint shapes ' , async ( ) => {
216
227
const finalWebpackConfig = await materializeFinalWebpackConfig ( {
217
228
userNextConfig,
218
229
incomingWebpackConfig : serverWebpackConfig ,
@@ -221,38 +232,53 @@ describe('webpack config', () => {
221
232
222
233
expect ( finalWebpackConfig . entry ) . toEqual (
223
234
expect . objectContaining ( {
224
- [ SERVER_SDK_INIT_PATH . slice ( 0 , - 3 ) ] : SENTRY_SERVER_CONFIG_FILE ,
235
+ // original entry point value is a string
236
+ // (was 'private-next-pages/api/dogs/[name].js')
237
+ 'pages/api/dogs/[name]' : [ SERVER_SDK_CONFIG_FILE , 'private-next-pages/api/dogs/[name].js' ] ,
238
+
239
+ // original entry point value is a string array
240
+ // (was ['./node_modules/smellOVision/index.js', 'private-next-pages/_app.js'])
241
+ 'pages/_app' : [ SERVER_SDK_CONFIG_FILE , './node_modules/smellOVision/index.js' , 'private-next-pages/_app.js' ] ,
242
+
243
+ // original entry point value is an object containg string `import` value
244
+ // (`import` was 'private-next-pages/api/simulator/dogStats/[name].js')
245
+ 'pages/api/simulator/dogStats/[name]' : {
246
+ import : [ SERVER_SDK_CONFIG_FILE , 'private-next-pages/api/simulator/dogStats/[name].js' ] ,
247
+ } ,
248
+
249
+ // original entry point value is an object containg string array `import` value
250
+ // (`import` was ['./node_modules/dogPoints/converter.js', 'private-next-pages/api/simulator/leaderboard.js'])
251
+ 'pages/api/simulator/leaderboard' : {
252
+ import : [
253
+ SERVER_SDK_CONFIG_FILE ,
254
+ './node_modules/dogPoints/converter.js' ,
255
+ 'private-next-pages/api/simulator/leaderboard.js' ,
256
+ ] ,
257
+ } ,
258
+
259
+ // original entry point value is an object containg properties besides `import`
260
+ // (`dependOn` remains untouched)
261
+ 'pages/api/tricks/[trickName]' : {
262
+ import : [ SERVER_SDK_CONFIG_FILE , 'private-next-pages/api/tricks/[trickName].js' ] ,
263
+ dependOn : 'treats' ,
264
+ } ,
225
265
} ) ,
226
266
) ;
227
267
} ) ;
228
268
229
- it ( 'injects correct code when building client bundle ' , async ( ) => {
269
+ it ( 'does not inject into non-_app, non-API routes ' , async ( ) => {
230
270
const finalWebpackConfig = await materializeFinalWebpackConfig ( {
231
271
userNextConfig,
232
272
incomingWebpackConfig : clientWebpackConfig ,
233
273
incomingWebpackBuildContext : clientBuildContext ,
234
274
} ) ;
235
275
236
- expect ( finalWebpackConfig . entry ) . toEqual (
237
- expect . objectContaining ( { main : [ './src/index.ts' , './sentry.client.config.js' ] } ) ,
238
- ) ;
239
- } ) ;
240
-
241
- // see https://github.com/getsentry/sentry-javascript/pull/3696#issuecomment-863363803
242
- it ( 'handles non-empty `main.js` entry point' , async ( ) => {
243
- const finalWebpackConfig = await materializeFinalWebpackConfig ( {
244
- userNextConfig,
245
- incomingWebpackConfig : {
246
- ...clientWebpackConfig ,
247
- entry : ( ) => Promise . resolve ( { main : './src/index.ts' , 'main.js' : [ 'sitLieDownRollOver.config.js' ] } ) ,
248
- } ,
249
- incomingWebpackBuildContext : clientBuildContext ,
250
- } ) ;
251
-
252
276
expect ( finalWebpackConfig . entry ) . toEqual (
253
277
expect . objectContaining ( {
254
- main : [ 'sitLieDownRollOver.config.js' , './src/index.ts' , './sentry.client.config.js' ] ,
255
- 'main.js' : [ ] ,
278
+ // no injected file
279
+ main : './src/index.ts' ,
280
+ // was 'next-client-pages-loader?page=%2F_app'
281
+ 'pages/_app' : [ CLIENT_SDK_CONFIG_FILE , 'next-client-pages-loader?page=%2F_app' ] ,
256
282
} ) ,
257
283
) ;
258
284
} ) ;
0 commit comments