Skip to content

Commit

Permalink
Bug-fix RE: handler methods being bound incorrectly.
Browse files Browse the repository at this point in the history
  • Loading branch information
theakman2 committed Feb 24, 2014
1 parent 31f7a2c commit bc7e0f5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 34 deletions.
2 changes: 1 addition & 1 deletion lib/util/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function push(handler,intoHandlers,intoAliases) {
}
var j = exts.length;
while(j--) {
intoHandlers[exts[j]] = handler.handle;
intoHandlers[exts[j]] = handler.handle.bind(handler);
}
}
if (handler.aliases && (typeof handler.aliases === "object")) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webant",
"version": "4.3.0",
"version": "4.3.1",
"description": "Bringing CommonJS-style requires to the browser and more.",
"keywords": ["ant", "browser", "browserify", "build", "builder", "bundle", "bundler", "cjs", "commonjs", "deploy", "generator", "make", "modules", "package", "packager", "require", "requirejs", "web", "webant", "webmake"],
"author": "A Kazim",
Expand Down
90 changes: 58 additions & 32 deletions test/tests/parseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ test("parseConfig 2",function(t){

var settings = parseConfig(rawConfig);

delete settings.handlers;

t.equivalent(
settings,
{
Expand All @@ -43,7 +45,6 @@ test("parseConfig 2",function(t){
postProcess:"none",
defaultExtension:".js",
requireBase:"",
handlers:{".js":jsHandler.handle},
aliases:{}
},
"Defaults should have been merged in properly."
Expand All @@ -55,7 +56,9 @@ test("parseConfig 2",function(t){
test("parseConfig 3",function(t){
var extraHandler = {
extensions:[".foo"],
handle:function(){}
handle:function(){
return this.extensions[0];
}
};

var rawConfig = {
Expand All @@ -64,6 +67,8 @@ test("parseConfig 3",function(t){
};

var settings = parseConfig(rawConfig);
var h = settings.handlers;
delete settings.handlers;

t.equivalent(
settings,
Expand All @@ -74,33 +79,41 @@ test("parseConfig 3",function(t){
postProcess:"none",
defaultExtension:".js",
requireBase:"",
handlers:{
".js":jsHandler.handle,
".foo":extraHandler.handle
},
aliases:{}
},
"Defaults should have been merged in properly."
);

t.strictEqual(
h[".foo"](),
".foo",
"Handlers should have been merged in correctly."
);

t.end();
});

test("parseConfig 4",function(t){
var foo = {
extensions:[".bar",".baz"],
handle:function(){}
handle:function(){
return this.extensions[1];
}
};

var bar = {
handle:function(){},
extensions:[".foo"]
};

function baz() {}
function baz() {
this._test = "testing";
}

baz.prototype = {
handle:function(){},
handle:function(){
return this._test;
},
extensions:[".qwe"]
};

Expand All @@ -112,6 +125,10 @@ test("parseConfig 4",function(t){

var settings = parseConfig(rawConfig);

var h = settings.handlers;

delete settings.handlers;

t.equivalent(
settings,
{
Expand All @@ -121,17 +138,28 @@ test("parseConfig 4",function(t){
postProcess:"none",
defaultExtension:".js",
requireBase:"",
handlers:{
".js":jsHandler.handle,
".bar":foo.handle,
".baz":foo.handle,
".foo":bar.handle,
".qwe":baz.prototype.handle
},
aliases:{}
},
"Defaults should have been merged in properly."
);

t.equivalent(
Object.keys(h).sort(),
[".bar",".baz",".foo",".js",".qwe"],
"Handlers should have been merged in correctly."
);

t.strictEqual(
h[".bar"](),
".baz",
"Handler's 'handle' method should have been bound correctly - .bar."
);

t.strictEqual(
h[".qwe"](),
"testing",
"Handler's 'handle' method should have been bound correctly - .qwe."
);

t.end();
});
Expand Down Expand Up @@ -171,6 +199,9 @@ test("parseConfig 5",function(t){
};

var settings = parseConfig(rawConfig);
var h = settings.handlers;

delete settings.handlers;

t.equivalent(
settings,
Expand All @@ -181,13 +212,6 @@ test("parseConfig 5",function(t){
postProcess:"none",
defaultExtension:".js",
requireBase:"",
handlers:{
".js":jsHandler.handle,
".bar":foo.handle,
".baz":foo.handle,
".foo":bar.handle,
".qwe":baz.handle
},
aliases:{
">>a":"/path/to/foo",
">>e":"/foo/nar/ser",
Expand All @@ -199,6 +223,12 @@ test("parseConfig 5",function(t){
"Defaults should have been merged in properly."
);

t.equivalent(
Object.keys(h).sort(),
[".bar",".baz",".foo",".js",".qwe"],
"Handlers should have been merged in correctly."
);

t.end();
});

Expand Down Expand Up @@ -247,7 +277,7 @@ test("parseConfig 7",function(t) {
};

var settings = parseConfig(rawConfig);

delete settings.handlers;
t.equivalent(
settings,
{
Expand All @@ -257,7 +287,6 @@ test("parseConfig 7",function(t) {
postProcess:"none",
requireBase:process.cwd(),
defaultExtension:".js",
handlers:{".js":jsHandler.handle},
aliases:{}
},
"Defaults should have been merged in properly."
Expand All @@ -273,7 +302,7 @@ test("parseConfig 8",function(t) {
};

var settings = parseConfig(rawConfig);

delete settings.handlers;
t.equivalent(
settings,
{
Expand All @@ -283,7 +312,6 @@ test("parseConfig 8",function(t) {
postProcess:"none",
requireBase:"",
defaultExtension:".coffee",
handlers:{".js":jsHandler.handle},
aliases:{}
},
"Defaults should have been merged in properly."
Expand All @@ -302,6 +330,7 @@ test("parseConfig 9",function(t){
];

var settings = parseConfig(rawConfig);
delete settings.handlers;

t.equivalent(
settings,
Expand All @@ -312,7 +341,6 @@ test("parseConfig 9",function(t){
postProcess:"debug",
requireBase:"",
defaultExtension:".coffee",
handlers:{".js":jsHandler.handle},
aliases:{}
},
"Defaults should have been merged in properly."
Expand All @@ -333,7 +361,7 @@ test("parseConfig 10",function(t){
];

var settings = parseConfig(rawConfig);

delete settings.handlers;
t.equivalent(
settings,
{
Expand All @@ -343,7 +371,6 @@ test("parseConfig 10",function(t){
postProcess:"compress",
requireBase:"",
defaultExtension:".ts",
handlers:{".js":jsHandler.handle},
aliases:{},
useConfig:configFile
},
Expand All @@ -357,7 +384,7 @@ test("parseConfig 11",function(t){
var rawConfig = "/path/to/src/js/main.js";

var settings = parseConfig(rawConfig);

delete settings.handlers;
t.equivalent(
settings,
{
Expand All @@ -367,7 +394,6 @@ test("parseConfig 11",function(t){
postProcess:"none",
defaultExtension:".js",
requireBase:"",
handlers:{".js":jsHandler.handle},
aliases:{}
},
"Defaults should have been merged in properly."
Expand Down

0 comments on commit bc7e0f5

Please sign in to comment.