-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
6 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/netlify': minor | ||
--- | ||
|
||
Adds opt-out option for Image CDN. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
packages/netlify/test/functions/fixtures/middleware/src/pages/astronaut.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
import { Image } from 'astro:assets'; | ||
import astronautImage from "../astronaut.jpg" | ||
export const prerender = true; | ||
--- | ||
|
||
<Image src={astronautImage} alt="an astronaut floating in space" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
}) | ||
}); |