diff options
Diffstat (limited to 'packages/integrations/netlify/test/functions')
7 files changed, 129 insertions, 0 deletions
diff --git a/packages/integrations/netlify/test/functions/cookies.test.js b/packages/integrations/netlify/test/functions/cookies.test.js new file mode 100644 index 000000000..93cc05229 --- /dev/null +++ b/packages/integrations/netlify/test/functions/cookies.test.js @@ -0,0 +1,42 @@ +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('Cookies', () => { + /** @type {import('../../../astro/test/test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/cookies/', import.meta.url).toString(), + experimental: { + ssr: true, + }, + adapter: netlifyAdapter({ + dist: new URL('./fixtures/cookies/dist/', import.meta.url), + }), + site: `http://example.com`, + integrations: [ testIntegration() ] + }); + await fixture.build(); + }); + + it('Can set multiple', async () => { + const entryURL = new URL('./fixtures/cookies/dist/functions/entry.mjs', import.meta.url); + const { handler } = await import(entryURL); + const resp = await handler({ + httpMethod: 'POST', + headers: {}, + rawUrl: 'http://example.com/login', + body: '{}', + isBase64Encoded: false, + }); + expect(resp.statusCode).to.equal(301); + expect(resp.headers.location).to.equal('/'); + expect(resp.multiValueHeaders).to.be.deep.equal({ + 'set-cookie': ['foo=foo; HttpOnly', 'bar=bar; HttpOnly'], + }); + }); +}); diff --git a/packages/integrations/netlify/test/functions/dynamic-route.test.js b/packages/integrations/netlify/test/functions/dynamic-route.test.js new file mode 100644 index 000000000..279982767 --- /dev/null +++ b/packages/integrations/netlify/test/functions/dynamic-route.test.js @@ -0,0 +1,28 @@ +import { expect } from 'chai'; +import netlifyAdapter from '../../dist/index.js'; +import { loadFixture, testIntegration } from './test-utils.js'; + +describe('Dynamic pages', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/dynamic-route/', import.meta.url).toString(), + experimental: { + ssr: true, + }, + adapter: netlifyAdapter({ + dist: new URL('./fixtures/dynamic-route/dist/', import.meta.url), + }), + site: `http://example.com`, + integrations: [ testIntegration() ] + }); + await fixture.build(); + }); + + it('Dynamic pages are included in the redirects file', async () => { + const redir = await fixture.readFile('/_redirects'); + expect(redir).to.match(/\/products\/\*/); + }); +}); diff --git a/packages/integrations/netlify/test/functions/fixtures/.gitignore b/packages/integrations/netlify/test/functions/fixtures/.gitignore new file mode 100644 index 000000000..916f60644 --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/.gitignore @@ -0,0 +1 @@ +**/netlify diff --git a/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/index.astro new file mode 100644 index 000000000..53e029f04 --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/index.astro @@ -0,0 +1,6 @@ +<html> +<head><title>Testing</title></head> +<body> + <h1>Testing</h1> +</body> +</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/login.js b/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/login.js new file mode 100644 index 000000000..a9ca52f69 --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/login.js @@ -0,0 +1,12 @@ + +export function post() { + const headers = new Headers(); + headers.append('Set-Cookie', `foo=foo; HttpOnly`); + headers.append('Set-Cookie', `bar=bar; HttpOnly`); + headers.append('Location', '/'); + + return new Response('', { + status: 301, + headers, + }); +} diff --git a/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/products/[id].astro b/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/products/[id].astro new file mode 100644 index 000000000..5ed06d251 --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/products/[id].astro @@ -0,0 +1,11 @@ +--- + +--- +<html> +<head> + <title>Testing</title> +</head> +<body> + <h1>Testing</h1> +</body> +</html> diff --git a/packages/integrations/netlify/test/functions/test-utils.js b/packages/integrations/netlify/test/functions/test-utils.js new file mode 100644 index 000000000..19cd7ef66 --- /dev/null +++ b/packages/integrations/netlify/test/functions/test-utils.js @@ -0,0 +1,29 @@ +// @ts-check +import { fileURLToPath } from 'url'; + +export * from '../../../../astro/test/test-utils.js'; + +/** + * + * @returns {import('../../../../astro/dist/types/@types/astro').AstroIntegration} + */ +export function testIntegration() { + return { + name: '@astrojs/netlify/test-integration', + hooks: { + 'astro:config:setup':({ updateConfig }) => { + updateConfig({ + vite: { + resolve: { + alias: { + '@astrojs/netlify/netlify-functions.js': fileURLToPath( + new URL('../../dist/netlify-functions.js', import.meta.url) + ), + }, + }, + }, + }); + } + } + }; +} |