Skip to content

Commit 9a5fd04

Browse files
committed
use helper function in existing tests
1 parent 6f0b32d commit 9a5fd04

File tree

1 file changed

+53
-18
lines changed

1 file changed

+53
-18
lines changed

packages/nextjs/test/config.test.ts

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '../src/config/types';
1616
import {
1717
constructWebpackConfigFunction,
18+
findWebpackPlugin,
1819
getUserConfigFile,
1920
getWebpackPluginOptions,
2021
SentryWebpackPlugin,
@@ -336,7 +337,12 @@ describe('Sentry webpack plugin config', () => {
336337
incomingWebpackBuildContext: serverBuildContext,
337338
});
338339

339-
expect(finalWebpackConfig.plugins?.[0].options).toEqual(
340+
const sentryWebpackPluginInstance = findWebpackPlugin(
341+
finalWebpackConfig,
342+
'SentryCliPlugin',
343+
) as SentryWebpackPluginType;
344+
345+
expect(sentryWebpackPluginInstance.options).toEqual(
340346
expect.objectContaining({
341347
include: expect.any(Array), // default, tested separately elsewhere
342348
ignore: [], // default
@@ -360,7 +366,12 @@ describe('Sentry webpack plugin config', () => {
360366
incomingWebpackBuildContext: serverBuildContext,
361367
});
362368

363-
expect((finalWebpackConfig.plugins?.[0].options as SentryWebpackPluginOptions).debug).toEqual(true);
369+
const sentryWebpackPluginInstance = findWebpackPlugin(
370+
finalWebpackConfig,
371+
'SentryCliPlugin',
372+
) as SentryWebpackPluginType;
373+
374+
expect(sentryWebpackPluginInstance.options.debug).toEqual(true);
364375
});
365376

366377
it('warns when overriding certain default values', () => {
@@ -379,9 +390,12 @@ describe('Sentry webpack plugin config', () => {
379390
incomingWebpackBuildContext: clientBuildContext,
380391
});
381392

382-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
393+
const sentryWebpackPluginInstance = findWebpackPlugin(
394+
finalWebpackConfig,
395+
'SentryCliPlugin',
396+
) as SentryWebpackPluginType;
383397

384-
expect(sentryWebpackPlugin.options?.include).toEqual([
398+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
385399
{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/_next/static/chunks/pages' },
386400
]);
387401
});
@@ -396,9 +410,12 @@ describe('Sentry webpack plugin config', () => {
396410
incomingWebpackBuildContext: getBuildContext('server', userNextConfigServerless),
397411
});
398412

399-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
413+
const sentryWebpackPluginInstance = findWebpackPlugin(
414+
finalWebpackConfig,
415+
'SentryCliPlugin',
416+
) as SentryWebpackPluginType;
400417

401-
expect(sentryWebpackPlugin.options?.include).toEqual([
418+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
402419
{ paths: ['.next/serverless/'], urlPrefix: '~/_next/serverless' },
403420
]);
404421
});
@@ -413,9 +430,12 @@ describe('Sentry webpack plugin config', () => {
413430
incomingWebpackBuildContext: serverBuildContextWebpack4,
414431
});
415432

416-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
433+
const sentryWebpackPluginInstance = findWebpackPlugin(
434+
finalWebpackConfig,
435+
'SentryCliPlugin',
436+
) as SentryWebpackPluginType;
417437

418-
expect(sentryWebpackPlugin.options?.include).toEqual([
438+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
419439
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
420440
]);
421441
});
@@ -427,9 +447,12 @@ describe('Sentry webpack plugin config', () => {
427447
incomingWebpackBuildContext: serverBuildContext,
428448
});
429449

430-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
450+
const sentryWebpackPluginInstance = findWebpackPlugin(
451+
finalWebpackConfig,
452+
'SentryCliPlugin',
453+
) as SentryWebpackPluginType;
431454

432-
expect(sentryWebpackPlugin.options?.include).toEqual([
455+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
433456
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
434457
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
435458
]);
@@ -449,9 +472,12 @@ describe('Sentry webpack plugin config', () => {
449472
incomingWebpackBuildContext: getBuildContext('client', userNextConfigWithBasePath),
450473
});
451474

452-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
475+
const sentryWebpackPluginInstance = findWebpackPlugin(
476+
finalWebpackConfig,
477+
'SentryCliPlugin',
478+
) as SentryWebpackPluginType;
453479

454-
expect(sentryWebpackPlugin.options?.include).toEqual([
480+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
455481
{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/city-park/_next/static/chunks/pages' },
456482
]);
457483
});
@@ -466,9 +492,12 @@ describe('Sentry webpack plugin config', () => {
466492
incomingWebpackBuildContext: getBuildContext('server', userNextConfigServerless),
467493
});
468494

469-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
495+
const sentryWebpackPluginInstance = findWebpackPlugin(
496+
finalWebpackConfig,
497+
'SentryCliPlugin',
498+
) as SentryWebpackPluginType;
470499

471-
expect(sentryWebpackPlugin.options?.include).toEqual([
500+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
472501
{ paths: ['.next/serverless/'], urlPrefix: '~/city-park/_next/serverless' },
473502
]);
474503
});
@@ -483,9 +512,12 @@ describe('Sentry webpack plugin config', () => {
483512
incomingWebpackBuildContext: serverBuildContextWebpack4,
484513
});
485514

486-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
515+
const sentryWebpackPluginInstance = findWebpackPlugin(
516+
finalWebpackConfig,
517+
'SentryCliPlugin',
518+
) as SentryWebpackPluginType;
487519

488-
expect(sentryWebpackPlugin.options?.include).toEqual([
520+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
489521
{ paths: ['.next/server/pages/'], urlPrefix: '~/city-park/_next/server/pages' },
490522
]);
491523
});
@@ -497,9 +529,12 @@ describe('Sentry webpack plugin config', () => {
497529
incomingWebpackBuildContext: getBuildContext('server', userNextConfigWithBasePath),
498530
});
499531

500-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
532+
const sentryWebpackPluginInstance = findWebpackPlugin(
533+
finalWebpackConfig,
534+
'SentryCliPlugin',
535+
) as SentryWebpackPluginType;
501536

502-
expect(sentryWebpackPlugin.options?.include).toEqual([
537+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
503538
{ paths: ['.next/server/pages/'], urlPrefix: '~/city-park/_next/server/pages' },
504539
{ paths: ['.next/server/chunks/'], urlPrefix: '~/city-park/_next/server/chunks' },
505540
]);

0 commit comments

Comments
 (0)