diff --git a/.travis.yml b/.travis.yml index d982d417..80520260 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ gemfile: - test/gemfiles/sass_3_3.gemfile - test/gemfiles/sass_head.gemfile before_install: - - "npm install node-sass" + - "npm install node-sass mincer ejs" matrix: allow_failures: - gemfile: test/gemfiles/sass_head.gemfile diff --git a/test/dummy_node_mincer/apple-touch-icon-144-precomposed.png b/test/dummy_node_mincer/apple-touch-icon-144-precomposed.png new file mode 100644 index 00000000..622a865a Binary files /dev/null and b/test/dummy_node_mincer/apple-touch-icon-144-precomposed.png differ diff --git a/test/dummy_node_mincer/application.css b/test/dummy_node_mincer/application.css new file mode 100644 index 00000000..a7bc37fc --- /dev/null +++ b/test/dummy_node_mincer/application.css @@ -0,0 +1,4 @@ + +/* + *= require require_all + */ \ No newline at end of file diff --git a/test/dummy_node_mincer/manifest.js b/test/dummy_node_mincer/manifest.js new file mode 100644 index 00000000..5c968865 --- /dev/null +++ b/test/dummy_node_mincer/manifest.js @@ -0,0 +1,86 @@ +'use strict'; + + +// Build script from https://github.com/nodeca/mincer/tree/master/examples + +// +// Require module +// + + +var Mincer = require('mincer'); + + +// +// Get Mincer environment +// + + +// +// Configure Mincers logger, by default, all +// messages are going to the middle of nowhere +// + + +Mincer.logger.use(console); + + +// +// Create and export environment +// + + +var environment = new Mincer.Environment(process.cwd()); + + +// +// Configure environment load paths (where to find ssets) +// + +// Include bootstrap scss load path +environment.appendPath('../../vendor/assets/stylesheets'); + +// Include fonts load path +environment.appendPath('../../vendor/assets/fonts'); + +// Include dir with assets, root just for test +environment.appendPath('./'); + + +// +// Define environment essential *_path helper that will be available in the +// processed assets. See `assets/stylesheets/app.css.ejs` for example. +// + + +environment.ContextClass.defineAssetPath(function (pathname, options) { + var asset = this.environment.findAsset(pathname, options); + + if (!asset) { + throw new Error("File " + pathname + " not found"); + } + + return '/assets/' + asset.digestPath; +}); + + +// +// Create and compile Manifest +// + +var manifest_path = process.argv[2] || __dirname + '/assets'; + +var manifest = new Mincer.Manifest(environment, manifest_path); + + +manifest.compile(['application.css'], function (err, assetsData) { + if (err) { + console.error("Failed compile assets: " + (err.message || err.toString())); + process.exit(128); + } + + console.info('\n\nAssets were successfully compiled.\n' + + 'Manifest data (a proper JSON) was written to:\n' + + manifest.path + '\n\n'); + console.dir(assetsData); +}); diff --git a/test/dummy_node_mincer/require_all.css.ejs.scss b/test/dummy_node_mincer/require_all.css.ejs.scss new file mode 100644 index 00000000..458fa55d --- /dev/null +++ b/test/dummy_node_mincer/require_all.css.ejs.scss @@ -0,0 +1,8 @@ + + +@import "bootstrap/bootstrap-mincer"; +@import "bootstrap"; + +#image-retina { + @include img-retina("apple-touch-icon-144-precomposed.png", "apple-touch-icon-144-precomposed.png", 72px, 72px); +} \ No newline at end of file diff --git a/test/node_mincer_test.rb b/test/node_mincer_test.rb new file mode 100644 index 00000000..ad9697ab --- /dev/null +++ b/test/node_mincer_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' +require 'json' + +class NodeMincerTest < Test::Unit::TestCase + DUMMY_PATH = 'test/dummy_node_mincer' + + def test_font_helper_without_suffix + assert_match %r(url\(['"]?/assets/.*eot['"]?\)), @css + end + + def test_font_helper_with_suffix_sharp + assert_match %r(url\(['"]?/assets/.*svg#.+['"]?\)), @css + end + + def test_font_helper_with_suffix_question + assert_match %r(url\(['"]?/assets/.*eot\?.*['"]?\)), @css + end + + def test_image_helper + assert_match %r(url\(['"]?/assets/apple-touch-icon-144-precomposed.*png['"]?\)), @css + end + + def setup + tmp_dir = File.join Bootstrap.gem_path, 'tmp/node-mincer' + command = "node manifest.js #{tmp_dir}" + Dir.chdir DUMMY_PATH do + assert silence_stream(STDOUT) { + system(command) + }, 'Node.js Mincer compilation failed' + end + manifest = JSON.parse(File.read("#{tmp_dir}/manifest.json")) + css_name = manifest["assets"]["application.css"] + @css = File.read("#{tmp_dir}/#{css_name}") + end +end