0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-mime-whatwg.js
Bradley Farias 87cdf7d412
util: add MIME utilities (#21128)
Co-authored-by: Rich Trott <rtrott@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/21128
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-10-19 04:26:16 +02:00

24 lines
720 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { MIMEType } = require('util');
const fixtures = require('../common/fixtures');
function test(mimes) {
for (const entry of mimes) {
if (typeof entry === 'string') continue;
const { input, output } = entry;
if (output === null) {
assert.throws(() => new MIMEType(input), /ERR_INVALID_MIME_SYNTAX/i);
} else {
const str = `${new MIMEType(input)}`;
assert.strictEqual(str, output);
}
}
}
// These come from https://github.com/web-platform-tests/wpt/tree/master/mimesniff/mime-types/resources
test(require(fixtures.path('./mime-whatwg.js')));
test(require(fixtures.path('./mime-whatwg-generated.js')));