fixing things up and cleaning more things
This commit is contained in:
parent
ca8c655f00
commit
d214674620
@ -1,5 +1,4 @@
|
|||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'sprockets'
|
|
||||||
|
|
||||||
module Jasmine::Headless
|
module Jasmine::Headless
|
||||||
autoload :CommandLine, 'jasmine/headless/command_line'
|
autoload :CommandLine, 'jasmine/headless/command_line'
|
||||||
@ -29,21 +28,3 @@ module Jasmine::Headless
|
|||||||
end
|
end
|
||||||
|
|
||||||
require 'jasmine/headless/errors'
|
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 'time'
|
||||||
require 'multi_json'
|
require 'multi_json'
|
||||||
require 'set'
|
require 'set'
|
||||||
|
require 'sprockets'
|
||||||
|
|
||||||
module Jasmine::Headless
|
module Jasmine::Headless
|
||||||
class FilesList
|
class FilesList
|
||||||
@ -99,26 +100,35 @@ module Jasmine::Headless
|
|||||||
|
|
||||||
def add_dependencies(file, source_root)
|
def add_dependencies(file, source_root)
|
||||||
TestFile.new(file, source_root).dependencies.each do |type, name|
|
TestFile.new(file, source_root).dependencies.each do |type, name|
|
||||||
if !@checked_dependency.include?(name)
|
add_dependency(type, name, source_root)
|
||||||
@checked_dependency << name
|
|
||||||
add_dependency(type, name, source_root)
|
|
||||||
end
|
|
||||||
end
|
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)
|
def add_dependency(type, file, source_root)
|
||||||
case type
|
files = case type
|
||||||
when 'require'
|
when 'require'
|
||||||
if result = find_dependency(file)
|
if !@checked_dependency.include?(file)
|
||||||
add_file(*result)
|
@checked_dependency << file
|
||||||
|
|
||||||
|
[ file ]
|
||||||
|
else
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
when 'require_tree'
|
when 'require_tree'
|
||||||
Dir[File.join(source_root, file, '**/*')].find_all { |path| File.file?(path) && path[EXTENSION_FILTER] }.sort.each do |tree_path|
|
Dir[File.join(source_root, file, '**/*')].find_all { |path|
|
||||||
if result = find_dependency(tree_path.gsub(%r{^#{source_root}/}, ''))
|
File.file?(path) && path[extension_filter]
|
||||||
add_file(*result)
|
}.sort.collect { |path| path.gsub(%r{^#{source_root}/}, '') }
|
||||||
end
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
files.each do |file|
|
||||||
|
if result = find_dependency(file)
|
||||||
|
add_file(result[0], result[1], false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -129,7 +139,7 @@ module Jasmine::Headless
|
|||||||
root = path.gsub(%r{^#{dir}/}, '')
|
root = path.gsub(%r{^#{dir}/}, '')
|
||||||
|
|
||||||
ok = (root == file)
|
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)
|
expanded_path = File.expand_path(path)
|
||||||
|
|
||||||
@ -218,10 +228,12 @@ module Jasmine::Headless
|
|||||||
end
|
end
|
||||||
|
|
||||||
def expanded_dir(path)
|
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
|
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)
|
add_dependencies(file, source_root)
|
||||||
|
|
||||||
@files << file if !@files.include?(file)
|
@files << file if !@files.include?(file)
|
||||||
|
@ -4,6 +4,8 @@ require 'coffee-script'
|
|||||||
require 'rainbow'
|
require 'rainbow'
|
||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
require 'sprockets'
|
||||||
|
|
||||||
|
|
||||||
module Jasmine
|
module Jasmine
|
||||||
module Headless
|
module Headless
|
||||||
@ -23,9 +25,30 @@ module Jasmine
|
|||||||
|
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
|
|
||||||
def self.run(options = {})
|
class << self
|
||||||
options = Options.new(options) if !options.kind_of?(Options)
|
def reset!
|
||||||
new(options).run
|
# 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
|
end
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
@ -67,6 +90,7 @@ module Jasmine
|
|||||||
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
|
||||||
|
|
||||||
Jasmine::Headless::FilesList.reset!
|
Jasmine::Headless::FilesList.reset!
|
||||||
|
self.class.reset!
|
||||||
|
|
||||||
files_list = Jasmine::Headless::FilesList.new(
|
files_list = Jasmine::Headless::FilesList.new(
|
||||||
:config => jasmine_config,
|
:config => jasmine_config,
|
||||||
|
@ -199,9 +199,12 @@ describe Jasmine::Headless::FilesList do
|
|||||||
let(:other_file) { 'other' }
|
let(:other_file) { 'other' }
|
||||||
let(:path) { 'path' }
|
let(:path) { 'path' }
|
||||||
|
|
||||||
|
let(:set) { Set.new }
|
||||||
|
|
||||||
before do
|
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.stubs(:find_dependency).with(other_file).returns(false)
|
||||||
|
files_list.instance_variable_set(:@checked_dependency, set)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'not found' do
|
context 'not found' do
|
||||||
@ -211,16 +214,20 @@ describe Jasmine::Headless::FilesList do
|
|||||||
|
|
||||||
it 'should do nothing' do
|
it 'should do nothing' do
|
||||||
files_list.add_dependency('', other_file, nil)
|
files_list.add_dependency('', other_file, nil)
|
||||||
|
set.should be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'require' do
|
context 'require' do
|
||||||
before do
|
context 'not already added' do
|
||||||
files_list.expects(:add_file).with(path, nil)
|
before do
|
||||||
end
|
files_list.expects(:add_file).with(path, nil, false)
|
||||||
|
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, nil)
|
files_list.add_dependency('require', file, nil)
|
||||||
|
set.should include(file)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -235,14 +242,15 @@ describe Jasmine::Headless::FilesList do
|
|||||||
File.open(path, 'wb')
|
File.open(path, 'wb')
|
||||||
|
|
||||||
if path[%r{\.(js|css|coffee)$}]
|
if path[%r{\.(js|css|coffee)$}]
|
||||||
files_list.expects(:find_dependency).with(path).returns(other_file)
|
files_list.expects(:find_dependency).with(path).returns([ other_file, nil ])
|
||||||
files_list.expects(:add_file).with(other_file, nil)
|
files_list.expects(:add_file).with(other_file, nil, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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_tree', '.', File.expand_path('.'))
|
files_list.add_dependency('require_tree', '.', File.expand_path('.'))
|
||||||
|
set.should be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -351,5 +359,31 @@ describe Jasmine::Headless::FilesList do
|
|||||||
it { should == [ File.join(dir, 'file.sub.js'), dir ] }
|
it { should == [ File.join(dir, 'file.sub.js'), dir ] }
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
@ -8,6 +8,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.reset!
|
Jasmine::Headless::FilesList.reset!
|
||||||
|
Jasmine::Headless::Runner.reset!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user