@@ -10,39 +10,74 @@ import {
10
10
} from './fixtures' ;
11
11
import { materializeFinalWebpackConfig } from './testUtils' ;
12
12
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
+
13
41
describe ( '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
+ } ) ;
19
59
} ) ;
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
+ } ) ;
20
69
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 ( {
25
72
use : [
26
73
{
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' ) } ) ,
31
76
} ,
32
77
] ,
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
+ ) ;
43
80
} ) ;
44
-
45
- expect ( finalWebpackConfig . module ) . toBeUndefined ( ) ;
46
81
} ) ;
47
82
} ) ;
48
83
0 commit comments