diff --git a/package.json b/package.json index 84a5f9d..82d1e3b 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "stylus": "*", "nib": "*", "csso": "*", - "handlebars": "*" + "handlebars": "*", + "require-tree": "*" }, "repository": { "type": "git", diff --git a/test/compilers/coffeescript.spec.coffee b/test/compilers/coffeescript.spec.coffee new file mode 100644 index 0000000..d4c9f96 --- /dev/null +++ b/test/compilers/coffeescript.spec.coffee @@ -0,0 +1,26 @@ +flour = require '../../flour' +should = require 'should' +fs = require 'fs' + +flour.silent() + +describe 'CoffeeScript compiler', -> + + input_file = "#{dir.sources}/compile.coffee" + output_file = "#{dir.temp}/compile.js" + + it 'should compile CoffeeScript and return the output', (done) -> + flour.compile input_file, (output) -> + output.should.include 'bacon = function' + done() + + it 'should compile CoffeeScript to a file', (done) -> + flour.compile input_file, output_file, -> + readFile(output_file).should.include 'bacon = function' + done() + + it 'should compile CoffeeScript to a file && return the output', (done) -> + flour.compile input_file, output_file, (res) -> + should.exist fs.existsSync output_file + res.should.include 'bacon = function' + done() diff --git a/test/compilers/less.spec.coffee b/test/compilers/less.spec.coffee new file mode 100644 index 0000000..c89a5c4 --- /dev/null +++ b/test/compilers/less.spec.coffee @@ -0,0 +1,37 @@ +flour = require '../../flour' +should = require 'should' + +flour.silent() + +describe 'LESS compiler', -> + + input_file = "#{dir.sources}/compile.less" + output_file = "#{dir.temp}/compile.css" + + it 'should compile LESS and return the output', (done) -> + flour.compile input_file, (output) -> + output.should.include '.one .two' + done() + + it 'should compile LESS to a file', (done) -> + flour.compile input_file, output_file, -> + readFile(output_file).should.include '.one .two{color' # compressed by default + done() + + it 'should compile LESS to a file && return the output', (done) -> + flour.compile input_file, output_file, (res) -> + readFile(output_file).should.include '.one .two' + res.should.include '.one .two' + done() + + it 'should compile LESS with compression disabled', (done) -> + flour.compilers.less.compress = false + flour.compile input_file, (output) -> + output.should.include '.one .two {\n color: #abcdef;\n}' + done() + + it 'should compile LESS with yui compression enabled', (done) -> + flour.compilers.less.yuicompress = true + flour.compile input_file, (output) -> + output.should.include '.one .two{color:#abcdef}' + done() diff --git a/test/compilers/stylus.spec.coffee b/test/compilers/stylus.spec.coffee new file mode 100644 index 0000000..fa2b21e --- /dev/null +++ b/test/compilers/stylus.spec.coffee @@ -0,0 +1,31 @@ +flour = require '../../flour' +should = require 'should' + +flour.silent() + +describe 'Stylus compiler', -> + + input_file = "#{dir.sources}/compile.styl" + output_file = "#{dir.temp}/compile.css" + + it 'should compile Stylus and return the output', (done) -> + flour.compile input_file, (output) -> + output.should.include '.one .two' + done() + + it 'should compile Stylus to a file', (done) -> + flour.compile input_file, output_file, -> + readFile(output_file).should.include '.one .two' + done() + + it 'should compile Stylus to a file && return the output', (done) -> + flour.compile input_file, output_file, (res) -> + readFile(output_file).should.include '.one .two' + res.should.include '.one .two' + done() + + it 'should compile Stylus with compression disabled', (done) -> + flour.compilers.styl.compress = false + flour.compile input_file, (output) -> + output.should.include '.one .two {\n color: #abcdef;\n}' + done() \ No newline at end of file diff --git a/test/flour.spec.coffee b/test/flour.spec.coffee index 2910e0a..3c79c01 100644 --- a/test/flour.spec.coffee +++ b/test/flour.spec.coffee @@ -5,10 +5,10 @@ path = require 'path' flour = require '../flour' File = require '../lib/file' -readFile = (file) -> fs.readFileSync(file).toString() -copyFile = (file, out) -> fs.writeFileSync out, readFile file +global.readFile = (file) -> fs.readFileSync(file).toString() +global.copyFile = (file, out) -> fs.writeFileSync out, readFile file -dir = +global.dir = sources: 'test/sources' temp: 'test/temp' @@ -34,119 +34,6 @@ describe 'Flour', -> it 'should expose a watch method', -> flour.bundle.should.be.a('function') -describe 'CoffeeScript compiler', -> - - input_file = "#{dir.sources}/compile.coffee" - output_file = "#{dir.temp}/compile.js" - - it 'should compile CoffeeScript and return the output', (done) -> - flour.compile input_file, (output) -> - output.should.include 'bacon = function' - done() - - it 'should compile CoffeeScript to a file', (done) -> - flour.compile input_file, output_file, -> - readFile(output_file).should.include 'bacon = function' - done() - - it 'should compile CoffeeScript to a file && return the output', (done) -> - flour.compile input_file, output_file, (res) -> - should.exist fs.existsSync output_file - res.should.include 'bacon = function' - done() - -describe 'LESS compiler', -> - - input_file = "#{dir.sources}/compile.less" - output_file = "#{dir.temp}/compile.css" - - it 'should compile LESS and return the output', (done) -> - flour.compile input_file, (output) -> - output.should.include '.one .two' - done() - - it 'should compile LESS to a file', (done) -> - flour.compile input_file, output_file, -> - readFile(output_file).should.include '.one .two{color' # compressed by default - done() - - it 'should compile LESS to a file && return the output', (done) -> - flour.compile input_file, output_file, (res) -> - readFile(output_file).should.include '.one .two' - res.should.include '.one .two' - done() - - it 'should compile LESS with compression disabled', (done) -> - flour.compilers.less.compress = false - flour.compile input_file, (output) -> - output.should.include '.one .two {\n color: #abcdef;\n}' - done() - - it 'should compile LESS with yui compression enabled', (done) -> - flour.compilers.less.yuicompress = true - flour.compile input_file, (output) -> - output.should.include '.one .two{color:#abcdef}' - done() - - -describe 'Stylus compiler', -> - - input_file = "#{dir.sources}/compile.styl" - output_file = "#{dir.temp}/compile.css" - - it 'should compile Stylus and return the output', (done) -> - flour.compile input_file, (output) -> - output.should.include '.one .two' - done() - - it 'should compile Stylus to a file', (done) -> - flour.compile input_file, output_file, -> - readFile(output_file).should.include '.one .two' - done() - - it 'should compile Stylus to a file && return the output', (done) -> - flour.compile input_file, output_file, (res) -> - readFile(output_file).should.include '.one .two' - res.should.include '.one .two' - done() - - it 'should compile Stylus with compression disabled', (done) -> - flour.compilers.styl.compress = false - flour.compile input_file, (output) -> - output.should.include '.one .two {\n color: #abcdef;\n}' - done() - - -describe 'JS minifier', -> - - input_file = "#{dir.sources}/minify.js" - output_file = "#{dir.temp}/minify.min.js" - - it 'should minify javascript and return the output', (done) -> - flour.minify input_file, (output) -> - output.should.include 'function test(){return' - done() - - it 'should minify javascript to a file', (done) -> - flour.minify input_file, output_file, -> - readFile(output_file).should.include 'function test(){return' - done() - - -describe 'CSS minifier', -> - - input_file = "#{dir.sources}/minify.css" - output_file = "#{dir.temp}/minify.min.css" - - it 'should minify css and return the output', (done) -> - flour.minify input_file, (output) -> - output.should.include 'body,p{color:red}' - done() - - it 'should minify css to a file', (done) -> - flour.minify input_file, output_file, -> - readFile(output_file).should.include 'body,p{color:red}' - done() describe 'Bundle', -> @@ -353,3 +240,7 @@ describe 'File path handling', -> should.exist fs.existsSync out readFile(out).should.include 'bacon = function' done() + +requiretree = require 'require-tree' +requiretree('test/compilers') +requiretree('test/minifiers') diff --git a/test/minifiers/csso.spec.coffee b/test/minifiers/csso.spec.coffee new file mode 100644 index 0000000..2ebf411 --- /dev/null +++ b/test/minifiers/csso.spec.coffee @@ -0,0 +1,19 @@ +flour = require '../../flour' +should = require 'should' + +flour.silent() + +describe 'CSS minifier', -> + + input_file = "#{dir.sources}/minify.css" + output_file = "#{dir.temp}/minify.min.css" + + it 'should minify css and return the output', (done) -> + flour.minify input_file, (output) -> + output.should.include 'body,p{color:red}' + done() + + it 'should minify css to a file', (done) -> + flour.minify input_file, output_file, -> + readFile(output_file).should.include 'body,p{color:red}' + done() diff --git a/test/minifiers/uglify-js.spec.coffee b/test/minifiers/uglify-js.spec.coffee new file mode 100644 index 0000000..1fef363 --- /dev/null +++ b/test/minifiers/uglify-js.spec.coffee @@ -0,0 +1,19 @@ +flour = require '../../flour' +should = require 'should' + +flour.silent() + +describe 'JS minifier', -> + + input_file = "#{dir.sources}/minify.js" + output_file = "#{dir.temp}/minify.min.js" + + it 'should minify javascript and return the output', (done) -> + flour.minify input_file, (output) -> + output.should.include 'function test(){return' + done() + + it 'should minify javascript to a file', (done) -> + flour.minify input_file, output_file, -> + readFile(output_file).should.include 'function test(){return' + done()