more work on making sprockets support better, oh yeah
This commit is contained in:
parent
a2e3ea90c9
commit
537b2e437d
@ -20,6 +20,10 @@ module Jasmine::Headless
|
|||||||
File.directory?(path) ? path : nil
|
File.directory?(path) ? path : nil
|
||||||
}.compact
|
}.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reset!
|
||||||
|
@vendor_asset_paths = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DEFAULT_FILES = %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}
|
DEFAULT_FILES = %w{jasmine.js jasmine-html jasmine.css jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}
|
||||||
@ -32,7 +36,7 @@ module Jasmine::Headless
|
|||||||
@files = []
|
@files = []
|
||||||
@filtered_files = []
|
@filtered_files = []
|
||||||
|
|
||||||
DEFAULT_FILES.each { |file| add_dependency('require', file) }
|
DEFAULT_FILES.each { |file| add_dependency('require', file, nil) }
|
||||||
|
|
||||||
@spec_outside_scope = false
|
@spec_outside_scope = false
|
||||||
@spec_files = []
|
@spec_files = []
|
||||||
@ -85,16 +89,20 @@ module Jasmine::Headless
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_dependencies(file, source_root)
|
def add_dependencies(file, source_root)
|
||||||
TestFile.new(file, source_root).dependencies.each { |type, name| add_dependency(type, name) }
|
TestFile.new(file, source_root).dependencies.each { |type, name| add_dependency(type, name, source_root) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_dependency(type, file)
|
def add_dependency(type, file, source_root)
|
||||||
if result = find_dependency(file)
|
case type
|
||||||
path, source_root = result
|
when 'require'
|
||||||
|
if result = find_dependency(file)
|
||||||
case type
|
add_file(*result)
|
||||||
when 'require'
|
end
|
||||||
add_file(path, source_root)
|
when 'require_tree'
|
||||||
|
Dir[File.join(source_root, file, '**/*.{js,css,coffee}')].each do |tree_path|
|
||||||
|
if result = find_dependency(tree_path.gsub(%r{^#{source_root}/}, ''))
|
||||||
|
add_file(*result)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -103,11 +111,11 @@ module Jasmine::Headless
|
|||||||
search_paths.each do |dir|
|
search_paths.each do |dir|
|
||||||
if file[%r{\.(js|css|coffee)$}]
|
if file[%r{\.(js|css|coffee)$}]
|
||||||
if File.file?(path = File.join(dir, file))
|
if File.file?(path = File.join(dir, file))
|
||||||
return [ File.expand_path(path), dir ]
|
return [ File.expand_path(path), File.expand_path(dir) ]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if path = Dir[File.join(dir, "#{file}.*")].first
|
if path = Dir[File.join(dir, "#{file}.*")].first
|
||||||
return [ File.expand_path(path), dir ]
|
return [ File.expand_path(path), File.expand_path(dir) ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -163,6 +171,7 @@ module Jasmine::Headless
|
|||||||
def add_files(searches, type)
|
def add_files(searches, type)
|
||||||
searches.each do |search|
|
searches.each do |search|
|
||||||
dir = @config[SEARCH_ROOTS[type]] || Dir.pwd
|
dir = @config[SEARCH_ROOTS[type]] || Dir.pwd
|
||||||
|
dir = File.expand_path(dir)
|
||||||
|
|
||||||
path = File.expand_path(File.join(dir, search))
|
path = File.expand_path(File.join(dir, search))
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ module Jasmine
|
|||||||
def run
|
def run
|
||||||
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
||||||
|
|
||||||
|
Jasmine::Headless::FilesList.reset!
|
||||||
|
|
||||||
files_list = Jasmine::Headless::FilesList.new(
|
files_list = Jasmine::Headless::FilesList.new(
|
||||||
:config => jasmine_config,
|
:config => jasmine_config,
|
||||||
:only => @options[:files]
|
:only => @options[:files]
|
||||||
|
@ -46,7 +46,7 @@ module Jasmine::Headless
|
|||||||
|
|
||||||
processor = Sprockets::DirectiveProcessor.new(path)
|
processor = Sprockets::DirectiveProcessor.new(path)
|
||||||
@dependencies = processor.directives.collect do |_, type, name|
|
@dependencies = processor.directives.collect do |_, type, name|
|
||||||
if name[%r{^./}]
|
if name[%r{^\.}]
|
||||||
name = File.expand_path(File.join(File.dirname(path), name)).gsub(%r{^#{source_root}/}, '')
|
name = File.expand_path(File.join(File.dirname(path), name)).gsub(%r{^#{source_root}/}, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ describe Jasmine::Headless::FilesList do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should do nothing' do
|
it 'should do nothing' do
|
||||||
files_list.add_dependency('', other_file)
|
files_list.add_dependency('', other_file, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -247,7 +247,29 @@ describe Jasmine::Headless::FilesList do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should add the file to the front' do
|
it 'should add the file to the front' do
|
||||||
files_list.add_dependency('require', file)
|
files_list.add_dependency('require', file, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'require_tree' do
|
||||||
|
include FakeFS::SpecHelpers
|
||||||
|
|
||||||
|
let(:paths) { %w{one.js dir/two.coffee dir/three.css dir/subdir/four.js.erb other/five.css.erb} }
|
||||||
|
|
||||||
|
before do
|
||||||
|
paths.each do |path|
|
||||||
|
FileUtils.mkdir_p File.dirname(path)
|
||||||
|
File.open(path, 'wb')
|
||||||
|
|
||||||
|
if path[%r{\.(js|css|coffee)$}]
|
||||||
|
files_list.expects(:find_dependency).with(path).returns(other_file)
|
||||||
|
files_list.expects(:add_file).with(other_file, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should add the file to the front' do
|
||||||
|
files_list.add_dependency('require_tree', '.', File.expand_path('.'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -99,5 +99,15 @@ describe Jasmine::Headless::TestFile do
|
|||||||
|
|
||||||
it { should == [ [ 'require', 'subdir/subsubdir/test' ] ] }
|
it { should == [ [ 'require', 'subdir/subsubdir/test' ] ] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'dot' do
|
||||||
|
let(:path) { File.join(source_root, 'subdir/subsubdir/path.js') }
|
||||||
|
|
||||||
|
let(:req) { '.' }
|
||||||
|
|
||||||
|
subject { file.dependencies }
|
||||||
|
|
||||||
|
it { should == [ [ 'require', 'subdir/subsubdir' ] ] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ RSpec.configure do |c|
|
|||||||
|
|
||||||
c.before(:each) do
|
c.before(:each) do
|
||||||
Jasmine::Headless::CacheableAction.enabled = false
|
Jasmine::Headless::CacheableAction.enabled = false
|
||||||
Jasmine::Headless::FilesList.instance_variable_set(:@vendor_asset_paths, nil)
|
Jasmine::Headless::FilesList.reset!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -67,6 +67,10 @@ module RSpec::Matchers
|
|||||||
|
|
||||||
file_list.length == 0
|
file_list.length == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
failure_message_for_should do |lines|
|
||||||
|
%{expected\n#{lines.join("\n")}\nto contain the following files, in order:\n#{files.join("\n")}}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user