source: trip-planner-front/node_modules/mime/src/test.js@ 6fe77af

Last change on this file since 6fe77af was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[6a3a178]1/**
2 * Usage: node test.js
3 */
4
5var mime = require('../mime');
6var assert = require('assert');
7var path = require('path');
8
9//
10// Test mime lookups
11//
12
13assert.equal('text/plain', mime.lookup('text.txt')); // normal file
14assert.equal('text/plain', mime.lookup('TEXT.TXT')); // uppercase
15assert.equal('text/plain', mime.lookup('dir/text.txt')); // dir + file
16assert.equal('text/plain', mime.lookup('.text.txt')); // hidden file
17assert.equal('text/plain', mime.lookup('.txt')); // nameless
18assert.equal('text/plain', mime.lookup('txt')); // extension-only
19assert.equal('text/plain', mime.lookup('/txt')); // extension-less ()
20assert.equal('text/plain', mime.lookup('\\txt')); // Windows, extension-less
21assert.equal('application/octet-stream', mime.lookup('text.nope')); // unrecognized
22assert.equal('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
23
24//
25// Test extensions
26//
27
28assert.equal('txt', mime.extension(mime.types.text));
29assert.equal('html', mime.extension(mime.types.htm));
30assert.equal('bin', mime.extension('application/octet-stream'));
31assert.equal('bin', mime.extension('application/octet-stream '));
32assert.equal('html', mime.extension(' text/html; charset=UTF-8'));
33assert.equal('html', mime.extension('text/html; charset=UTF-8 '));
34assert.equal('html', mime.extension('text/html; charset=UTF-8'));
35assert.equal('html', mime.extension('text/html ; charset=UTF-8'));
36assert.equal('html', mime.extension('text/html;charset=UTF-8'));
37assert.equal('html', mime.extension('text/Html;charset=UTF-8'));
38assert.equal(undefined, mime.extension('unrecognized'));
39
40//
41// Test node.types lookups
42//
43
44assert.equal('font/woff', mime.lookup('file.woff'));
45assert.equal('application/octet-stream', mime.lookup('file.buffer'));
46// TODO: Uncomment once #157 is resolved
47// assert.equal('audio/mp4', mime.lookup('file.m4a'));
48assert.equal('font/otf', mime.lookup('file.otf'));
49
50//
51// Test charsets
52//
53
54assert.equal('UTF-8', mime.charsets.lookup('text/plain'));
55assert.equal('UTF-8', mime.charsets.lookup(mime.types.js));
56assert.equal('UTF-8', mime.charsets.lookup(mime.types.json));
57assert.equal(undefined, mime.charsets.lookup(mime.types.bin));
58assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
59
60console.log('\nAll tests passed');
Note: See TracBrowser for help on using the repository browser.