Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"imports": {
"@std/cli": "jsr:@std/cli@^1.0.27",
"@std/fs": "jsr:@std/fs@^1.0.22",
"@std/path": "jsr:@std/path@^1.1.4",
"@std/assert": "https://deno.land/std@0.224.0/assert/mod.ts",
"@std/cli/parse-args": "https://deno.land/std@0.224.0/cli/parse_args.ts",
"@std/fs/exists": "https://deno.land/std@0.224.0/fs/exists.ts",
"@std/path": "https://deno.land/std@0.224.0/path/mod.ts",
"sharp": "npm:sharp@^0.34.5"
},
"tasks": {
"compile": "deno compile --allow-all main.ts"
"compile": "deno compile --allow-all main.ts",
"test": "deno test --allow-read --allow-env --allow-ffi"
},
"version": "0.0.1"
}
150 changes: 112 additions & 38 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions src/lib.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { assert, assertEquals, assertRejects } from "@std/assert";
import { getImageProperties } from "./lib.ts";

Deno.test("getImageProperties - should return correct properties for valid PNG image", async () => {
const imagePath = "test.png";
const properties = await getImageProperties(imagePath);

assertEquals(properties.width, 512);
assertEquals(properties.height, 512);
assertEquals(properties.format, "png");
});

Deno.test("getImageProperties - should throw error for non-existent file", async () => {
const imagePath = "non-existent-file.png";

await assertRejects(
async () => {
await getImageProperties(imagePath);
},
Deno.errors.NotFound,
);
});

Deno.test("getImageProperties - should return correct properties for 3x2 checker image", async () => {
const imagePath = "3x2-checker.png";
const properties = await getImageProperties(imagePath);

// Verify it has correct aspect ratio (3:2)
assertEquals(properties.format, "png");
const aspectRatio = properties.width / properties.height;
assertEquals(aspectRatio, 1.5);
});

Deno.test("getImageProperties - should return properties with valid types", async () => {
const imagePath = "test.png";
const properties = await getImageProperties(imagePath);

// Verify property types
assertEquals(typeof properties.width, "number");
assertEquals(typeof properties.height, "number");
assertEquals(typeof properties.format, "string");

// Verify positive dimensions
assert(properties.width > 0);
assert(properties.height > 0);
});