diff options
Diffstat (limited to 'packages/integrations/image/test')
107 files changed, 0 insertions, 3446 deletions
diff --git a/packages/integrations/image/test/assets-prefix.test.js b/packages/integrations/image/test/assets-prefix.test.js deleted file mode 100644 index 099acfeb3..000000000 --- a/packages/integrations/image/test/assets-prefix.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; - -const assetsPrefixRegex = /^http:\/\/localhost:4321\/_astro\/.*/; - -describe('Assets Prefix', function () { - /** @type {import('../../../astro/test/test-utils').Fixture} */ - let fixture; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/assets-prefix/' }); - await fixture.build(); - }); - - it('images src has assets prefix', async () => { - const html = await fixture.readFile('/index.html'); - const $ = cheerio.load(html); - const img = $('#social-jpg'); - expect(img.attr('src')).to.match(assetsPrefixRegex); - }); -}); diff --git a/packages/integrations/image/test/background-color-image-ssg.test.js b/packages/integrations/image/test/background-color-image-ssg.test.js deleted file mode 100644 index 6723ac1d5..000000000 --- a/packages/integrations/image/test/background-color-image-ssg.test.js +++ /dev/null @@ -1,127 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import sharp from 'sharp'; -import { fileURLToPath } from 'node:url'; -import { loadFixture } from './test-utils.js'; - -describe('SSG image with background - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/background-color-image/' }); - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Named color', - id: '#named', - bg: 'dimgray', - }, - { - title: 'Hex color', - id: '#hex', - bg: '#696969', - }, - { - title: 'Hex color short', - id: '#hex-short', - bg: '#666', - }, - { - title: 'RGB color', - id: '#rgb', - bg: 'rgb(105,105,105)', - }, - { - title: 'RGB color with spaces', - id: '#rgb-spaced', - bg: 'rgb(105, 105, 105)', - }, - ].forEach(({ title, id, bg }) => { - it(title, async () => { - const image = $(id); - const src = image.attr('src'); - const [, params] = src.split('?'); - const searchParams = new URLSearchParams(params); - expect(searchParams.get('bg')).to.equal(bg); - }); - }); -}); - -describe('SSG image with background - build', function () { - let fixture; - let $; - let html; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/background-color-image/' }); - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - async function verifyImage(pathname, expectedBg) { - const url = new URL('./fixtures/background-color-image/dist/' + pathname, import.meta.url); - const dist = fileURLToPath(url); - const data = await sharp(dist).raw().toBuffer(); - // check that the first RGB pixel indeed has the requested background color - expect(data[0]).to.equal(expectedBg[0]); - expect(data[1]).to.equal(expectedBg[1]); - expect(data[2]).to.equal(expectedBg[2]); - } - - [ - { - title: 'Named color', - id: '#named', - bg: [105, 105, 105], - }, - { - title: 'Hex color', - id: '#hex', - bg: [105, 105, 105], - }, - { - title: 'Hex color short', - id: '#hex-short', - bg: [102, 102, 102], - }, - { - title: 'RGB color', - id: '#rgb', - bg: [105, 105, 105], - }, - { - title: 'RGB color with spaces', - id: '#rgb-spaced', - bg: [105, 105, 105], - }, - - { - title: 'RGBA color', - id: '#rgba', - bg: [105, 105, 105], - }, - { - title: 'RGBA color with spaces', - id: '#rgba-spaced', - bg: [105, 105, 105], - }, - ].forEach(({ title, id, bg }) => { - it(title, async () => { - const image = $(id); - const src = image.attr('src'); - await verifyImage(src, bg); - }); - }); -}); diff --git a/packages/integrations/image/test/background-color-image-ssr.test.js b/packages/integrations/image/test/background-color-image-ssr.test.js deleted file mode 100644 index 66b512e30..000000000 --- a/packages/integrations/image/test/background-color-image-ssr.test.js +++ /dev/null @@ -1,120 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; -import testAdapter from '../../../astro/test/test-adapter.js'; - -let fixture; - -describe('SSR image with background', function () { - before(async () => { - fixture = await loadFixture({ - root: './fixtures/background-color-image/', - adapter: testAdapter({ streaming: false }), - output: 'server', - }); - await fixture.build(); - }); - - [ - { - title: 'Named color', - id: '#named', - query: { - f: 'jpeg', - w: '256', - h: '256', - href: /^\/_astro\/file-icon.\w{8}.png/, - bg: 'dimgray', - }, - }, - { - title: 'Hex color', - id: '#hex', - query: { - f: 'jpeg', - w: '256', - h: '256', - href: /^\/_astro\/file-icon.\w{8}.png/, - bg: '#696969', - }, - }, - { - title: 'Hex color short', - id: '#hex-short', - query: { - f: 'jpeg', - w: '256', - h: '256', - href: /^\/_astro\/file-icon.\w{8}.png/, - bg: '#666', - }, - }, - { - title: 'RGB color', - id: '#rgb', - query: { - f: 'jpeg', - w: '256', - h: '256', - href: /^\/_astro\/file-icon.\w{8}.png/, - bg: 'rgb(105,105,105)', - }, - }, - { - title: 'RGB color with spaces', - id: '#rgb-spaced', - query: { - f: 'jpeg', - w: '256', - h: '256', - href: /^\/_astro\/file-icon.\w{8}.png/, - bg: 'rgb(105, 105, 105)', - }, - }, - { - title: 'RGBA color', - id: '#rgba', - query: { - f: 'jpeg', - w: '256', - h: '256', - href: /^\/_astro\/file-icon.\w{8}.png/, - bg: 'rgb(105,105,105,0.5)', - }, - }, - { - title: 'RGBA color with spaces', - id: '#rgba-spaced', - query: { - f: 'jpeg', - w: '256', - h: '256', - href: /^\/_astro\/file-icon.\w{8}.png/, - bg: 'rgb(105, 105, 105, 0.5)', - }, - }, - ].forEach(({ title, id, query }) => { - it(title, async () => { - const app = await fixture.loadTestAdapterApp(); - - const request = new Request('http://example.com/'); - const response = await app.render(request); - const html = await response.text(); - const $ = cheerio.load(html); - - const image = $(id); - const src = image.attr('src'); - const [, params] = src.split('?'); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - if (typeof value === 'string') { - expect(searchParams.get(key)).to.equal(value); - } else { - expect(searchParams.get(key)).to.match(value); - } - } - }); - }); -}); diff --git a/packages/integrations/image/test/fixtures/assets-prefix/astro.config.mjs b/packages/integrations/image/test/fixtures/assets-prefix/astro.config.mjs deleted file mode 100644 index e5a629ed0..000000000 --- a/packages/integrations/image/test/fixtures/assets-prefix/astro.config.mjs +++ /dev/null @@ -1,10 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - integrations: [image()], - build: { - assetsPrefix: 'http://localhost:4321', - } -}); diff --git a/packages/integrations/image/test/fixtures/assets-prefix/package.json b/packages/integrations/image/test/fixtures/assets-prefix/package.json deleted file mode 100644 index a72317c84..000000000 --- a/packages/integrations/image/test/fixtures/assets-prefix/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@test/image-assets-prefix", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "astro": "workspace:*" - } -} diff --git a/packages/integrations/image/test/fixtures/assets-prefix/src/assets/social.png b/packages/integrations/image/test/fixtures/assets-prefix/src/assets/social.png Binary files differdeleted file mode 100644 index 1399856f1..000000000 --- a/packages/integrations/image/test/fixtures/assets-prefix/src/assets/social.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/assets-prefix/src/pages/index.astro b/packages/integrations/image/test/fixtures/assets-prefix/src/pages/index.astro deleted file mode 100644 index b66a202be..000000000 --- a/packages/integrations/image/test/fixtures/assets-prefix/src/pages/index.astro +++ /dev/null @@ -1,13 +0,0 @@ ---- -import socialJpg from '../assets/social.png'; -import { Image } from '@astrojs/image/components'; ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Image id="social-jpg" src={socialJpg} width={506} height={253} alt="social-jpg" /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/background-color-image/astro.config.mjs b/packages/integrations/image/test/fixtures/background-color-image/astro.config.mjs deleted file mode 100644 index f00c6ebae..000000000 --- a/packages/integrations/image/test/fixtures/background-color-image/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' })] -}); diff --git a/packages/integrations/image/test/fixtures/background-color-image/package.json b/packages/integrations/image/test/fixtures/background-color-image/package.json deleted file mode 100644 index db45dae31..000000000 --- a/packages/integrations/image/test/fixtures/background-color-image/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@test/background-color-image", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/background-color-image/public/favicon.ico b/packages/integrations/image/test/fixtures/background-color-image/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/background-color-image/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/background-color-image/server/server.mjs b/packages/integrations/image/test/fixtures/background-color-image/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/background-color-image/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/background-color-image/src/assets/file-icon.png b/packages/integrations/image/test/fixtures/background-color-image/src/assets/file-icon.png Binary files differdeleted file mode 100644 index a633da6a6..000000000 --- a/packages/integrations/image/test/fixtures/background-color-image/src/assets/file-icon.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/background-color-image/src/pages/index.astro b/packages/integrations/image/test/fixtures/background-color-image/src/pages/index.astro deleted file mode 100644 index 76f1fe936..000000000 --- a/packages/integrations/image/test/fixtures/background-color-image/src/pages/index.astro +++ /dev/null @@ -1,25 +0,0 @@ ---- -import { Image } from '@astrojs/image/components'; ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Image id="named" src={import('../assets/file-icon.png')} width={256} format="jpeg" background="dimgray" alt="named" /> - <br /> - <Image id="hex" src={import('../assets/file-icon.png')} width={256} format="jpeg" background="#696969" alt="hex" /> - <br /> - <Image id="hex-short" src={import('../assets/file-icon.png')} width={256} format="jpeg" background="#666" alt="hex-short" /> - <br /> - <Image id="rgb" src={import('../assets/file-icon.png')} width={256} format="jpeg" background="rgb(105,105,105)" alt="rgb" /> - <br /> - <Image id="rgb-spaced" src={import('../assets/file-icon.png')} width={256} format="jpeg" background="rgb(105, 105, 105)" alt="rgb-spaced" /> - <br /> - <Image id="rgba" src={import('../assets/file-icon.png')} width={256} format="jpeg" background="rgb(105,105,105,0.5)" alt="rgba" /> - <br /> - <Image id="rgba-spaced" src={import('../assets/file-icon.png')} width={256} format="jpeg" background="rgb(105, 105, 105, 0.5)" alt="rgba-spaced" /> - <br /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/basic-image/astro.config.mjs b/packages/integrations/image/test/fixtures/basic-image/astro.config.mjs deleted file mode 100644 index f00c6ebae..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' })] -}); diff --git a/packages/integrations/image/test/fixtures/basic-image/package.json b/packages/integrations/image/test/fixtures/basic-image/package.json deleted file mode 100644 index 4df1316ba..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@test/basic-image", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/basic-image/public/favicon.ico b/packages/integrations/image/test/fixtures/basic-image/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-image/public/hero.jpg b/packages/integrations/image/test/fixtures/basic-image/public/hero.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/public/hero.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-image/server/server.mjs b/packages/integrations/image/test/fixtures/basic-image/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/basic-image/social.png b/packages/integrations/image/test/fixtures/basic-image/social.png Binary files differdeleted file mode 100644 index 1399856f1..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/social.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-image/src/assets/blog/introducing astro.jpg b/packages/integrations/image/test/fixtures/basic-image/src/assets/blog/introducing astro.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/src/assets/blog/introducing astro.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-image/src/assets/logo.svg b/packages/integrations/image/test/fixtures/basic-image/src/assets/logo.svg deleted file mode 100644 index a1388d931..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/src/assets/logo.svg +++ /dev/null @@ -1,22 +0,0 @@ -<svg width="192" height="256" fill="none" xmlns="http://www.w3.org/2000/svg"> - <path fill-rule="evenodd" clip-rule="evenodd" - d="M131.008 18.929c1.944 2.413 2.935 5.67 4.917 12.181l43.309 142.27a180.277 180.277 0 00-51.778-17.53L99.258 60.56a3.67 3.67 0 00-7.042.01l-27.857 95.232a180.225 180.225 0 00-52.01 17.557l43.52-142.281c1.99-6.502 2.983-9.752 4.927-12.16a15.999 15.999 0 016.484-4.798c2.872-1.154 6.271-1.154 13.07-1.154h31.085c6.807 0 10.211 0 13.086 1.157a16.004 16.004 0 016.487 4.806z" - fill="url(#paint0_linear)" /> - <path fill-rule="evenodd" clip-rule="evenodd" - d="M136.19 180.151c-7.139 6.105-21.39 10.268-37.804 10.268-20.147 0-37.033-6.272-41.513-14.707-1.602 4.835-1.961 10.367-1.961 13.902 0 0-1.056 17.355 11.015 29.426 0-6.268 5.081-11.349 11.35-11.349 10.742 0 10.73 9.373 10.72 16.977v.679c0 11.542 7.054 21.436 17.086 25.606a23.27 23.27 0 01-2.339-10.2c0-11.008 6.463-15.107 13.974-19.87 5.976-3.79 12.616-8.001 17.192-16.449a31.024 31.024 0 003.743-14.82c0-3.299-.513-6.479-1.463-9.463z" - fill="#FF5D01" /> - <path fill-rule="evenodd" clip-rule="evenodd" - d="M136.19 180.151c-7.139 6.105-21.39 10.268-37.804 10.268-20.147 0-37.033-6.272-41.513-14.707-1.602 4.835-1.961 10.367-1.961 13.902 0 0-1.056 17.355 11.015 29.426 0-6.268 5.081-11.349 11.35-11.349 10.742 0 10.73 9.373 10.72 16.977v.679c0 11.542 7.054 21.436 17.086 25.606a23.27 23.27 0 01-2.339-10.2c0-11.008 6.463-15.107 13.974-19.87 5.976-3.79 12.616-8.001 17.192-16.449a31.024 31.024 0 003.743-14.82c0-3.299-.513-6.479-1.463-9.463z" - fill="url(#paint1_linear)" /> - <defs> - <linearGradient id="paint0_linear" x1="144.599" y1="5.423" x2="95.791" y2="173.38" gradientUnits="userSpaceOnUse"> - <stop stop-color="#000014" /> - <stop offset="1" stop-color="#150426" /> - </linearGradient> - <linearGradient id="paint1_linear" x1="168.336" y1="130.49" x2="126.065" y2="218.982" - gradientUnits="userSpaceOnUse"> - <stop stop-color="#FF1639" /> - <stop offset="1" stop-color="#FF1639" stop-opacity="0" /> - </linearGradient> - </defs> -</svg> diff --git a/packages/integrations/image/test/fixtures/basic-image/src/assets/social.jpg b/packages/integrations/image/test/fixtures/basic-image/src/assets/social.jpg Binary files differdeleted file mode 100644 index 906c76144..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/src/assets/social.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-image/src/assets/social.png b/packages/integrations/image/test/fixtures/basic-image/src/assets/social.png Binary files differdeleted file mode 100644 index 1399856f1..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/src/assets/social.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-image/src/pages/index.astro b/packages/integrations/image/test/fixtures/basic-image/src/pages/index.astro deleted file mode 100644 index ed1d79db6..000000000 --- a/packages/integrations/image/test/fixtures/basic-image/src/pages/index.astro +++ /dev/null @@ -1,37 +0,0 @@ ---- -import socialJpg from '../assets/social.jpg'; -import logoSvg from '../assets/logo.svg'; -import introJpg from '../assets/blog/introducing astro.jpg'; -import outsideSrc from '../../social.png'; -import { Image } from '@astrojs/image/components'; -const publicImage = new URL('./hero.jpg', Astro.url); ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Image id="hero" src={publicImage.pathname} width={768} height={414} format="webp" alt="hero" /> - <br /> - <Image id="spaces" src={introJpg} width={768} height={414} format="webp" alt="spaces" /> - <br /> - <Image id="social-jpg" src={socialJpg} width={506} height={253} alt="social-jpg" /> - <br /> - <Image id="no-transforms" src={socialJpg} alt="no-transforms" /> - <br /> - <Image id="outside-src" src={outsideSrc} alt="outside-src" /> - <br /> - <Image id="logo-svg" src={logoSvg} alt="logo-svg" /> - <br /> - <Image id="google" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width={544} height={184} format="webp" alt="Google" /> - <br /> - <Image id="inline" src={import('../assets/social.jpg')} width={506} alt="inline" /> - <br /> - <Image id="query" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?token=abc" width={544} height={184} format="webp" alt="query" /> - <br /> - <Image id="bg-color" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width={544} height={184} format="jpeg" alt="Google" background="#333333" /> - <br /> - <Image id="ipsum" src="https://dummyimage.com/200x300" width={200} height={300} alt="ipsum" format="jpeg" /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/basic-picture/astro.config.mjs b/packages/integrations/image/test/fixtures/basic-picture/astro.config.mjs deleted file mode 100644 index f00c6ebae..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' })] -}); diff --git a/packages/integrations/image/test/fixtures/basic-picture/package.json b/packages/integrations/image/test/fixtures/basic-picture/package.json deleted file mode 100644 index 1949eb5a9..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@test/basic-picture", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/basic-picture/public/favicon.ico b/packages/integrations/image/test/fixtures/basic-picture/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-picture/public/hero.jpg b/packages/integrations/image/test/fixtures/basic-picture/public/hero.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/public/hero.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-picture/server/server.mjs b/packages/integrations/image/test/fixtures/basic-picture/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/basic-picture/social.png b/packages/integrations/image/test/fixtures/basic-picture/social.png Binary files differdeleted file mode 100644 index 1399856f1..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/social.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-picture/src/assets/blog/introducing astro.jpg b/packages/integrations/image/test/fixtures/basic-picture/src/assets/blog/introducing astro.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/src/assets/blog/introducing astro.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-picture/src/assets/social.jpg b/packages/integrations/image/test/fixtures/basic-picture/src/assets/social.jpg Binary files differdeleted file mode 100644 index 906c76144..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/src/assets/social.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-picture/src/assets/social.png b/packages/integrations/image/test/fixtures/basic-picture/src/assets/social.png Binary files differdeleted file mode 100644 index 1399856f1..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/src/assets/social.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/basic-picture/src/pages/index.astro b/packages/integrations/image/test/fixtures/basic-picture/src/pages/index.astro deleted file mode 100644 index 39e997ba8..000000000 --- a/packages/integrations/image/test/fixtures/basic-picture/src/pages/index.astro +++ /dev/null @@ -1,32 +0,0 @@ ---- -import socialJpg from '../assets/social.jpg'; -import introJpg from '../assets/blog/introducing astro.jpg'; -import outsideSrc from '../../social.png'; -import { Picture } from '@astrojs/image/components'; -const publicImage = new URL('./hero.jpg', Astro.url); ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Picture id="hero" src={publicImage.pathname} sizes="100vw" widths={[384, 768]} aspectRatio={768/414} alt="Hero image" /> - <br /> - <Picture id="spaces" src={introJpg} sizes="100vw" widths={[384, 768]} aspectRatio={768/414} alt="spaces" /> - <br /> - <Picture id="outside-src" src={outsideSrc} sizes="100vw" widths={[384, 768]} aspectRatio={768/414} alt="outside-src" /> - <br /> - <Picture id="social-jpg" src={socialJpg} sizes="(min-width: 640px) 50vw, 100vw" widths={[253, 506]} alt="Social image" /> - <br /> - <Picture id="google" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" sizes="(min-width: 640px) 50vw, 100vw" widths={[272, 544]} aspectRatio={544/184} alt="Google logo" formats={["avif", "webp", "png"]} /> - <br /> - <Picture id='inline' src={import('../assets/social.jpg')} sizes="(min-width: 640px) 50vw, 100vw" widths={[253, 506]} alt="Inline social image" /> - <br /> - <Picture id="bg-color" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" sizes="(min-width: 640px) 50vw, 100vw" widths={[272, 544]} aspectRatio={544/184} alt="Google logo" background="rgb(51, 51, 51)" formats={['avif', 'jpeg']} /> - <br /> - <Picture id="ipsum" src="https://dummyimage.com/200x300" sizes="100vw" widths={[100, 200]} aspectRatio={2/3} formats={["avif", "webp", "jpg"]} alt="ipsum" /> - <br /> - <Picture id="query" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?token=abc" sizes="100vw" widths={[544]} aspectRatio={544/184} alt="query" /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/get-image-remote/astro.config.mjs b/packages/integrations/image/test/fixtures/get-image-remote/astro.config.mjs deleted file mode 100644 index f00c6ebae..000000000 --- a/packages/integrations/image/test/fixtures/get-image-remote/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' })] -}); diff --git a/packages/integrations/image/test/fixtures/get-image-remote/package.json b/packages/integrations/image/test/fixtures/get-image-remote/package.json deleted file mode 100644 index 83f0e02de..000000000 --- a/packages/integrations/image/test/fixtures/get-image-remote/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@test/image-get-image-remote", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/get-image-remote/src/pages/index.astro b/packages/integrations/image/test/fixtures/get-image-remote/src/pages/index.astro deleted file mode 100644 index ff45cd498..000000000 --- a/packages/integrations/image/test/fixtures/get-image-remote/src/pages/index.astro +++ /dev/null @@ -1,25 +0,0 @@ ---- -import { getImage } from "@astrojs/image"; - -const i = { - src: "https://images.unsplash.com/photo-1664309570712-564c233f112b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=80", - format: 'avif', - width: 200, - height: 300, -} -const image = await getImage(i as any); ---- - -<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> - <img {...image} /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/no-alt-text-image/astro.config.mjs b/packages/integrations/image/test/fixtures/no-alt-text-image/astro.config.mjs deleted file mode 100644 index f00c6ebae..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-image/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' })] -}); diff --git a/packages/integrations/image/test/fixtures/no-alt-text-image/package.json b/packages/integrations/image/test/fixtures/no-alt-text-image/package.json deleted file mode 100644 index 9347ad25d..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-image/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@test/no-alt-text-image", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/no-alt-text-image/public/favicon.ico b/packages/integrations/image/test/fixtures/no-alt-text-image/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-image/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/no-alt-text-image/server/server.mjs b/packages/integrations/image/test/fixtures/no-alt-text-image/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-image/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/no-alt-text-image/src/assets/social.jpg b/packages/integrations/image/test/fixtures/no-alt-text-image/src/assets/social.jpg Binary files differdeleted file mode 100644 index 906c76144..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-image/src/assets/social.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/no-alt-text-image/src/pages/index.astro b/packages/integrations/image/test/fixtures/no-alt-text-image/src/pages/index.astro deleted file mode 100644 index d2df3e56e..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-image/src/pages/index.astro +++ /dev/null @@ -1,13 +0,0 @@ ---- -import socialJpg from '../assets/social.jpg'; -import { Image } from '@astrojs/image/components'; ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Image id="social-jpg" src={socialJpg} width={506} height={253} /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/no-alt-text-picture/astro.config.mjs b/packages/integrations/image/test/fixtures/no-alt-text-picture/astro.config.mjs deleted file mode 100644 index f00c6ebae..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-picture/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' })] -}); diff --git a/packages/integrations/image/test/fixtures/no-alt-text-picture/package.json b/packages/integrations/image/test/fixtures/no-alt-text-picture/package.json deleted file mode 100644 index f253b6709..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-picture/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@test/no-alt-text-picture", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/no-alt-text-picture/public/favicon.ico b/packages/integrations/image/test/fixtures/no-alt-text-picture/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-picture/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/no-alt-text-picture/server/server.mjs b/packages/integrations/image/test/fixtures/no-alt-text-picture/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-picture/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/no-alt-text-picture/src/assets/social.jpg b/packages/integrations/image/test/fixtures/no-alt-text-picture/src/assets/social.jpg Binary files differdeleted file mode 100644 index 906c76144..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-picture/src/assets/social.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/no-alt-text-picture/src/pages/index.astro b/packages/integrations/image/test/fixtures/no-alt-text-picture/src/pages/index.astro deleted file mode 100644 index 4f5a17ce8..000000000 --- a/packages/integrations/image/test/fixtures/no-alt-text-picture/src/pages/index.astro +++ /dev/null @@ -1,13 +0,0 @@ ---- -import socialJpg from '../assets/social.jpg'; -import { Picture } from '@astrojs/image/components'; ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Picture id="social-jpg" src={socialJpg} sizes="(min-width: 640px) 50vw, 100vw" /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/rotation/astro.config.mjs b/packages/integrations/image/test/fixtures/rotation/astro.config.mjs deleted file mode 100644 index f00c6ebae..000000000 --- a/packages/integrations/image/test/fixtures/rotation/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' })] -}); diff --git a/packages/integrations/image/test/fixtures/rotation/package.json b/packages/integrations/image/test/fixtures/rotation/package.json deleted file mode 100644 index 8605d684e..000000000 --- a/packages/integrations/image/test/fixtures/rotation/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "@test/rotation", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/rotation/public/favicon.ico b/packages/integrations/image/test/fixtures/rotation/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/rotation/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/server/server.mjs b/packages/integrations/image/test/fixtures/rotation/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/rotation/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_0.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_0.jpg Binary files differdeleted file mode 100644 index 8518c82b5..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_0.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_1.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_1.jpg Binary files differdeleted file mode 100644 index fda188236..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_1.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_2.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_2.jpg Binary files differdeleted file mode 100644 index d2605f81b..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_2.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_3.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_3.jpg Binary files differdeleted file mode 100644 index f50805234..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_3.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_4.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_4.jpg Binary files differdeleted file mode 100644 index d73dee8fd..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_4.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_5.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_5.jpg Binary files differdeleted file mode 100644 index 975d85883..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_5.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_6.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_6.jpg Binary files differdeleted file mode 100644 index b579b7f9a..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_6.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_7.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_7.jpg Binary files differdeleted file mode 100644 index b1e919cfd..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_7.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_8.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_8.jpg Binary files differdeleted file mode 100644 index c381db10e..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Landscape_8.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_0.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_0.jpg Binary files differdeleted file mode 100644 index aa9632e5e..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_0.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_1.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_1.jpg Binary files differdeleted file mode 100644 index dcb57c537..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_1.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_2.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_2.jpg Binary files differdeleted file mode 100644 index 8c3adf7af..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_2.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_3.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_3.jpg Binary files differdeleted file mode 100644 index 5a5544f23..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_3.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_4.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_4.jpg Binary files differdeleted file mode 100644 index 9eb2a6a1e..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_4.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_5.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_5.jpg Binary files differdeleted file mode 100644 index 905169aa7..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_5.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_6.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_6.jpg Binary files differdeleted file mode 100644 index 8fc576e06..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_6.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_7.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_7.jpg Binary files differdeleted file mode 100644 index cfa04d66e..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_7.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_8.jpg b/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_8.jpg Binary files differdeleted file mode 100644 index b2a50d6eb..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/assets/Portrait_8.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/rotation/src/pages/index.astro b/packages/integrations/image/test/fixtures/rotation/src/pages/index.astro deleted file mode 100644 index 5fa379926..000000000 --- a/packages/integrations/image/test/fixtures/rotation/src/pages/index.astro +++ /dev/null @@ -1,48 +0,0 @@ ---- -import { Image } from '@astrojs/image/components'; ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Image id='landscape-0' src={import('../assets/Landscape_0.jpg')} alt="landscape-0" /> - <br /> - <Image id='landscape-1' src={import('../assets/Landscape_1.jpg')} alt="landscape-1" /> - <br /> - <Image id='landscape-2' src={import('../assets/Landscape_2.jpg')} alt="landscape-2" /> - <br /> - <Image id='landscape-3' src={import('../assets/Landscape_3.jpg')} alt="landscape-3" /> - <br /> - <Image id='landscape-4' src={import('../assets/Landscape_4.jpg')} alt="landscape-4" /> - <br /> - <Image id='landscape-5' src={import('../assets/Landscape_5.jpg')} alt="landscape-5" /> - <br /> - <Image id='landscape-6' src={import('../assets/Landscape_6.jpg')} alt="landscape-6" /> - <br /> - <Image id='landscape-7' src={import('../assets/Landscape_7.jpg')} alt="landscape-7" /> - <br /> - <Image id='landscape-8' src={import('../assets/Landscape_8.jpg')} alt="landscape-8" /> - <br /> - - <Image id='portrait-0' src={import('../assets/Portrait_0.jpg')} alt="portrait-0" /> - <br /> - <Image id='portrait-1' src={import('../assets/Portrait_1.jpg')} alt="portrait-1" /> - <br /> - <Image id='portrait-2' src={import('../assets/Portrait_2.jpg')} alt="portrait-2" /> - <br /> - <Image id='portrait-3' src={import('../assets/Portrait_3.jpg')} alt="portrait-3" /> - <br /> - <Image id='portrait-4' src={import('../assets/Portrait_4.jpg')} alt="portrait-4" /> - <br /> - <Image id='portrait-5' src={import('../assets/Portrait_5.jpg')} alt="portrait-5" /> - <br /> - <Image id='portrait-6' src={import('../assets/Portrait_6.jpg')} alt="portrait-6" /> - <br /> - <Image id='portrait-7' src={import('../assets/Portrait_7.jpg')} alt="portrait-7" /> - <br /> - <Image id='portrait-8' src={import('../assets/Portrait_8.jpg')} alt="portrait-8" /> - <br /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/squoosh-service/astro.config.mjs b/packages/integrations/image/test/fixtures/squoosh-service/astro.config.mjs deleted file mode 100644 index 7dafac3b6..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/astro.config.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent' })] -}); diff --git a/packages/integrations/image/test/fixtures/squoosh-service/package.json b/packages/integrations/image/test/fixtures/squoosh-service/package.json deleted file mode 100644 index 49db3bfff..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@test/squoosh-service", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*" - } -} diff --git a/packages/integrations/image/test/fixtures/squoosh-service/public/favicon.ico b/packages/integrations/image/test/fixtures/squoosh-service/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/squoosh-service/public/hero.jpg b/packages/integrations/image/test/fixtures/squoosh-service/public/hero.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/public/hero.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/squoosh-service/server/server.mjs b/packages/integrations/image/test/fixtures/squoosh-service/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/squoosh-service/src/assets/blog/introducing astro.jpg b/packages/integrations/image/test/fixtures/squoosh-service/src/assets/blog/introducing astro.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/src/assets/blog/introducing astro.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/squoosh-service/src/assets/social.jpg b/packages/integrations/image/test/fixtures/squoosh-service/src/assets/social.jpg Binary files differdeleted file mode 100644 index 906c76144..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/src/assets/social.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/squoosh-service/src/assets/social.png b/packages/integrations/image/test/fixtures/squoosh-service/src/assets/social.png Binary files differdeleted file mode 100644 index 1399856f1..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/src/assets/social.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/squoosh-service/src/pages/index.astro b/packages/integrations/image/test/fixtures/squoosh-service/src/pages/index.astro deleted file mode 100644 index 25feb1716..000000000 --- a/packages/integrations/image/test/fixtures/squoosh-service/src/pages/index.astro +++ /dev/null @@ -1,20 +0,0 @@ ---- -import socialJpg from '../assets/social.jpg'; -import introJpg from '../assets/blog/introducing astro.jpg'; -import { Image } from '@astrojs/image/components'; ---- - -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <Image id="hero" src="/hero.jpg" width={768} height={414} format="webp" alt="hero" /> - <br /> - <Image id="social-jpg" src={socialJpg} width={506} height={253} alt="social-jpg" /> - <br /> - <Image id="google" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width={544} height={184} format="webp" alt="Google" /> - <br> - <Image id="google-alt" src="//www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width={544} height={184} format="webp" alt="Google" /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/with-mdx/astro.config.mjs b/packages/integrations/image/test/fixtures/with-mdx/astro.config.mjs deleted file mode 100644 index 7989a6f57..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/astro.config.mjs +++ /dev/null @@ -1,9 +0,0 @@ -import { defineConfig } from 'astro/config'; -import image from '@astrojs/image'; -import mdx from '@astrojs/mdx'; - -// https://astro.build/config -export default defineConfig({ - site: 'http://localhost:3000', - integrations: [image({ logLevel: 'silent', serviceEntryPoint: '@astrojs/image/sharp' }), mdx()] -}); diff --git a/packages/integrations/image/test/fixtures/with-mdx/package.json b/packages/integrations/image/test/fixtures/with-mdx/package.json deleted file mode 100644 index 3d0e8329a..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "@test/with-mdx", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/image": "workspace:*", - "@astrojs/mdx": "workspace:*", - "@astrojs/node": "workspace:*", - "astro": "workspace:*", - "sharp": "^0.32.1" - } -} diff --git a/packages/integrations/image/test/fixtures/with-mdx/public/favicon.ico b/packages/integrations/image/test/fixtures/with-mdx/public/favicon.ico Binary files differdeleted file mode 100644 index 578ad458b..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/public/favicon.ico +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/with-mdx/public/hero.jpg b/packages/integrations/image/test/fixtures/with-mdx/public/hero.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/public/hero.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/with-mdx/server/server.mjs b/packages/integrations/image/test/fixtures/with-mdx/server/server.mjs deleted file mode 100644 index 7dd4756af..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/server/server.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import mime from 'mime'; -import fs from 'node:fs'; -import { createServer } from 'node:http'; -import { handler as ssrHandler } from '../dist/server/entry.mjs'; - -const clientRoot = new URL('../dist/client/', import.meta.url); - -async function handle(req, res) { - ssrHandler(req, res, async (err) => { - if (err) { - res.writeHead(500); - res.end(err.stack); - return; - } - - let local = new URL('.' + req.url, clientRoot); - try { - const data = await fs.promises.readFile(local); - res.writeHead(200, { - 'Content-Type': mime.getType(req.url), - }); - res.end(data); - } catch { - res.writeHead(404); - res.end(); - } - }); -} - -const server = createServer((req, res) => { - handle(req, res).catch((err) => { - console.error(err); - res.writeHead(500, { - 'Content-Type': 'text/plain', - }); - res.end(err.toString()); - }); -}); - -server.listen(8085); -console.log('Serving at http://localhost:8085'); - -// Silence weird <time> warning -console.error = () => {}; diff --git a/packages/integrations/image/test/fixtures/with-mdx/src/assets/blog/introducing-astro.jpg b/packages/integrations/image/test/fixtures/with-mdx/src/assets/blog/introducing-astro.jpg Binary files differdeleted file mode 100644 index c58aacf66..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/src/assets/blog/introducing-astro.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/with-mdx/src/assets/social.jpg b/packages/integrations/image/test/fixtures/with-mdx/src/assets/social.jpg Binary files differdeleted file mode 100644 index 906c76144..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/src/assets/social.jpg +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/with-mdx/src/assets/social.png b/packages/integrations/image/test/fixtures/with-mdx/src/assets/social.png Binary files differdeleted file mode 100644 index 1399856f1..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/src/assets/social.png +++ /dev/null diff --git a/packages/integrations/image/test/fixtures/with-mdx/src/layouts/Base.astro b/packages/integrations/image/test/fixtures/with-mdx/src/layouts/Base.astro deleted file mode 100644 index c0c286cd5..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/src/layouts/Base.astro +++ /dev/null @@ -1,8 +0,0 @@ -<html> - <head> - <!-- Head Stuff --> - </head> - <body> - <slot /> - </body> -</html> diff --git a/packages/integrations/image/test/fixtures/with-mdx/src/pages/index.mdx b/packages/integrations/image/test/fixtures/with-mdx/src/pages/index.mdx deleted file mode 100644 index 6bd2d253f..000000000 --- a/packages/integrations/image/test/fixtures/with-mdx/src/pages/index.mdx +++ /dev/null @@ -1,19 +0,0 @@ ---- -layout: '../layouts/Base.astro' ---- - -import socialJpg from '../assets/social.jpg'; -import { Image } from '@astrojs/image/components'; - - -<Image id="hero" src="/hero.jpg" width={768} height={414} format="webp" alt="hero" /> -<br /> -<Image id="social-jpg" src={socialJpg} width={506} height={253} alt="social-jpg" /> -<br /> -<Image id="google" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width={544} height={184} format="webp" alt="Google" /> -<br /> -<Image id="inline" src={import('../assets/social.jpg')} width={506} alt="inline" /> -<br /> -<Image id="query" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?token=abc" width={544} height={184} format="webp" alt="query" /> -<br /> -<Image id="bg-color" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" width={544} height={184} format="jpeg" alt="Google" background="#333333" /> diff --git a/packages/integrations/image/test/get-image.test.js b/packages/integrations/image/test/get-image.test.js deleted file mode 100644 index 74fa67feb..000000000 --- a/packages/integrations/image/test/get-image.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture } from './test-utils.js'; - -describe('getImage', function () { - /** @type {import('../../../astro/test/test-utils').Fixture} */ - let fixture; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/get-image-remote/' }); - await fixture.build(); - }); - - it('Remote images works', async () => { - const assets = await fixture.readdir('/_astro'); - expect(assets).to.have.a.lengthOf(1); - }); -}); diff --git a/packages/integrations/image/test/image-ssg.test.js b/packages/integrations/image/test/image-ssg.test.js deleted file mode 100644 index a1be5df02..000000000 --- a/packages/integrations/image/test/image-ssg.test.js +++ /dev/null @@ -1,419 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import sizeOf from 'image-size'; -import fs from 'node:fs/promises'; -import { join } from 'node:path'; -import { fileURLToPath, pathToFileURL } from 'node:url'; -import { loadFixture } from './test-utils.js'; - -const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const toAstroImage = (relpath) => - '/@astroimage' + pathToFileURL(join(__dirname, 'fixtures/basic-image', relpath)).pathname; - -describe('SSG images - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-image/' }); - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - }, - { - title: 'Local image no transforms', - id: '#no-transforms', - url: toAstroImage('src/assets/social.jpg'), - query: {}, - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { f: 'webp', w: '768', h: '414' }, - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '2024', h: '1012' }, - contentType: 'image/png', - }, - { - title: 'SVG image', - id: '#logo-svg', - url: toAstroImage('src/assets/logo.svg'), - query: { f: 'svg', w: '192', h: '256' }, - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'webp', w: '768', h: '414', href: '/hero.jpg' }, - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'jpeg', - w: '544', - h: '184', - bg: '#333333', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - ].forEach(({ title, id, url, query }) => { - it(title, () => { - const image = $(id); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - }); - }); -}); - -describe('SSG images with subpath - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-image/', base: '/docs' }); - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/docs/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - }, - { - title: 'Local image no transforms', - id: '#no-transforms', - url: toAstroImage('src/assets/social.jpg'), - query: {}, - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { f: 'webp', w: '768', h: '414' }, - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '2024', h: '1012' }, - contentType: 'image/png', - }, - { - title: 'SVG image', - id: '#logo-svg', - url: toAstroImage('src/assets/logo.svg'), - query: { f: 'svg', w: '192', h: '256' }, - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'webp', w: '768', h: '414', href: '/docs/hero.jpg' }, - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'jpeg', - w: '544', - h: '184', - bg: '#333333', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - ].forEach(({ title, id, url, query }) => { - it(title, () => { - const image = $(id); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - }); - }); -}); - -describe('SSG images - build', function () { - let fixture; - let $; - let html; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-image/' }); - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - function verifyImage(pathname, expected) { - const dist = join( - fileURLToPath(new URL('.', import.meta.url)), - 'fixtures/basic-image/dist', - pathname - ); - const result = sizeOf(dist); - expect(result).to.deep.equal(expected); - } - - [ - { - title: 'Local images', - id: '#social-jpg', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - }, - { - title: 'Filename with spaces', - id: '#spaces', - regex: /^\/_astro\/introducing astro.\w{8}_\w{4,10}.webp/, - size: { width: 768, height: 414, type: 'webp' }, - }, - { - title: 'File outside src', - id: '#outside-src', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.png/, - size: { type: 'png', width: 2024, height: 1012 }, - }, - { - title: 'SVG image', - id: '#logo-svg', - regex: /^\/_astro\/logo.\w{8}_\w{4,10}.svg/, - size: { width: 192, height: 256, type: 'svg' }, - }, - { - title: 'Inline imports', - id: '#inline', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - }, - { - title: 'Remote images', - id: '#google', - regex: /^\/_astro\/googlelogo_color_272x92dp_\w{4,10}.webp/, - size: { width: 544, height: 184, type: 'webp' }, - }, - { - title: 'Remote without file extension', - id: '#ipsum', - regex: /^\/_astro\/200x300_\w{4,10}/, - size: { width: 200, height: 300, type: 'jpg' }, - }, - { - title: 'Public images', - id: '#hero', - regex: /^\/_astro\/hero_\w{4,10}.webp/, - size: { width: 768, height: 414, type: 'webp' }, - }, - { - title: 'Remote images', - id: '#bg-color', - regex: /^\/_astro\/googlelogo_color_272x92dp_\w{4,10}.jpeg/, - size: { width: 544, height: 184, type: 'jpg' }, - }, - ].forEach(({ title, id, regex, size }) => { - it(title, async () => { - const image = $(id); - - expect(image.attr('src')).to.match(regex); - expect(image.attr('width')).to.equal(size.width.toString()); - expect(image.attr('height')).to.equal(size.height.toString()); - - verifyImage(image.attr('src'), size); - - const url = new URL( - './fixtures/basic-image/node_modules/.astro/image' + image.attr('src'), - import.meta.url - ); - expect(await fs.stat(url), 'transformed image was cached').to.not.be.undefined; - }); - }); -}); - -describe('SSG images with subpath - build', function () { - let fixture; - let $; - let html; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-image/', base: '/docs' }); - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - function verifyImage(pathname, expected) { - const url = new URL('./fixtures/basic-image/dist/' + pathname, import.meta.url); - const dist = fileURLToPath(url); - const result = sizeOf(dist); - expect(result).to.deep.equal(expected); - } - - [ - { - title: 'Local images', - id: '#social-jpg', - regex: /^\/docs\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - }, - { - title: 'Filename with spaces', - id: '#spaces', - regex: /^\/docs\/_astro\/introducing astro.\w{8}_\w{4,10}.webp/, - size: { width: 768, height: 414, type: 'webp' }, - }, - { - title: 'File outside src', - id: '#outside-src', - regex: /^\/docs\/_astro\/social.\w{8}_\w{4,10}.png/, - size: { type: 'png', width: 2024, height: 1012 }, - }, - { - title: 'SVG image', - id: '#logo-svg', - regex: /^\/docs\/_astro\/logo.\w{8}_\w{4,10}.svg/, - size: { width: 192, height: 256, type: 'svg' }, - }, - { - title: 'Inline imports', - id: '#inline', - regex: /^\/docs\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - }, - { - title: 'Remote images', - id: '#google', - regex: /^\/docs\/_astro\/googlelogo_color_272x92dp_\w{4,10}.webp/, - size: { width: 544, height: 184, type: 'webp' }, - }, - { - title: 'Remote without file extension', - id: '#ipsum', - regex: /^\/docs\/_astro\/200x300_\w{4,10}/, - size: { width: 200, height: 300, type: 'jpg' }, - }, - { - title: 'Public images', - id: '#hero', - regex: /^\/docs\/_astro\/hero_\w{4,10}.webp/, - size: { width: 768, height: 414, type: 'webp' }, - }, - { - title: 'Remote images', - id: '#bg-color', - regex: /^\/docs\/_astro\/googlelogo_color_272x92dp_\w{4,10}.jpeg/, - size: { width: 544, height: 184, type: 'jpg' }, - }, - ].forEach(({ title, id, regex, size }) => { - it(title, () => { - const image = $(id); - - expect(image.attr('src')).to.match(regex); - expect(image.attr('width')).to.equal(size.width.toString()); - expect(image.attr('height')).to.equal(size.height.toString()); - - verifyImage(image.attr('src').replace('/docs', ''), size); - }); - }); -}); diff --git a/packages/integrations/image/test/image-ssr-build.test.js b/packages/integrations/image/test/image-ssr-build.test.js deleted file mode 100644 index f85373c27..000000000 --- a/packages/integrations/image/test/image-ssr-build.test.js +++ /dev/null @@ -1,242 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; -import testAdapter from '../../../astro/test/test-adapter.js'; - -describe('SSR images - build', async function () { - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-image/', - adapter: testAdapter({ streaming: false }), - output: 'server', - }); - await fixture.build(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/_astro\/social.\w{8}.jpg/ }, - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: '/_image', - query: { f: 'webp', w: '768', h: '414', href: /^\/_astro\/introducing astro.\w{8}.jpg/ }, - }, - { - title: 'SVG image', - id: '#logo-svg', - url: '/_image', - query: { f: 'svg', w: '192', h: '256', href: /^\/_astro\/logo.\w{8}.svg/ }, - }, - { - title: 'Inline imports', - id: '#inline', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/_astro\/social.\w{8}.jpg/ }, - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - }, - { - title: 'Remote images with search', - id: '#query', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?token=abc', - }, - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'webp', w: '768', h: '414', href: '/hero.jpg' }, - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'jpeg', - w: '544', - h: '184', - bg: '#333333', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - ].forEach(({ title, id, url, query }) => { - it(title, async () => { - const app = await fixture.loadTestAdapterApp(); - - const request = new Request('http://example.com/'); - const response = await app.render(request); - const html = await response.text(); - const $ = cheerio.load(html); - - const image = $(id); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - if (typeof value === 'string') { - expect(searchParams.get(key)).to.equal(value); - } else { - expect(searchParams.get(key)).to.match(value); - } - } - }); - }); -}); - -describe('SSR images with subpath - build', function () { - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-image/', - adapter: testAdapter({ streaming: false }), - output: 'server', - base: '/docs', - }); - await fixture.build(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/docs\/_astro\/social.\w{8}.jpg/ }, - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: '/_image', - query: { - f: 'webp', - w: '768', - h: '414', - href: /^\/docs\/_astro\/introducing astro.\w{8}.jpg/, - }, - }, - { - title: 'SVG image', - id: '#logo-svg', - url: '/_image', - query: { f: 'svg', w: '192', h: '256', href: /^\/docs\/_astro\/logo.\w{8}.svg/ }, - }, - { - title: 'Inline imports', - id: '#inline', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/docs\/_astro\/social.\w{8}.jpg/ }, - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - }, - { - title: 'Remote images with search', - id: '#query', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png?token=abc', - }, - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'webp', w: '768', h: '414', href: '/docs/hero.jpg' }, - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'jpeg', - w: '544', - h: '184', - bg: '#333333', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - ].forEach(({ title, id, url, query }) => { - it(title, async () => { - const app = await fixture.loadTestAdapterApp(); - - const request = new Request('http://example.com/docs/'); - const response = await app.render(request); - const html = await response.text(); - const $ = cheerio.load(html); - - const image = $(id); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - if (typeof value === 'string') { - expect(searchParams.get(key)).to.equal(value); - } else { - expect(searchParams.get(key)).to.match(value); - } - } - }); - }); -}); diff --git a/packages/integrations/image/test/image-ssr-dev.test.js b/packages/integrations/image/test/image-ssr-dev.test.js deleted file mode 100644 index 186100b12..000000000 --- a/packages/integrations/image/test/image-ssr-dev.test.js +++ /dev/null @@ -1,274 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { fileURLToPath, pathToFileURL } from 'node:url'; -import { join } from 'node:path'; -import { loadFixture } from './test-utils.js'; -import testAdapter from '../../../astro/test/test-adapter.js'; - -const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const toAstroImage = (relpath) => - '/@astroimage' + pathToFileURL(join(__dirname, 'fixtures/basic-image', relpath)).pathname; - -describe('SSR images - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-image/', - adapter: testAdapter(), - output: 'server', - }); - - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - }, - { - title: 'Local image no transforms', - id: '#no-transforms', - url: toAstroImage('src/assets/social.jpg'), - query: {}, - contentType: 'image/jpeg', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { f: 'webp', w: '768', h: '414' }, - contentType: 'image/webp', - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '2024', h: '1012' }, - contentType: 'image/png', - }, - { - title: 'SVG image', - id: '#logo-svg', - url: toAstroImage('src/assets/logo.svg'), - query: { f: 'svg', w: '192', h: '256' }, - contentType: 'image/svg+xml', - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - contentType: 'image/webp', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - contentType: 'image/jpeg', - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { - f: 'webp', - w: '768', - h: '414', - href: '/hero.jpg', - }, - contentType: 'image/webp', - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'jpeg', - w: '544', - h: '184', - bg: '#333333', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - contentType: 'image/jpeg', - }, - ].forEach(({ title, id, url, query, contentType }) => { - it(title, async () => { - const image = $(id); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - - const res = await fixture.fetch(image.attr('src')); - - expect(res.status).to.equal(200); - expect(res.headers.get('Content-Type')).to.equal(contentType); - }); - }); -}); - -describe('SSR images with subpath - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-image/', - adapter: testAdapter(), - output: 'server', - base: '/docs', - }); - - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/docs/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { f: 'webp', w: '768', h: '414' }, - contentType: 'image/webp', - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '2024', h: '1012' }, - contentType: 'image/png', - }, - { - title: 'SVG image', - id: '#logo-svg', - url: toAstroImage('src/assets/logo.svg'), - query: { f: 'svg', w: '192', h: '256' }, - contentType: 'image/svg+xml', - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - contentType: 'image/webp', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - contentType: 'image/jpeg', - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { - f: 'webp', - w: '768', - h: '414', - href: '/docs/hero.jpg', - }, - contentType: 'image/webp', - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'jpeg', - w: '544', - h: '184', - bg: '#333333', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - contentType: 'image/jpeg', - }, - ].forEach(({ title, id, url, query, contentType }) => { - it(title, async () => { - const image = $(id); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - - const res = await fixture.fetch(image.attr('src')); - - expect(res.status).to.equal(200); - expect(res.headers.get('Content-Type')).to.equal(contentType); - }); - }); -}); diff --git a/packages/integrations/image/test/no-alt-text-image-ssg.test.js b/packages/integrations/image/test/no-alt-text-image-ssg.test.js deleted file mode 100644 index 4c998bdb4..000000000 --- a/packages/integrations/image/test/no-alt-text-image-ssg.test.js +++ /dev/null @@ -1,24 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture } from './test-utils.js'; - -let fixture; - -const errorMessage = - 'The <Image> component requires you provide alt text. If this image does not require an accessible label, set alt="".'; - -/** TODO: enable the test once missing alt text throws an error instead of a console warning */ -describe.skip('SSG image without alt text', function () { - before(async () => { - fixture = await loadFixture({ root: './fixtures/no-alt-text-image/' }); - }); - - it('throws during build', async () => { - try { - await fixture.build(); - } catch (err) { - expect(err.message).to.equal(errorMessage); - return; - } - expect.fail(0, 1, 'Exception not thrown'); - }); -}); diff --git a/packages/integrations/image/test/no-alt-text-image-ssr.test.js b/packages/integrations/image/test/no-alt-text-image-ssr.test.js deleted file mode 100644 index 95d6572bc..000000000 --- a/packages/integrations/image/test/no-alt-text-image-ssr.test.js +++ /dev/null @@ -1,33 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture } from './test-utils.js'; -import testAdapter from '../../../astro/test/test-adapter.js'; - -let fixture; - -const errorMessage = - 'The <Image> component requires you provide alt text. If this image does not require an accessible label, set alt="".'; - -/** TODO: enable the test once missing alt text throws an error instead of a console warning */ -describe.skip('SSR image without alt text', function () { - before(async () => { - fixture = await loadFixture({ - root: './fixtures/no-alt-text-image/', - adapter: testAdapter({ streaming: false }), - output: 'server', - }); - await fixture.build(); - }); - - it('throws during build', async () => { - try { - const app = await fixture.loadTestAdapterApp(); - const request = new Request('http://example.com/'); - const response = await app.render(request); - await response.text(); - } catch (err) { - expect(err.message).to.equal(errorMessage); - return; - } - expect.fail(0, 1, 'Exception not thrown'); - }); -}); diff --git a/packages/integrations/image/test/no-alt-text-picture-ssg.test.js b/packages/integrations/image/test/no-alt-text-picture-ssg.test.js deleted file mode 100644 index db0c5629f..000000000 --- a/packages/integrations/image/test/no-alt-text-picture-ssg.test.js +++ /dev/null @@ -1,24 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture } from './test-utils.js'; - -let fixture; - -const errorMessage = - 'The <Picture> component requires you provide alt text. If this picture does not require an accessible label, set alt="".'; - -/** TODO: enable the test once missing alt text throws an error instead of a console warning */ -describe.skip('SSG picture without alt text', function () { - before(async () => { - fixture = await loadFixture({ root: './fixtures/no-alt-text-picture/' }); - }); - - it('throws during build', async () => { - try { - await fixture.build(); - } catch (err) { - expect(err.message).to.equal(errorMessage); - return; - } - expect.fail(0, 1, 'Exception not thrown'); - }); -}); diff --git a/packages/integrations/image/test/no-alt-text-picture-ssr.test.js b/packages/integrations/image/test/no-alt-text-picture-ssr.test.js deleted file mode 100644 index 82ea4daa2..000000000 --- a/packages/integrations/image/test/no-alt-text-picture-ssr.test.js +++ /dev/null @@ -1,33 +0,0 @@ -import { expect } from 'chai'; -import { loadFixture } from './test-utils.js'; -import testAdapter from '../../../astro/test/test-adapter.js'; - -let fixture; - -const errorMessage = - 'The <Picture> component requires you provide alt text. If this picture does not require an accessible label, set alt="".'; - -/** TODO: enable the test once missing alt text throws an error instead of a console warning */ -describe.skip('SSR picture without alt text', function () { - before(async () => { - fixture = await loadFixture({ - root: './fixtures/no-alt-text-picture/', - adapter: testAdapter({ streaming: false }), - output: 'server', - }); - await fixture.build(); - }); - - it('throws during build', async () => { - try { - const app = await fixture.loadTestAdapterApp(); - const request = new Request('http://example.com/'); - const response = await app.render(request); - await response.text(); - } catch (err) { - expect(err.message).to.equal(errorMessage); - return; - } - expect.fail(0, 1, 'Exception not thrown'); - }); -}); diff --git a/packages/integrations/image/test/picture-ssg.test.js b/packages/integrations/image/test/picture-ssg.test.js deleted file mode 100644 index e74b4583d..000000000 --- a/packages/integrations/image/test/picture-ssg.test.js +++ /dev/null @@ -1,463 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import sizeOf from 'image-size'; -import fs from 'node:fs'; -import path, { join } from 'node:path'; -import { fileURLToPath, pathToFileURL } from 'node:url'; -import srcsetParse from 'srcset-parse'; -import { loadFixture } from './test-utils.js'; - -const matchSrcset = srcsetParse.default; - -const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const toAstroImage = (relpath) => - '/@astroimage' + pathToFileURL(join(__dirname, 'fixtures/basic-picture', relpath)).pathname; - -describe('SSG pictures - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-picture/' }); - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - alt: 'Social image', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { f: 'jpg', w: '768', h: '414' }, - alt: 'spaces', - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '768', h: '414' }, - alt: 'outside-src', - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - alt: 'Google logo', - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'jpg', w: '768', h: '414', href: '/hero.jpg' }, - alt: 'Hero image', - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - bg: 'rgb(51, 51, 51)', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - alt: 'Google logo', - }, - ].forEach(({ title, id, url, query, alt }) => { - it(title, () => { - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - sources.each((_, el) => { - const srcset = $(el).attr('srcset'); - expect(matchSrcset(srcset).length).to.equal(2); - }); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - - expect(image.attr('alt')).to.equal(alt); - }); - }); -}); - -describe('SSG pictures with subpath - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-picture/', base: '/docs' }); - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/docs/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - alt: 'Social image', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { f: 'jpg', w: '768', h: '414' }, - alt: 'spaces', - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '768', h: '414' }, - alt: 'outside-src', - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - alt: 'Google logo', - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'jpg', w: '768', h: '414', href: '/docs/hero.jpg' }, - alt: 'Hero image', - }, - ].forEach(({ title, id, url, query, alt }) => { - it(title, () => { - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - for (const srcset of picture - .children('source') - .map((_, source) => source.attribs['srcset'])) { - for (const pictureSrc of srcset.split(',')) { - const pictureParams = pictureSrc.split('?')[1]; - - const expected = new URLSearchParams(params).get('href'); - const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, ''); - expect(expected).to.equal(actual); - } - } - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - - expect(image.attr('alt')).to.equal(alt); - }); - }); -}); - -describe('SSG pictures - build', function () { - let fixture; - let $; - let html; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-picture/' }); - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - function verifyImage(pathname, expected) { - const url = new URL('./fixtures/basic-picture/dist/' + pathname, import.meta.url); - const dist = fileURLToPath(url); - - // image-size doesn't support AVIF files - if (expected.type !== 'avif') { - const result = sizeOf(dist); - expect(result).to.deep.equal(expected); - } else { - expect(fs.statSync(dist)).not.to.be.undefined; - } - } - - [ - { - title: 'Local images', - id: '#social-jpg', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - alt: 'Social image', - }, - { - title: 'Filename with spaces', - id: '#spaces', - regex: /^\/_astro\/introducing astro.\w{8}_\w{4,10}.jpg/, - size: { width: 768, height: 414, type: 'jpg' }, - alt: 'spaces', - }, - { - title: 'File outside src', - id: '#outside-src', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.png/, - size: { type: 'png', width: 768, height: 414 }, - alt: 'outside-src', - }, - { - title: 'Inline images', - id: '#inline', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - regex: /^\/_astro\/googlelogo_color_272x92dp_\w{4,10}.png/, - size: { width: 544, height: 184, type: 'png' }, - alt: 'Google logo', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - regex: /^\/_astro\/200x300_\w{4,10}/, - size: { width: 200, height: 300, type: 'jpg' }, - alt: 'ipsum', - }, - { - title: 'Public images', - id: '#hero', - regex: /^\/_astro\/hero_\w{4,10}.jpg/, - size: { width: 768, height: 414, type: 'jpg' }, - alt: 'Hero image', - }, - ].forEach(({ title, id, regex, size, alt }) => { - it(title, () => { - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - expect(image.attr('src')).to.match(regex); - expect(image.attr('alt')).to.equal(alt); - - verifyImage(image.attr('src'), size); - - sources.each((_, el) => { - const source = $(el); - const srcset = source.attr('srcset'); - - expect(matchSrcset(srcset).length).to.equal(2); - - for (const src of srcset.split(',')) { - const segments = src.split(' '); - - // filenames may have a space in them, pop the last item for the - // width and join the other segments back for the filepath - const width = segments.pop(); - const pathname = segments.join(' '); - - const widthNum = parseInt(width.substring(0, width.length - 1)); - - verifyImage(pathname, { - width: widthNum, - height: widthNum === size.width ? size.height : Math.round(size.height / 2), - type: path.extname(pathname).substring(1), - }); - } - }); - }); - }); -}); - -describe('SSG pictures with subpath - build', function () { - let fixture; - let $; - let html; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-picture/', base: '/docs' }); - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - function verifyImage(pathname, expected) { - const url = new URL('./fixtures/basic-picture/dist/' + pathname, import.meta.url); - const dist = fileURLToPath(url); - - // image-size doesn't support AVIF files - if (expected.type !== 'avif') { - const result = sizeOf(dist); - expect(result).to.deep.equal(expected); - } else { - expect(fs.statSync(dist)).not.to.be.undefined; - } - } - - [ - { - title: 'Local images', - id: '#social-jpg', - regex: /^\/docs\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - alt: 'Social image', - }, - { - title: 'File outside src', - id: '#outside-src', - regex: /^\/docs\/_astro\/social.\w{8}_\w{4,10}.png/, - size: { type: 'png', width: 768, height: 414 }, - alt: 'outside-src', - }, - { - title: 'Inline images', - id: '#inline', - regex: /^\/docs\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - regex: /^\/docs\/_astro\/googlelogo_color_272x92dp_\w{4,10}.png/, - size: { width: 544, height: 184, type: 'png' }, - alt: 'Google logo', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - regex: /^\/docs\/_astro\/200x300_\w{4,10}/, - size: { width: 200, height: 300, type: 'jpg' }, - alt: 'ipsum', - }, - { - title: 'Public images', - id: '#hero', - regex: /^\/docs\/_astro\/hero_\w{4,10}.jpg/, - size: { width: 768, height: 414, type: 'jpg' }, - alt: 'Hero image', - }, - ].forEach(({ title, id, regex, size, alt }) => { - it(title, () => { - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - expect(image.attr('src')).to.match(regex); - expect(image.attr('alt')).to.equal(alt); - - verifyImage(image.attr('src').replace('/docs', ''), size); - - sources.each((_, el) => { - const source = $(el); - const srcset = source.attr('srcset'); - - expect(matchSrcset(srcset).length).to.equal(2); - - for (const src of srcset.split(',')) { - const [pathname, width] = src.split(' '); - const widthNum = parseInt(width.substring(0, width.length - 1)); - - verifyImage(pathname.replace('/docs', ''), { - width: widthNum, - height: widthNum === size.width ? size.height : Math.round(size.height / 2), - type: path.extname(pathname).substring(1), - }); - } - }); - }); - }); -}); - -describe('SSG pictures others - build', function () { - let fixture; - let $; - let html; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/basic-picture/' }); - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - it('fallback image should share last source', async () => { - const hero = $('#hero'); - const picture = hero.closest('picture'); - - const source = picture.children('source').last(); - const image = picture.children('img').last(); - - expect(source.attr('srcset')).to.include(image.attr('src')); - }); -}); diff --git a/packages/integrations/image/test/picture-ssr-build.test.js b/packages/integrations/image/test/picture-ssr-build.test.js deleted file mode 100644 index 8aba191a4..000000000 --- a/packages/integrations/image/test/picture-ssr-build.test.js +++ /dev/null @@ -1,251 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { loadFixture } from './test-utils.js'; -import testAdapter from '../../../astro/test/test-adapter.js'; - -describe('SSR pictures - build', function () { - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-picture/', - adapter: testAdapter(), - output: 'server', - }); - await fixture.build(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/_astro\/social.\w{8}.jpg/ }, - alt: 'Social image', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: '/_image', - query: { w: '768', h: '414', f: 'jpg', href: /^\/_astro\/introducing astro.\w{8}.jpg/ }, - alt: 'spaces', - }, - { - title: 'File outside src', - id: '#outside-src', - url: '/_image', - query: { w: '768', h: '414', f: 'png', href: /^\/_astro\/social.\w{8}.png/ }, - alt: 'outside-src', - }, - { - title: 'Inline imports', - id: '#inline', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/_astro\/social.\w{8}.jpg/ }, - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - alt: 'Google logo', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - alt: 'ipsum', - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'jpg', w: '768', h: '414', href: '/hero.jpg' }, - alt: 'Hero image', - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - bg: 'rgb(51, 51, 51)', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - alt: 'Google logo', - }, - ].forEach(({ title, id, url, query }) => { - it(title, async () => { - const app = await fixture.loadTestAdapterApp(); - - const request = new Request('http://example.com/'); - const response = await app.render(request); - const html = await response.text(); - const $ = cheerio.load(html); - - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - if (typeof value === 'string') { - expect(searchParams.get(key)).to.equal(value); - } else { - expect(searchParams.get(key)).to.match(value); - } - } - }); - }); -}); - -describe('SSR pictures with subpath - build', function () { - let fixture; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-picture/', - adapter: testAdapter(), - output: 'server', - base: '/docs', - }); - await fixture.build(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/docs\/_astro\/social.\w{8}.jpg/ }, - alt: 'Social image', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: '/_image', - query: { w: '768', h: '414', f: 'jpg', href: /^\/docs\/_astro\/introducing astro.\w{8}.jpg/ }, - alt: 'spaces', - }, - { - title: 'File outside src', - id: '#outside-src', - url: '/_image', - query: { w: '768', h: '414', f: 'png', href: /^\/docs\/_astro\/social.\w{8}.png/ }, - alt: 'outside-src', - }, - { - title: 'Inline imports', - id: '#inline', - url: '/_image', - query: { f: 'jpg', w: '506', h: '253', href: /^\/docs\/_astro\/social.\w{8}.jpg/ }, - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - alt: 'Google logo', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - alt: 'ipsum', - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'jpg', w: '768', h: '414', href: '/docs/hero.jpg' }, - alt: 'Hero image', - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - bg: 'rgb(51, 51, 51)', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - alt: 'Google logo', - }, - ].forEach(({ title, id, url, query }) => { - it(title, async () => { - const app = await fixture.loadTestAdapterApp(); - - const request = new Request('http://example.com/docs/'); - const response = await app.render(request); - const html = await response.text(); - const $ = cheerio.load(html); - - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - for (const srcset of picture - .children('source') - .map((_, source) => source.attribs['srcset'])) { - for (const pictureSrc of srcset.split(',')) { - const pictureParams = pictureSrc.split('?')[1]; - - const expected = new URLSearchParams(params).get('href'); - const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, ''); - expect(expected).to.equal(actual); - } - } - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - if (typeof value === 'string') { - expect(searchParams.get(key)).to.equal(value); - } else { - expect(searchParams.get(key)).to.match(value); - } - } - }); - }); -}); diff --git a/packages/integrations/image/test/picture-ssr-dev.test.js b/packages/integrations/image/test/picture-ssr-dev.test.js deleted file mode 100644 index 896ff8262..000000000 --- a/packages/integrations/image/test/picture-ssr-dev.test.js +++ /dev/null @@ -1,282 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { fileURLToPath, pathToFileURL } from 'node:url'; -import { join } from 'node:path'; -import { loadFixture } from './test-utils.js'; -import testAdapter from '../../../astro/test/test-adapter.js'; - -const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const toAstroImage = (relpath) => - '/@astroimage' + pathToFileURL(join(__dirname, 'fixtures/basic-picture', relpath)).pathname; - -describe('SSR pictures - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-picture/', - adapter: testAdapter(), - output: 'server', - }); - - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - alt: 'Social image', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { w: '768', h: '414', f: 'jpg' }, - contentType: 'image/jpeg', - alt: 'spaces', - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '768', h: '414' }, - contentType: 'image/png', - alt: 'outside-src', - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - contentType: 'image/png', - alt: 'Google logo', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - f: 'jpg', - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - contentType: 'image/jpeg', - alt: 'ipsum', - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { - f: 'jpg', - w: '768', - h: '414', - href: '/hero.jpg', - }, - contentType: 'image/jpeg', - alt: 'Hero image', - }, - { - title: 'Background color', - id: '#bg-color', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - bg: 'rgb(51, 51, 51)', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - contentType: 'image/png', - alt: 'Google logo', - }, - ].forEach(({ title, id, url, query, alt, contentType }) => { - it(title, async () => { - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - for (const srcset of picture - .children('source') - .map((_, source) => source.attribs['srcset'])) { - for (const pictureSrc of srcset.split(',')) { - const pictureParams = pictureSrc.split('?')[1]; - - const expected = new URLSearchParams(params).get('href'); - const actual = new URLSearchParams(pictureParams).get('href').replace(/\s+\d+w$/, ''); - expect(expected).to.equal(actual); - } - } - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - - expect(image.attr('alt')).to.equal(alt); - - const res = await fixture.fetch(image.attr('src')); - - expect(res.status).to.equal(200); - expect(res.headers.get('Content-Type')).to.equal(contentType); - }); - }); -}); - -describe('SSR pictures with subpath - dev', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ - root: './fixtures/basic-picture/', - adapter: testAdapter(), - output: 'server', - base: '/docs', - }); - - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/docs/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - alt: 'Social image', - }, - { - title: 'Filename with spaces', - id: '#spaces', - url: toAstroImage('src/assets/blog/introducing astro.jpg'), - query: { w: '768', h: '414', f: 'jpg' }, - contentType: 'image/jpeg', - alt: 'spaces', - }, - { - title: 'File outside src', - id: '#outside-src', - url: toAstroImage('social.png'), - query: { f: 'png', w: '768', h: '414' }, - contentType: 'image/png', - alt: 'outside-src', - }, - { - title: 'Inline imports', - id: '#inline', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - contentType: 'image/jpeg', - alt: 'Inline social image', - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'png', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - contentType: 'image/png', - alt: 'Google logo', - }, - { - title: 'Remote without file extension', - id: '#ipsum', - url: '/_image', - query: { - f: 'jpg', - w: '200', - h: '300', - href: 'https://dummyimage.com/200x300', - }, - contentType: 'image/jpeg', - alt: 'ipsum', - }, - , - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { - f: 'jpg', - w: '768', - h: '414', - href: '/docs/hero.jpg', - }, - contentType: 'image/jpeg', - alt: 'Hero image', - }, - ].forEach(({ title, id, url, query, alt, contentType }) => { - it(title, async () => { - const image = $(`${id}`); - const picture = image.closest('picture'); - - const sources = picture.children('source'); - expect(sources.length).to.equal(3); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - - expect(image.attr('alt')).to.equal(alt); - - const res = await fixture.fetch(image.attr('src')); - - expect(res.status).to.equal(200); - expect(res.headers.get('Content-Type')).to.equal(contentType); - }); - }); -}); diff --git a/packages/integrations/image/test/rotation.test.js b/packages/integrations/image/test/rotation.test.js deleted file mode 100644 index 2477ec8b2..000000000 --- a/packages/integrations/image/test/rotation.test.js +++ /dev/null @@ -1,66 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import sizeOf from 'image-size'; -import { fileURLToPath } from 'node:url'; -import { loadFixture } from './test-utils.js'; - -let fixture; - -describe('Image rotation', function () { - before(async () => { - fixture = await loadFixture({ root: './fixtures/rotation/' }); - }); - - function verifyImage(pathname, expected) { - const url = new URL('./fixtures/rotation/dist/' + pathname, import.meta.url); - const dist = fileURLToPath(url); - const result = sizeOf(dist); - expect(result).to.deep.equal(expected); - } - - describe('build', () => { - let $; - let html; - - before(async () => { - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - it('Landscape images', () => { - for (let i = 0; i < 9; i++) { - const image = $(`#landscape-${i}`); - const regex = new RegExp(`\^/_astro\/Landscape_${i}.\\w{8}_\\w{4,10}.jpg`); - - expect(image.attr('src')).to.match(regex); - expect(image.attr('width')).to.equal('1800'); - expect(image.attr('height')).to.equal('1200'); - - verifyImage(image.attr('src'), { - width: 1800, - height: 1200, - type: 'jpg', - }); - } - }); - - it('Portait images', () => { - for (let i = 0; i < 9; i++) { - const image = $(`#portrait-${i}`); - const regex = new RegExp(`\^/_astro\/Portrait_${i}.\\w{8}_\\w{4,10}.jpg`); - - expect(image.attr('src')).to.match(regex); - expect(image.attr('width')).to.equal('1200'); - expect(image.attr('height')).to.equal('1800'); - - verifyImage(image.attr('src'), { - width: 1200, - height: 1800, - type: 'jpg', - }); - } - }); - }); -}); diff --git a/packages/integrations/image/test/sharp.test.js b/packages/integrations/image/test/sharp.test.js deleted file mode 100644 index 8e2d1d3af..000000000 --- a/packages/integrations/image/test/sharp.test.js +++ /dev/null @@ -1,73 +0,0 @@ -import { expect } from 'chai'; -import sharp from '../dist/loaders/sharp.js'; - -describe('Sharp service', () => { - describe('serializeTransform', () => { - const src = '/assets/image.png'; - - [ - ['only requires src', { src }], - ['quality', { src, quality: 80 }], - ['format', { src, format: 'jpeg' }], - ['width', { src, width: 1280 }], - ['height', { src, height: 414 }], - ['width & height', { src, height: 400, width: 200 }], - ['aspect ratio string', { src, aspectRatio: '16:9' }], - ['aspect ratio float', { src, aspectRatio: 1.7 }], - ['background color', { src, format: 'jpeg', background: '#333333' }], - ['crop fit', { src, fit: 'cover' }], - ['crop position', { src, position: 'center' }], - ].forEach(([description, props]) => { - it(description, async () => { - const { searchParams } = await sharp.serializeTransform(props); - - function verifyProp(expected, search) { - if (expected) { - expect(searchParams.get(search)).to.equal(expected.toString()); - } else { - expect(searchParams.has(search)).to.be.false; - } - } - - verifyProp(props.quality, 'q'); - verifyProp(props.format, 'f'); - verifyProp(props.width, 'w'); - verifyProp(props.height, 'h'); - verifyProp(props.aspectRatio, 'ar'); - verifyProp(props.fit, 'fit'); - verifyProp(props.position, 'p'); - verifyProp(props.background, 'bg'); - }); - }); - }); - - describe('parseTransform', async () => { - const src = '/assets/image.png'; - const href = encodeURIComponent(src); - - [ - ['only requires src', `href=${href}`, { src }], - ['quality', `q=80&href=${href}`, { src, quality: 80 }], - ['format', `f=jpeg&href=${href}`, { src, format: 'jpeg' }], - ['width', `w=1280&href=${href}`, { src, width: 1280 }], - ['height', `h=414&href=${href}`, { src, height: 414 }], - ['width & height', `w=200&h=400&href=${href}`, { src, height: 400, width: 200 }], - ['aspect ratio string', `ar=16:9&href=${href}`, { src, aspectRatio: '16:9' }], - ['aspect ratio float', `ar=1.7&href=${href}`, { src, aspectRatio: 1.7 }], - [ - 'background color', - `f=jpeg&bg=%23333333&href=${href}`, - { src, format: 'jpeg', background: '#333333' }, - ], - ['crop fit', `fit=contain&href=${href}`, { src, fit: 'contain' }], - ['crop position', `p=right%20top&href=${href}`, { src, position: 'right top' }], - ].forEach(([description, params, expected]) => { - it(description, async () => { - const searchParams = new URLSearchParams(params); - const props = sharp.parseTransform(searchParams); - - expect(props).to.deep.equal(expected); - }); - }); - }); -}); diff --git a/packages/integrations/image/test/squoosh-service.test.js b/packages/integrations/image/test/squoosh-service.test.js deleted file mode 100644 index 9a3eabd8e..000000000 --- a/packages/integrations/image/test/squoosh-service.test.js +++ /dev/null @@ -1,78 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import { fileURLToPath, pathToFileURL } from 'node:url'; -import { join } from 'node:path'; -import { loadFixture } from './test-utils.js'; - -const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const toAstroImage = (relpath) => - '/@astroimage' + pathToFileURL(join(__dirname, 'fixtures/squoosh-service', relpath)).pathname; - -describe('Squoosh service', function () { - let fixture; - let devServer; - let $; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/squoosh-service/' }); - devServer = await fixture.startDevServer(); - const html = await fixture.fetch('/').then((res) => res.text()); - $ = cheerio.load(html); - }); - - after(async () => { - await devServer.stop(); - }); - - [ - { - title: 'Local images', - id: '#social-jpg', - url: toAstroImage('src/assets/social.jpg'), - query: { f: 'jpg', w: '506', h: '253' }, - }, - { - title: 'Remote images', - id: '#google', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - { - title: 'Remote images with relative protocol', - id: '#google-alt', - url: '/_image', - query: { - f: 'webp', - w: '544', - h: '184', - href: 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', - }, - }, - { - title: 'Public images', - id: '#hero', - url: '/_image', - query: { f: 'webp', w: '768', h: '414', href: '/hero.jpg' }, - }, - ].forEach(({ title, id, url, query }) => { - it(title, () => { - const image = $(id); - - const src = image.attr('src'); - const [route, params] = src.split('?'); - - expect(route).to.equal(url); - - const searchParams = new URLSearchParams(params); - - for (const [key, value] of Object.entries(query)) { - expect(searchParams.get(key)).to.equal(value); - } - }); - }); -}); diff --git a/packages/integrations/image/test/test-utils.js b/packages/integrations/image/test/test-utils.js deleted file mode 100644 index 122e90132..000000000 --- a/packages/integrations/image/test/test-utils.js +++ /dev/null @@ -1,12 +0,0 @@ -import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; - -export function loadFixture(inlineConfig) { - if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); - - // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath - // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` - return baseLoadFixture({ - ...inlineConfig, - root: new URL(inlineConfig.root, import.meta.url).toString(), - }); -} diff --git a/packages/integrations/image/test/with-mdx.test.js b/packages/integrations/image/test/with-mdx.test.js deleted file mode 100644 index 6b44bb6d4..000000000 --- a/packages/integrations/image/test/with-mdx.test.js +++ /dev/null @@ -1,69 +0,0 @@ -import { expect } from 'chai'; -import * as cheerio from 'cheerio'; -import sizeOf from 'image-size'; -import { fileURLToPath } from 'node:url'; -import { loadFixture } from './test-utils.js'; - -describe('Images in MDX - build', function () { - let fixture; - let $; - let html; - - before(async () => { - fixture = await loadFixture({ root: './fixtures/with-mdx/' }); - await fixture.build(); - - html = await fixture.readFile('/index.html'); - $ = cheerio.load(html); - }); - - function verifyImage(pathname, expected) { - const url = new URL('./fixtures/with-mdx/dist/' + pathname, import.meta.url); - const dist = fileURLToPath(url); - const result = sizeOf(dist); - expect(result).to.deep.equal(expected); - } - - [ - { - title: 'Local images', - id: '#social-jpg', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - }, - { - title: 'Inline imports', - id: '#inline', - regex: /^\/_astro\/social.\w{8}_\w{4,10}.jpg/, - size: { width: 506, height: 253, type: 'jpg' }, - }, - { - title: 'Remote images', - id: '#google', - regex: /^\/_astro\/googlelogo_color_272x92dp_\w{4,10}.webp/, - size: { width: 544, height: 184, type: 'webp' }, - }, - { - title: 'Public images', - id: '#hero', - regex: /^\/_astro\/hero_\w{4,10}.webp/, - size: { width: 768, height: 414, type: 'webp' }, - }, - { - title: 'Background color', - id: '#bg-color', - regex: /^\/_astro\/googlelogo_color_272x92dp_\w{4,10}.jpeg/, - size: { width: 544, height: 184, type: 'jpg' }, - }, - ].forEach(({ title, id, regex, size }) => { - it(title, () => { - const image = $(id); - - expect(image.attr('src')).to.match(regex); - expect(image.attr('width')).to.equal(size.width.toString()); - expect(image.attr('height')).to.equal(size.height.toString()); - - verifyImage(image.attr('src'), size); - }); - }); -}); |