fixing things up and cleaning more things
This commit is contained in:
parent
ca8c655f00
commit
d214674620
@ -1,5 +1,4 @@
|
||||
require 'pathname'
|
||||
require 'sprockets'
|
||||
|
||||
module Jasmine::Headless
|
||||
autoload :CommandLine, 'jasmine/headless/command_line'
|
||||
@ -29,21 +28,3 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
require 'jasmine/headless/errors'
|
||||
|
||||
# register haml-sprockets if it's available...
|
||||
%w{haml-sprockets}.each do |library|
|
||||
begin
|
||||
require library
|
||||
rescue LoadError
|
||||
end
|
||||
end
|
||||
|
||||
# ...and unregister ones we don't want/need
|
||||
module Sprockets
|
||||
%w{less sass scss erb str}.each do |extension|
|
||||
@engines.delete(".#{extension}")
|
||||
end
|
||||
|
||||
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
|
||||
end
|
||||
|
||||
|
@ -2,6 +2,7 @@ require 'jasmine-core'
|
||||
require 'time'
|
||||
require 'multi_json'
|
||||
require 'set'
|
||||
require 'sprockets'
|
||||
|
||||
module Jasmine::Headless
|
||||
class FilesList
|
||||
@ -99,26 +100,35 @@ module Jasmine::Headless
|
||||
|
||||
def add_dependencies(file, source_root)
|
||||
TestFile.new(file, source_root).dependencies.each do |type, name|
|
||||
if !@checked_dependency.include?(name)
|
||||
@checked_dependency << name
|
||||
add_dependency(type, name, source_root)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
EXTENSION_FILTER = %r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$}
|
||||
def extension_filter
|
||||
%r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$}
|
||||
end
|
||||
|
||||
def add_dependency(type, file, source_root)
|
||||
case type
|
||||
files = case type
|
||||
when 'require'
|
||||
if result = find_dependency(file)
|
||||
add_file(*result)
|
||||
if !@checked_dependency.include?(file)
|
||||
@checked_dependency << file
|
||||
|
||||
[ file ]
|
||||
else
|
||||
[]
|
||||
end
|
||||
when 'require_tree'
|
||||
Dir[File.join(source_root, file, '**/*')].find_all { |path| File.file?(path) && path[EXTENSION_FILTER] }.sort.each do |tree_path|
|
||||
if result = find_dependency(tree_path.gsub(%r{^#{source_root}/}, ''))
|
||||
add_file(*result)
|
||||
Dir[File.join(source_root, file, '**/*')].find_all { |path|
|
||||
File.file?(path) && path[extension_filter]
|
||||
}.sort.collect { |path| path.gsub(%r{^#{source_root}/}, '') }
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
files.each do |file|
|
||||
if result = find_dependency(file)
|
||||
add_file(result[0], result[1], false)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -129,7 +139,7 @@ module Jasmine::Headless
|
||||
root = path.gsub(%r{^#{dir}/}, '')
|
||||
|
||||
ok = (root == file)
|
||||
ok ||= File.basename(path.gsub("#{file}.", '')).split('.').all? { |part| ".#{part}"[EXTENSION_FILTER] }
|
||||
ok ||= File.basename(path.gsub("#{file}.", '')).split('.').all? { |part| ".#{part}"[extension_filter] }
|
||||
|
||||
expanded_path = File.expand_path(path)
|
||||
|
||||
@ -218,10 +228,12 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def expanded_dir(path)
|
||||
Dir[path].collect { |file| File.expand_path(file) }.find_all { |path| File.file?(path) && path[EXTENSION_FILTER] }
|
||||
Dir[path].collect { |file| File.expand_path(file) }.find_all { |path| File.file?(path) && path[extension_filter] }
|
||||
end
|
||||
|
||||
def add_file(file, source_root)
|
||||
def add_file(file, source_root, clear_dependencies = true)
|
||||
@checked_dependency = Set.new if clear_dependencies
|
||||
|
||||
add_dependencies(file, source_root)
|
||||
|
||||
@files << file if !@files.include?(file)
|
||||
|
@ -4,6 +4,8 @@ require 'coffee-script'
|
||||
require 'rainbow'
|
||||
|
||||
require 'yaml'
|
||||
require 'sprockets'
|
||||
|
||||
|
||||
module Jasmine
|
||||
module Headless
|
||||
@ -23,10 +25,31 @@ module Jasmine
|
||||
|
||||
attr_reader :options
|
||||
|
||||
def self.run(options = {})
|
||||
class << self
|
||||
def reset!
|
||||
# register haml-sprockets if it's available...
|
||||
%w{haml-sprockets}.each do |library|
|
||||
begin
|
||||
require library
|
||||
rescue LoadError
|
||||
end
|
||||
end
|
||||
|
||||
# ...and unregister ones we don't want/need
|
||||
Sprockets.instance_eval do
|
||||
%w{less sass scss erb str}.each do |extension|
|
||||
@engines.delete(".#{extension}")
|
||||
end
|
||||
|
||||
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
|
||||
end
|
||||
end
|
||||
|
||||
def run(options = {})
|
||||
options = Options.new(options) if !options.kind_of?(Options)
|
||||
new(options).run
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options)
|
||||
if !File.file?(RUNNER)
|
||||
@ -67,6 +90,7 @@ module Jasmine
|
||||
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
||||
|
||||
Jasmine::Headless::FilesList.reset!
|
||||
self.class.reset!
|
||||
|
||||
files_list = Jasmine::Headless::FilesList.new(
|
||||
:config => jasmine_config,
|
||||
|
@ -199,9 +199,12 @@ describe Jasmine::Headless::FilesList do
|
||||
let(:other_file) { 'other' }
|
||||
let(:path) { 'path' }
|
||||
|
||||
let(:set) { Set.new }
|
||||
|
||||
before do
|
||||
files_list.stubs(:find_dependency).with(file).returns(path)
|
||||
files_list.stubs(:find_dependency).with(file).returns([ path, nil ])
|
||||
files_list.stubs(:find_dependency).with(other_file).returns(false)
|
||||
files_list.instance_variable_set(:@checked_dependency, set)
|
||||
end
|
||||
|
||||
context 'not found' do
|
||||
@ -211,16 +214,20 @@ describe Jasmine::Headless::FilesList do
|
||||
|
||||
it 'should do nothing' do
|
||||
files_list.add_dependency('', other_file, nil)
|
||||
set.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'require' do
|
||||
context 'not already added' do
|
||||
before do
|
||||
files_list.expects(:add_file).with(path, nil)
|
||||
files_list.expects(:add_file).with(path, nil, false)
|
||||
end
|
||||
|
||||
it 'should add the file to the front' do
|
||||
files_list.add_dependency('require', file, nil)
|
||||
set.should include(file)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -235,14 +242,15 @@ describe Jasmine::Headless::FilesList do
|
||||
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)
|
||||
files_list.expects(:find_dependency).with(path).returns([ other_file, nil ])
|
||||
files_list.expects(:add_file).with(other_file, nil, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'should add the file to the front' do
|
||||
files_list.add_dependency('require_tree', '.', File.expand_path('.'))
|
||||
set.should be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -351,5 +359,31 @@ describe Jasmine::Headless::FilesList do
|
||||
it { should == [ File.join(dir, 'file.sub.js'), dir ] }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#add_file' do
|
||||
let(:set) { Set.new([ :one ]) }
|
||||
|
||||
before do
|
||||
files_list.instance_variable_set(:@checked_dependency, set)
|
||||
|
||||
files_list.stubs(:add_dependencies)
|
||||
end
|
||||
|
||||
context 'clear dependencies' do
|
||||
it 'should clear dependency checking' do
|
||||
files_list.send(:add_file, 'file', 'root')
|
||||
|
||||
files_list.instance_variable_get(:@checked_dependency).should == Set.new
|
||||
end
|
||||
end
|
||||
|
||||
context 'do not clear dependencies' do
|
||||
it 'should clear dependency checking' do
|
||||
files_list.send(:add_file, 'file', 'root', false)
|
||||
|
||||
files_list.instance_variable_get(:@checked_dependency).should == set
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -8,6 +8,7 @@ RSpec.configure do |c|
|
||||
c.before(:each) do
|
||||
Jasmine::Headless::CacheableAction.enabled = false
|
||||
Jasmine::Headless::FilesList.reset!
|
||||
Jasmine::Headless::Runner.reset!
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user