0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/mdx/test/remark-imgattr.test.js
Oliver Speir df37366556
MDX remark image props (#9753)
* rearrange plugins and add props to Image component

* add tests and update lockfile

* add changeset

* re-rearrange plugin order, gfm/smartypants then user defined then image related then shiki/prism

* make more generic

* add more/better tests

* remove unused logger

---------

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
2024-01-23 18:18:09 -05:00

50 lines
1.3 KiB
JavaScript

import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from '../../../astro/test/test-utils.js';
const FIXTURE_ROOT = new URL('./fixtures/image-remark-imgattr/', import.meta.url);
describe('Testing remark plugins for image processing', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
describe('start dev server', () => {
/** @type {import('./test-utils').DevServer} */
let devServer;
before(async () => {
fixture = await loadFixture({
root: FIXTURE_ROOT,
});
devServer = await fixture.startDevServer();
});
after(async () => {
await devServer.stop();
});
describe('Test image attributes can be added by remark plugins', () => {
let $;
before(async () => {
let res = await fixture.fetch('/');
let html = await res.text();
$ = cheerio.load(html);
});
it('<img> has correct attributes', async () => {
let $img = $('img');
expect($img.attr('id')).to.equal('test');
expect($img.attr('sizes')).to.equal('(min-width: 600px) 600w, 300w');
expect($img.attr('srcset')).to.not.be.empty;
});
it('<img> was processed properly', async () => {
let $img = $('img');
expect(new URL($img.attr('src'), 'http://example.com').searchParams.get('w')).to.equal(
'300'
);
});
});
});
});