fix extension search issue and expand bad extension searches to jasmine-style includes
This commit is contained in:
parent
00468fc1b3
commit
352ee417c5
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ jhw-test
|
|||||||
_site/
|
_site/
|
||||||
jhw.*.html
|
jhw.*.html
|
||||||
coverage/
|
coverage/
|
||||||
|
tmp/
|
||||||
|
@ -1,10 +1,21 @@
|
|||||||
module Jasmine::Headless::FileChecker
|
module Jasmine::Headless::FileChecker
|
||||||
def bad_format?(file)
|
def bad_format?(file)
|
||||||
return if file.nil?
|
return if file.nil?
|
||||||
::Jasmine::Headless::EXCLUDED_FORMATS.any? {|format| file.include?(".#{format}") }
|
|
||||||
|
::Jasmine::Headless::EXCLUDED_FORMATS.any? do |format|
|
||||||
|
file[%r{\.#{format}(\.|$)}]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def alert_bad_format(file)
|
def alert_bad_format(file)
|
||||||
puts "[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ]
|
puts "[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def alert_if_bad_format?(file)
|
||||||
|
if result = bad_format?(file)
|
||||||
|
alert_bad_format(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
end
|
end
|
@ -6,8 +6,9 @@ require 'sprockets'
|
|||||||
require 'sprockets/engines'
|
require 'sprockets/engines'
|
||||||
|
|
||||||
module Jasmine::Headless
|
module Jasmine::Headless
|
||||||
|
|
||||||
class FilesList
|
class FilesList
|
||||||
|
include FileChecker
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def vendor_asset_paths
|
def vendor_asset_paths
|
||||||
return @vendor_asset_paths if @vendor_asset_paths
|
return @vendor_asset_paths if @vendor_asset_paths
|
||||||
@ -54,6 +55,12 @@ module Jasmine::Headless
|
|||||||
def default_files
|
def default_files
|
||||||
%w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}
|
%w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extension_filter
|
||||||
|
extensions = (%w{.js .css} + Sprockets.engine_extensions)
|
||||||
|
|
||||||
|
%r{(#{extensions.join('|')})$}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
PLEASE_WAIT_IM_WORKING_TIME = 2
|
PLEASE_WAIT_IM_WORKING_TIME = 2
|
||||||
@ -212,11 +219,17 @@ module Jasmine::Headless
|
|||||||
end
|
end
|
||||||
|
|
||||||
def expanded_dir(path)
|
def expanded_dir(path)
|
||||||
Dir[path].find_all { |file| file[extension_filter] }.collect { |file| File.expand_path(file) }.find_all { |path| File.file?(path) }
|
Dir[path].find_all { |file|
|
||||||
|
file[extension_filter] && !alert_if_bad_format?(file)
|
||||||
|
}.collect {
|
||||||
|
|file| File.expand_path(file)
|
||||||
|
}.find_all {
|
||||||
|
|path| File.file?(path)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def extension_filter
|
def extension_filter
|
||||||
%r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$}
|
self.class.extension_filter
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_path(path, type)
|
def add_path(path, type)
|
||||||
|
@ -9,11 +9,15 @@ describe 'sprockets' do
|
|||||||
'vendor/assets/javascripts/jquery.js',
|
'vendor/assets/javascripts/jquery.js',
|
||||||
'templates/that.jst.ejs',
|
'templates/that.jst.ejs',
|
||||||
'templates/this.jst',
|
'templates/this.jst',
|
||||||
|
'things/jquery.string.js',
|
||||||
'assets/things/required.js',
|
'assets/things/required.js',
|
||||||
'assets/things/code.js',
|
'assets/things/code.js',
|
||||||
'assets/things/subcode/more_code.js',
|
'assets/things/subcode/more_code.js',
|
||||||
'spec_helper.js',
|
'spec_helper.js',
|
||||||
'spec/things/code_spec.js'
|
'spec/things/code_spec.js'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
files.lines.to_a.any? { |line| line['assets/jquery.string.js: unsupported format'] }.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
//= require 'jquery'
|
//= require 'jquery'
|
||||||
|
//= require 'things/jquery.string'
|
||||||
|
|
||||||
|
@ -13,10 +13,13 @@ describe Jasmine::Headless::FileChecker do
|
|||||||
it "should return false wth correct format" do
|
it "should return false wth correct format" do
|
||||||
test_class.bad_format?('foobar.js').should be_false
|
test_class.bad_format?('foobar.js').should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return false wth wrong format" do
|
it "should return false wth wrong format" do
|
||||||
test_class.bad_format?('foobar.js.erb').should be_true
|
test_class.bad_format?('foobar.js.erb').should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should check for the whole extension" do
|
||||||
|
test_class.bad_format?('foobar.string.js').should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -204,15 +204,23 @@ describe Jasmine::Headless::FilesList do
|
|||||||
10.times do |index|
|
10.times do |index|
|
||||||
File.open(File.join(dir, "file-#{index}.js"), 'wb')
|
File.open(File.join(dir, "file-#{index}.js"), 'wb')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
File.open(File.join(dir, 'file.js.erb'), 'wb')
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should load spec files in a random order' do
|
it 'should load spec files in a random order' do
|
||||||
files_list.send(:add_files, [ '*' ], 'spec_files', [ dir ])
|
|
||||||
|
|
||||||
files_list.files.collect { |name| name[%r{\d+}] }.should == %w{6 7 1 0 5 3 4 8 2 9}
|
files_list.files.collect { |name| name[%r{\d+}] }.should == %w{6 7 1 0 5 3 4 8 2 9}
|
||||||
|
|
||||||
FileUtils.rm_rf dir
|
FileUtils.rm_rf dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not load an excluded format' do
|
||||||
|
files_list.files.any? { |file| file['.erb'] }.should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user