diff options
Diffstat (limited to 'packages/integrations/netlify/test')
50 files changed, 0 insertions, 940 deletions
diff --git a/packages/integrations/netlify/test/functions/404.test.js b/packages/integrations/netlify/test/functions/404.test.js deleted file mode 100644 index f12919a39..000000000 --- a/packages/integrations/netlify/test/functions/404.test.js +++ /dev/null @@ -1,27 +0,0 @@ -import { expect } from 'chai'; -import netlifyAdapter from '../../dist/index.js'; -import { loadFixture, testIntegration } from './test-utils.js'; - -describe('404 page', () => { - /** @type {import('./test-utils').Fixture} */ - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: new URL('./fixtures/404/', import.meta.url).toString(), - output: 'server', - adapter: netlifyAdapter({ - dist: new URL('./fixtures/404/dist/', import.meta.url), - }), - site: `http://example.com`, - integrations: [testIntegration()], - }); - await fixture.build(); - }); - - it('404 route is included in the redirect file', async () => { - const redir = await fixture.readFile('/_redirects'); - const expr = new RegExp('/* /.netlify/functions/entry 404'); - expect(redir).to.match(expr); - }); -}); diff --git a/packages/integrations/netlify/test/functions/base64-response.test.js b/packages/integrations/netlify/test/functions/base64-response.test.js deleted file mode 100644 index 6e59bd192..000000000 --- a/packages/integrations/netlify/test/functions/base64-response.test.js +++ /dev/null @@ -1,62 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture, testIntegration } from './test-utils.js'; -import netlifyAdapter from '../../dist/index.js'; - -describe('Base64 Responses', () => { - /** @type {import('../../../astro/test/test-utils').Fixture} */ - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: new URL('./fixtures/base64-response/', import.meta.url).toString(), - output: 'server', - adapter: netlifyAdapter({ - dist: new URL('./fixtures/base64-response/dist/', import.meta.url), - binaryMediaTypes: ['font/otf'], - }), - site: `http://example.com`, - integrations: [testIntegration()], - }); - await fixture.build(); - }); - - it('Can return base64 encoded strings', async () => { - const entryURL = new URL( - './fixtures/base64-response/.netlify/functions-internal/entry.mjs', - import.meta.url - ); - const { handler } = await import(entryURL); - const resp = await handler({ - httpMethod: 'GET', - headers: {}, - rawUrl: 'http://example.com/image', - body: '{}', - isBase64Encoded: false, - }); - expect(resp.statusCode, 'successful response').to.equal(200); - expect(resp.isBase64Encoded, 'includes isBase64Encoded flag').to.be.true; - - const buffer = Buffer.from(resp.body, 'base64'); - expect(buffer.toString(), 'decoded base64 string matches').to.equal('base64 test string'); - }); - - it('Can define custom binaryMediaTypes', async () => { - const entryURL = new URL( - './fixtures/base64-response/.netlify/functions-internal/entry.mjs', - import.meta.url - ); - const { handler } = await import(entryURL); - const resp = await handler({ - httpMethod: 'GET', - headers: {}, - rawUrl: 'http://example.com/font', - body: '{}', - isBase64Encoded: false, - }); - expect(resp.statusCode, 'successful response').to.equal(200); - expect(resp.isBase64Encoded, 'includes isBase64Encoded flag').to.be.true; - - const buffer = Buffer.from(resp.body, 'base64'); - expect(buffer.toString(), 'decoded base64 string matches').to.equal('base64 test font'); - }); -}); diff --git a/packages/integrations/netlify/test/functions/builders.test.js b/packages/integrations/netlify/test/functions/builders.test.js deleted file mode 100644 index d47af92c0..000000000 --- a/packages/integrations/netlify/test/functions/builders.test.js +++ /dev/null @@ -1,37 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture, testIntegration } from './test-utils.js'; -import netlifyAdapter from '../../dist/index.js'; - -describe('Builders', () => { - /** @type {import('../../../astro/test/test-utils').Fixture} */ - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: new URL('./fixtures/builders/', import.meta.url).toString(), - output: 'server', - adapter: netlifyAdapter({ - dist: new URL('./fixtures/builders/dist/', import.meta.url), - builders: true, - }), - site: `http://example.com`, - integrations: [testIntegration()], - }); - await fixture.build(); - }); - - it('A route can set builders ttl', async () => { - const entryURL = new URL( - './fixtures/builders/.netlify/functions-internal/entry.mjs', - import.meta.url - ); - const { handler } = await import(entryURL); - const resp = await handler({ - httpMethod: 'GET', - headers: {}, - rawUrl: 'http://example.com/', - isBase64Encoded: false, - }); - expect(resp.ttl).to.equal(45); - }); -}); diff --git a/packages/integrations/netlify/test/functions/cookies.test.js b/packages/integrations/netlify/test/functions/cookies.test.js deleted file mode 100644 index f15695235..000000000 --- a/packages/integrations/netlify/test/functions/cookies.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture, testIntegration } from './test-utils.js'; -import netlifyAdapter from '../../dist/index.js'; - -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(), - output: 'server', - 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/.netlify/functions-internal/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 deleted file mode 100644 index 6bb68eab8..000000000 --- a/packages/integrations/netlify/test/functions/dynamic-route.test.js +++ /dev/null @@ -1,33 +0,0 @@ -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(), - output: 'server', - 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\/:id/); - }); - - it('Prerendered routes are also included using placeholder syntax', async () => { - const redir = await fixture.readFile('/_redirects'); - expect(redir).to.include('/pets/:cat /pets/:cat/index.html 200'); - expect(redir).to.include('/pets/:dog /pets/:dog/index.html 200'); - expect(redir).to.include('/pets /.netlify/functions/entry 200'); - }); -}); diff --git a/packages/integrations/netlify/test/functions/edge-middleware.test.js b/packages/integrations/netlify/test/functions/edge-middleware.test.js deleted file mode 100644 index a83720a4d..000000000 --- a/packages/integrations/netlify/test/functions/edge-middleware.test.js +++ /dev/null @@ -1,44 +0,0 @@ -import netlifyAdapter from '../../dist/index.js'; -import { testIntegration, loadFixture } from './test-utils.js'; -import { expect } from 'chai'; - -describe('Middleware', () => { - it('with edge handle file, should successfully build the middleware', async () => { - /** @type {import('./test-utils').Fixture} */ - const fixture = await loadFixture({ - root: new URL('./fixtures/middleware-with-handler-file/', import.meta.url).toString(), - output: 'server', - adapter: netlifyAdapter({ - dist: new URL('./fixtures/middleware-with-handler-file/dist/', import.meta.url), - edgeMiddleware: true, - }), - site: `http://example.com`, - integrations: [testIntegration()], - build: { - excludeMiddleware: true, - }, - }); - await fixture.build(); - const contents = await fixture.readFile('../.netlify/edge-functions/edgeMiddleware.js'); - expect(contents.includes('"Hello world"')).to.be.true; - }); - - it('without edge handle file, should successfully build the middleware', async () => { - /** @type {import('./test-utils').Fixture} */ - const fixture = await loadFixture({ - root: new URL('./fixtures/middleware-without-handler-file/', import.meta.url).toString(), - output: 'server', - adapter: netlifyAdapter({ - dist: new URL('./fixtures/middleware-without-handler-file/dist/', import.meta.url), - }), - site: `http://example.com`, - integrations: [testIntegration()], - build: { - excludeMiddleware: true, - }, - }); - await fixture.build(); - const contents = await fixture.readFile('../.netlify/edge-functions/edgeMiddleware.js'); - expect(contents.includes('"Hello world"')).to.be.false; - }); -}); diff --git a/packages/integrations/netlify/test/functions/fixtures/.gitignore b/packages/integrations/netlify/test/functions/fixtures/.gitignore deleted file mode 100644 index 916f60644..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/.gitignore +++ /dev/null @@ -1 +0,0 @@ -**/netlify diff --git a/packages/integrations/netlify/test/functions/fixtures/404/src/pages/404.astro b/packages/integrations/netlify/test/functions/fixtures/404/src/pages/404.astro deleted file mode 100644 index b60b5e55a..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/404/src/pages/404.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- - ---- -<html> -<head> - <title>Not found</title> -</head> -<body> - <h1>Not found</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/404/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/404/src/pages/index.astro deleted file mode 100644 index 5ed06d251..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/404/src/pages/index.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- - ---- -<html> -<head> - <title>Testing</title> -</head> -<body> - <h1>Testing</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/base64-response/src/pages/font.js b/packages/integrations/netlify/test/functions/fixtures/base64-response/src/pages/font.js deleted file mode 100644 index 3ec4c8364..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/base64-response/src/pages/font.js +++ /dev/null @@ -1,11 +0,0 @@ - -export function get() { - const buffer = Buffer.from('base64 test font', 'utf-8') - - return new Response(buffer, { - status: 200, - headers: { - 'Content-Type': 'font/otf' - } - }); -} diff --git a/packages/integrations/netlify/test/functions/fixtures/base64-response/src/pages/image.js b/packages/integrations/netlify/test/functions/fixtures/base64-response/src/pages/image.js deleted file mode 100644 index ca3b4d9d3..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/base64-response/src/pages/image.js +++ /dev/null @@ -1,11 +0,0 @@ - -export function get() { - const buffer = Buffer.from('base64 test string', 'utf-8') - - return new Response(buffer, { - status: 200, - headers: { - 'content-type': 'image/jpeg;foo=foo' - } - }); -} diff --git a/packages/integrations/netlify/test/functions/fixtures/builders/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/builders/src/pages/index.astro deleted file mode 100644 index ab8853785..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/builders/src/pages/index.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- -Astro.locals.runtime.setBuildersTtl(45) ---- -<html> - <head> - <title>Astro on Netlify</title> - </head> - <body> - <h1>{new Date(Date.now())}</h1> - </body> -</html> 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 deleted file mode 100644 index 53e029f04..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/index.astro +++ /dev/null @@ -1,6 +0,0 @@ -<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 deleted file mode 100644 index a9ca52f69..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/cookies/src/pages/login.js +++ /dev/null @@ -1,12 +0,0 @@ - -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/pets/[cat].astro b/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/[cat].astro deleted file mode 100644 index f86ee6ca9..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/[cat].astro +++ /dev/null @@ -1,27 +0,0 @@ ---- -export const prerender = true - -export function getStaticPaths() { - return [ - { - params: {cat: 'cat1'}, - props: {cat: 'cat1'} - }, - { - params: {cat: 'cat2'}, - props: {cat: 'cat2'} - }, - { - params: {cat: 'cat3'}, - props: {cat: 'cat3'} - }, - ]; -} - -const { cat } = Astro.props; - ---- - -<div>Good cat, {cat}!</div> - -<a href="/">back</a> diff --git a/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/[dog].astro b/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/[dog].astro deleted file mode 100644 index 0f3300f04..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/[dog].astro +++ /dev/null @@ -1,27 +0,0 @@ ---- -export const prerender = true - -export function getStaticPaths() { - return [ - { - params: {dog: 'dog1'}, - props: {dog: 'dog1'} - }, - { - params: {dog: 'dog2'}, - props: {dog: 'dog2'} - }, - { - params: {dog: 'dog3'}, - props: {dog: 'dog3'} - }, - ]; -} - -const { dog } = Astro.props; - ---- - -<div>Good dog, {dog}!</div> - -<a href="/">back</a> diff --git a/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/index.astro b/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/index.astro deleted file mode 100644 index d1423f8ef..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/pets/index.astro +++ /dev/null @@ -1,12 +0,0 @@ -<html lang="en"> - <head> - <meta charset="utf-8" /> - <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> - <meta name="viewport" content="width=device-width" /> - <meta name="generator" content={Astro.generator} /> - <title>Astro</title> - </head> - <body> - <h1>Astro</h1> - </body> -</html> 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 deleted file mode 100644 index 5ed06d251..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/dynamic-route/src/pages/products/[id].astro +++ /dev/null @@ -1,11 +0,0 @@ ---- - ---- -<html> -<head> - <title>Testing</title> -</head> -<body> - <h1>Testing</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/middleware.ts b/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/middleware.ts deleted file mode 100644 index 8cab418c1..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/middleware.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const onRequest = (context, next) => { - context.locals.title = 'Middleware'; - - return next(); -}; diff --git a/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/netlify-edge-middleware.js b/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/netlify-edge-middleware.js deleted file mode 100644 index bf69edb3e..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/netlify-edge-middleware.js +++ /dev/null @@ -1,5 +0,0 @@ -export default function ({ request, context }) { - return { - title: 'Hello world', - }; -} diff --git a/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/pages/index.astro deleted file mode 100644 index d97f70698..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/middleware-with-handler-file/src/pages/index.astro +++ /dev/null @@ -1,12 +0,0 @@ ---- -const title = Astro.locals.title; ---- - -<html> -<head> - <title>{title}</title> -</head> -<body> -<h1>{title}</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/middleware-without-handler-file/src/middleware.ts b/packages/integrations/netlify/test/functions/fixtures/middleware-without-handler-file/src/middleware.ts deleted file mode 100644 index 8cab418c1..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/middleware-without-handler-file/src/middleware.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const onRequest = (context, next) => { - context.locals.title = 'Middleware'; - - return next(); -}; diff --git a/packages/integrations/netlify/test/functions/fixtures/middleware-without-handler-file/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/middleware-without-handler-file/src/pages/index.astro deleted file mode 100644 index d97f70698..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/middleware-without-handler-file/src/pages/index.astro +++ /dev/null @@ -1,12 +0,0 @@ ---- -const title = Astro.locals.title; ---- - -<html> -<head> - <title>{title}</title> -</head> -<body> -<h1>{title}</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/404.astro b/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/404.astro deleted file mode 100644 index ad5d44aa2..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/404.astro +++ /dev/null @@ -1,8 +0,0 @@ -<html> -<head> - <title>Testing</title> -</head> -<body> - <h1>testing</h1> -</body> -</html> 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 deleted file mode 100644 index 852d00b7b..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/index.astro +++ /dev/null @@ -1,8 +0,0 @@ -<html> -<head> - <title>Blog</title> -</head> -<body> -<h1>Blog</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/one.astro b/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/one.astro deleted file mode 100644 index 342e98cfa..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/prerender/src/pages/one.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- -export const prerender = import.meta.env.PRERENDER; ---- -<html> -<head> - <title>Testing</title> -</head> -<body> - <h1>testing</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/index.astro b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/index.astro deleted file mode 100644 index 41f740c4c..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/index.astro +++ /dev/null @@ -1,9 +0,0 @@ ---- -export const prerender = false; ---- -<html> -<head><title>Testing</title></head> -<body> - <h1>Testing</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/nope.astro b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/nope.astro deleted file mode 100644 index f48d767ee..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/nope.astro +++ /dev/null @@ -1,3 +0,0 @@ ---- -return Astro.redirect('/'); ---- diff --git a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/team/articles/[...slug].astro b/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/team/articles/[...slug].astro deleted file mode 100644 index 996cd989e..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/redirects/src/pages/team/articles/[...slug].astro +++ /dev/null @@ -1,27 +0,0 @@ ---- -export const prerender = false; - -export const getStaticPaths = (async () => { - const posts = [ - { slug: 'one', data: {draft: false, title: 'One'} }, - { slug: 'two', data: {draft: false, title: 'Two'} } - ]; - return posts.map((post) => { - return { - params: { slug: post.slug }, - props: { draft: post.data.draft, title: post.data.title }, - }; - }); -}) - -const { slug } = Astro.params; -const { title } = Astro.props; ---- -<html> - <head> - <title>{ title }</title> - </head> - <body> - <h1>{ title }</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 deleted file mode 100644 index 248c2218b..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/blog.astro +++ /dev/null @@ -1,8 +0,0 @@ -<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 deleted file mode 100644 index 852d00b7b..000000000 --- a/packages/integrations/netlify/test/functions/fixtures/split-support/src/pages/index.astro +++ /dev/null @@ -1,8 +0,0 @@ -<html> -<head> - <title>Blog</title> -</head> -<body> -<h1>Blog</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/functions/prerender.test.js b/packages/integrations/netlify/test/functions/prerender.test.js deleted file mode 100644 index 2028e89c3..000000000 --- a/packages/integrations/netlify/test/functions/prerender.test.js +++ /dev/null @@ -1,74 +0,0 @@ -import { expect } from 'chai'; -import netlifyAdapter from '../../dist/index.js'; -import { loadFixture, testIntegration } from './test-utils.js'; - -describe('Mixed Prerendering with SSR', () => { - /** @type {import('./test-utils').Fixture} */ - let fixture; - - before(async () => { - process.env.PRERENDER = true; - fixture = await loadFixture({ - root: new URL('./fixtures/prerender/', import.meta.url).toString(), - output: 'server', - adapter: netlifyAdapter({ - dist: new URL('./fixtures/prerender/dist/', import.meta.url), - }), - site: `http://example.com`, - integrations: [testIntegration()], - }); - await fixture.build(); - }); - - after(() => { - delete process.env.PRERENDER; - }); - - it('Wildcard 404 is sorted last', async () => { - const redir = await fixture.readFile('/_redirects'); - const baseRouteIndex = redir.indexOf('/ /.netlify/functions/entry 200'); - const oneRouteIndex = redir.indexOf('/one /one/index.html 200'); - const fourOhFourWildCardIndex = redir.indexOf('/* /.netlify/functions/entry 404'); - - expect(oneRouteIndex).to.not.be.equal(-1); - expect(fourOhFourWildCardIndex).to.be.greaterThan(baseRouteIndex); - expect(fourOhFourWildCardIndex).to.be.greaterThan(oneRouteIndex); - }); -}); - -describe('Mixed Hybrid rendering with SSR', () => { - /** @type {import('./test-utils').Fixture} */ - let fixture; - - before(async () => { - process.env.PRERENDER = false; - fixture = await loadFixture({ - root: new URL('./fixtures/prerender/', import.meta.url).toString(), - output: 'hybrid', - adapter: netlifyAdapter({ - dist: new URL('./fixtures/prerender/dist/', import.meta.url), - }), - site: `http://example.com`, - integrations: [testIntegration()], - }); - await fixture.build(); - }); - - after(() => { - delete process.env.PRERENDER; - }); - - it('outputs a correct redirect file', async () => { - const redir = await fixture.readFile('/_redirects'); - console.log(redir); - const baseRouteIndex = redir.indexOf('/one /.netlify/functions/entry 200'); - const rootRouteIndex = redir.indexOf('/ /index.html 200'); - const fourOhFourIndex = redir.indexOf('/404 /404.html 200'); - const imageEndpoint = redir.indexOf('/_image /.netlify/functions/entry 200'); - - expect(rootRouteIndex).to.not.be.equal(-1); - expect(baseRouteIndex).to.not.be.equal(-1); - expect(fourOhFourIndex).to.not.be.equal(-1); - expect(imageEndpoint).to.not.be.equal(-1); - }); -}); diff --git a/packages/integrations/netlify/test/functions/redirects.test.js b/packages/integrations/netlify/test/functions/redirects.test.js deleted file mode 100644 index 8e3d46a68..000000000 --- a/packages/integrations/netlify/test/functions/redirects.test.js +++ /dev/null @@ -1,63 +0,0 @@ -import { expect } from 'chai'; -import netlifyAdapter from '../../dist/index.js'; -import { loadFixture, testIntegration } from './test-utils.js'; - -describe('SSG - Redirects', () => { - /** @type {import('../../../astro/test/test-utils').Fixture} */ - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: new URL('../functions/fixtures/redirects/', import.meta.url).toString(), - output: 'hybrid', - adapter: netlifyAdapter({ - dist: new URL('../functions/fixtures/redirects/dist/', import.meta.url), - }), - site: `http://example.com`, - integrations: [testIntegration()], - redirects: { - '/other': '/', - }, - }); - await fixture.build(); - }); - - it('Creates a redirects file', async () => { - let redirects = await fixture.readFile('/_redirects'); - let parts = redirects.split(/\s+/); - console.log(parts); - 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', - - // Image endpoint - '/_image', - '/.netlify/functions/entry', - '200', - - // A real route - '/team/articles/*', - '/.netlify/functions/entry', - '200', - ]); - expect(redirects).to.matchSnapshot(); - }); - - it('Does not create .html files', async () => { - try { - await fixture.readFile('/other/index.html'); - expect(false).to.equal(true, 'this file should not exist'); - } catch { - expect(true).to.equal(true); - } - }); -}); diff --git a/packages/integrations/netlify/test/functions/redirects.test.js.snap b/packages/integrations/netlify/test/functions/redirects.test.js.snap deleted file mode 100644 index 54095f052..000000000 --- a/packages/integrations/netlify/test/functions/redirects.test.js.snap +++ /dev/null @@ -1,9 +0,0 @@ -// 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 -/_image /.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 deleted file mode 100644 index 90427523c..000000000 --- a/packages/integrations/netlify/test/functions/split-support.test.js +++ /dev/null @@ -1,63 +0,0 @@ -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), - functionPerRoute: true, - }), - site: `http://example.com`, - integrations: [ - testIntegration({ - setEntryPoints(ep) { - _entryPoints = ep; - }, - }), - ], - }); - 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(3); - - 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 [routeData, filePath] of _entryPoints) { - if (routeData.route !== '/_image') { - const { handler } = await import(filePath.toString()); - const resp = await handler({ - httpMethod: 'GET', - headers: {}, - rawUrl: `http://example.com${routeData.route}`, - 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 deleted file mode 100644 index bed187962..000000000 --- a/packages/integrations/netlify/test/functions/test-utils.js +++ /dev/null @@ -1,34 +0,0 @@ -// @ts-check -import { fileURLToPath } from 'node:url'; - -export * from '../../../../astro/test/test-utils.js'; - -/** - * - * @returns {import('../../../../astro/dist/types/@types/astro').AstroIntegration} - */ -export function testIntegration({ setEntryPoints } = {}) { - 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) - ), - }, - }, - }, - }); - }, - 'astro:build:ssr': ({ entryPoints }) => { - if (entryPoints.size) { - setEntryPoints(entryPoints); - } - }, - }, - }; -} diff --git a/packages/integrations/netlify/test/hosted/README.md b/packages/integrations/netlify/test/hosted/README.md deleted file mode 100644 index 8c1814844..000000000 --- a/packages/integrations/netlify/test/hosted/README.md +++ /dev/null @@ -1,3 +0,0 @@ -The tests in this folder are done directly on a deployed Netlify website (hosted at https://curious-boba-495d6d.netlify.app) and are not run by the test suite. They instead run every week through a GitHub action. - -The purpose of those tests is to make sure that everything works as expected while deployed. In a way, they're as E2E as it gets. diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs b/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs deleted file mode 100644 index 464c03a6c..000000000 --- a/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import netlify from '@astrojs/netlify'; -import { defineConfig } from 'astro/config'; - -// https://astro.build/config -export default defineConfig({ - output: 'server', - adapter: netlify(), -}); diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/package.json b/packages/integrations/netlify/test/hosted/hosted-astro-project/package.json deleted file mode 100644 index 328f3048d..000000000 --- a/packages/integrations/netlify/test/hosted/hosted-astro-project/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "netlify-hosted-astro-project", - "version": "0.0.0", - "private": true, - "scripts": { - "build": "astro build" - }, - "dependencies": { - "@astrojs/netlify": "workspace:*", - "astro": "workspace:*" - } -} diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/assets/penguin.png b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/assets/penguin.png Binary files differdeleted file mode 100644 index 218acde5b..000000000 --- a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/assets/penguin.png +++ /dev/null diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/env.d.ts b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/env.d.ts deleted file mode 100644 index f7cbe9c1d..000000000 --- a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// <reference types="astro/client-image" /> diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/index.astro b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/index.astro deleted file mode 100644 index 256bfb407..000000000 --- a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/index.astro +++ /dev/null @@ -1,6 +0,0 @@ ---- -import { Image } from 'astro:assets'; -import penguin from '../assets/penguin.png'; ---- - -<Image src={penguin} width={300} alt="" /> diff --git a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/time.astro b/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/time.astro deleted file mode 100644 index 873b5c720..000000000 --- a/packages/integrations/netlify/test/hosted/hosted-astro-project/src/pages/time.astro +++ /dev/null @@ -1,5 +0,0 @@ ---- -const currentTime = new Date().getTime(); ---- - -{currentTime} diff --git a/packages/integrations/netlify/test/hosted/hosted.test.js b/packages/integrations/netlify/test/hosted/hosted.test.js deleted file mode 100644 index 2dc8c67ce..000000000 --- a/packages/integrations/netlify/test/hosted/hosted.test.js +++ /dev/null @@ -1,21 +0,0 @@ -import { expect } from 'chai'; - -const NETLIFY_TEST_URL = 'https://curious-boba-495d6d.netlify.app'; - -describe('Hosted Netlify Tests', () => { - it('Image endpoint works', async () => { - const image = await fetch( - NETLIFY_TEST_URL + '/_image?href=%2F_astro%2Fpenguin.e9c64733.png&w=300&f=webp' - ); - - expect(image.status).to.equal(200); - }); - - it('Server returns fresh content', async () => { - const responseOne = await fetch(NETLIFY_TEST_URL + '/time'); - - const responseTwo = await fetch(NETLIFY_TEST_URL + '/time'); - - expect(responseOne.body).to.not.equal(responseTwo.body); - }); -}); diff --git a/packages/integrations/netlify/test/setup.js b/packages/integrations/netlify/test/setup.js deleted file mode 100644 index c53aa9894..000000000 --- a/packages/integrations/netlify/test/setup.js +++ /dev/null @@ -1,12 +0,0 @@ -import { use } from 'chai'; -import chaiJestSnapshot from 'chai-jest-snapshot'; - -use(chaiJestSnapshot); - -before(function () { - chaiJestSnapshot.resetSnapshotRegistry(); -}); - -beforeEach(function () { - chaiJestSnapshot.configureUsingMochaContext(this); -}); diff --git a/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/index.astro b/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/index.astro deleted file mode 100644 index 53e029f04..000000000 --- a/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/index.astro +++ /dev/null @@ -1,6 +0,0 @@ -<html> -<head><title>Testing</title></head> -<body> - <h1>Testing</h1> -</body> -</html> diff --git a/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/nope.astro b/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/nope.astro deleted file mode 100644 index f48d767ee..000000000 --- a/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/nope.astro +++ /dev/null @@ -1,3 +0,0 @@ ---- -return Astro.redirect('/'); ---- diff --git a/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/team/articles/[...slug].astro b/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/team/articles/[...slug].astro deleted file mode 100644 index 716d3bd5d..000000000 --- a/packages/integrations/netlify/test/static/fixtures/redirects/src/pages/team/articles/[...slug].astro +++ /dev/null @@ -1,25 +0,0 @@ ---- -export const getStaticPaths = (async () => { - const posts = [ - { slug: 'one', data: {draft: false, title: 'One'} }, - { slug: 'two', data: {draft: false, title: 'Two'} } - ]; - return posts.map((post) => { - return { - params: { slug: post.slug }, - props: { draft: post.data.draft, title: post.data.title }, - }; - }); -}) - -const { slug } = Astro.params; -const { title } = Astro.props; ---- -<html> - <head> - <title>{ title }</title> - </head> - <body> - <h1>{ title }</h1> - </body> -</html> diff --git a/packages/integrations/netlify/test/static/redirects.test.js b/packages/integrations/netlify/test/static/redirects.test.js deleted file mode 100644 index ae3ff1eb8..000000000 --- a/packages/integrations/netlify/test/static/redirects.test.js +++ /dev/null @@ -1,50 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture, testIntegration } from './test-utils.js'; -import { netlifyStatic } from '../../dist/index.js'; - -describe('SSG - Redirects', () => { - /** @type {import('../../../astro/test/test-utils').Fixture} */ - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: new URL('./fixtures/redirects/', import.meta.url).toString(), - output: 'static', - adapter: netlifyStatic(), - site: `http://example.com`, - integrations: [testIntegration()], - redirects: { - '/other': '/', - '/two': { - status: 302, - destination: '/', - }, - '/blog/[...slug]': '/team/articles/[...slug]', - }, - }); - 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([ - '/two', - '/', - '302', - '/other', - '/', - '301', - '/nope', - '/', - '301', - - '/blog/*', - '/team/articles/*/index.html', - '301', - '/team/articles/*', - '/team/articles/*/index.html', - '200', - ]); - }); -}); diff --git a/packages/integrations/netlify/test/static/test-utils.js b/packages/integrations/netlify/test/static/test-utils.js deleted file mode 100644 index f57abab1d..000000000 --- a/packages/integrations/netlify/test/static/test-utils.js +++ /dev/null @@ -1,29 +0,0 @@ -// @ts-check -import { fileURLToPath } from 'node: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) - ), - }, - }, - }, - }); - }, - }, - }; -} |