summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/test/functions
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/netlify/test/functions')
-rw-r--r--packages/integrations/netlify/test/functions/redirects.test.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/integrations/netlify/test/functions/redirects.test.js b/packages/integrations/netlify/test/functions/redirects.test.js
new file mode 100644
index 000000000..8a6d36694
--- /dev/null
+++ b/packages/integrations/netlify/test/functions/redirects.test.js
@@ -0,0 +1,44 @@
+import { expect } from 'chai';
+import { load as cheerioLoad } from 'cheerio';
+import { loadFixture, testIntegration } from './test-utils.js';
+import netlifyAdapter from '../../dist/index.js';
+import { fileURLToPath } from 'url';
+
+describe('SSG - Redirects', () => {
+ /** @type {import('../../../astro/test/test-utils').Fixture} */
+ let fixture;
+
+ before(async () => {
+ fixture = await loadFixture({
+ root: new URL('../static/fixtures/redirects/', import.meta.url).toString(),
+ output: 'server',
+ adapter: netlifyAdapter({
+ dist: new URL('../static/fixtures/redirects/dist/', import.meta.url),
+ }),
+ site: `http://example.com`,
+ integrations: [testIntegration()],
+ redirects: {
+ '/other': '/'
+ },
+ experimental: {
+ redirects: true,
+ },
+ });
+ await fixture.build();
+ });
+
+ it('Creates a redirects file', async () => {
+ let redirects = await fixture.readFile('/_redirects');
+ let parts = redirects.split(/\s+/);
+ expect(parts).to.deep.equal([
+ '/other', '/', '301',
+ // This uses the dynamic Astro.redirect, so we don't know that it's a redirect
+ // until runtime. This is correct!
+ '/nope', '/.netlify/functions/entry', '200',
+ '/', '/.netlify/functions/entry', '200',
+
+ // A real route
+ '/team/articles/*', '/.netlify/functions/entry', '200',
+ ]);
+ });
+});