@@ -10,39 +10,74 @@ import {
1010} from './fixtures' ;
1111import { materializeFinalWebpackConfig } from './testUtils' ;
1212
13+ type MatcherResult = { pass : boolean ; message : ( ) => string } ;
14+
15+ expect . extend ( {
16+ stringEndingWith ( received : string , expectedEnding : string ) : MatcherResult {
17+ const failsTest = ! received . endsWith ( expectedEnding ) ;
18+ const generateErrorMessage = ( ) =>
19+ failsTest
20+ ? // Regular error message for match failing
21+ `expected string ending with '${ expectedEnding } ', but got '${ received } '`
22+ : // Error message for the match passing if someone has called it with `expect.not`
23+ `expected string not ending with '${ expectedEnding } ', but got '${ received } '` ;
24+
25+ return {
26+ pass : ! failsTest ,
27+ message : generateErrorMessage ,
28+ } ;
29+ } ,
30+ } ) ;
31+
32+ declare global {
33+ // eslint-disable-next-line @typescript-eslint/no-namespace
34+ namespace jest {
35+ interface Expect {
36+ stringEndingWith : ( expectedEnding : string ) => MatcherResult ;
37+ }
38+ }
39+ }
40+
1341describe ( 'webpack loaders' , ( ) => {
14- it ( 'adds loader to server config' , async ( ) => {
15- const finalWebpackConfig = await materializeFinalWebpackConfig ( {
16- exportedNextConfig,
17- incomingWebpackConfig : serverWebpackConfig ,
18- incomingWebpackBuildContext : serverBuildContext ,
42+ describe ( 'server loaders' , ( ) => {
43+ it ( 'adds server `RewriteFrames` loader to server config' , async ( ) => {
44+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
45+ exportedNextConfig,
46+ incomingWebpackConfig : serverWebpackConfig ,
47+ incomingWebpackBuildContext : serverBuildContext ,
48+ } ) ;
49+
50+ expect ( finalWebpackConfig . module . rules ) . toContainEqual ( {
51+ test : / s e n t r y \. s e r v e r \. c o n f i g \. ( j s x ? | t s x ? ) / ,
52+ use : [
53+ {
54+ loader : expect . stringEndingWith ( 'prefixLoader.js' ) ,
55+ options : expect . objectContaining ( { templatePrefix : 'serverRewriteFrames' } ) ,
56+ } ,
57+ ] ,
58+ } ) ;
1959 } ) ;
60+ } ) ;
61+
62+ describe ( 'client loaders' , ( ) => {
63+ it ( "doesn't add `RewriteFrames` loader to client config" , async ( ) => {
64+ const finalWebpackConfig = await materializeFinalWebpackConfig ( {
65+ exportedNextConfig,
66+ incomingWebpackConfig : clientWebpackConfig ,
67+ incomingWebpackBuildContext : clientBuildContext ,
68+ } ) ;
2069
21- expect ( finalWebpackConfig . module ! . rules ) . toEqual (
22- expect . arrayContaining ( [
23- {
24- test : expect . any ( RegExp ) ,
70+ expect ( finalWebpackConfig . module . rules ) . not . toContainEqual (
71+ expect . objectContaining ( {
2572 use : [
2673 {
27- loader : expect . any ( String ) ,
28- // Having no criteria for what the object contains is better than using `expect.any(Object)`, because that
29- // could be anything
30- options : expect . objectContaining ( { } ) ,
74+ loader : expect . stringEndingWith ( 'prefixLoader.js' ) ,
75+ options : expect . objectContaining ( { templatePrefix : expect . stringContaining ( 'RewriteFrames' ) } ) ,
3176 } ,
3277 ] ,
33- } ,
34- ] ) ,
35- ) ;
36- } ) ;
37-
38- it ( "doesn't add loader to client config" , async ( ) => {
39- const finalWebpackConfig = await materializeFinalWebpackConfig ( {
40- exportedNextConfig,
41- incomingWebpackConfig : clientWebpackConfig ,
42- incomingWebpackBuildContext : clientBuildContext ,
78+ } ) ,
79+ ) ;
4380 } ) ;
44-
45- expect ( finalWebpackConfig . module ) . toBeUndefined ( ) ;
4681 } ) ;
4782} ) ;
4883
0 commit comments