1
0
Fork 0
easejs/test/inc-testcase.js

408 lines
9.4 KiB
JavaScript
Raw Normal View History

/**
* Simple X-Unit-style test cases
*
* Copyright (C) 2011, 2012, 2013 Mike Gerwitz
*
* This file is part of GNU ease.js.
*
* ease.js is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
var assert = require( 'assert' ),
assert_wrapped = {},
acount = 0,
icount = 0,
scount = 0,
skpcount = 0,
tcount = 0,
// when set to true, final statistics will be buffered until suite ends
suite = false,
failures = [],
// dummy object to be thrown for test skipping
SkipTest = { skip: true },
common_require = require( __dirname + '/common' ).require
;
// wrap each of the assertions so that we can keep track of the number of times
// that they were invoked
for ( var f in assert )
{
var _assert_cur = assert[ f ];
if ( typeof _assert_cur !== 'function' )
{
continue;
}
// wrap the assertion to keep count
assert_wrapped[ f ] = ( function( a )
{
return function()
{
incAssertCount();
a.apply( this, arguments );
};
} )( _assert_cur );
}
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
function incAssertCount()
{
acount++;
};
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
/**
* Defines and runs a test case
*
* This is a very basic system that provides a more familiar jUnit/phpUnit-style
* output for xUnit tests and allows all tests in the case to be run in the
* event of a test failure.
*
* The test name should be given as the key and the test itself as a function as
* the value. The test will be invoked within the context of the assertion
* module.
*
* This will be evolving throughout the life of the project. Mainly, it cannot
* be run as part of a suite without multiple summary outputs.
*
* @param {Object.<string,function()>} object containing tests
*
* @return {undefined}
*/
module.exports = function( test_case )
{
var context = prepareCaseContext(),
setUp = test_case.setUp;
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
// if we're not running a suite, clear out the failures
if ( !( suite ) )
{
init();
}
2011-10-21 09:51:42 -04:00
// perform case-wide setup
test_case.caseSetUp && test_case.caseSetUp.call( context );
// remove unneeded methods so we don't invoke them as tests below
delete test_case.caseSetUp;
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
delete test_case.setUp;
// run each test in the case
for ( var test in test_case )
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
{
var data = test.match( /^(?:@(.*?)\((.*?)\))?(.*)$/ ),
method = data[ 1 ],
prop = data[ 2 ],
name = data[ 3 ],
count = 1,
args = [ [] ]
;
if ( method === 'each' )
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
{
if ( !( context[ prop ] ) )
{
throw Error( "Unknown @each context: " + prop );
}
count = context[ prop ].length;
args = [];
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
for ( var i = 0; i < count; i++ )
{
args.push( [ context[ prop ][ i ] ] );
}
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
}
else if ( method )
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
{
throw Error( "Unknown test method: " + method );
}
// perform the appropriate number of tests
for ( var i = 0; i < count; i++ )
{
tryTest(
test_case,
test,
( setUp || null ),
name + ( ( count > 1 )
? ( ' (' + i + ')' )
: ''
),
context,
args[ i ]
);
// output a newline and the count every 60 tests
( tcount % 60 ) || testPrint( " " + tcount + "\n" );
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
}
}
// only output statistics if we're not running a suite (otherwise they'll be
// output at the end of the suite)
if ( !( suite ) )
{
endStats();
}
};
/**
* Attempt a test
*
* @param {Object} test_case object containing all test cases
* @param {string} test complete key of test to run
* @param {Function} setUp test setup method, or null
* @param {string} test_str text to use on failure
* @param {Object} context context to bind to test function
* @param {Array} args arguments to pass to test function
*
* @return {undefined}
*/
function tryTest( test_case, test, setUp, test_str, context, args )
{
var acount_last = acount;
try
{
// xUnit-style setup
if ( setUp )
{
setUp.call( context );
}
test_case[ test ].apply( context, args );
// if there were no assertions, then the test should be marked as
// incomplete
if ( acount_last === acount )
{
testPrint( 'I' );
icount++;
}
else
{
scount++;
testPrint( '.' );
}
}
catch ( e )
{
if ( e === SkipTest )
{
testPrint( 'S' );
skpcount++;
}
else
{
testPrint( 'F' );
failures.push( [ test_str, e ] );
}
}
tcount++;
}
/**
* Reset counters
*/
function init()
{
failures = [];
scount = acount = icount = skpcount = 0;
}
/**
* Display end stats (failures, counts)
*/
function endStats()
{
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
testPrint( "\n\n" );
if ( failures.length )
{
outputTestFailures( failures );
}
// print test case summary
testPrint(
( ( failures.length ) ? "FAILED" : "OK" ) + " - " +
scount + " successful, " + failures.length + " failure(s), " +
( ( icount > 0 ) ? icount + ' incomplete, ' : '' ) +
( ( skpcount > 0 ) ? skpcount + ' skipped, ' : '' ) +
( scount + icount + skpcount + failures.length ) + " total " +
'(' + acount + " assertion" + ( ( acount !== 1 ) ? 's' : '' ) + ")\n"
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
);
// exit with non-zero status to indicate failure
failures.length
&& typeof process !== 'undefined'
&& process.exit( 1 );
}
/**
* Start test suite, deferring summary stats until call to endSuite()
*/
module.exports.startSuite = function()
{
init();
suite = true;
};
/**
* Ens test suite, display stats buffered since startSuite()
*/
module.exports.endSuite = function()
{
suite = false;
endStats();
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
};
function getMock( proto )
{
var P = common_require( proto ),
Mock = function() {},
proto = Mock.prototype = new P()
;
for ( var i in proto )
{
// only mock out methods
if ( typeof proto[ i ] !== 'function' )
{
continue;
}
// clear the method
proto[ i ] = function() {};
}
return new Mock();
}
function skipTest()
{
throw SkipTest;
}
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
/**
* Prepare assertion methods on context
*
* @return {Object} context
*/
function prepareCaseContext()
{
return {
require: common_require,
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
fail: assert_wrapped.fail,
assertOk: assert_wrapped.ok,
assertEqual: assert_wrapped.equal,
assertNotEqual: assert_wrapped.notEqual,
assertDeepEqual: assert_wrapped.deepEqual,
assertStrictEqual: assert_wrapped.strictEqual,
assertNotStrictEqual: assert_wrapped.notStrictEqual,
assertThrows: assert_wrapped['throws'],
assertDoesNotThrow: assert_wrapped.doesNotThrow,
assertIfError: assert_wrapped.ifError,
incAssertCount: incAssertCount,
getMock: getMock,
skip: skipTest,
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
};
}
/**
* Outputs test failures and their stack traces
*
* @param {Array} failures
*
* @return {undefined}
*/
function outputTestFailures( failures )
{
var i, cur, name, e;
// if we don't have stdout access, throw an error containing each of the
// error strings
if ( typeof process === 'undefined' )
{
var err = '',
i = failures.length;
for ( var i in failures )
{
var failure = failures[ i ];
err += failure[ 0 ] +
' (' + ( failure[ 1 ].message || 'no message' ) + ')' +
( ( failure[ 1 ].stack )
? ( '<br />' +
failure[ 1 ].stack.replace( /\n/g, '<br />' ) +
'<br />'
)
: '; '
)
}
throw Error( err );
}
for ( var i = 0; i < failures.length; i++ )
Added very basic formatted output and failure tolerance for test case The one year anniversary of the beginning of the ease.js project is quickly approaching. I find myself to be not quite where I had expected many months ago, but find that the project has evolved so much further than I had event originally anticipated. My main motivation behind the project continues to be making my life at work easier, while providing an excellent library that others can hopefully benefit from. If anything, it's a fascinating experiment and clever hack around JavaScript. Now I find myself with a newborn child (nearly four weeks old), who demands my constant attention (and indeed, it is difficult to find the desire to put my attention elsewhere). Still - I am a hacker. Software is my passion. So the project must move forward. I also find myself unwilling to create a blog for ease.js. I feel it's inappropriate for a project that's in its (relative) infancy and does not have much popularity (it has never been announced to anyone). As such, I feel that commit messages will serve my purpose as useful journal entries regarding the status of the project. They will also be interesting easter eggs for those who would wish to seek them out for additional perspective on the project. (Granted, one could easy script the discovery of such entries by examining the absurd length of the commit message...perhaps the git log manpages would be useful). So. Let's get back to the project. ease.js is currently going through a strong refactoring in order to address design issues that have begun to creep up as the project grew. The initial design was a very simple one - a "series of modules", as it was originally described in a CommonJS sense, that would provide features of a classical Object-Oriented system. It would seem ironic that, having a focus on classical Object-Oriented development, one would avoid developing the project in such a paradigm. Instead, I wished to keep the design simple (because the project seemed simple), more natural to JS developers (prototypal) and performant (object literals do not have the overhead of instantiation). Well, unfortunately, the project scope has increased drastically due to the success of the implementation (and my playfulness), the chosen paradigm has become awkward in itself and the performance benefit is indeed a micro-optimization when compared with the performance of both the rest of the system and the system that will implement ease.js as a framework. You can only put off refactoring for so long before the system begins to trip over itself and stop being a pleasure to work with. In fact, it's a slap in the face. You develop this intricate and beautiful system (speaking collectively and generally, of course) and it begins to feel tainted. In order to prevent it from developing into a ball of mud - a truly unmaintainable mess - the act of refactoring is inevitable, especially if we want to ensure that the project survives and is actively developed for any length of time. In this case, the glaring problem is that each of the modules are terribly, tightly coupled. This reduces the flexibility of the system and forces us to resort to a system riddled with conditionals. This becomes increasingly apparent when we need to provide slightly different implementations between environments (e.g. ES5/pre-ES5, production/development, etc and every combination). Therefore, we need to decouple the modules in order to take advantage of composition in order to provide more flexible feature sets depending on environment. What does this mean? We need to move from object literals for the modules to prototypes (class-like, but remember that ease.js exists because JS does not have "classes"). A number of other prototypes can be extracted from the existing modules and abstracted to the point where they can be appropriately injected where necessary. Rather than using conditions for features such as fallbacks, we can encapsulate the entire system in a facade that contains the features relevant to that particular environment. This will also have the consequence that we can once again test individual units rather than systems. At the point of this commit (this entry was written before any work was done), the major hurdle is refactoring the test cases so that they do not depend on fallback logic and instead simply test specific units and skip the test if the unit (the prototype) is not supported by the environment (e.g. proxies in a pre-ES5 environment). This will allow us to finish refactoring the fallback and environment-specific logic. It will also allow us to cleanly specify a fallback implementation (through composition) in an ES5 environment while keeping ES5 detection mechanisms separate. The remaining refactorings will likely be progressive. This all stemmed out of the desire to add the method hiding feature, whose implementation varies depending on environment. I want to get back to developing that feature so I can get the first release (v0.1.0) out. Refactoring can continue after that point. This project needs a version number so it can be used reliably.
2011-10-10 23:25:23 -04:00
{
cur = failures[ i ];
name = cur[ 0 ];
e = cur[ 1 ];
// output the name followed by the stack trace
testPrint(
'#' + i + ' ' + name + '\n'
+ e.stack + "\n\n"
);
}
}
/**
* Outputs a string if stdout is available (node.js)
*
* @param {string} str string to output
*
* @return {undefined}
*/
var testPrint = ( ( typeof process === 'undefined' )
|| ( typeof process.stdout === 'undefined' ) )
? function() {}
: function( str )
{
process.stdout.write( str );
};