Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jan 22, 2024
1 parent 6bc71ab commit 7375ebf
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions packages/astro/test/i18n-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 7375ebf

Please sign in to comment.