91380378ce
* feat(vercel): Use Sharp in dev instead of Squoosh by default * fix(build): * nit: adjust with feedback * fix: imports * Update packages/integrations/vercel/README.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * docs: small change in other part of the README --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
77 lines
2.1 KiB
JavaScript
77 lines
2.1 KiB
JavaScript
import { expect } from 'chai';
|
|
import * as cheerio from 'cheerio';
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
describe('Image', () => {
|
|
/** @type {import('../../../astro/test/test-utils.js').Fixture} */
|
|
let fixture;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/image/',
|
|
});
|
|
await fixture.build();
|
|
});
|
|
|
|
it('build successful', async () => {
|
|
expect(await fixture.readFile('../.vercel/output/static/index.html')).to.be.ok;
|
|
});
|
|
|
|
it('has link to vercel in build with proper attributes', async () => {
|
|
const html = await fixture.readFile('../.vercel/output/static/index.html');
|
|
const $ = cheerio.load(html);
|
|
const img = $('#basic-image img');
|
|
|
|
expect(img.attr('src').startsWith('/_vercel/image?url=_astr')).to.be.true;
|
|
expect(img.attr('loading')).to.equal('lazy');
|
|
expect(img.attr('width')).to.equal('225');
|
|
});
|
|
|
|
it('has proper vercel config', async () => {
|
|
const vercelConfig = JSON.parse(await fixture.readFile('../.vercel/output/config.json'));
|
|
|
|
expect(vercelConfig.images).to.deep.equal({
|
|
sizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
|
|
domains: ['astro.build'],
|
|
remotePatterns: [
|
|
{
|
|
protocol: 'https',
|
|
hostname: '**.amazonaws.com',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
describe('dev', () => {
|
|
let devServer;
|
|
|
|
before(async () => {
|
|
devServer = await fixture.startDevServer();
|
|
});
|
|
|
|
after(async () => {
|
|
await devServer.stop();
|
|
});
|
|
|
|
it('has link to local image in dev with proper attributes', async () => {
|
|
const html = await fixture.fetch('/').then((res) => res.text());
|
|
const $ = cheerio.load(html);
|
|
const img = $('#basic-image img');
|
|
|
|
expect(img.attr('src').startsWith('/_image?href=')).to.be.true;
|
|
expect(img.attr('loading')).to.equal('lazy');
|
|
expect(img.attr('width')).to.equal('225');
|
|
});
|
|
|
|
it('supports SVGs', async () => {
|
|
const html = await fixture.fetch('/').then((res) => res.text());
|
|
const $ = cheerio.load(html);
|
|
const img = $('#svg img');
|
|
const src = img.attr('src');
|
|
|
|
const res = await fixture.fetch(src);
|
|
expect(res.status).to.equal(200);
|
|
expect(res.headers.get('content-type')).to.equal('image/svg+xml');
|
|
});
|
|
});
|
|
});
|