@@ -26,7 +26,46 @@ let appPort
2626
2727const locales = [ 'en-US' , 'nl-NL' , 'nl-BE' , 'nl' , 'fr-BE' , 'fr' , 'en' ]
2828
29- function runTests ( ) {
29+ function runTests ( isDev ) {
30+ it ( 'should update asPath on the client correctly' , async ( ) => {
31+ for ( const check of [ 'en' , 'En' ] ) {
32+ const browser = await webdriver ( appPort , `/${ check } ` )
33+
34+ expect ( await browser . elementByCss ( 'html' ) . getAttribute ( 'lang' ) ) . toBe ( 'en' )
35+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'en' )
36+ expect (
37+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
38+ ) . toEqual ( locales )
39+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe ( '/' )
40+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe ( '/' )
41+ }
42+ } )
43+
44+ if ( ! isDev ) {
45+ it ( 'should handle fallback correctly after generating' , async ( ) => {
46+ const browser = await webdriver (
47+ appPort ,
48+ '/en/gsp/fallback/hello-fallback'
49+ )
50+
51+ // wait for the fallback to be generated/stored to ISR cache
52+ browser . waitForElementByCss ( '#gsp' )
53+
54+ // now make sure we're serving the previously generated file from the cache
55+ const html = await renderViaHTTP (
56+ appPort ,
57+ '/en/gsp/fallback/hello-fallback'
58+ )
59+ const $ = cheerio . load ( html )
60+
61+ expect ( $ ( '#gsp' ) . text ( ) ) . toBe ( 'gsp page' )
62+ expect ( $ ( '#router-locale' ) . text ( ) ) . toBe ( 'en' )
63+ expect ( JSON . parse ( $ ( '#router-locales' ) . text ( ) ) ) . toEqual ( locales )
64+ expect ( $ ( '#router-pathname' ) . text ( ) ) . toBe ( '/gsp/fallback/[slug]' )
65+ expect ( $ ( '#router-as-path' ) . text ( ) ) . toBe ( '/gsp/fallback/hello-fallback' )
66+ } )
67+ }
68+
3069 it ( 'should use correct default locale for locale domains' , async ( ) => {
3170 const res = await fetchViaHTTP ( appPort , '/' , undefined , {
3271 headers : {
@@ -173,6 +212,15 @@ function runTests() {
173212 expect ( $ ( '#router-as-path' ) . text ( ) ) . toBe ( '/gsp' )
174213 expect ( $ ( '#router-pathname' ) . text ( ) ) . toBe ( '/gsp' )
175214 expect ( JSON . parse ( $ ( '#router-locales' ) . text ( ) ) ) . toEqual ( locales )
215+
216+ // make sure locale is case-insensitive
217+ const html2 = await renderViaHTTP ( appPort , `/${ locale . toUpperCase ( ) } /gsp` )
218+ const $2 = cheerio . load ( html2 )
219+ expect ( $2 ( 'html' ) . attr ( 'lang' ) ) . toBe ( locale )
220+ expect ( $2 ( '#router-locale' ) . text ( ) ) . toBe ( locale )
221+ expect ( $2 ( '#router-as-path' ) . text ( ) ) . toBe ( '/gsp' )
222+ expect ( $2 ( '#router-pathname' ) . text ( ) ) . toBe ( '/gsp' )
223+ expect ( JSON . parse ( $2 ( '#router-locales' ) . text ( ) ) ) . toEqual ( locales )
176224 }
177225 } )
178226
@@ -193,6 +241,21 @@ function runTests() {
193241
194242 expect ( parsedUrl . pathname ) . toBe ( '/' )
195243 expect ( parsedUrl . query ) . toEqual ( { } )
244+
245+ // make sure locale is case-insensitive
246+ const res2 = await fetchViaHTTP ( appPort , '/eN-Us' , undefined , {
247+ redirect : 'manual' ,
248+ headers : {
249+ 'Accept-Language' : 'en-US;q=0.9' ,
250+ } ,
251+ } )
252+
253+ expect ( res2 . status ) . toBe ( 307 )
254+
255+ const parsedUrl2 = url . parse ( res . headers . get ( 'location' ) , true )
256+
257+ expect ( parsedUrl2 . pathname ) . toBe ( '/' )
258+ expect ( parsedUrl2 . query ) . toEqual ( { } )
196259 } )
197260
198261 it ( 'should load getStaticProps page correctly SSR (default locale no prefix)' , async ( ) => {
@@ -391,8 +454,8 @@ function runTests() {
391454 it ( 'should navigate client side for default locale with no prefix' , async ( ) => {
392455 const browser = await webdriver ( appPort , '/' )
393456 // make sure default locale is used in case browser isn't set to
394- // favor en-US by default
395- await browser . manage ( ) . addCookie ( { name : 'NEXT_LOCALE' , value : 'en -US' } )
457+ // favor en-US by default, (we use all caps to ensure it's case-insensitive)
458+ await browser . manage ( ) . addCookie ( { name : 'NEXT_LOCALE' , value : 'EN -US' } )
396459 await browser . get ( browser . initUrl )
397460
398461 const checkIndexValues = async ( ) => {
@@ -705,7 +768,7 @@ describe('i18n Support', () => {
705768 } )
706769 afterAll ( ( ) => killApp ( app ) )
707770
708- runTests ( )
771+ runTests ( true )
709772 } )
710773
711774 describe ( 'production mode' , ( ) => {
0 commit comments