@@ -19,7 +19,7 @@ const context = {}
19
19
context . appDir = join ( __dirname , '../' )
20
20
21
21
const middlewareWarning = 'using beta Middleware (not covered by semver)'
22
- const urlsWarning = 'using relative URLs for Middleware will be deprecated soon '
22
+ const urlsError = 'Please use only absolute URLs '
23
23
24
24
describe ( 'Middleware base tests' , ( ) => {
25
25
describe ( 'dev mode' , ( ) => {
@@ -110,7 +110,7 @@ describe('Middleware base tests', () => {
110
110
} )
111
111
} )
112
112
113
- function urlTests ( log , locale = '' ) {
113
+ function urlTests ( _log , locale = '' ) {
114
114
it ( 'rewrites by default to a target location' , async ( ) => {
115
115
const res = await fetchViaHTTP ( context . appPort , `${ locale } /urls` )
116
116
const html = await res . text ( )
@@ -146,18 +146,39 @@ function urlTests(log, locale = '') {
146
146
} )
147
147
148
148
it ( 'warns when using Response.redirect with a relative URL' , async ( ) => {
149
- await fetchViaHTTP ( context . appPort , `${ locale } /urls/relative-redirect` )
150
- expect ( log . output ) . toContain ( urlsWarning )
149
+ const response = await fetchViaHTTP (
150
+ context . appPort ,
151
+ `${ locale } /urls/relative-redirect`
152
+ )
153
+ expect ( await response . json ( ) ) . toEqual ( {
154
+ error : {
155
+ message : expect . stringContaining ( urlsError ) ,
156
+ } ,
157
+ } )
151
158
} )
152
159
153
160
it ( 'warns when using NextResponse.redirect with a relative URL' , async ( ) => {
154
- await fetchViaHTTP ( context . appPort , `${ locale } /urls/relative-next-redirect` )
155
- expect ( log . output ) . toContain ( urlsWarning )
161
+ const response = await fetchViaHTTP (
162
+ context . appPort ,
163
+ `${ locale } /urls/relative-next-redirect`
164
+ )
165
+ expect ( await response . json ( ) ) . toEqual ( {
166
+ error : {
167
+ message : expect . stringContaining ( urlsError ) ,
168
+ } ,
169
+ } )
156
170
} )
157
171
158
- it ( 'warns when using NextResponse.rewrite with a relative URL' , async ( ) => {
159
- await fetchViaHTTP ( context . appPort , `${ locale } /urls/relative-next-rewrite` )
160
- expect ( log . output ) . toContain ( urlsWarning )
172
+ it ( 'throws when using NextResponse.rewrite with a relative URL' , async ( ) => {
173
+ const response = await fetchViaHTTP (
174
+ context . appPort ,
175
+ `${ locale } /urls/relative-next-rewrite`
176
+ )
177
+ expect ( await response . json ( ) ) . toEqual ( {
178
+ error : {
179
+ message : expect . stringContaining ( urlsError ) ,
180
+ } ,
181
+ } )
161
182
} )
162
183
}
163
184
0 commit comments