Skip to content

Commit

Permalink
Add test cases and coverage log
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Oct 7, 2024
1 parent ccfbc01 commit 52e4a30
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"dev": "deno serve --watch source/app.ts",
"bump": "deno add jsr:@std/http npm:simple-icons@latest npm:svg-path-bbox npm:svgpath",
"update-lockfile": "deno cache --reload source/*.ts test/*.ts",
"test": "deno fmt --check && deno lint && deno check source/*.ts test/*.ts && deno test"
"test": "deno fmt --check && deno lint && deno check source/*.ts test/*.ts && deno test --clean --coverage && deno coverage",
"coverage": "deno test --clean --coverage && deno coverage --lcov --output=coverage/cov.lcov && genhtml -o coverage/html coverage/cov.lcov"
},
"fmt": {
"useTabs": true,
Expand All @@ -16,6 +17,7 @@
]
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.6",
"@std/http": "jsr:@std/http@^1.0.7",
"simple-icons": "npm:simple-icons@^13.13.0",
"svg-path-bbox": "npm:svg-path-bbox@^2.1.0",
Expand Down
12 changes: 12 additions & 0 deletions deno.lock

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

37 changes: 37 additions & 0 deletions test/icon.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as si from 'simple-icons';
import { assertEquals } from '@std/assert';
import { getIconSvg, getSimpleIcon } from '../source/icon.ts';

Deno.test('getSimpleIcon()', () => {
assertEquals(getSimpleIcon('simpleicons'), si.siSimpleicons);
assertEquals(getSimpleIcon('simpleicon'), null);
assertEquals(getSimpleIcon(undefined), null);
});

Deno.test('getIconSvg()', () => {
const icon = getSimpleIcon('simpleicons') as si.SimpleIcon;
assertEquals(
getIconSvg(icon, {}),
'<svg fill="#111111" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Simple Icons</title><path d="M12 0C8.688 0 6 2.688 6 6s2.688 6 6 6c4.64-.001 7.526 5.039 5.176 9.04h1.68A7.507 7.507 0 0 0 12 10.5 4.502 4.502 0 0 1 7.5 6c0-2.484 2.016-4.5 4.5-4.5s4.5 2.016 4.5 4.5H18c0-3.312-2.688-6-6-6Zm0 3a3 3 0 0 0 0 6c4 0 4-6 0-6Zm0 1.5A1.5 1.5 0 0 1 13.5 6v.002c-.002 1.336-1.617 2.003-2.561 1.058C9.995 6.115 10.664 4.5 12 4.5ZM7.5 15v1.5H9v6H4.5V24h15v-1.5H15v-6h1.5V15Zm3 1.5h3v6h-3zm-6 1.47c0 1.09.216 2.109.644 3.069h1.684A5.957 5.957 0 0 1 6 17.97Z"/></svg>',
);
assertEquals(
getIconSvg(icon, { color: 'blue' }),
'<svg fill="#0000ff" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Simple Icons</title><path d="M12 0C8.688 0 6 2.688 6 6s2.688 6 6 6c4.64-.001 7.526 5.039 5.176 9.04h1.68A7.507 7.507 0 0 0 12 10.5 4.502 4.502 0 0 1 7.5 6c0-2.484 2.016-4.5 4.5-4.5s4.5 2.016 4.5 4.5H18c0-3.312-2.688-6-6-6Zm0 3a3 3 0 0 0 0 6c4 0 4-6 0-6Zm0 1.5A1.5 1.5 0 0 1 13.5 6v.002c-.002 1.336-1.617 2.003-2.561 1.058C9.995 6.115 10.664 4.5 12 4.5ZM7.5 15v1.5H9v6H4.5V24h15v-1.5H15v-6h1.5V15Zm3 1.5h3v6h-3zm-6 1.47c0 1.09.216 2.109.644 3.069h1.684A5.957 5.957 0 0 1 6 17.97Z"/></svg>',
);
assertEquals(
getIconSvg(icon, { color: 'blue', darkModeColor: 'red' }),
'<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Simple Icons</title><style>path{fill:#0000ff} @media (prefers-color-scheme:dark){path{fill:#ff0000}}</style><path d="M12 0C8.688 0 6 2.688 6 6s2.688 6 6 6c4.64-.001 7.526 5.039 5.176 9.04h1.68A7.507 7.507 0 0 0 12 10.5 4.502 4.502 0 0 1 7.5 6c0-2.484 2.016-4.5 4.5-4.5s4.5 2.016 4.5 4.5H18c0-3.312-2.688-6-6-6Zm0 3a3 3 0 0 0 0 6c4 0 4-6 0-6Zm0 1.5A1.5 1.5 0 0 1 13.5 6v.002c-.002 1.336-1.617 2.003-2.561 1.058C9.995 6.115 10.664 4.5 12 4.5ZM7.5 15v1.5H9v6H4.5V24h15v-1.5H15v-6h1.5V15Zm3 1.5h3v6h-3zm-6 1.47c0 1.09.216 2.109.644 3.069h1.684A5.957 5.957 0 0 1 6 17.97Z"/></svg>',
);
assertEquals(
getIconSvg(icon, { size: '32' }),
'<svg fill="#111111" width="32" height="32" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Simple Icons</title><path d="M12 0C8.688 0 6 2.688 6 6s2.688 6 6 6c4.64-.001 7.526 5.039 5.176 9.04h1.68A7.507 7.507 0 0 0 12 10.5 4.502 4.502 0 0 1 7.5 6c0-2.484 2.016-4.5 4.5-4.5s4.5 2.016 4.5 4.5H18c0-3.312-2.688-6-6-6Zm0 3a3 3 0 0 0 0 6c4 0 4-6 0-6Zm0 1.5A1.5 1.5 0 0 1 13.5 6v.002c-.002 1.336-1.617 2.003-2.561 1.058C9.995 6.115 10.664 4.5 12 4.5ZM7.5 15v1.5H9v6H4.5V24h15v-1.5H15v-6h1.5V15Zm3 1.5h3v6h-3zm-6 1.47c0 1.09.216 2.109.644 3.069h1.684A5.957 5.957 0 0 1 6 17.97Z"/></svg>',
);
assertEquals(
getIconSvg(icon, { viewbox: 'auto' }),
'<svg fill="#111111" role="img" viewBox="0 0 15 24" xmlns="http://www.w3.org/2000/svg"><title>Simple Icons</title><path d="M7.5 0C4.188 0 1.5 2.688 1.5 6s2.688 6 6 6c4.64-0.001 7.526 5.039 5.176 9.04h1.68A7.507 7.507 0 0 0 7.5 10.5 4.502 4.502 0 0 1 3 6c0-2.484 2.016-4.5 4.5-4.5s4.5 2.016 4.5 4.5H13.5c0-3.312-2.688-6-6-6Zm0 3a3 3 0 0 0 0 6c4 0 4-6 0-6Zm0 1.5A1.5 1.5 0 0 1 9 6v0.002c-0.002 1.336-1.617 2.003-2.561 1.058C5.495 6.115 6.164 4.5 7.5 4.5ZM3 15v1.5H4.5v6H0V24h15v-1.5H10.5v-6h1.5V15Zm3 1.5h3v6h-3z m-6 1.47c0 1.09 0.216 2.109 0.644 3.069h1.684A5.957 5.957 0 0 1 1.5 17.97Z"/></svg>',
);
assertEquals(
getIconSvg(icon, { viewbox: 'auto', size: '32' }),
'<svg fill="#111111" width="20" height="32" role="img" viewBox="0 0 15 24" xmlns="http://www.w3.org/2000/svg"><title>Simple Icons</title><path d="M7.5 0C4.188 0 1.5 2.688 1.5 6s2.688 6 6 6c4.64-0.001 7.526 5.039 5.176 9.04h1.68A7.507 7.507 0 0 0 7.5 10.5 4.502 4.502 0 0 1 3 6c0-2.484 2.016-4.5 4.5-4.5s4.5 2.016 4.5 4.5H13.5c0-3.312-2.688-6-6-6Zm0 3a3 3 0 0 0 0 6c4 0 4-6 0-6Zm0 1.5A1.5 1.5 0 0 1 9 6v0.002c-0.002 1.336-1.617 2.003-2.561 1.058C5.495 6.115 6.164 4.5 7.5 4.5ZM3 15v1.5H4.5v6H0V24h15v-1.5H10.5v-6h1.5V15Zm3 1.5h3v6h-3z m-6 1.47c0 1.09 0.216 2.109 0.644 3.069h1.684A5.957 5.957 0 0 1 1.5 17.97Z"/></svg>',
);
});
18 changes: 18 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { assertEquals } from '@std/assert';
import { normalizeColor } from '../source/utils.ts';

const fallback = '__fallback__';

Deno.test('normalizeColor()', () => {
assertEquals(normalizeColor('blue', fallback), '#0000ff');

assertEquals(normalizeColor('0cf', fallback), '#0cf');
assertEquals(normalizeColor('0cff', fallback), '#0cff');
assertEquals(normalizeColor('00ccff', fallback), '#00ccff');
assertEquals(normalizeColor('00ccffff', fallback), '#00ccffff');

assertEquals(normalizeColor('unicorn', fallback), fallback);
assertEquals(normalizeColor('#0cf', fallback), fallback);
assertEquals(normalizeColor('0cfff', fallback), fallback);
assertEquals(normalizeColor('00ccfff', fallback), fallback);
});
2 changes: 1 addition & 1 deletion test/viewbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const icons = new Map<string, si.SimpleIcon>(
) => [k.slice(2).toLowerCase(), v as si.SimpleIcon]),
);

Deno.test('test auto-viewbox', () => {
Deno.test('check auto-viewbox', () => {
const result: Array<{ title: string; time: number; fail: boolean }> = [];
for (const [, icon] of icons) {
const start = performance.now();
Expand Down

0 comments on commit 52e4a30

Please sign in to comment.