mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
f8f4d49aba
* WIP: emit assets to _astro * chore: better _astro handling * refactor: emit server assets to `chunks/` * chore: update /asset tests * test: add explicit build output tests * fix: update image to emit to configured asset path * chore: update changeset * chore: update image tests * chore: update image tests * test: update css test * test: update bundling test * test: update tests * Update packages/astro/src/@types/astro.ts Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * Update packages/astro/src/@types/astro.ts Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * Update packages/astro/src/@types/astro.ts Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * chore: add clarifying comment Co-authored-by: Nate Moore <nate@astro.build> Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
66 lines
1.6 KiB
JavaScript
66 lines
1.6 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);
|
|
});
|
|
|
|
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',
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|