mirror of
https://github.com/twbs/bootstrap-sass.git
synced 2022-11-09 12:27:02 -05:00
added tests for mincer font/image helpers
This commit is contained in:
parent
fe708c8241
commit
edc3b0f669
6 changed files with 134 additions and 1 deletions
|
@ -9,7 +9,7 @@ gemfile:
|
||||||
- test/gemfiles/sass_3_3.gemfile
|
- test/gemfiles/sass_3_3.gemfile
|
||||||
- test/gemfiles/sass_head.gemfile
|
- test/gemfiles/sass_head.gemfile
|
||||||
before_install:
|
before_install:
|
||||||
- "npm install node-sass"
|
- "npm install node-sass mincer ejs"
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- gemfile: test/gemfiles/sass_head.gemfile
|
- gemfile: test/gemfiles/sass_head.gemfile
|
||||||
|
|
BIN
test/dummy_node_mincer/apple-touch-icon-144-precomposed.png
Normal file
BIN
test/dummy_node_mincer/apple-touch-icon-144-precomposed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
4
test/dummy_node_mincer/application.css
Normal file
4
test/dummy_node_mincer/application.css
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
*= require require_all
|
||||||
|
*/
|
86
test/dummy_node_mincer/manifest.js
Normal file
86
test/dummy_node_mincer/manifest.js
Normal file
|
@ -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);
|
||||||
|
});
|
8
test/dummy_node_mincer/require_all.css.ejs.scss
Normal file
8
test/dummy_node_mincer/require_all.css.ejs.scss
Normal file
|
@ -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);
|
||||||
|
}
|
35
test/node_mincer_test.rb
Normal file
35
test/node_mincer_test.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue