mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
af867f3910
* chore: changeset
* feat: add experimental responsive images config option (#12378)
* feat: add experimental responsive images config option
* Apply suggestions from code review
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* Update config types
* Move config into `images`
* Move jsdocs
---------
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* feat: add responsive image component (#12381)
* feat: add experimental responsive images config option
* Apply suggestions from code review
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* Update config types
* Move config into `images`
* Move jsdocs
* wip: responsive image component
* Improve srcset logic
* Improve fixture
* Lock
* Update styling
* Fix style prop handling
* Update test (there's an extra style for images now)
* Safely access the src props
* Remove unused export
* Handle priority images
* Consolidate styles
* Update tests
* Comment
* Refactor srcset
* Avoid dupes of original image
* Calculate missing dimensions
* Bugfixes
* Add tests
* Fix test
* Correct order
* Lint
* Fix fspath
* Update test
* Fix test
* Conditional component per flag
* Fix class concatenation
* Remove logger
* Rename helper
* Add comments
* Format
* Fix markdoc tests
* Add test for style tag
---------
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* feat: add crop support to image services (#12414)
* wip: add crop support to image services
* Add tests
* Strip crop attributes
* Don't upscale
* Format
* Get build working properly
* Changes from review
* Fix jsdoc
* feat: add responsive support to picture component (#12423)
* feat: add responsive support to picture component
* Add picture tests
* Fix test
* Implement own define vars
* Share logic
* Prevent extra astro-* class
* Use dataset scoping
* Revert unit test
* Revert "Fix test"
This reverts commit f9ec6e2938
.
* Changes from review
* docs: add docs for responsive images (#12429)
* docs: add responsive images flag docs
* docs: adds jsdoc for image components
* chore: updates from review
* Fix jsdoc
* Changes from review
* Add breakpoints option
* typo
---------
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
93 lines
3.2 KiB
JavaScript
93 lines
3.2 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { after, before, describe, it } from 'node:test';
|
|
import { parseHTML } from 'linkedom';
|
|
import { loadFixture } from '../../../astro/test/test-utils.js';
|
|
|
|
const root = new URL('./fixtures/image-assets/', import.meta.url);
|
|
|
|
describe('Markdoc - Image assets', () => {
|
|
let baseFixture;
|
|
|
|
before(async () => {
|
|
baseFixture = await loadFixture({
|
|
root,
|
|
});
|
|
});
|
|
|
|
describe('dev', () => {
|
|
let devServer;
|
|
|
|
before(async () => {
|
|
devServer = await baseFixture.startDevServer();
|
|
});
|
|
|
|
after(async () => {
|
|
await devServer.stop();
|
|
});
|
|
|
|
it('uses public/ image paths unchanged', async () => {
|
|
const res = await baseFixture.fetch('/');
|
|
const html = await res.text();
|
|
const { document } = parseHTML(html);
|
|
assert.equal(document.querySelector('#public > img')?.src, '/favicon.svg');
|
|
});
|
|
|
|
it('transforms relative image paths to optimized path', async () => {
|
|
const res = await baseFixture.fetch('/');
|
|
const html = await res.text();
|
|
const { document } = parseHTML(html);
|
|
assert.match(
|
|
document.querySelector('#relative > img')?.src,
|
|
/\/_image\?href=.*%2Fsrc%2Fassets%2Frelative%2Foar.jpg%3ForigWidth%3D420%26origHeight%3D630%26origFormat%3Djpg&w=420&h=630&f=webp/,
|
|
);
|
|
});
|
|
|
|
it('transforms aliased image paths to optimized path', async () => {
|
|
const res = await baseFixture.fetch('/');
|
|
const html = await res.text();
|
|
const { document } = parseHTML(html);
|
|
assert.match(
|
|
document.querySelector('#alias > img')?.src,
|
|
/\/_image\?href=.*%2Fsrc%2Fassets%2Falias%2Fcityscape.jpg%3ForigWidth%3D420%26origHeight%3D280%26origFormat%3Djpg&w=420&h=280&f=webp/,
|
|
);
|
|
});
|
|
|
|
it('passes images inside image tags to configured image component', async () => {
|
|
const res = await baseFixture.fetch('/');
|
|
const html = await res.text();
|
|
const { document } = parseHTML(html);
|
|
assert.equal(document.querySelector('#component > img')?.className, 'custom-styles');
|
|
});
|
|
});
|
|
|
|
describe('build', () => {
|
|
before(async () => {
|
|
await baseFixture.build();
|
|
});
|
|
|
|
it('uses public/ image paths unchanged', async () => {
|
|
const html = await baseFixture.readFile('/index.html');
|
|
const { document } = parseHTML(html);
|
|
assert.equal(document.querySelector('#public > img')?.src, '/favicon.svg');
|
|
});
|
|
|
|
it('transforms relative image paths to optimized path', async () => {
|
|
const html = await baseFixture.readFile('/index.html');
|
|
const { document } = parseHTML(html);
|
|
assert.match(document.querySelector('#relative > img')?.src, /^\/_astro\/oar.*\.webp$/);
|
|
});
|
|
|
|
it('transforms aliased image paths to optimized path', async () => {
|
|
const html = await baseFixture.readFile('/index.html');
|
|
const { document } = parseHTML(html);
|
|
assert.match(document.querySelector('#alias > img')?.src, /^\/_astro\/cityscape.*\.webp$/);
|
|
});
|
|
|
|
it('passes images inside image tags to configured image component', async () => {
|
|
const html = await baseFixture.readFile('/index.html');
|
|
const { document } = parseHTML(html);
|
|
assert.equal(document.querySelector('#component > img')?.className, 'custom-styles');
|
|
assert.match(document.querySelector('#component > img')?.src, /^\/_astro\/oar.*\.webp$/);
|
|
});
|
|
});
|
|
});
|