Skip to content

Commit

Permalink
Switching from harness to YUI3 Tests for node target
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdoiel committed Jun 2, 2013
1 parent bffbac7 commit 143274c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 58 deletions.
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name" : "mimetype",
"version" : "0.0.4",
"version" : "0.0.5",
"description" : "A mime type catalog driven by filename extensions.",
"main" : "./mimetype.js",
"repository" : {
Expand All @@ -20,8 +20,8 @@
"node" : ">= 0.8",
"npm" : ">= 1"
},
"dependencies" : {
"harness": ">= 0.0.2"
"devDependencies" : {
"yui": "3.10.x"
},
"scripts" : {
"test" : "node tests/mimetype_test.js"
Expand Down
109 changes: 54 additions & 55 deletions tests/mimetype_test.js
Expand Up @@ -8,77 +8,76 @@
// See: http://opensource.org/licenses/bsd-license.php
//

var assert = require('assert'),
var Y = require("yui/test"),
assert = Y.Assert,
path = require('path'),
harness = require('harness'),
v0_0_3 = require('../lib/v0.0.3').data,
mimetype = require('../mimetype');

// Tests for version 0.0.2
harness.push({callback: function () {
assert.equal(mimetype.lookup("myfile.txt"), 'text/plain', "lookup should return text/plain");
assert.equal(mimetype.set('.exotic', 'x-application/experimental'), true, "set should return true.");
assert.equal(mimetype.lookup("myfile.exotic"), "x-application/experimental", "lookup should return x-application/experimental");
assert.equal(mimetype.del('.exotic'), true, "del() should return true");
assert.equal(mimetype.lookup("myfile.exotic"), false, "lookup(myfile.exotic) should return false now");
var basicTests = new Y.Test.Case({
name: "Basic Tests",
"Should pass tests for version 0.0.2": function () {
assert.areEqual(mimetype.lookup("myfile.txt"), 'text/plain', "lookup should return text/plain");
assert.areEqual(mimetype.set('.exotic', 'x-application/experimental'), true, "set should return true.");
assert.areEqual(mimetype.lookup("myfile.exotic"), "x-application/experimental", "lookup should return x-application/experimental");
assert.areEqual(mimetype.del('.exotic'), true, "del() should return true");
assert.areEqual(mimetype.lookup("myfile.exotic"), false, "lookup(myfile.exotic) should return false now");
ky_cnt = Object.keys(mimetype.catalog).length;
i = 0;
mimetype.forEach(function (ext, mime_type_string) {
assert.ok(ext, "Should have an ext");
assert.ok(mime_type_string, "Should have a mime_type string");
assert.strictEqual(mimetype.catalog[ext], mime_type_string);
Y.assert(ext, "Should have an ext");
Y.assert(mime_type_string, "Should have a mime_type string");
assert.areSame(mimetype.catalog[ext], mime_type_string);
i += 1;
});
assert.equal(ky_cnt, i, "i should equal ky_cnt");
assert.areEqual(ky_cnt, i, "i should equal ky_cnt");

// Test multi-extension set()
assert.equal(mimetype.lookup("test.txt1"), false, "Should not have the .txt1 defined yet.");
assert.equal(mimetype.lookup("test.txt2"), false, "Should not have the .txt2 defined yet.");
assert.equal(mimetype.lookup("test.txt3"), false, "Should not have the .txt3 defined yet.");
assert.areEqual(mimetype.lookup("test.txt1"), false, "Should not have the .txt1 defined yet.");
assert.areEqual(mimetype.lookup("test.txt2"), false, "Should not have the .txt2 defined yet.");
assert.areEqual(mimetype.lookup("test.txt3"), false, "Should not have the .txt3 defined yet.");
mimetype.set(".txt1,.txt2,.txt3", "text/plain");
assert.equal(mimetype.lookup("test.txt1"), "text/plain", "Should have the .txt1 now.");
assert.equal(mimetype.lookup("test.txt2"), "text/plain", "Should have the .txt2 now.");
assert.equal(mimetype.lookup("test.txt3"), "text/plain", "Should have the .txt3 now.");
assert.equal(mimetype.lookup("this.isNotDefined"), false, "Should not have a mime type defined for this.isNotDefined");
assert.equal(mimetype.lookup("this.isNotDefined", false, "text/plain"), "text/plain", "Should not have a mime type defined for this.isNotDefined");
assert.equal(mimetype.lookup("this.isNotDefined", true, "text/plain"), "text/plain; charset=UTF-8", "Should have a mime type with charset defined for this.isNotDefined: " + mimetype.lookup("this.isNotDefined", true, "text/plain"));
assert.equal(mimetype.lookup("this.isNotDefined", "UTF-8", "text/plain"), "text/plain; charset=UTF-8", "this.isNotDefined should be text/plain;charset=UTF-8: " + mimetype.lookup("this.isNotDefined", "UTF-8", "text/plain"));
assert.areEqual(mimetype.lookup("test.txt1"), "text/plain", "Should have the .txt1 now.");
assert.areEqual(mimetype.lookup("test.txt2"), "text/plain", "Should have the .txt2 now.");
assert.areEqual(mimetype.lookup("test.txt3"), "text/plain", "Should have the .txt3 now.");
assert.areEqual(mimetype.lookup("this.isNotDefined"), false, "Should not have a mime type defined for this.isNotDefined");
assert.areEqual(mimetype.lookup("this.isNotDefined", false, "text/plain"), "text/plain", "Should not have a mime type defined for this.isNotDefined");
assert.areEqual(mimetype.lookup("this.isNotDefined", true, "text/plain"), "text/plain; charset=UTF-8", "Should have a mime type with charset defined for this.isNotDefined: " + mimetype.lookup("this.isNotDefined", true, "text/plain"));
assert.areEqual(mimetype.lookup("this.isNotDefined", "UTF-8", "text/plain"), "text/plain; charset=UTF-8", "this.isNotDefined should be text/plain;charset=UTF-8: " + mimetype.lookup("this.isNotDefined", "UTF-8", "text/plain"));

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"});
assert.areEqual(mimetype.lookup("README"), "text/plain", "README should return text/plain mime-type.");
assert.areEqual(mimetype.lookup("manifest"), "text/cache-manifest", "manifest should return text/plain mime-type.");
},

// tests for version 0.0.3
harness.push({callback: function () {
Object.keys(v0_0_3).forEach(function (i) {
var vals, j, testname;

assert.ok(v0_0_3[i].mime_type, "Missing v0_0_3 index:" + i);
if (v0_0_3[i].ext !== undefined) {
if (v0_0_3[i].ext.indexOf(" ") > 0) {
vals = v0_0_3[i].ext.split(" ");
for (j = 0; j < vals.length; j += 1) {
testname = ["testname", vals[j]].join(".");
assert.equal(
mimetype.lookup(testname),
// tests for version 0.0.3
"Should pass tests for version 0.0.3": function () {
Object.keys(v0_0_3).forEach(function (i) {
var vals, j, testname;

Y.assert(v0_0_3[i].mime_type, "Missing v0_0_3 index:" + i);
if (v0_0_3[i].ext !== undefined) {
if (v0_0_3[i].ext.indexOf(" ") > 0) {
vals = v0_0_3[i].ext.split(" ");
for (j = 0; j < vals.length; j += 1) {
testname = ["testname", vals[j]].join(".");
assert.areEqual(
mimetype.lookup(testname),
v0_0_3[i].mime_type,
[testname, mimetype.lookup(testname), '->', v0_0_3[i].mime_type, vals[j], "failed"].join(" "));
}
} else {
testname = ["testname", v0_0_3[i].ext].join(".");
assert.areEqual(
mimetype.lookup(testname),
v0_0_3[i].mime_type,
[testname, mimetype.lookup(testname), '->', v0_0_3[i].mime_type, vals[j], "failed"].join(" "));
[testname, v0_0_3[i].mime_type, "failed"].join(" "));
}
} else {
testname = ["testname", v0_0_3[i].ext].join(".");
assert.equal(
mimetype.lookup(testname),
v0_0_3[i].mime_type,
[testname, v0_0_3[i].mime_type, "failed"].join(" "));
}
}
});
harness.completed("tests for version 0.0.3");
}, label: "tests for version 0.0.3"});
});
}
});

Y.Test.Runner.add(basicTests);
Y.Test.Runner.run();

if (require.main === module) {
harness.RunIt(path.basename(module.filename), 10);
} else {
exports.RunIt = harness.RunIt;
}

0 comments on commit 143274c

Please sign in to comment.