Permalink
Browse files

Added tests for relative compilation.

  • Loading branch information...
petebacondarwin committed Jul 20, 2012
1 parent 19cb4ce commit 06a9da0cfda00d3e75452d13a5ecc7d4e3eed5e4
Showing with 34 additions and 16 deletions.
  1. +34 −16 test/coffee_test.js
View
@@ -22,34 +22,52 @@ var grunt = require('grunt'),
test.ifError(value) test.ifError(value)
*/ */
var src = 'test/fixtures/hello_world.coffee';
var destFolder = 'tmp/js';
var relativeDest = function(src) {
var out = path.resolve(path.dirname(src),path.basename(src, '.coffee') + '.js');
return out;
};
exports['coffee'] = { exports['coffee'] = {
setUp: function(done) { setUp: function(done) {
// setup here done();
fs.exists('tmp/coffee', function(exists) { },
if (exists) {
fs.rmdir('tmp/coffee', done); tearDown: function(done) {
} else { if (path.existsSync(destFolder)) {
done(); if ( path.existsSync(destFolder + '/hello_world.js') ) {
fs.unlinkSync(destFolder + '/hello_world.js');
} }
}); fs.rmdirSync(destFolder);
}
if (path.existsSync(relativeDest(src))) {
fs.unlinkSync(relativeDest(src));
}
done();
}, },
'helper': function(test) { 'helper': function(test) {
test.expect(2); test.expect(2);
var files = [
'test/fixtures/hello_world.coffee' grunt.helper('coffee', [src], destFolder);
]; test.equal(grunt.file.read(destFolder + '/hello_world.js'),
var dest = 'tmp/js';
// tests here
grunt.helper('coffee', files, dest);
test.equal(grunt.file.read(dest + '/hello_world.js'),
'\nconsole.log("Hello CoffeeScript!");\n', '\nconsole.log("Hello CoffeeScript!");\n',
'it should compile the coffee'); 'it should compile the coffee');
grunt.helper('coffee', files, dest, { bare:false }); grunt.helper('coffee', [src], destFolder, { bare:false });
test.equal(grunt.file.read(dest + '/hello_world.js'), test.equal(grunt.file.read(destFolder + '/hello_world.js'),
'(function() {\n\n console.log("Hello CoffeeScript!");\n\n}).call(this);\n', '(function() {\n\n console.log("Hello CoffeeScript!");\n\n}).call(this);\n',
'it should compile the coffee'); 'it should compile the coffee');
test.done(); test.done();
},
'helper-nodest': function(test) {
grunt.helper('coffee', [src], null);
test.equal(grunt.file.read(relativeDest(src)),
'\nconsole.log("Hello CoffeeScript!");\n',
'it should compile the coffee');
test.done();
} }
}; };

0 comments on commit 06a9da0

Please sign in to comment.