From 7375ebfbf26e9fa3f4463f82cc7583e1245fd887 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 22 Jan 2024 12:06:11 +0000 Subject: [PATCH] add more tests --- packages/astro/test/i18n-routing.test.js | 79 ++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.test.js index 08dfcb7702f7..6cc445c1ceea 100644 --- a/packages/astro/test/i18n-routing.test.js +++ b/packages/astro/test/i18n-routing.test.js @@ -229,6 +229,44 @@ describe('[DEV] i18n routing', () => { const response = await fixture.fetch('/new-site/fr/start'); expect(response.status).to.equal(404); }); + + describe('when `build.format` is `directory`', () => { + before(async () => { + fixture = await loadFixture({ + root: './fixtures/i18n-routing-prefix-other-locales/', + i18n: { + defaultLocale: 'en', + locales: [ + 'en', + 'pt', + 'it', + { + path: 'spanish', + codes: ['es', 'es-AR'], + }, + ], + fallback: { + it: 'en', + spanish: 'en', + }, + }, + build: { + format: 'directory', + }, + }); + devServer = await fixture.startDevServer(); + }); + + after(async () => { + await devServer.stop(); + }); + + it('should redirect to the english locale with trailing slash', async () => { + const response = await fixture.fetch('/new-site/it/start/'); + expect(response.status).to.equal(200); + expect(await response.text()).includes('Start'); + }); + }); }); describe('i18n routing with routing strategy [pathname-prefix-always-no-redirect]', () => { @@ -745,6 +783,25 @@ describe('[SSG] i18n routing', () => { expect(html).to.include('url=/new-site/en'); }); }); + + describe('when `build.format` is `directory`', () => { + before(async () => { + fixture = await loadFixture({ + root: './fixtures/i18n-routing-prefix-always/', + build: { + format: 'directory', + }, + }); + await fixture.build(); + }); + + it('should redirect to the index of the default locale', async () => { + const html = await fixture.readFile('/index.html'); + expect(html).to.include('http-equiv="refresh'); + expect(html).to.include('http-equiv="refresh'); + expect(html).to.include('url=/new-site/en/'); + }); + }); }); describe('i18n routing with fallback', () => { @@ -1174,6 +1231,28 @@ describe('[SSR] i18n routing', () => { expect(response.headers.get('location')).to.equal('/new-site/en/'); }); }); + + describe('when `build.format` is `directory`', () => { + before(async () => { + fixture = await loadFixture({ + root: './fixtures/i18n-routing-prefix-always/', + output: 'server', + adapter: testAdapter(), + build: { + format: 'directory', + }, + }); + await fixture.build(); + app = await fixture.loadTestAdapterApp(); + }); + + it('should redirect to the index of the default locale', async () => { + let request = new Request('http://example.com/new-site/'); + let response = await app.render(request); + expect(response.status).to.equal(302); + expect(response.headers.get('location')).to.equal('/new-site/en/'); + }); + }); }); describe('with fallback', () => {