mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
00c605ce35
* WIP: simplifying the use of `fs` vs. the vite plugin * removing a few node deps (etag and node:path) * adding ts defs for sharp * using the same mime package as astro's core App * fixing file URL support in windows * using file URLs when loading local image metadata * fixing a bug in the etag helper * Windows compat * splitting out dev & build tests * why do these suites fail in parallel? * one last windows compat case * Adding tests for treating /public images the same as remote URLs * a couple fixes for Astro's `base` config * adding base path tests for SSR * fixing a bad merge, lost the kleur dependency * adding a test suite for images + MDX * chore: add changeset * simplifying the with-mdx tests * bugfix: don't duplicate the period when using existing file extensions * let Vite cache the image loader service * adding some docs for using /public images * fixing changeset * Update packages/integrations/image/README.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update packages/integrations/image/README.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * nit: minor README syntax tweaks Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
100 lines
2.5 KiB
JavaScript
100 lines
2.5 KiB
JavaScript
import { expect } from 'chai';
|
|
import * as cheerio from 'cheerio';
|
|
import sizeOf from 'image-size';
|
|
import { fileURLToPath } from '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);
|
|
});
|
|
|
|
describe('Landscape images', () => {
|
|
const hashes = [
|
|
'/Landscape_0.080ebd7a_ZdTMkT.jpg',
|
|
'/Landscape_1.c92e81c9_4Eikw.jpg',
|
|
'/Landscape_2.f54c85e5_1iKxtI.jpg',
|
|
'/Landscape_3.8e20af03_Z2sFwFL.jpg',
|
|
'/Landscape_4.15f511b0_1dNJQt.jpg',
|
|
'/Landscape_5.6d88c17f_ZtLntP.jpg',
|
|
'/Landscape_6.1a88f6d8_Z1Pl4xy.jpg',
|
|
'/Landscape_7.cb1008c2_Z1JYr40.jpg',
|
|
'/Landscape_8.3d2837d2_1xTOBN.jpg'
|
|
];
|
|
|
|
it('includes <img> attributes', () => {
|
|
for (let i = 0; i < 9; i++) {
|
|
const image = $(`#landscape-${i}`);
|
|
|
|
expect(image.attr('src')).to.equal(hashes[i]);
|
|
expect(image.attr('width')).to.equal('1800');
|
|
expect(image.attr('height')).to.equal('1200');
|
|
}
|
|
});
|
|
|
|
it('built the optimized image', () => {
|
|
for (let i = 0; i < 9; i++) {
|
|
verifyImage(hashes[i], {
|
|
width: 1800,
|
|
height: 1200,
|
|
type: 'jpg',
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Portait images', () => {
|
|
const hashes = [
|
|
'/Portrait_0.e09ae908_5e5uz.jpg',
|
|
'/Portrait_1.c7b4942e_1RJQep.jpg',
|
|
'/Portrait_2.8e8be39f_T6sr4.jpg',
|
|
'/Portrait_3.1dcc58b4_Z1uaoxA.jpg',
|
|
'/Portrait_4.2f89d418_ZLQlNB.jpg',
|
|
'/Portrait_5.b3b6cc6f_Z23Ek26.jpg',
|
|
'/Portrait_6.94e06390_ak2Ek.jpg',
|
|
'/Portrait_7.9ffdecfe_Z1S4klG.jpg',
|
|
'/Portrait_8.9d01343d_2dak03.jpg'
|
|
];
|
|
|
|
it('includes <img> attributes', () => {
|
|
for (let i = 0; i < 9; i++) {
|
|
const image = $(`#portrait-${i}`);
|
|
|
|
expect(image.attr('src')).to.equal(hashes[i]);
|
|
expect(image.attr('width')).to.equal('1200');
|
|
expect(image.attr('height')).to.equal('1800');
|
|
}
|
|
});
|
|
|
|
it('built the optimized image', () => {
|
|
for (let i = 0; i < 9; i++) {
|
|
verifyImage(hashes[i], {
|
|
width: 1200,
|
|
height: 1800,
|
|
type: 'jpg',
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|