mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
chore: add test-image-service
This commit is contained in:
parent
6a23bd60f9
commit
6eaac77a47
3 changed files with 41 additions and 7 deletions
|
@ -1,15 +1,17 @@
|
|||
import vercel from '@astrojs/vercel/static';
|
||||
import { defineConfig } from 'astro/config';
|
||||
import { testImageService } from '../../../../../astro/test/test-image-service.js';
|
||||
import { testImageService } from '../../test-image-service.js';
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel({imageService: true}),
|
||||
adapter: vercel({ imageService: true }),
|
||||
image: {
|
||||
service: testImageService(),
|
||||
domains: ['astro.build'],
|
||||
remotePatterns: [{
|
||||
protocol: 'https',
|
||||
hostname: '**.amazonaws.com',
|
||||
}],
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: '**.amazonaws.com',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
|
|
@ -22,7 +22,7 @@ describe('Serverless prerender', () => {
|
|||
const [file] = await fixture.glob(
|
||||
'../.vercel/output/functions/_render.func/packages/integrations/vercel/test/fixtures/serverless-prerender/.vercel/output/_functions/pages/_image.astro.mjs'
|
||||
);
|
||||
const contents = await fixture.readFile(file);
|
||||
const contents = await fixture.readfile(file);
|
||||
assert.ok(!contents.includes('const outDir ='), "outDir is tree-shaken if it's not imported");
|
||||
});
|
||||
|
||||
|
|
32
packages/integrations/vercel/test/test-image-service.js
Normal file
32
packages/integrations/vercel/test/test-image-service.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { fileURLToPath } from 'node:url';
|
||||
import { baseService } from 'astro/assets';
|
||||
|
||||
/**
|
||||
* stub image service that returns images as-is without optimization
|
||||
* @param {{ foo?: string }} [config]
|
||||
*/
|
||||
export function testImageService(config = {}) {
|
||||
return {
|
||||
entrypoint: fileURLToPath(import.meta.url),
|
||||
config,
|
||||
};
|
||||
}
|
||||
|
||||
/** @type {import("../dist/@types/astro").LocalImageService} */
|
||||
export default {
|
||||
...baseService,
|
||||
propertiesToHash: [...baseService.propertiesToHash, 'data-custom'],
|
||||
getHTMLAttributes(options, serviceConfig) {
|
||||
options['data-service'] = 'my-custom-service';
|
||||
if (serviceConfig.service.config.foo) {
|
||||
options['data-service-config'] = serviceConfig.service.config.foo;
|
||||
}
|
||||
return baseService.getHTMLAttributes(options);
|
||||
},
|
||||
async transform(buffer, transform) {
|
||||
return {
|
||||
data: buffer,
|
||||
format: transform.format,
|
||||
};
|
||||
},
|
||||
};
|
Loading…
Add table
Reference in a new issue