Explorar el Código

test: replace /etc/mime.types stream with mime-db for cross-platform support

The async fs.createReadStream('/etc/mime.types') failed on Windows
(path resolved to D:\etc\mime.types) and caused an uncaught error
outside the test suite before any test ran.

mime-db is already a transitive dependency via mime-types, ships 2500+
MIME type strings as object keys, and is synchronous — no stream, no
OS-specific file path, no async race.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rugk hace 1 mes
padre
commit
a39036904e
Se han modificado 1 ficheros con 2 adiciones y 39 borrados
  1. 2 39
      js/common.js

+ 2 - 39
js/common.js

@@ -83,45 +83,8 @@ var a2zString    = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
     ),
     schemas = ['ftp','http','https'],
     supportedLanguages = ['ar', 'bg', 'ca', 'co', 'cs', 'de', 'el', 'es', 'et', 'fi', 'fr', 'he', 'hu', 'id', 'it', 'ja', 'jbo', 'lt', 'no', 'nl', 'pl', 'pt', 'oc', 'ru', 'sk', 'sl', 'th', 'tr', 'uk', 'zh'],
-    mimeTypes = ['image/png', 'application/octet-stream'],
-    formats = ['plaintext', 'markdown', 'syntaxhighlighting'],
-    mimeFile = fs.createReadStream('/etc/mime.types'),
-    mimeLine = '';
-
-// populate mime types from environment
-mimeFile.on('data', function(data) {
-    mimeLine += data;
-    var index = mimeLine.indexOf('\n');
-    while (index > -1) {
-        var line = mimeLine.substring(0, index);
-        mimeLine = mimeLine.substring(index + 1);
-        parseMime(line);
-        index = mimeLine.indexOf('\n');
-    }
-});
-
-mimeFile.on('end', function() {
-    if (mimeLine.length > 0) {
-        parseMime(mimeLine);
-    }
-});
-
-function parseMime(line) {
-    // ignore comments
-    var index = line.indexOf('#');
-    if (index > -1) {
-        line = line.substring(0, index);
-    }
-
-    // ignore bits after tabs
-    index = line.indexOf('\t');
-    if (index > -1) {
-        line = line.substring(0, index);
-    }
-    if (line.length > 0) {
-        mimeTypes.push(line);
-    }
-}
+    mimeTypes = ['image/png', 'application/octet-stream'].concat(Object.keys(require('mime-db'))),
+    formats = ['plaintext', 'markdown', 'syntaxhighlighting'];
 
 // common testing helper functions
 // as of jsDOM 22 the base64 functions provided in the DOM are more restrictive