@@ -118,6 +118,24 @@ const expectedManifestRoutes = () => [
118118 ) ,
119119 page : '/non-json' ,
120120 } ,
121+ {
122+ dataRouteRegex : `^\\/_next\\/data\\/${ escapeRegex (
123+ buildId
124+ ) } \\/not-found.json$`,
125+ page : '/not-found' ,
126+ } ,
127+ {
128+ dataRouteRegex : `^\\/_next\\/data\\/${ escapeRegex (
129+ buildId
130+ ) } \\/not\\-found\\/([^\\/]+?)\\.json$`,
131+ namedDataRouteRegex : `^/_next/data/${ escapeRegex (
132+ buildId
133+ ) } /not\\-found/(?<slug>[^/]+?)\\.json$`,
134+ page : '/not-found/[slug]' ,
135+ routeKeys : {
136+ slug : 'slug' ,
137+ } ,
138+ } ,
121139 {
122140 dataRouteRegex : normalizeRegEx (
123141 `^\\/_next\\/data\\/${ escapeRegex ( buildId ) } \\/refresh.json$`
@@ -235,6 +253,50 @@ const navigateTest = (dev = false) => {
235253const runTests = ( dev = false ) => {
236254 navigateTest ( dev )
237255
256+ it ( 'should render 404 correctly when notFound is returned (non-dynamic)' , async ( ) => {
257+ const res = await fetchViaHTTP ( appPort , '/not-found' , { hiding : true } )
258+
259+ expect ( res . status ) . toBe ( 404 )
260+ expect ( await res . text ( ) ) . toContain ( 'This page could not be found' )
261+ } )
262+
263+ it ( 'should render 404 correctly when notFound is returned client-transition (non-dynamic)' , async ( ) => {
264+ const browser = await webdriver ( appPort , '/' )
265+ await browser . eval ( `(function() {
266+ window.beforeNav = 1
267+ window.next.router.push('/not-found?hiding=true')
268+ })()` )
269+
270+ await browser . waitForElementByCss ( 'h1' )
271+ expect ( await browser . elementByCss ( 'html' ) . text ( ) ) . toContain (
272+ 'This page could not be found'
273+ )
274+ expect ( await browser . eval ( 'window.beforeNav' ) ) . toBe ( null )
275+ } )
276+
277+ it ( 'should render 404 correctly when notFound is returned (dynamic)' , async ( ) => {
278+ const res = await fetchViaHTTP ( appPort , '/not-found/first' , {
279+ hiding : true ,
280+ } )
281+
282+ expect ( res . status ) . toBe ( 404 )
283+ expect ( await res . text ( ) ) . toContain ( 'This page could not be found' )
284+ } )
285+
286+ it ( 'should render 404 correctly when notFound is returned client-transition (dynamic)' , async ( ) => {
287+ const browser = await webdriver ( appPort , '/' )
288+ await browser . eval ( `(function() {
289+ window.beforeNav = 1
290+ window.next.router.push('/not-found/first?hiding=true')
291+ })()` )
292+
293+ await browser . waitForElementByCss ( 'h1' )
294+ expect ( await browser . elementByCss ( 'html' ) . text ( ) ) . toContain (
295+ 'This page could not be found'
296+ )
297+ expect ( await browser . eval ( 'window.beforeNav' ) ) . toBe ( null )
298+ } )
299+
238300 it ( 'should SSR normal page correctly' , async ( ) => {
239301 const html = await renderViaHTTP ( appPort , '/' )
240302 expect ( html ) . toMatch ( / h e l l o .* ?w o r l d / )
0 commit comments