2010-12-20 22:49:52 -05:00
|
|
|
/**
|
|
|
|
* Tests combined file (basic evaluation)
|
|
|
|
*
|
2013-12-20 01:11:26 -05:00
|
|
|
* Copyright (C) 2010, 2011, 2013 Mike Gerwitz
|
2010-12-20 22:49:52 -05:00
|
|
|
*
|
2013-12-22 09:37:21 -05:00
|
|
|
* This file is part of GNU ease.js.
|
2010-12-20 22:49:52 -05:00
|
|
|
*
|
2014-01-15 23:56:00 -05:00
|
|
|
* 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.
|
2010-12-20 22:49:52 -05:00
|
|
|
*
|
2014-01-15 23:56:00 -05:00
|
|
|
* 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.
|
2010-12-20 22:49:52 -05:00
|
|
|
*
|
2014-01-15 23:56:00 -05:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-20 22:49:52 -05:00
|
|
|
*/
|
|
|
|
|
2010-12-21 23:25:12 -05:00
|
|
|
var common = require( './common' ),
|
|
|
|
assert = require( 'assert' ),
|
2011-12-04 12:50:01 -05:00
|
|
|
vm = require( 'vm' ),
|
2010-12-21 23:25:12 -05:00
|
|
|
Class = common.require( 'class' ),
|
2011-03-06 10:55:13 -05:00
|
|
|
|
|
|
|
// sandbox in which combined script will be run
|
|
|
|
sandbox = {
|
|
|
|
// stub document.write() so we don't blow up
|
|
|
|
document: { write: function() {} },
|
|
|
|
};
|
2010-12-20 22:49:52 -05:00
|
|
|
|
2010-12-28 00:23:13 -05:00
|
|
|
|
2011-05-23 18:38:13 -04:00
|
|
|
// test all combined files, including minified files
|
2011-08-31 00:24:19 -04:00
|
|
|
var files = [ 'ease.js', 'ease-full.js'],
|
2010-12-28 00:23:13 -05:00
|
|
|
file = '',
|
|
|
|
i = files.length;
|
|
|
|
|
|
|
|
while ( i-- )
|
2010-12-20 22:49:52 -05:00
|
|
|
{
|
2010-12-28 00:23:13 -05:00
|
|
|
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(
|
2011-05-23 18:38:13 -04:00
|
|
|
"Combined/minified file not found. Test skipped. Please run " +
|
|
|
|
"`make min`."
|
2010-12-28 00:23:13 -05:00
|
|
|
);
|
|
|
|
process.exit( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// run the script (if this fails to compile, the generated code is invalid)
|
2011-12-04 12:50:01 -05:00
|
|
|
vm.runInNewContext( data, sandbox );
|
2010-12-28 00:23:13 -05:00
|
|
|
|
|
|
|
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"
|
2010-12-20 22:49:52 -05:00
|
|
|
);
|
|
|
|
|
2010-12-28 00:23:13 -05:00
|
|
|
assert.ok(
|
|
|
|
( sandbox.easejs !== undefined ),
|
|
|
|
"'easejs' namespace is defined within combined file"
|
|
|
|
);
|
2010-12-20 22:49:52 -05:00
|
|
|
|
2011-05-23 07:12:46 -04:00
|
|
|
[
|
|
|
|
'Class',
|
|
|
|
'AbstractClass',
|
|
|
|
'FinalClass',
|
2011-12-23 00:00:50 -05:00
|
|
|
'Interface',
|
|
|
|
'version'
|
2011-05-23 07:12:46 -04:00
|
|
|
] .forEach( function( item )
|
2011-01-09 02:00:36 -05:00
|
|
|
{
|
|
|
|
assert.ok(
|
|
|
|
sandbox.easejs[ item ],
|
|
|
|
"Combined file exports exposes " + item
|
|
|
|
);
|
|
|
|
} );
|
2010-12-20 22:49:52 -05:00
|
|
|
|
2010-12-28 00:23:13 -05:00
|
|
|
// the full file has tests included to be run client-side
|
2011-05-23 18:38:13 -04:00
|
|
|
if ( file.match( /ease-full/ ) )
|
2010-12-28 00:23:13 -05:00
|
|
|
{
|
|
|
|
assert.ok(
|
|
|
|
( typeof sandbox.easejs.runTests === 'function' ),
|
|
|
|
"Full ease.js file contains test runner"
|
|
|
|
);
|
2010-12-20 22:49:52 -05:00
|
|
|
|
2010-12-28 00:23:13 -05:00
|
|
|
// cross your fingers
|
|
|
|
sandbox.easejs.runTests();
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 22:49:52 -05:00
|
|
|
|