summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/netlify/test')
-rw-r--r--packages/integrations/netlify/test/functions/404.test.js32
-rw-r--r--packages/integrations/netlify/test/functions/base64-response.test.js93
-rw-r--r--packages/integrations/netlify/test/functions/builders.test.js44
-rw-r--r--packages/integrations/netlify/test/functions/cookies.test.js54
-rw-r--r--packages/integrations/netlify/test/functions/dynamic-route.test.js50
-rw-r--r--packages/integrations/netlify/test/functions/edge-middleware.test.js46
-rw-r--r--packages/integrations/netlify/test/functions/prerender.test.js120
-rw-r--r--packages/integrations/netlify/test/functions/redirects.test.js92
-rw-r--r--packages/integrations/netlify/test/functions/test-utils.js50
-rw-r--r--packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs8
-rw-r--r--packages/integrations/netlify/test/hosted/hosted.test.js29
-rw-r--r--packages/integrations/netlify/test/setup.js8
-rw-r--r--packages/integrations/netlify/test/static/redirects.test.js90
-rw-r--r--packages/integrations/netlify/test/static/test-utils.js40
-rw-r--r--packages/integrations/netlify/test/test-utils.js14
15 files changed, 413 insertions, 357 deletions
diff --git a/packages/integrations/netlify/test/functions/404.test.js b/packages/integrations/netlify/test/functions/404.test.js
index 1782507db..a1f792ce0 100644
--- a/packages/integrations/netlify/test/functions/404.test.js
+++ b/packages/integrations/netlify/test/functions/404.test.js
@@ -1,19 +1,21 @@
-import { expect } from 'chai';
-import fs from 'fs/promises';
-import { cli } from './test-utils.js';
-import { fileURLToPath } from 'url';
+import { expect } from "chai";
+import fs from "fs/promises";
+import { cli } from "./test-utils.js";
+import { fileURLToPath } from "url";
-const root = new URL('./fixtures/404/', import.meta.url).toString();
+const root = new URL("./fixtures/404/", import.meta.url).toString();
-describe('404 page', () => {
+describe("404 page", () => {
+ before(async () => {
+ await cli("build", "--root", fileURLToPath(root));
+ });
- before(async () => {
- await cli('build', '--root', fileURLToPath(root));
- });
-
- it('404 route is included in the redirect file', async () => {
- const redir = await fs.readFile(new URL('./dist/_redirects', root), 'utf-8');
- const expr = new RegExp('/* /.netlify/functions/entry 404');
- expect(redir).to.match(expr);
- });
+ it("404 route is included in the redirect file", async () => {
+ const redir = await fs.readFile(
+ new URL("./dist/_redirects", root),
+ "utf-8",
+ );
+ 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
index 520eaf646..07c1bbafe 100644
--- a/packages/integrations/netlify/test/functions/base64-response.test.js
+++ b/packages/integrations/netlify/test/functions/base64-response.test.js
@@ -1,52 +1,55 @@
-import { expect } from 'chai';
-import { cli } from './test-utils.js';
-import { fileURLToPath } from 'url';
+import { expect } from "chai";
+import { cli } from "./test-utils.js";
+import { fileURLToPath } from "url";
-const root = new URL('./fixtures/base64-response/', import.meta.url).toString();
+const root = new URL("./fixtures/base64-response/", import.meta.url).toString();
-describe('Base64 Responses', () => {
+describe("Base64 Responses", () => {
+ before(async () => {
+ await cli("build", "--root", fileURLToPath(root));
+ });
- before(async () => {
- await cli('build', '--root', fileURLToPath(root));
- });
+ 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;
- 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",
+ );
+ });
- 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;
- 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');
- });
+ 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
index e927527a1..281c4f3da 100644
--- a/packages/integrations/netlify/test/functions/builders.test.js
+++ b/packages/integrations/netlify/test/functions/builders.test.js
@@ -1,26 +1,26 @@
-import { expect } from 'chai';
-import { cli } from './test-utils.js';
-import { fileURLToPath } from 'url';
+import { expect } from "chai";
+import { cli } from "./test-utils.js";
+import { fileURLToPath } from "url";
-const root = new URL('./fixtures/builders/', import.meta.url).toString();
+const root = new URL("./fixtures/builders/", import.meta.url).toString();
-describe('Builders', () => {
- before(async () => {
- await cli('build', '--root', fileURLToPath(root));
- });
+describe("Builders", () => {
+ before(async () => {
+ await cli("build", "--root", fileURLToPath(root));
+ });
- 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);
- });
+ 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
index 328294d10..05727207e 100644
--- a/packages/integrations/netlify/test/functions/cookies.test.js
+++ b/packages/integrations/netlify/test/functions/cookies.test.js
@@ -1,31 +1,31 @@
-import { expect } from 'chai';
-import { cli } from './test-utils.js';
-import { fileURLToPath } from 'url';
+import { expect } from "chai";
+import { cli } from "./test-utils.js";
+import { fileURLToPath } from "url";
-const root = new URL('./fixtures/cookies/', import.meta.url).toString();
+const root = new URL("./fixtures/cookies/", import.meta.url).toString();
-describe('Cookies', () => {
- before(async () => {
- await cli('build', '--root', fileURLToPath(root));
- });
+describe("Cookies", () => {
+ before(async () => {
+ await cli("build", "--root", fileURLToPath(root));
+ });
- 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'],
- });
- });
+ 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
index 2e20454e6..69d25a11e 100644
--- a/packages/integrations/netlify/test/functions/dynamic-route.test.js
+++ b/packages/integrations/netlify/test/functions/dynamic-route.test.js
@@ -1,24 +1,36 @@
-import { expect } from 'chai';
-import { cli } from './test-utils.js';
-import { fileURLToPath } from 'url';
-import fs from 'fs/promises';
+import { expect } from "chai";
+import { cli } from "./test-utils.js";
+import { fileURLToPath } from "url";
+import fs from "fs/promises";
-const root = new URL('./fixtures/dynamic-route/', import.meta.url).toString();
+const root = new URL("./fixtures/dynamic-route/", import.meta.url).toString();
-describe('Dynamic pages', () => {
- before(async () => {
- await cli('build', '--root', fileURLToPath(root));
- });
+describe("Dynamic pages", () => {
+ before(async () => {
+ await cli("build", "--root", fileURLToPath(root));
+ });
- it('Dynamic pages are included in the redirects file', async () => {
- const redir = await fs.readFile(new URL('./dist/_redirects', root), 'utf-8');
- expect(redir).to.match(/\/products\/:id/);
- });
+ it("Dynamic pages are included in the redirects file", async () => {
+ const redir = await fs.readFile(
+ new URL("./dist/_redirects", root),
+ "utf-8",
+ );
+ expect(redir).to.match(/\/products\/:id/);
+ });
- it('Prerendered routes are also included using placeholder syntax', async () => {
- const redir = await fs.readFile(new URL('./dist/_redirects', root), 'utf-8');
- 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');
- });
+ it("Prerendered routes are also included using placeholder syntax", async () => {
+ const redir = await fs.readFile(
+ new URL("./dist/_redirects", root),
+ "utf-8",
+ );
+ 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
index 7e51b20da..90bcd69c7 100644
--- a/packages/integrations/netlify/test/functions/edge-middleware.test.js
+++ b/packages/integrations/netlify/test/functions/edge-middleware.test.js
@@ -1,20 +1,32 @@
-import { fileURLToPath } from 'url';
-import { cli } from './test-utils.js';
-import fs from 'fs/promises';
-import { expect } from 'chai';
+import { fileURLToPath } from "url";
+import { cli } from "./test-utils.js";
+import fs from "fs/promises";
+import { expect } from "chai";
-describe('Middleware', () => {
- it('with edge handle file, should successfully build the middleware', async () => {
- const root = new URL('./fixtures/middleware-with-handler-file/', import.meta.url).toString();
- await cli('build', '--root', fileURLToPath(root));
- const contents = await fs.readFile(new URL('./.netlify/edge-functions/edgeMiddleware.js', root), 'utf-8');
- expect(contents.includes('"Hello world"')).to.be.true;
- });
+describe("Middleware", () => {
+ it("with edge handle file, should successfully build the middleware", async () => {
+ const root = new URL(
+ "./fixtures/middleware-with-handler-file/",
+ import.meta.url,
+ ).toString();
+ await cli("build", "--root", fileURLToPath(root));
+ const contents = await fs.readFile(
+ new URL("./.netlify/edge-functions/edgeMiddleware.js", root),
+ "utf-8",
+ );
+ expect(contents.includes('"Hello world"')).to.be.true;
+ });
- it('without edge handle file, should successfully build the middleware', async () => {
- const root = new URL('./fixtures/middleware-without-handler-file/', import.meta.url).toString();
- await cli('build', '--root', fileURLToPath(root));
- const contents = await fs.readFile(new URL('./.netlify/edge-functions/edgeMiddleware.js', root), 'utf-8');
- expect(contents.includes('"Hello world"')).to.be.false;
- });
+ it("without edge handle file, should successfully build the middleware", async () => {
+ const root = new URL(
+ "./fixtures/middleware-without-handler-file/",
+ import.meta.url,
+ ).toString();
+ await cli("build", "--root", fileURLToPath(root));
+ const contents = await fs.readFile(
+ new URL("./.netlify/edge-functions/edgeMiddleware.js", root),
+ "utf-8",
+ );
+ expect(contents.includes('"Hello world"')).to.be.false;
+ });
});
diff --git a/packages/integrations/netlify/test/functions/prerender.test.js b/packages/integrations/netlify/test/functions/prerender.test.js
index 8acc5a519..61af252cb 100644
--- a/packages/integrations/netlify/test/functions/prerender.test.js
+++ b/packages/integrations/netlify/test/functions/prerender.test.js
@@ -1,53 +1,73 @@
-import { expect } from 'chai';
-import fs from 'fs/promises';
-import { cli } from './test-utils.js';
-import { fileURLToPath } from 'url';
-
-const root = new URL('./fixtures/prerender/', import.meta.url).toString();
-
-describe('Mixed Prerendering with SSR', () => {
- before(async () => {
- process.env.PRERENDER = true;
- await cli('build', '--root', fileURLToPath(root));
- });
-
- after(() => {
- delete process.env.PRERENDER;
- });
-
- it('Wildcard 404 is sorted last', async () => {
- const redir = await fs.readFile(new URL('./dist/_redirects', root), 'utf-8');
- 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);
- });
+import { expect } from "chai";
+import fs from "fs/promises";
+import { cli } from "./test-utils.js";
+import { fileURLToPath } from "url";
+
+const root = new URL("./fixtures/prerender/", import.meta.url).toString();
+
+describe("Mixed Prerendering with SSR", () => {
+ before(async () => {
+ process.env.PRERENDER = true;
+ await cli("build", "--root", fileURLToPath(root));
+ });
+
+ after(() => {
+ delete process.env.PRERENDER;
+ });
+
+ it("Wildcard 404 is sorted last", async () => {
+ const redir = await fs.readFile(
+ new URL("./dist/_redirects", root),
+ "utf-8",
+ );
+ 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', () => {
- before(async () => {
- process.env.PRERENDER = false;
- process.env.ASTRO_OUTPUT = 'hybrid';
- await cli('build', '--root', fileURLToPath(root));
- });
-
- after(() => {
- delete process.env.PRERENDER;
- });
-
- it('outputs a correct redirect file', async () => {
- const redir = await fs.readFile(new URL('./dist/_redirects', root), 'utf-8');
- 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);
- });
+describe("Mixed Hybrid rendering with SSR", () => {
+ before(async () => {
+ process.env.PRERENDER = false;
+ process.env.ASTRO_OUTPUT = "hybrid";
+ await cli("build", "--root", fileURLToPath(root));
+ });
+
+ after(() => {
+ delete process.env.PRERENDER;
+ });
+
+ it("outputs a correct redirect file", async () => {
+ const redir = await fs.readFile(
+ new URL("./dist/_redirects", root),
+ "utf-8",
+ );
+ 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
index 855378ad4..43fc0cd5d 100644
--- a/packages/integrations/netlify/test/functions/redirects.test.js
+++ b/packages/integrations/netlify/test/functions/redirects.test.js
@@ -1,50 +1,56 @@
-import { expect } from 'chai';
-import fs from 'fs/promises';
-import { cli } from './test-utils.js';
-import { fileURLToPath } from 'url';
+import { expect } from "chai";
+import fs from "fs/promises";
+import { cli } from "./test-utils.js";
+import { fileURLToPath } from "url";
-const root = new URL('../functions/fixtures/redirects/', import.meta.url).toString();
+const root = new URL(
+ "../functions/fixtures/redirects/",
+ import.meta.url,
+).toString();
-describe('SSG - Redirects', () => {
- before(async () => {
- await cli('build', '--root', fileURLToPath(root));
- });
+describe("SSG - Redirects", () => {
+ before(async () => {
+ await cli("build", "--root", fileURLToPath(root));
+ });
- it('Creates a redirects file', async () => {
- let redirects = await fs.readFile(new URL('./dist/_redirects', root), 'utf-8');
- 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',
+ it("Creates a redirects file", async () => {
+ let redirects = await fs.readFile(
+ new URL("./dist/_redirects", root),
+ "utf-8",
+ );
+ 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",
- // Image endpoint
- '/_image',
- '/.netlify/functions/entry',
- '200',
+ // Image endpoint
+ "/_image",
+ "/.netlify/functions/entry",
+ "200",
- // A real route
- '/team/articles/*',
- '/.netlify/functions/entry',
- '200',
- ]);
- expect(redirects).to.matchSnapshot();
- });
+ // 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);
- }
- });
+ 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/test-utils.js b/packages/integrations/netlify/test/functions/test-utils.js
index c977af42e..46128095e 100644
--- a/packages/integrations/netlify/test/functions/test-utils.js
+++ b/packages/integrations/netlify/test/functions/test-utils.js
@@ -1,34 +1,34 @@
// @ts-check
-import { fileURLToPath } from 'node:url';
+import { fileURLToPath } from "node:url";
-export * from '../test-utils.js';
+export * from "../test-utils.js";
/**
*
* @returns {import('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);
- }
- },
- },
- };
+ 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/hosted-astro-project/astro.config.mjs b/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs
index 464c03a6c..6c8117f41 100644
--- a/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs
+++ b/packages/integrations/netlify/test/hosted/hosted-astro-project/astro.config.mjs
@@ -1,8 +1,8 @@
-import netlify from '@astrojs/netlify';
-import { defineConfig } from 'astro/config';
+import netlify from "@astrojs/netlify";
+import { defineConfig } from "astro/config";
// https://astro.build/config
export default defineConfig({
- output: 'server',
- adapter: netlify(),
+ output: "server",
+ adapter: netlify(),
});
diff --git a/packages/integrations/netlify/test/hosted/hosted.test.js b/packages/integrations/netlify/test/hosted/hosted.test.js
index 2dc8c67ce..3ec8cb3f3 100644
--- a/packages/integrations/netlify/test/hosted/hosted.test.js
+++ b/packages/integrations/netlify/test/hosted/hosted.test.js
@@ -1,21 +1,22 @@
-import { expect } from 'chai';
+import { expect } from "chai";
-const NETLIFY_TEST_URL = 'https://curious-boba-495d6d.netlify.app';
+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'
- );
+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);
- });
+ expect(image.status).to.equal(200);
+ });
- it('Server returns fresh content', async () => {
- const responseOne = await fetch(NETLIFY_TEST_URL + '/time');
+ it("Server returns fresh content", async () => {
+ const responseOne = await fetch(NETLIFY_TEST_URL + "/time");
- const responseTwo = await fetch(NETLIFY_TEST_URL + '/time');
+ const responseTwo = await fetch(NETLIFY_TEST_URL + "/time");
- expect(responseOne.body).to.not.equal(responseTwo.body);
- });
+ expect(responseOne.body).to.not.equal(responseTwo.body);
+ });
});
diff --git a/packages/integrations/netlify/test/setup.js b/packages/integrations/netlify/test/setup.js
index c53aa9894..e7e74f42f 100644
--- a/packages/integrations/netlify/test/setup.js
+++ b/packages/integrations/netlify/test/setup.js
@@ -1,12 +1,12 @@
-import { use } from 'chai';
-import chaiJestSnapshot from 'chai-jest-snapshot';
+import { use } from "chai";
+import chaiJestSnapshot from "chai-jest-snapshot";
use(chaiJestSnapshot);
before(function () {
- chaiJestSnapshot.resetSnapshotRegistry();
+ chaiJestSnapshot.resetSnapshotRegistry();
});
beforeEach(function () {
- chaiJestSnapshot.configureUsingMochaContext(this);
+ chaiJestSnapshot.configureUsingMochaContext(this);
});
diff --git a/packages/integrations/netlify/test/static/redirects.test.js b/packages/integrations/netlify/test/static/redirects.test.js
index ae3ff1eb8..9eafce0f8 100644
--- a/packages/integrations/netlify/test/static/redirects.test.js
+++ b/packages/integrations/netlify/test/static/redirects.test.js
@@ -1,50 +1,50 @@
-import { expect } from 'chai';
-import { loadFixture, testIntegration } from './test-utils.js';
-import { netlifyStatic } from '../../dist/index.js';
+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;
+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();
- });
+ 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',
+ 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',
- ]);
- });
+ "/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
index 44fcf84e0..dfabfb002 100644
--- a/packages/integrations/netlify/test/static/test-utils.js
+++ b/packages/integrations/netlify/test/static/test-utils.js
@@ -1,29 +1,29 @@
// @ts-check
-import { fileURLToPath } from 'node:url';
+import { fileURLToPath } from "node:url";
-export * from '../test-utils.js';
+export * from "../test-utils.js";
/**
*
* @returns {import('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)
- ),
- },
- },
- },
- });
- },
- },
- };
+ 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),
+ ),
+ },
+ },
+ },
+ });
+ },
+ },
+ };
}
diff --git a/packages/integrations/netlify/test/test-utils.js b/packages/integrations/netlify/test/test-utils.js
index 5ec8b49ba..6da676180 100644
--- a/packages/integrations/netlify/test/test-utils.js
+++ b/packages/integrations/netlify/test/test-utils.js
@@ -1,12 +1,12 @@
-import { execa } from 'execa';
+import { execa } from "execa";
/** Returns a process running the Astro CLI. */
export function cli(/** @type {string[]} */ ...args) {
- const spawned = execa('npx', ['astro', ...args], {
- env: { ASTRO_TELEMETRY_DISABLED: true },
- });
+ const spawned = execa("npx", ["astro", ...args], {
+ env: { ASTRO_TELEMETRY_DISABLED: true },
+ });
- spawned.stdout.setEncoding('utf8');
+ spawned.stdout.setEncoding("utf8");
- return spawned;
-} \ No newline at end of file
+ return spawned;
+}