chore: remove usages of mime module from infrastructure
Follow-up to 4d84e35096
This commit is contained in:
parent
84f5700294
commit
4fcc63f2e1
|
|
@ -17,13 +17,19 @@
|
|||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const Diff = require('text-diff');
|
||||
const mime = require('mime');
|
||||
const PNG = require('pngjs').PNG;
|
||||
const jpeg = require('jpeg-js');
|
||||
const pixelmatch = require('pixelmatch');
|
||||
|
||||
module.exports = {compare};
|
||||
|
||||
const extensionToMimeType = {
|
||||
'png': 'image/png',
|
||||
'txt': 'text/plain',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
};
|
||||
|
||||
const GoldenComparators = {
|
||||
'image/png': compareImages,
|
||||
'image/jpeg': compareImages,
|
||||
|
|
@ -98,7 +104,8 @@ function compare(goldenPath, outputPath, actual, goldenName) {
|
|||
};
|
||||
}
|
||||
const expected = fs.readFileSync(expectedPath);
|
||||
const mimeType = mime.getType(goldenName);
|
||||
const extension = goldenName.substring(goldenName.lastIndexOf('.') + 1);
|
||||
const mimeType = extensionToMimeType[extension];
|
||||
const comparator = GoldenComparators[mimeType];
|
||||
if (!comparator) {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -129,12 +129,12 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
|
|||
).toBe(
|
||||
fs.readFileSync(path.join(__dirname, '/assets/file-to-upload.txt')).toString()
|
||||
);
|
||||
expect(file2.name).toBe('file-to-upload.png');
|
||||
expect(file2.name).toBe('pptr.png');
|
||||
expect(file2.type).toBe('image/png');
|
||||
expect(
|
||||
fs.readFileSync(file2.path).toString()
|
||||
).toBe(
|
||||
fs.readFileSync(path.join(__dirname, '/assets/file-to-upload.png')).toString()
|
||||
fs.readFileSync(path.join(__dirname, '/assets/pptr.png')).toString()
|
||||
);
|
||||
callback();
|
||||
});
|
||||
|
|
@ -147,7 +147,7 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
|
|||
<input type="submit" value="Submit">
|
||||
</form>`)
|
||||
await (await page.$('input[name=file1]')).setInputFiles(path.join(__dirname, '/assets/file-to-upload.txt'));
|
||||
await (await page.$('input[name=file2]')).setInputFiles(path.join(__dirname, '/assets/file-to-upload.png'));
|
||||
await (await page.$('input[name=file2]')).setInputFiles(path.join(__dirname, '/assets/pptr.png'));
|
||||
page.click('input[type=submit]');
|
||||
await result;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ const https = require('https');
|
|||
const url = require('url');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const mime = require('mime');
|
||||
const WebSocketServer = require('ws').Server;
|
||||
|
||||
const fulfillSymbol = Symbol('fullfil callback');
|
||||
|
|
@ -248,7 +247,8 @@ class TestServer {
|
|||
response.end(`File not found: ${filePath}`);
|
||||
return;
|
||||
}
|
||||
const mimeType = mime.getType(filePath);
|
||||
const extension = filePath.substring(filePath.lastIndexOf('.') + 1);
|
||||
const mimeType = extensionToMime[extension] || 'application/octet-stream';
|
||||
const isTextEncoding = /^text\/|^application\/(javascript|json)/.test(mimeType);
|
||||
const contentType = isTextEncoding ? `${mimeType}; charset=utf-8` : mimeType;
|
||||
response.setHeader('Content-Type', contentType);
|
||||
|
|
@ -269,4 +269,204 @@ class TestServer {
|
|||
}
|
||||
}
|
||||
|
||||
const extensionToMime = {
|
||||
'ai': 'application/postscript',
|
||||
'apng': 'image/apng',
|
||||
'appcache': 'text/cache-manifest',
|
||||
'au': 'audio/basic',
|
||||
'bmp': 'image/bmp',
|
||||
'cer': 'application/pkix-cert',
|
||||
'cgm': 'image/cgm',
|
||||
'coffee': 'text/coffeescript',
|
||||
'conf': 'text/plain',
|
||||
'crl': 'application/pkix-crl',
|
||||
'css': 'text/css',
|
||||
'csv': 'text/csv',
|
||||
'def': 'text/plain',
|
||||
'doc': 'application/msword',
|
||||
'dot': 'application/msword',
|
||||
'drle': 'image/dicom-rle',
|
||||
'dtd': 'application/xml-dtd',
|
||||
'ear': 'application/java-archive',
|
||||
'emf': 'image/emf',
|
||||
'eps': 'application/postscript',
|
||||
'exr': 'image/aces',
|
||||
'fits': 'image/fits',
|
||||
'g3': 'image/g3fax',
|
||||
'gbr': 'application/rpki-ghostbusters',
|
||||
'gif': 'image/gif',
|
||||
'glb': 'model/gltf-binary',
|
||||
'gltf': 'model/gltf+json',
|
||||
'gz': 'application/gzip',
|
||||
'h261': 'video/h261',
|
||||
'h263': 'video/h263',
|
||||
'h264': 'video/h264',
|
||||
'heic': 'image/heic',
|
||||
'heics': 'image/heic-sequence',
|
||||
'heif': 'image/heif',
|
||||
'heifs': 'image/heif-sequence',
|
||||
'htm': 'text/html',
|
||||
'html': 'text/html',
|
||||
'ics': 'text/calendar',
|
||||
'ief': 'image/ief',
|
||||
'ifb': 'text/calendar',
|
||||
'iges': 'model/iges',
|
||||
'igs': 'model/iges',
|
||||
'in': 'text/plain',
|
||||
'ini': 'text/plain',
|
||||
'jade': 'text/jade',
|
||||
'jar': 'application/java-archive',
|
||||
'jls': 'image/jls',
|
||||
'jp2': 'image/jp2',
|
||||
'jpe': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'jpf': 'image/jpx',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpg2': 'image/jp2',
|
||||
'jpgm': 'video/jpm',
|
||||
'jpgv': 'video/jpeg',
|
||||
'jpm': 'image/jpm',
|
||||
'jpx': 'image/jpx',
|
||||
'js': 'application/javascript',
|
||||
'json': 'application/json',
|
||||
'json5': 'application/json5',
|
||||
'jsx': 'text/jsx',
|
||||
'jxr': 'image/jxr',
|
||||
'kar': 'audio/midi',
|
||||
'ktx': 'image/ktx',
|
||||
'less': 'text/less',
|
||||
'list': 'text/plain',
|
||||
'litcoffee': 'text/coffeescript',
|
||||
'log': 'text/plain',
|
||||
'm1v': 'video/mpeg',
|
||||
'm21': 'application/mp21',
|
||||
'm2a': 'audio/mpeg',
|
||||
'm2v': 'video/mpeg',
|
||||
'm3a': 'audio/mpeg',
|
||||
'm4a': 'audio/mp4',
|
||||
'm4p': 'application/mp4',
|
||||
'man': 'text/troff',
|
||||
'manifest': 'text/cache-manifest',
|
||||
'markdown': 'text/markdown',
|
||||
'mathml': 'application/mathml+xml',
|
||||
'md': 'text/markdown',
|
||||
'mdx': 'text/mdx',
|
||||
'me': 'text/troff',
|
||||
'mesh': 'model/mesh',
|
||||
'mft': 'application/rpki-manifest',
|
||||
'mid': 'audio/midi',
|
||||
'midi': 'audio/midi',
|
||||
'mj2': 'video/mj2',
|
||||
'mjp2': 'video/mj2',
|
||||
'mjs': 'application/javascript',
|
||||
'mml': 'text/mathml',
|
||||
'mov': 'video/quicktime',
|
||||
'mp2': 'audio/mpeg',
|
||||
'mp21': 'application/mp21',
|
||||
'mp2a': 'audio/mpeg',
|
||||
'mp3': 'audio/mpeg',
|
||||
'mp4': 'video/mp4',
|
||||
'mp4a': 'audio/mp4',
|
||||
'mp4s': 'application/mp4',
|
||||
'mp4v': 'video/mp4',
|
||||
'mpe': 'video/mpeg',
|
||||
'mpeg': 'video/mpeg',
|
||||
'mpg': 'video/mpeg',
|
||||
'mpg4': 'video/mp4',
|
||||
'mpga': 'audio/mpeg',
|
||||
'mrc': 'application/marc',
|
||||
'ms': 'text/troff',
|
||||
'msh': 'model/mesh',
|
||||
'n3': 'text/n3',
|
||||
'oga': 'audio/ogg',
|
||||
'ogg': 'audio/ogg',
|
||||
'ogv': 'video/ogg',
|
||||
'ogx': 'application/ogg',
|
||||
'otf': 'font/otf',
|
||||
'p10': 'application/pkcs10',
|
||||
'p7c': 'application/pkcs7-mime',
|
||||
'p7m': 'application/pkcs7-mime',
|
||||
'p7s': 'application/pkcs7-signature',
|
||||
'p8': 'application/pkcs8',
|
||||
'pdf': 'application/pdf',
|
||||
'pki': 'application/pkixcmp',
|
||||
'pkipath': 'application/pkix-pkipath',
|
||||
'png': 'image/png',
|
||||
'ps': 'application/postscript',
|
||||
'pskcxml': 'application/pskc+xml',
|
||||
'qt': 'video/quicktime',
|
||||
'rmi': 'audio/midi',
|
||||
'rng': 'application/xml',
|
||||
'roa': 'application/rpki-roa',
|
||||
'roff': 'text/troff',
|
||||
'rsd': 'application/rsd+xml',
|
||||
'rss': 'application/rss+xml',
|
||||
'rtf': 'application/rtf',
|
||||
'rtx': 'text/richtext',
|
||||
's3m': 'audio/s3m',
|
||||
'sgi': 'image/sgi',
|
||||
'sgm': 'text/sgml',
|
||||
'sgml': 'text/sgml',
|
||||
'shex': 'text/shex',
|
||||
'shtml': 'text/html',
|
||||
'sil': 'audio/silk',
|
||||
'silo': 'model/mesh',
|
||||
'slim': 'text/slim',
|
||||
'slm': 'text/slim',
|
||||
'snd': 'audio/basic',
|
||||
'spx': 'audio/ogg',
|
||||
'stl': 'model/stl',
|
||||
'styl': 'text/stylus',
|
||||
'stylus': 'text/stylus',
|
||||
'svg': 'image/svg+xml',
|
||||
'svgz': 'image/svg+xml',
|
||||
't': 'text/troff',
|
||||
't38': 'image/t38',
|
||||
'text': 'text/plain',
|
||||
'tfx': 'image/tiff-fx',
|
||||
'tif': 'image/tiff',
|
||||
'tiff': 'image/tiff',
|
||||
'tr': 'text/troff',
|
||||
'ts': 'video/mp2t',
|
||||
'tsv': 'text/tab-separated-values',
|
||||
'ttc': 'font/collection',
|
||||
'ttf': 'font/ttf',
|
||||
'ttl': 'text/turtle',
|
||||
'txt': 'text/plain',
|
||||
'uri': 'text/uri-list',
|
||||
'uris': 'text/uri-list',
|
||||
'urls': 'text/uri-list',
|
||||
'vcard': 'text/vcard',
|
||||
'vrml': 'model/vrml',
|
||||
'vtt': 'text/vtt',
|
||||
'war': 'application/java-archive',
|
||||
'wasm': 'application/wasm',
|
||||
'wav': 'audio/wav',
|
||||
'weba': 'audio/webm',
|
||||
'webm': 'video/webm',
|
||||
'webmanifest': 'application/manifest+json',
|
||||
'webp': 'image/webp',
|
||||
'wmf': 'image/wmf',
|
||||
'woff': 'font/woff',
|
||||
'woff2': 'font/woff2',
|
||||
'wrl': 'model/vrml',
|
||||
'x3d': 'model/x3d+xml',
|
||||
'x3db': 'model/x3d+fastinfoset',
|
||||
'x3dbz': 'model/x3d+binary',
|
||||
'x3dv': 'model/x3d-vrml',
|
||||
'x3dvz': 'model/x3d+vrml',
|
||||
'x3dz': 'model/x3d+xml',
|
||||
'xaml': 'application/xaml+xml',
|
||||
'xht': 'application/xhtml+xml',
|
||||
'xhtml': 'application/xhtml+xml',
|
||||
'xm': 'audio/xm',
|
||||
'xml': 'text/xml',
|
||||
'xsd': 'application/xml',
|
||||
'xsl': 'application/xml',
|
||||
'xslt': 'application/xslt+xml',
|
||||
'yaml': 'text/yaml',
|
||||
'yml': 'text/yaml',
|
||||
'zip': 'application/zip'
|
||||
};
|
||||
|
||||
module.exports = {TestServer};
|
||||
|
|
|
|||
Loading…
Reference in a new issue