polymech-astro/packages/imagetools_3/tests/commons.js
2025-08-27 21:12:10 +02:00

53 lines
1.6 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
const testCachePath = path.join(process.cwd(), "test_cache/");
export const invalid_urls = ["https://example.com/non-existent-image.jpg"];
export const real_urls = [
"https://picsum.photos/200/300",
"https://fastly.picsum.photos/id/343/200/300.jpg?hmac=_7ttvLezG-XONDvp0ILwQCv50ivQa_oewm7m6xV2uZA",
"https://assets.osr-plastic.org//products/sheetpress/cassandra-edczmax-rc2/media/gallery/latest_controller.jpg",
"https://images.unsplash.com/photo-1555066931-4365d14bab8c?w=800&h=400&fit=crop",
"https://assets.osr-plastic.org//products/sheetpress/cassandra-edczmax-rc2/media/samples/30mm.jpg",
"https://assets.osr-plastic.org//products/sheetpress/cassandra-edczmax-rc2/media/samples/DSC05051.JPG",
];
export const default_options = {
format: ["webp", "avif", "jpg"],
formatOptions: {
jpg: {
quality: 80,
},
png: {
quality: 80,
},
webp: {
quality: 50,
},
},
placeholder: "blurred",
includeSourceFormat: false,
fallbackFormat: ["webp", "avif", "jpg"],
// cacheRoot: testCachePath,
sizes: (breakpoints) => {
const maxWidth = breakpoints[breakpoints.length - 1];
return `(min-width: ${maxWidth}px) ${maxWidth}px, 100vw`;
},
};
export function setup() {
// Create a temporary cache directory for tests
if (!fs.existsSync(testCachePath)) {
fs.mkdirSync(testCachePath, { recursive: true });
}
}
export function teardown() {
// Clean up the temporary cache directory
if (fs.existsSync(testCachePath)) {
// fs.rmSync(testCachePath, { recursive: true, force: true });
}
}