smartmime/test/test.ts

65 lines
1.5 KiB
TypeScript

import { expect, tap } from '@push.rocks/tapbundle';
import * as smartmime from '../ts/index.js';
tap.test('should detect image', async () => {
const filePath = 'file.jpg';
const fileType = await smartmime.detectMimeType({
path: filePath,
});
console.log(fileType);
expect(await smartmime.isBinary({
path: filePath,
})).toBeTrue();
});
tap.test('should detect text', async () => {
const filePath = 'file.svg';
const fileType = await smartmime.detectMimeType({
path: filePath,
});
console.log(fileType);
expect(await smartmime.isBinary({
path: filePath,
})).toBeFalse();
});
tap.test('should detect json', async () => {
const filePath = 'file.json';
const fileType = await smartmime.detectMimeType({
path: filePath,
});
console.log(fileType);
expect(await smartmime.isBinary({
path: filePath,
})).toBeFalse();
});
tap.test('should detect html', async () => {
const filePath = 'file.html';
const fileType = await smartmime.detectMimeType({
path: filePath,
});
expect(fileType.mime).toEqual('text/html');
console.log(fileType);
});
tap.test('should detect woff', async () => {
const filePath = 'file.woff';
const fileType = await smartmime.detectMimeType({
path: filePath,
});
expect(fileType.mime).toEqual('font/woff');
console.log(fileType);
});
tap.test('should detect woff2', async () => {
const filePath = 'file.woff2';
const fileType = await smartmime.detectMimeType({
path: filePath,
});
expect(fileType.mime).toEqual('font/woff2');
console.log(fileType);
});
tap.start();