diff options
Diffstat (limited to 'packages/integrations/netlify/test/functions')
7 files changed, 96 insertions, 3 deletions
diff --git a/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/index.astro index ad5d44aa2..852d00b7b 100644 --- a/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/index.astro +++ b/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/index.astro @@ -1,8 +1,8 @@ <html> <head> - <title>Testing</title> + <title>Blog</title> </head> <body> - <h1>testing</h1> +<h1>Blog</h1> </body> </html> diff --git a/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/blog.astro b/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/blog.astro new file mode 100644 index 000000000..248c2218b --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/blog.astro @@ -0,0 +1,8 @@ +<html> +<head> + <title>Testing</title> +</head> +<body> +<h1>testing</h1> +</body> +</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/index.astro new file mode 100644 index 000000000..852d00b7b --- /dev/null +++ b/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/index.astro @@ -0,0 +1,8 @@ +<html> +<head> + <title>Blog</title> +</head> +<body> +<h1>Blog</h1> +</body> +</html> diff --git a/packages/integrations/netlify/test/functions/redirects.test.js b/packages/integrations/netlify/test/functions/redirects.test.js index 1e20d41a0..566b88f4d 100644 --- a/packages/integrations/netlify/test/functions/redirects.test.js +++ b/packages/integrations/netlify/test/functions/redirects.test.js @@ -46,5 +46,6 @@ describe('SSG - Redirects', () => { '/.netlify/functions/entry', '200', ]); + expect(redirects).to.matchSnapshot(); }); }); diff --git a/packages/integrations/netlify/test/functions/redirects.test.js.snap b/packages/integrations/netlify/test/functions/redirects.test.js.snap new file mode 100644 index 000000000..322b4ee85 --- /dev/null +++ b/packages/integrations/netlify/test/functions/redirects.test.js.snap @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SSG - Redirects Creates a redirects file 1`] = ` +"/other / 301 +/nope /.netlify/functions/entry 200 +/ /.netlify/functions/entry 200 +/team/articles/* /.netlify/functions/entry 200" +`; diff --git a/packages/integrations/netlify/test/functions/split-support.test.js b/packages/integrations/netlify/test/functions/split-support.test.js new file mode 100644 index 000000000..217b3c0d3 --- /dev/null +++ b/packages/integrations/netlify/test/functions/split-support.test.js @@ -0,0 +1,63 @@ +import { expect } from 'chai'; +import netlifyAdapter from '../../dist/index.js'; +import { loadFixture, testIntegration } from './test-utils.js'; + +describe('Split support', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + let _entryPoints; + + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/split-support/', import.meta.url).toString(), + output: 'server', + adapter: netlifyAdapter({ + dist: new URL('./fixtures/split-support/dist/', import.meta.url), + }), + site: `http://example.com`, + integrations: [ + testIntegration({ + setEntryPoints(ep) { + _entryPoints = ep; + }, + }), + ], + build: { + split: true, + }, + }); + await fixture.build(); + }); + + it('outputs a correct redirect file', async () => { + const redir = await fixture.readFile('/_redirects'); + const lines = redir.split(/[\r\n]+/); + expect(lines.length).to.equal(2); + + expect(lines[0].includes('/blog')).to.be.true; + expect(lines[0].includes('blog.astro')).to.be.true; + expect(lines[0].includes('200')).to.be.true; + expect(lines[1].includes('/')).to.be.true; + expect(lines[1].includes('index.astro')).to.be.true; + expect(lines[1].includes('200')).to.be.true; + }); + + describe('Should create multiple functions', () => { + it('and hit 200', async () => { + if (_entryPoints) { + for (const [, filePath] of _entryPoints) { + const { handler } = await import(filePath.toString()); + const resp = await handler({ + httpMethod: 'POST', + headers: {}, + rawUrl: 'http://example.com/', + body: '{}', + }); + expect(resp.statusCode).to.equal(200); + } + } else { + expect(false).to.be.true; + } + }); + }); +}); diff --git a/packages/integrations/netlify/test/functions/test-utils.js b/packages/integrations/netlify/test/functions/test-utils.js index 02b5d2ad9..eff6c2782 100644 --- a/packages/integrations/netlify/test/functions/test-utils.js +++ b/packages/integrations/netlify/test/functions/test-utils.js @@ -7,7 +7,7 @@ export * from '../../../../astro/test/test-utils.js'; * * @returns {import('../../../../astro/dist/types/@types/astro').AstroIntegration} */ -export function testIntegration() { +export function testIntegration({ setEntryPoints } = {}) { return { name: '@astrojs/netlify/test-integration', hooks: { @@ -24,6 +24,11 @@ export function testIntegration() { }, }); }, + 'astro:build:ssr': ({ entryPoints }) => { + if (entryPoints.size) { + setEntryPoints(entryPoints); + } + }, }, }; } |