Skip to content

Commit

Permalink
fix(optimize-css): do not print diff if zero
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Apr 8, 2024
1 parent 80e7b7a commit 80cf4aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/plugins/print-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export function printDiff(props: {

const original_size = stringSizeInKB(original_css.toString());
const optimized_size = stringSizeInKB(optimized_css);

if (original_size === optimized_size) {
return;
}

const original = toHumanReadableSize(original_size);
const optimized = toHumanReadableSize(optimized_size);
const original_display = padIfNeeded(original, optimized);
Expand Down
14 changes: 14 additions & 0 deletions tests/print-diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,18 @@ describe("print-diff", () => {
["After: ", "0.02 kB", "(-37.5%)\n"],
]);
});

test("no diff", () => {
const log = jest.spyOn(console, "log");

expect(
printDiff({
original_css: "body { color: red; }",
optimized_css: "body { color: red; }",
id: "id",
}),
);

expect(log.mock.calls).toEqual([]);
});
});

0 comments on commit 80cf4aa

Please sign in to comment.