文件
mynode/packages/lib/mimeUtils.test.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

34 行
1.2 KiB
TypeScript

// cSpell:ignore csvg cpath AAAANS
import * as mimeUtils from './mime-utils';
describe('mimeUtils', () => {
it('should get the file extension from the mime type', (async () => {
expect(mimeUtils.toFileExtension('image/jpeg')).toBe('jpg');
expect(mimeUtils.toFileExtension('image/jpg')).toBe('jpg');
expect(mimeUtils.toFileExtension('IMAGE/JPG')).toBe('jpg');
expect(mimeUtils.toFileExtension('')).toBe(null);
}));
it('should get the mime type from the filename', (async () => {
expect(mimeUtils.fromFilename('test.jpg')).toBe('image/jpeg');
expect(mimeUtils.fromFilename('test.JPG')).toBe('image/jpeg');
expect(mimeUtils.fromFilename('test.doesntexist')).toBe(null);
expect(mimeUtils.fromFilename('test')).toBe(null);
}));
it.each([
['Not a data URL.', 'text/plain'],
// No encoding type
['data:image/svg+xml,%3csvg%3e%3cpath fill=\'%23fff\' d=\'M1,2,3z\'/%3e%3c/svg%3e', 'image/svg+xml'],
// Shouldn't need a full data URL
['data:image/jpeg;base64,/9j/4AAQSkZJR...', 'image/jpeg'],
['data:image/png;base64,iVBORw0KGgoAAAANSUhEU...', 'image/png'],
])('should get MIME types from data URLs (case %#)', (url, expected) => {
expect(mimeUtils.fromDataUrl(url)).toBe(expected);
});
});