This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,36 @@
import test from 'ava';
import getFileExtension from './getFileExtension';
test('returns the correct file extension', (t) => {
const extensions = ['.jpeg', '.js', '.css', '.json', '.xml'];
const filePath = 'source/static/images/hello-world';
extensions.forEach((ext) => {
t.true(getFileExtension(`${filePath}${ext}`) === ext);
});
});
test('sanitize file hash', (t) => {
const hashes = ['?', '#'];
const filePath = 'source/static/images/hello-world.jpeg';
hashes.forEach((hash) => {
t.true(getFileExtension(`${filePath}${hash}d587bbd6e38337f5accd`) === '.jpeg');
});
});
test('returns empty string when there is no file extension', (t) => {
const filePath = 'source/static/resource';
t.true(getFileExtension(filePath) === '');
});
test('should work even with null/undefined arg', (t) => {
const filePaths = ['', null, undefined];
filePaths.forEach((path) => {
t.true(getFileExtension(path) === '');
});
});