Skip to content

Commit

Permalink
fix(netlify): correct "fit" param (#97)
Browse files Browse the repository at this point in the history
* fix(netlify): correct "fit" param

* fix: update test
  • Loading branch information
ascorbic committed Nov 15, 2023
1 parent 07dbe42 commit 66a48d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/transformers/netlify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const remoteImage = "https://example.org/static/moose.png";
Deno.test("netlify", async (t) => {
await t.step("should parse a URL", () => {
const result = parse(
"https://example.netlify.app/.netlify/images?url=/cappadocia.jpg&w=200&h=300&fit=crop&q=80&fm=webp",
"https://example.netlify.app/.netlify/images?url=/cappadocia.jpg&w=200&h=300&fit=cover&q=80&fm=webp",
);
assertEquals(
result.width,
Expand All @@ -35,7 +35,7 @@ Deno.test("netlify", async (t) => {
});
assertEquals(
result?.toString(),
"https://example.netlify.app/.netlify/images?w=200&h=100&fit=crop&url=%2Fcappadocia.jpg",
"https://example.netlify.app/.netlify/images?w=200&h=100&fit=cover&url=%2Fcappadocia.jpg",
);
});

Expand All @@ -48,15 +48,15 @@ Deno.test("netlify", async (t) => {
});
assertEquals(
result?.toString(),
"/.netlify/images?w=200&h=100&fit=crop&url=https%3A%2F%2Fexample.org%2Fstatic%2Fbuffalo.png",
"/.netlify/images?w=200&h=100&fit=cover&url=https%3A%2F%2Fexample.org%2Fstatic%2Fbuffalo.png",
);
});

await t.step("should not set height if not provided", () => {
const result = transform({ url: img, width: 200 });
assertEquals(
result?.toString(),
"https://example.netlify.app/.netlify/images?w=200&fit=crop&url=%2Fcappadocia.jpg",
"https://example.netlify.app/.netlify/images?w=200&fit=cover&url=%2Fcappadocia.jpg",
);
});

Expand All @@ -66,7 +66,7 @@ Deno.test("netlify", async (t) => {
const result = transform({ url, width: 200 });
assertEquals(
result?.toString(),
"https://example.netlify.app/.netlify/images?w=200&fit=crop&url=%2Fcappadocia.jpg",
"https://example.netlify.app/.netlify/images?w=200&fit=cover&url=%2Fcappadocia.jpg",
);
});

Expand All @@ -78,7 +78,7 @@ Deno.test("netlify", async (t) => {
});
assertEquals(
result?.toString(),
"https://example.netlify.app/.netlify/images?w=201&h=100&fit=crop&url=%2Fcappadocia.jpg",
"https://example.netlify.app/.netlify/images?w=201&h=100&fit=cover&url=%2Fcappadocia.jpg",
);
});

Expand All @@ -91,7 +91,7 @@ Deno.test("netlify", async (t) => {
});
assertEquals(
result?.toString(),
"/.netlify/images?w=100&h=200&fm=webp&fit=crop&url=https%3A%2F%2Fexample.org%2Fstatic%2Fmoose.png",
"/.netlify/images?w=100&h=200&fm=webp&fit=cover&url=https%3A%2F%2Fexample.org%2Fstatic%2Fmoose.png",
);
});

Expand All @@ -104,7 +104,7 @@ Deno.test("netlify", async (t) => {
});
assertEquals(
result?.toString(),
"/.netlify/images?w=100&h=200&fm=webp&fit=crop&url=%2Fstatic%2Fmoose.png",
"/.netlify/images?w=100&h=200&fm=webp&fit=cover&url=%2Fstatic%2Fmoose.png",
);
});

Expand All @@ -122,7 +122,7 @@ Deno.test("netlify", async (t) => {
});
assertEquals(
result?.toString(),
"https://petsofnetlify.com/.netlify/images?w=100&h=200&fm=webp&fit=crop&url=https%3A%2F%2Fexample.org%2Fstatic%2Fmoose.png",
"https://petsofnetlify.com/.netlify/images?w=100&h=200&fm=webp&fit=cover&url=https%3A%2F%2Fexample.org%2Fstatic%2Fmoose.png",
);
});

Expand All @@ -135,7 +135,7 @@ Deno.test("netlify", async (t) => {
});
assertEquals(
result?.toString(),
"/.netlify/images?q=10&w=200&h=100&fit=crop&url=https%3A%2F%2Fexample.org%2Fstatic%2Fbuffalo.png",
"/.netlify/images?q=10&w=200&h=100&fit=cover&url=https%3A%2F%2Fexample.org%2Fstatic%2Fbuffalo.png",
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/transformers/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const generate: UrlGenerator<NetlifyParams> = (
setParamIfDefined(url, "w", width, true, true);
setParamIfDefined(url, "h", height, true, true);
setParamIfDefined(url, "fm", format);
setParamIfUndefined(url, "fit", "crop");
setParamIfUndefined(url, "fit", "cover");
url.searchParams.set("url", base.toString());
return toCanonicalUrlString(url);
};
Expand Down

0 comments on commit 66a48d4

Please sign in to comment.