Added ease-full.js, which includes tests to be run client-side (initial implementation; may be buggy)
parent
828a366f29
commit
3347b8f6d5
2
Makefile
2
Makefile
|
@ -2,6 +2,7 @@
|
|||
PATH_BUILD=./build
|
||||
PATH_TOOLS=./tools
|
||||
PATH_COMBINE_OUTPUT=${PATH_BUILD}/ease.js
|
||||
PATH_COMBINE_OUTPUT_FULL=${PATH_BUILD}/ease-full.js
|
||||
|
||||
COMBINE=${PATH_TOOLS}/combine
|
||||
|
||||
|
@ -19,6 +20,7 @@ mkbuild:
|
|||
# browser)
|
||||
combine: mkbuild
|
||||
${COMBINE} > ${PATH_COMBINE_OUTPUT}
|
||||
INC_TEST=1 ${COMBINE} > ${PATH_COMBINE_OUTPUT_FULL}
|
||||
|
||||
# run tests
|
||||
test: default
|
||||
|
|
|
@ -28,45 +28,68 @@ var common = require( './common' ),
|
|||
Script = process.binding( 'evals' ).Script,
|
||||
sandbox = {};
|
||||
|
||||
// attempt to read the combined file
|
||||
try
|
||||
|
||||
var files = [ 'ease.js', 'ease-full.js' ],
|
||||
file = '',
|
||||
i = files.length;
|
||||
|
||||
while ( i-- )
|
||||
{
|
||||
var data = require( 'fs' )
|
||||
.readFileSync( ( __dirname + '/../build/ease.js' ), 'ascii' );
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
// if the file doesn't exit, just skip the test
|
||||
console.log(
|
||||
"Combined file not found. Test skipped. Please run `make combined`."
|
||||
file = files[ i ];
|
||||
|
||||
// attempt to read the combined file
|
||||
try
|
||||
{
|
||||
var data = require( 'fs' )
|
||||
.readFileSync( ( __dirname + '/../build/' + file ), 'ascii' );
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
// if the file doesn't exit, just skip the test
|
||||
console.log(
|
||||
"Combined file not found. Test skipped. Please run `make combined`."
|
||||
);
|
||||
process.exit( 0 );
|
||||
}
|
||||
|
||||
// run the script (if this fails to compile, the generated code is invalid)
|
||||
var cmb_script = new Script( data );
|
||||
cmb_script.runInNewContext( sandbox );
|
||||
|
||||
assert.equal(
|
||||
sandbox.require,
|
||||
undefined,
|
||||
"require() function is not in the global scope"
|
||||
);
|
||||
process.exit( 0 );
|
||||
|
||||
assert.equal(
|
||||
sandbox.exports,
|
||||
undefined,
|
||||
"exports are not in the global scope"
|
||||
);
|
||||
|
||||
|
||||
assert.ok(
|
||||
( sandbox.easejs !== undefined ),
|
||||
"'easejs' namespace is defined within combined file"
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
( sandbox.easejs.Class !== undefined ),
|
||||
"easejs namespace contains class exports"
|
||||
);
|
||||
|
||||
|
||||
// the full file has tests included to be run client-side
|
||||
if ( file === 'ease-full.js' )
|
||||
{
|
||||
assert.ok(
|
||||
( typeof sandbox.easejs.runTests === 'function' ),
|
||||
"Full ease.js file contains test runner"
|
||||
);
|
||||
|
||||
// cross your fingers
|
||||
sandbox.easejs.runTests();
|
||||
}
|
||||
}
|
||||
|
||||
// run the script (if this fails to compile, the generated code is invalid)
|
||||
var cmb_script = new Script( data );
|
||||
cmb_script.runInNewContext( sandbox );
|
||||
|
||||
assert.equal(
|
||||
sandbox.require,
|
||||
undefined,
|
||||
"require() function is not in the global scope"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
sandbox.exports,
|
||||
undefined,
|
||||
"exports are not in the global scope"
|
||||
);
|
||||
|
||||
|
||||
assert.ok(
|
||||
( sandbox.easejs !== undefined ),
|
||||
"'easejs' namespace is defined within combined file"
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
( sandbox.easejs.Class !== undefined ),
|
||||
"easejs namespace contains class exports"
|
||||
);
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
|
||||
PATH_TOOLS=$( dirname "$0" )
|
||||
PATH_LIB="$PATH_TOOLS/../lib"
|
||||
PATH_TEST="$PATH_TOOLS/../test"
|
||||
MODULE_EXT='js'
|
||||
TPL_PATH="$PATH_TOOLS/combine.tpl"
|
||||
TPL_TEST_PATH="$PATH_TOOLS/combine-test.tpl"
|
||||
TPL_VAR='/**{CONTENT}**/'
|
||||
RMTRAIL="$PATH_TOOLS/rmtrail"
|
||||
|
||||
|
@ -91,6 +93,41 @@ for module in $CAT_MODULES; do
|
|||
echo "} )( exports['$module'] = {} );"
|
||||
done
|
||||
|
||||
# include tests?
|
||||
if [ "$INC_TEST" ]; then
|
||||
# note that not all tests are included
|
||||
TEST_CASES=$( find $PATH_TEST \
|
||||
\( -name 'test-*.js' \
|
||||
! -name 'test-combine.js' \
|
||||
! -name 'test-index.js' \
|
||||
\) \
|
||||
-exec basename {} \; \
|
||||
)
|
||||
|
||||
# include test combine template
|
||||
cat "$TPL_TEST_PATH" | grep -v '^#'
|
||||
|
||||
echo "/** TEST CASES **/"
|
||||
echo "ns_exports.runTests = function ()"
|
||||
echo "{"
|
||||
|
||||
for testcase in $TEST_CASES; do
|
||||
filename="$PATH_TEST/$testcase"
|
||||
|
||||
# each module must be enclosed in a closure to emulate a module
|
||||
echo "/** TEST CASE: $testcase **/"
|
||||
echo "( function()"
|
||||
echo "{"
|
||||
|
||||
# add the module, removing trailing commas
|
||||
cat $filename | $RMTRAIL
|
||||
|
||||
echo "} )();"
|
||||
done
|
||||
|
||||
echo "};"
|
||||
fi
|
||||
|
||||
# output combined file footer
|
||||
tpl_footer
|
||||
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
# Included in full combined file for test cases
|
||||
#
|
||||
# Copyright (C) 2010 Mike Gerwitz
|
||||
#
|
||||
# This file is part of ease.js.
|
||||
#
|
||||
# ease.js is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Lesser 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 Lesser General Public License
|
||||
# for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# #
|
||||
|
||||
exports.common = {
|
||||
require: function ( id )
|
||||
{
|
||||
return require( id );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Bare-bones implementation of node.js assert module
|
||||
*
|
||||
* This contains only the used assertions
|
||||
*/
|
||||
exports.assert = {
|
||||
equal: function ( val, cmp, err )
|
||||
{
|
||||
if ( val !== cmp )
|
||||
{
|
||||
throw Error( err );
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
notEqual: function ( val, cmp, err )
|
||||
{
|
||||
if ( val === cmp )
|
||||
{
|
||||
throw Error( err );
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
deepEqual: function ( val, cmp, err )
|
||||
{
|
||||
// todo: not yet implemented
|
||||
},
|
||||
|
||||
|
||||
ok: function ( result, err )
|
||||
{
|
||||
if ( !result )
|
||||
{
|
||||
throw Error( err );
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
throws: function ( test, expected, err )
|
||||
{
|
||||
try
|
||||
{
|
||||
test();
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
if ( !( e instanceof expected ) )
|
||||
{
|
||||
throw Error( err );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
doesNotThrow: function ( test, not_expected, err )
|
||||
{
|
||||
try
|
||||
{
|
||||
test();
|
||||
}
|
||||
catch ( e )
|
||||
{
|
||||
if ( e instanceof not_expected )
|
||||
{
|
||||
throw Error( err );
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
@ -67,7 +67,7 @@ var easejs = {};
|
|||
{
|
||||
// remove the './' directory prefix (every module is currently included
|
||||
// via a relative path)
|
||||
var id_clean = module_id.substring( 2 );
|
||||
var id_clean = module_id.replace( /^.\//, '' );
|
||||
|
||||
// attempt to retrieve the module
|
||||
var module = exports[ id_clean ];
|
||||
|
|
Loading…
Reference in New Issue