Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilnasy committed Sep 24, 2023
1 parent 811882c commit f3986df
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
export function getStaticPaths() {
return [{ params: { dynamic:'hello' } }]
}
---
{JSON.stringify(Astro.params)}

<a href="/">home</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
export function getStaticPaths() {
return [{ params: { dynamic:'hello', route:'world' } }]
}
---
{JSON.stringify(Astro.params)}

<a href="/">home</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
export function getStaticPaths() {
return [{ params: {spread:'welcome/world'} }]
}
---
{JSON.stringify(Astro.params)}

<a href="/">home</a>
30 changes: 29 additions & 1 deletion packages/astro/test/redirects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ describe('Astro.redirect', () => {
status: 302,
destination: '/test',
},
'/more/old/[dynamic]': '/more/[dynamic]',
'/more/old/[dynamic]/[route]': '/more/[dynamic]/[route]',
'/more/old/[...spread]': '/more/new/[...spread]',
},
});
await fixture.build();
Expand Down Expand Up @@ -149,6 +152,12 @@ describe('Astro.redirect', () => {
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/test');
});

it('falls back to spread rule when dynamic rules should not match', async () => {
const html = await fixture.readFile('/more/old/welcome/world/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/more/new/welcome/world');
});
});

describe('dev', () => {
Expand All @@ -161,6 +170,9 @@ describe('Astro.redirect', () => {
output: 'static',
redirects: {
'/one': '/',
'/more/old/[dynamic]': '/more/[dynamic]',
'/more/old/[dynamic]/[route]': '/more/[dynamic]/[route]',
'/more/old/[...spread]': '/more/new/[...spread]',
},
});
devServer = await fixture.startDevServer();
Expand All @@ -170,11 +182,27 @@ describe('Astro.redirect', () => {
await devServer.stop();
});

it('Returns 301', async () => {
it('performs simple redirects', async () => {
let res = await fixture.fetch('/one', {
redirect: 'manual',
});
expect(res.status).to.equal(301);
expect(res.headers.get('Location')).to.equal('/');
});

it('performs dynamic redirects', async () => {
const response = await fixture.fetch('/more/old/hello', { redirect: 'manual' });
expect(response.headers.get('Location')).to.equal('/more/hello');
});

it('performs dynamic redirects with multiple params', async () => {
const response = await fixture.fetch('/more/old/hello/world', { redirect: 'manual' });
expect(response.headers.get('Location')).to.equal('/more/hello/world');
});

it.skip('falls back to spread rule when dynamic rules should not match', async () => {
const response = await fixture.fetch('/more/old/welcome/world', { redirect: 'manual' });
expect(response.headers.get('Location')).to.equal('/more/new/welcome/world');
});
});
});
Expand Down

0 comments on commit f3986df

Please sign in to comment.