Skip to content

Commit

Permalink
Merge pull request #392 from kate2753/master
Browse files Browse the repository at this point in the history
Add Rhino and Rhino unit tests
  • Loading branch information
jimmyhchan committed Jan 16, 2014
2 parents 2272b30 + 5441c40 commit 3ef4816
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ language: node_js
node_js:
- "0.10"
- "0.8"
env:
- TEST="all"
- TEST="node"
matrix:
exclude:
- node_js: "0.10"
env: TEST="node"
- node_js: "0.8"
env: TEST="all"
notifications:
email:
- jdemorais@linkedin.com
Expand All @@ -10,3 +19,5 @@ notifications:
- jchan@linkedin.com
before_install:
- npm install -g grunt-cli
script:
- "[ $TEST = 'all' ] && grunt test || grunt testNode"
37 changes: 36 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,41 @@ module.exports = function(grunt) {
' * npm publish'].join('\n')
}
}
},
testRhino : {
files: ['test/rhino/lib/**/*.jar']
}
});

grunt.registerMultiTask('testRhino', function(){
var shellTaskConfig = grunt.config.get('shell'),
commandList= [];

//iterate over rhino jars - list is defined in task config
this.files.forEach(function(fileGroup) {
fileGroup.src.forEach(function(rhinoJar) {
commandList.push('java -jar ' + rhinoJar + ' -f test/rhino/rhinoTest.js');
});
});

grunt.log.ok(JSON.stringify(commandList));

shellTaskConfig['rhinoTests'] = {
command : commandList.join('&&'),
options: {
stdout: true,
callback: function(err, stdout, stderr, cb) {
if(err || stderr){
grunt.warn('There are failing unit tests in Rhino');
}
cb();
}
}
};
grunt.config.set('shell', shellTaskConfig);
grunt.task.run('shell:rhinoTests');
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
Expand All @@ -209,9 +241,12 @@ module.exports = function(grunt) {
// Npm tasks
grunt.registerTask('default', ['build']);
grunt.registerTask('build', ['clean:build', 'jshint', 'shell:buildParser','concat', 'uglify']);
grunt.registerTask('test', ['clean:specRunner', 'build', 'jasmine', 'shell:oldTests']);

grunt.registerTask('test', ['clean:specRunner', 'build', 'jasmine', 'shell:oldTests', 'testRhino']);
grunt.registerTask('testNode', ['shell:oldTests']);
grunt.registerTask('testClient', ['build', 'jasmine:allTests:build', 'log:testClient', 'connect:testServer']);


grunt.registerTask('copyForRelease', ['clean:dist', 'copy:core', 'copy:coreMin', 'copy:full', 'copy:fullMin', 'copy:license', 'log:copyForRelease']);
grunt.registerTask('buildRelease', ['test', 'copyForRelease', 'compress']);
grunt.registerTask('releasePatch', ['bump-only:patch', 'buildRelease', 'bump-commit', 'log:release']);
Expand Down
4 changes: 2 additions & 2 deletions test/jasmine-test/spec/coreTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ var coreTests = [
{
name: "array reference $idx/$len not changed in nested object",
source: "{#results}{#info}{$idx}{name}-{$len} {/info}{/results}",
context: { results: [ {info: {name: "Steven"}  },  {info: {name: "Richard"} } ]  },
context: {results: [{info: {name: "Steven"}},{info: {name: "Richard"}}]},
expected: "0Steven-2 1Richard-2 ",
message: "test array reference $idx/$len not changed in nested object"
},
Expand Down Expand Up @@ -1875,5 +1875,5 @@ var coreTests = [
if (typeof module !== "undefined" && typeof require !== "undefined") {
module.exports = coreTests; // We're on node.js
} else {
window.coreTests = coreTests; // We're on the browser
this['coreTests'] = coreTests; // Set it up as global - browser or rhino
}
Binary file added test/rhino/lib/rhino-1.7R3.jar
Binary file not shown.
Binary file added test/rhino/lib/rhino-1.7R5.jar
Binary file not shown.
81 changes: 81 additions & 0 deletions test/rhino/rhinoTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
var setTimeout,
clearTimeout,
setInterval,
clearInterval;

//set up functions missing in Rhino
(function () {
var timer = new java.util.Timer();
var counter = 1,
ids = {};

setTimeout = function (fn, delay) {
var id = counter++;
ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});
timer.schedule(ids[id], delay);
return id;
}

clearTimeout = function (id) {
ids[id].cancel();
timer.purge();
delete ids[id];
}

setInterval = function (fn,delay) {
var id = counter++;
ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});
timer.schedule(ids[id],delay,delay);
return id;
}

clearInterval = clearTimeout;
})();

print('Running unit tests with ' + environment['java.class.path']);

var requiredFiles = [
'node_modules/grunt-contrib-jasmine/vendor/jasmine-1.3.1/jasmine.js',
'tmp/dust-full.js',
'test/jasmine-test/spec/testHelpers.js',
'test/jasmine-test/spec/coreTests.js',
'test/jasmine-test/spec/renderTestSpec.js'
];

//load all of the dependencies and unit tests
for(var i = 0; i < requiredFiles.length; i++){
load(requiredFiles[i]);
}
var jasmineEnv = jasmine.getEnv(),
reporter = new jasmine.Reporter();

jasmineEnv.addReporter(reporter);

reporter.reportSpecResults = function(spec){
java.lang.System.out.print('.');
}

//set up reporter to print results to console and quit rhino shell
reporter.reportSuiteResults = function (suite) {
print('\n');
var passed = 0, failed = [];
for(var i = 0; i < suite.specs_.length; i ++) {
if(suite.specs_[i].results_.failedCount > 0) {
print('\tFailed: ' + suite.specs_[i].description);
failed.push(suite.specs_[i]);
} else {
//print('\tPassed: ' + suite.specs_[i].description);
passed++;
}
}
print('Passed ' + passed + ' Failed ' + failed.length + '\n');

if(failed.length > 0) {
throw 'There are failing tests.';
} else {
quit();
}
};

//execute unit tests
jasmineEnv.execute();

0 comments on commit 3ef4816

Please sign in to comment.