smartmime/test/test.ts

65 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-05-20 22:57:24 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2023-07-11 22:32:17 +00:00
import * as smartmime from '../ts/index.js';
2020-03-04 14:21:44 +00:00
tap.test('should detect image', async () => {
const filePath = 'file.jpg';
2024-05-20 22:57:24 +00:00
const fileType = await smartmime.detectMimeType({
path: filePath,
});
2020-03-04 14:21:44 +00:00
console.log(fileType);
2024-05-20 22:57:24 +00:00
expect(await smartmime.isBinary({
path: filePath,
})).toBeTrue();
2020-03-04 14:21:44 +00:00
});
tap.test('should detect text', async () => {
const filePath = 'file.svg';
2024-05-20 22:57:24 +00:00
const fileType = await smartmime.detectMimeType({
path: filePath,
});
2020-03-04 14:21:44 +00:00
console.log(fileType);
2024-05-20 22:57:24 +00:00
expect(await smartmime.isBinary({
path: filePath,
})).toBeFalse();
2020-03-04 14:21:44 +00:00
});
tap.test('should detect json', async () => {
const filePath = 'file.json';
2024-05-20 22:57:24 +00:00
const fileType = await smartmime.detectMimeType({
path: filePath,
});
2020-03-04 14:21:44 +00:00
console.log(fileType);
2024-05-20 22:57:24 +00:00
expect(await smartmime.isBinary({
path: filePath,
})).toBeFalse();
2020-03-04 14:21:44 +00:00
});
tap.test('should detect html', async () => {
const filePath = 'file.html';
2024-05-20 22:57:24 +00:00
const fileType = await smartmime.detectMimeType({
path: filePath,
});
expect(fileType.mime).toEqual('text/html');
2021-08-10 09:49:39 +00:00
console.log(fileType);
});
tap.test('should detect woff', async () => {
const filePath = 'file.woff';
2024-05-20 22:57:24 +00:00
const fileType = await smartmime.detectMimeType({
path: filePath,
});
expect(fileType.mime).toEqual('font/woff');
2021-08-10 09:49:39 +00:00
console.log(fileType);
});
tap.test('should detect woff2', async () => {
const filePath = 'file.woff2';
2024-05-20 22:57:24 +00:00
const fileType = await smartmime.detectMimeType({
path: filePath,
});
expect(fileType.mime).toEqual('font/woff2');
2020-03-04 14:21:44 +00:00
console.log(fileType);
});
tap.start();