Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated code to pass tests for both NodeJS and Mongo

  • Loading branch information...
commit 9dd3e84c3f95f530512fc93d8f7da22a6694ee96 1 parent d1bd1b7
R. S. Doiel authored
View
51 lib/harness.js
@@ -1,51 +0,0 @@
-//
-// A simple test harness to run groups of tests as a simple setInterval
-// service.
-//
-// @author: R. S. Doiel, <rsdoiel@gmail.com>
-// copyright (c) 2012 all rights reserved
-//
-// Released under Simplified the BSD License.
-// See: http://opensource.org/licenses/bsd-license.php
-//
-// revision: 0.0.1
-//
-
-var test_groups = [];
-
-// Push a test batch into harness
-exports.push = function (test) {
- if (test.callback === undefined) {
- throw "missing function definition.";
- }
- if (test.label === undefined) {
- throw "missing test label.";
- }
- test_groups.push(test);
-};
-
-exports.RunIt = function (module_name, test_delay) {
- var int_id;
-
- if (test_delay === undefined) {
- test_delay = 1000;
- }
-
- console.log("Starting [" + module_name.trim() + "] ...");
- int_id = setInterval(function () {
- var group_test = test_groups.shift();
-
- if (group_test && typeof group_test.callback === "function" &&
- typeof group_test.label === "string") {
- process.stdout.write("\tstarting " + group_test.label + " ...");
- group_test.callback();
- process.stdout.write(" OK\n");
- } else if (group_test === undefined) {
- process.stdout.write(module_name.trim() + " Success!\n");
- clearInterval(int_id);
- } else {
- throw module_name.trim() + " Failed!";
- }
- }, test_delay);
-};
-
View
66 mimetype.js
@@ -95,68 +95,16 @@
return (this.catalog[ext] === undefined);
},
forEach: function (callback) {
- var self = this;
- Object.keys(self.catalog).forEach(function (ext) {
- callback(ext, self.catalog[ext]);
- });
+ var self = this, ext;
+ // Mongo 2.2. Shell doesn't support Object.keys()
+ for (ext in self.catalog) {
+ if (self.catalog.hasOwnProperty(ext)) {
+ callback(ext, self.catalog[ext]);
+ }
+ }
return self.catalog;
}
};
- /*
- // Quick and dirty list of common mime-types I've run across
- MimeType.set('.txt,.text,.md,README','text/plain');
- MimeType.set('.html,.htm', 'text/html');
- MimeType.set('.js', 'application/javascript');
- MimeType.set('.json', 'application/json');
- MimeType.set('.css', 'text/css');
- MimeType.set('.xml,.dtd', 'text/xml');
- MimeType.set('.csv', 'text/csv');
- MimeType.set('.tsv', 'text/tab-separated-value');
- MimeType.set('.ico', 'image/icon');
- MimeType.set('.jpg,.jpeg,.jpe', 'image/jpeg');
- MimeType.set('.qt,.mov', 'video/quicktime');
- MimeType.set('.mpg,.mpeg,.mpe', 'video/mpeg');
- MimeType.set('.png', 'image/png');
- MimeType.set('.doc,.docx', 'application/msword');
- MimeType.set('.xls', 'application/excel');
- MimeType.set('.ppt', 'application/powerpoint');
- MimeType.set('.bin', 'application/octet-stream');
- MimeType.set('.pdf', 'application/pdf');
- MimeType.set('.rtf', 'application/rtf');
- MimeType.set(".ai,.eps,.ps", "application/postscript");
- MimeType.set(".tar", "application/x-tar");
- MimeType.set(".gz", "application/x-gzip");
- MimeType.set(".tar.gz,.tgz", "application/x-tar-gz");
- MimeType.set(".tar.bz,.tbz", "application/x-tar-bzip");
- MimeType.set(".zip", "application/zip");
- MimeType.set(".bz", "application/bzip");
- MimeType.set(".au,.snd", "audio/basic");
- MimeType.set(".wav", "audio/x-wav");
- MimeType.set(".aif,.aiff,.aifc", "audio/x-aiff");
- MimeType.set(".ogx", "application/ogg");
- MimeType.set(".ogg,.spx,.oga", "audio/ogg");
- MimeType.set(".ogv", "video/ogg");
- MimeType.set(".mp3,.mp2,.mpga", "audio/mpeg");
- MimeType.set(".rpm", "audio/x-pn-realaudio-plugin");
- MimeType.set(".ram,.rm", "audio/x-pn-realaudio");
- MimeType.set(".ra", "audio/x-realaudio");
- MimeType.set(".flac", "audio/flac");
- MimeType.set(".aac", "audio/x-aac");
-
- MimeType.set(".gif", "image/gif");
- MimeType.set(".jpg,.jpeg,.jpe", "image/jpeg");
- MimeType.set(".png", "image/png");
- MimeType.set(".tif,.tiff", "image/tiff");
- // Not sure if this is real for .raw files
- MimeType.set(".raw", "image/x-raw");
- MimeType.set(".mpg,.mpeg,.mpe", "video/mpeg");
- MimeType.set(".mp4,.m4a", "video/mp4");
- MimeType.set(".qt,.mov", "video/quicktime");
- MimeType.set(".avi", "video/x-msvideo");
- MimeType.set(".asf", "video/x-ms-asf");
- MimeType.set(".asx", "video/x-ms-asx");
- MimeType.set(".wmv", "video/x-ms-wmv");
- */
// From Apache project's mime type list.
MimeType.set(".ez", "application/andrew-inset");
View
3  package.json
@@ -1,6 +1,6 @@
{
"name" : "mimetype",
- "version" : "0.0.3",
+ "version" : "0.0.4",
"description" : "A mime type catalog driven by filename extensions.",
"main" : "./mimetype.js",
"repository" : {
@@ -21,6 +21,7 @@
"npm" : ">= 1"
},
"dependencies" : {
+ "harness": ">= 0.0.2"
},
"scripts" : {
"test" : "node tests/mimetype_test.js"
View
6 tests/mimetype_test.js
@@ -10,7 +10,7 @@
var assert = require('assert'),
path = require('path'),
- harness = require('../lib/harness'),
+ harness = require('harness'),
v0_0_3 = require('../lib/v0.0.3').data,
mimetype = require('../mimetype');
@@ -46,6 +46,7 @@ harness.push({callback: function () {
assert.equal(mimetype.lookup("README"), "text/plain", "README should return text/plain mime-type.");
assert.equal(mimetype.lookup("manifest"), "text/cache-manifest", "manifest should return text/plain mime-type.");
+ harness.completed("tests for version 0.0.2");
}, label: "tests for version 0.0.2"});
// tests for version 0.0.3
@@ -73,10 +74,11 @@ harness.push({callback: function () {
}
}
});
+ harness.completed("tests for version 0.0.3");
}, label: "tests for version 0.0.3"});
if (require.main === module) {
- harness.RunIt(path.basename(module.filename), 10, true);
+ harness.RunIt(path.basename(module.filename), 10);
} else {
exports.RunIt = harness.RunIt;
}
Please sign in to comment.
Something went wrong with that request. Please try again.