mime.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. const test = require('tap').test;
  3. const mime = require('mime');
  4. test('mime package lookup', (t) => {
  5. t.plan(7);
  6. t.equal(mime.lookup('/path/to/file.css'), 'text/css');
  7. t.equal(mime.lookup('/path/to/file.js'), 'application/javascript');
  8. t.equal(mime.lookup('/path/to/file.mjs'), 'application/javascript');
  9. t.equal(mime.lookup('/path/to/file.txt'), 'text/plain');
  10. t.equal(mime.lookup('file.txt'), 'text/plain');
  11. t.equal(mime.lookup('.TXT'), 'text/plain');
  12. t.equal(mime.lookup('htm'), 'text/html');
  13. t.end();
  14. });
  15. test('custom definition of mime-type with the mime package', (t) => {
  16. t.plan(1);
  17. mime.define({
  18. 'application/xml': ['opml'],
  19. });
  20. t.equal(mime.lookup('.opml'), 'application/xml');
  21. t.end();
  22. });
  23. test('custom definition of mime-type with a .types file', (t) => {
  24. t.plan(2);
  25. try {
  26. mime.load('test/public/custom_mime_type.types');
  27. } catch (e) {
  28. t.fail(e.message);
  29. t.end();
  30. }
  31. t.equal(mime.lookup('.opml'), 'application/foo'); // see public/custom_mime_type.types
  32. t.throws(mime.load.bind(mime, 'public/this_file_does_not_exist.types'));
  33. t.end();
  34. });