@@ -52,11 +52,13 @@ function runTests(isDev) {
5252 http : true ,
5353 domain : 'example.be' ,
5454 defaultLocale : 'nl-BE' ,
55+ locales : [ 'nl' , 'nl-NL' , 'nl-BE' ] ,
5556 } ,
5657 {
5758 http : true ,
5859 domain : 'example.fr' ,
5960 defaultLocale : 'fr' ,
61+ locales : [ 'fr' , 'fr-BE' ] ,
6062 } ,
6163 ] ,
6264 } )
@@ -661,12 +663,17 @@ function runTests(isDev) {
661663 } )
662664
663665 it ( 'should handle locales with domain' , async ( ) => {
664- const checkDomainLocales = async ( domainDefault = '' , domain = '' ) => {
666+ const checkDomainLocales = async (
667+ domainDefault = '' ,
668+ domainLocales = [ ] ,
669+ domain = ''
670+ ) => {
665671 for ( const locale of locales ) {
666- // skip other domains' default locale since we redirect these
667- if ( [ 'fr' , 'nl-BE' ] . includes ( locale ) && locale !== domainDefault ) {
668- continue
669- }
672+ // other domains' default locale is redirected
673+ const isRedirected =
674+ [ 'fr' , 'nl-BE' ] . includes ( locale ) && locale !== domainDefault
675+
676+ if ( isRedirected ) continue
670677
671678 const res = await fetchViaHTTP (
672679 appPort ,
@@ -680,19 +687,28 @@ function runTests(isDev) {
680687 }
681688 )
682689
683- expect ( res . status ) . toBe ( 200 )
690+ const isDomain404 = ! domainLocales . includes ( locale )
691+
692+ expect ( res . status ) . toBe ( isDomain404 ? 404 : 200 )
684693
685- const html = await res . text ( )
686- const $ = cheerio . load ( html )
694+ if ( ! isRedirected ) {
695+ const html = await res . text ( )
696+ const $ = cheerio . load ( html )
687697
688- expect ( $ ( 'html' ) . attr ( 'lang' ) ) . toBe ( locale )
689- expect ( $ ( '#router-locale' ) . text ( ) ) . toBe ( locale )
690- expect ( JSON . parse ( $ ( '#router-locales' ) . text ( ) ) ) . toEqual ( locales )
698+ expect ( $ ( 'html' ) . attr ( 'lang' ) ) . toBe (
699+ isDomain404 ? domainDefault : locale
700+ )
701+
702+ if ( ! isDomain404 ) {
703+ expect ( $ ( '#router-locale' ) . text ( ) ) . toBe ( locale )
704+ expect ( JSON . parse ( $ ( '#router-locales' ) . text ( ) ) ) . toEqual ( locales )
705+ }
706+ }
691707 }
692708 }
693709
694- await checkDomainLocales ( 'nl-BE' , 'example.be' )
695- await checkDomainLocales ( 'fr' , 'example.fr' )
710+ await checkDomainLocales ( 'nl-BE' , [ 'nl' , 'nl-NL' , 'nl-BE' ] , 'example.be' )
711+ await checkDomainLocales ( 'fr' , [ 'fr' , 'fr-BE' ] , 'example.fr' )
696712 } )
697713
698714 it ( 'should generate AMP pages with all locales' , async ( ) => {
0 commit comments