summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/test/functions/image-cdn.test.js
diff options
context:
space:
mode:
authorGravatar Simon Knott <info@simonknott.de> 2024-01-03 15:44:34 +0100
committerGravatar GitHub <noreply@github.com> 2024-01-03 14:44:34 +0000
commitee994c34a4a9833c48a622c13d51fd54d9f0c7b8 (patch)
treecd674cc0209f22eceb4543edd53b3143adae8358 /packages/integrations/netlify/test/functions/image-cdn.test.js
parentffdc2e76d5d828502288eed161abc1cdcdc75536 (diff)
downloadastro-ee994c34a4a9833c48a622c13d51fd54d9f0c7b8.tar.gz
astro-ee994c34a4a9833c48a622c13d51fd54d9f0c7b8.tar.zst
astro-ee994c34a4a9833c48a622c13d51fd54d9f0c7b8.zip
[netlify] allow opting out of Image CDN (#120)
* chore: add image CDN tests * feat: allow image cdn opt-out * write docs * add changeset * fix: put proper jsdoc values
Diffstat (limited to 'packages/integrations/netlify/test/functions/image-cdn.test.js')
-rw-r--r--packages/integrations/netlify/test/functions/image-cdn.test.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/integrations/netlify/test/functions/image-cdn.test.js b/packages/integrations/netlify/test/functions/image-cdn.test.js
new file mode 100644
index 000000000..21b5d195e
--- /dev/null
+++ b/packages/integrations/netlify/test/functions/image-cdn.test.js
@@ -0,0 +1,43 @@
+import { loadFixture } from '@astrojs/test-utils';
+import { expect } from 'chai';
+import { describe } from 'node:test';
+
+describe('Image CDN', () => {
+ const root = new URL('./fixtures/middleware/', import.meta.url);
+
+ describe("when running outside of netlify", () => {
+ it("does not enable Image CDN", async () => {
+ const fixture = await loadFixture({ root });
+ await fixture.build();
+
+ const astronautPage = await fixture.readFile('astronaut/index.html');
+ expect(astronautPage).contains(`src="/_astro/astronaut.`)
+ })
+ })
+
+ describe("when running inside of netlify", () => {
+ it("enables Netlify Image CDN", async () => {
+ process.env.NETLIFY = 'true'
+ const fixture = await loadFixture({ root });
+ await fixture.build();
+
+ const astronautPage = await fixture.readFile('astronaut/index.html');
+ expect(astronautPage).contains(`src="/.netlify/image`)
+
+ process.env.NETLIFY = undefined
+ })
+
+ it("respects image CDN opt-out", async () => {
+ process.env.NETLIFY = 'true'
+ process.env.DISABLE_IMAGE_CDN = 'true'
+ const fixture = await loadFixture({ root });
+ await fixture.build();
+
+ const astronautPage = await fixture.readFile('astronaut/index.html');
+ expect(astronautPage).contains(`src="/_astro/astronaut.`)
+
+ process.env.NETLIFY = undefined
+ process.env.DISABLE_IMAGE_CDN = undefined
+ })
+ })
+});