0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

test: add test in the Node adapter for astro:assets (#7734)

This commit is contained in:
Erika 2023-07-26 23:58:47 +02:00 committed by GitHub
parent 78549e9e7b
commit 477f2af527
4 changed files with 59 additions and 0 deletions

View file

@ -0,0 +1,13 @@
{
"name": "@test/nodejs-image",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*",
"@astrojs/node": "workspace:*"
},
"scripts": {
"build": "astro build",
"preview": "astro preview"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

View file

@ -0,0 +1,6 @@
---
import { Image } from "astro:assets";
import penguin from "../assets/some_penguin.png";
---
<Image src={penguin} alt="Penguins" width={50} />

View file

@ -0,0 +1,40 @@
import { expect } from 'chai';
import nodejs from '../dist/index.js';
import { loadFixture } from './test-utils.js';
describe('Image endpoint', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let devPreview;
before(async () => {
fixture = await loadFixture({
root: './fixtures/image/',
output: 'server',
adapter: nodejs({ mode: 'standalone' }),
experimental: {
assets: true,
},
});
await fixture.build();
devPreview = await fixture.preview();
});
after(async () => {
await devPreview.stop();
});
it('it returns images', async () => {
const res = await fixture.fetch('/');
expect(res.status).to.equal(200);
const resImage = await fixture.fetch(
'/_image?href=/_astro/some_penguin.97ef5f92.png&w=50&f=webp'
);
console.log(resImage);
const content = resImage.text();
console.log(content);
expect(resImage.status).to.equal(200);
});
});