whoa actually just plug in sprockets, need to backfill tests later since i have real work to do

This commit is contained in:
John Bintz 2011-11-22 10:36:42 -05:00
parent 130a65ecdd
commit 7d75b5466f
16 changed files with 141 additions and 679 deletions

View File

@ -11,12 +11,12 @@ module Jasmine::Headless
autoload :Options, 'jasmine/headless/options' autoload :Options, 'jasmine/headless/options'
autoload :Task, 'jasmine/headless/task' autoload :Task, 'jasmine/headless/task'
autoload :FilesList, 'jasmine/headless/files_list' autoload :FilesList, 'jasmine/headless/files_list'
autoload :RequiredFile, 'jasmine/headless/required_file'
autoload :PathSearcher, 'jasmine/headless/path_searcher'
autoload :TemplateWriter, 'jasmine/headless/template_writer' autoload :TemplateWriter, 'jasmine/headless/template_writer'
autoload :CoffeeTemplate, 'jasmine/headless/coffee_template' autoload :CoffeeTemplate, 'jasmine/headless/coffee_template'
autoload :JSTemplate, 'jasmine/headless/js_template'
autoload :CSSTemplate, 'jasmine/headless/css_template'
autoload :Report, 'jasmine/headless/report' autoload :Report, 'jasmine/headless/report'
autoload :ReportMessage, 'jasmine/headless/report_message' autoload :ReportMessage, 'jasmine/headless/report_message'

View File

@ -2,6 +2,8 @@ require 'tilt/template'
module Jasmine::Headless module Jasmine::Headless
class CoffeeTemplate < Tilt::Template class CoffeeTemplate < Tilt::Template
self.default_mime_type = 'application/javascript'
def prepare ; end def prepare ; end
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)

View File

@ -0,0 +1,14 @@
require 'tilt/template'
module Jasmine::Headless
class CSSTemplate < Tilt::Template
self.default_mime_type = 'text/css'
def prepare ; end
def evaluate(scope, locals, &block)
file ? %{<link rel="stylesheet" href="#{file}" type="text/css" />} : data
end
end
end

View File

@ -42,6 +42,8 @@ module Jasmine::Headless
end end
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
register_engine '.js', Jasmine::Headless::JSTemplate
register_engine '.css', Jasmine::Headless::CSSTemplate
end end
end end
@ -61,18 +63,20 @@ module Jasmine::Headless
@potential_files_to_filter = [] @potential_files_to_filter = []
self.class.default_files.each do |file| self.class.default_files.each do |file|
@required_files << RequiredFile.new(*[ path_searcher.find(file.dup), self ].flatten) @required_files << sprockets_environment.find_asset(file, :bundle => false)
end end
use_config! if config? use_config! if config?
end end
def files def files
required_files.collect { |file| file.file_paths }.flatten.uniq required_files.collect { |file| file.send(:required_assets).collect { |asset| asset.pathname.to_s } }.flatten.uniq
end end
def spec_files def spec_files
filter_for_requested_specs(required_files.find_all(&:spec_file?).collect(&:path)) filter_for_requested_specs(
files.find_all { |file| spec_dir.any? { |dir| file[dir] } }
)
end end
def filtered_files def filtered_files
@ -90,6 +94,17 @@ module Jasmine::Headless
@search_paths @search_paths
end end
def sprockets_environment
return @sprockets_environment if @sprockets_environment
@sprockets_environment = Sprockets::Environment.new
search_paths.each do |path|
@sprockets_environment.append_path(path)
end
@sprockets_environment
end
def path_searcher def path_searcher
@path_searcher ||= PathSearcher.new(self) @path_searcher ||= PathSearcher.new(self)
end end
@ -98,10 +113,13 @@ module Jasmine::Headless
if is_outside_scope = !spec_filter.empty? if is_outside_scope = !spec_filter.empty?
is_outside_scope = spec_dir.any? do |dir| is_outside_scope = spec_dir.any? do |dir|
spec_file_searches.any? do |search| spec_file_searches.any? do |search|
!spec_files.any? { |file| File.fnmatch?(File.join(dir, search), file) } !spec_files.any? { |file|
File.fnmatch?(File.join(dir, search), file)
}
end end
end end
end end
is_outside_scope is_outside_scope
end end
@ -139,11 +157,7 @@ module Jasmine::Headless
alert_time = nil alert_time = nil
end end
search_paths.collect do |path| sprockets_environment.find_asset(file, :bundle => false).to_s
if file[%r{^#{path}}]
Jasmine::Headless::RequiredFile.new(file, path, self).to_html
end
end.compact.first
end.flatten.compact.reject(&:empty?) end.flatten.compact.reject(&:empty?)
end end
@ -178,6 +192,16 @@ module Jasmine::Headless
add_files(@searches[type] = data.flatten, type, dirs) add_files(@searches[type] = data.flatten, type, dirs)
end end
end end
filtered_required_files = []
@required_files.each do |file|
if !filtered_required_files.any? { |other_file| other_file.logical_path == file.logical_path }
filtered_required_files << file
end
end
@required_files = filtered_required_files
end end
def add_files(patterns, type, dirs) def add_files(patterns, type, dirs)
@ -186,36 +210,16 @@ module Jasmine::Headless
search = File.expand_path(File.join(dir, search)) search = File.expand_path(File.join(dir, search))
Dir[search].find_all { |file| file[extension_filter] }.each do |path| Dir[search].find_all { |file| file[extension_filter] }.each do |path|
@required_files << (file = RequiredFile.new(path, dir, self)) add_path(path, type) if File.file?(path)
if type == 'spec_files'
file.spec_file = true
@potential_files_to_filter << path
end
end end
end end
end end
if type == 'spec_files' if type == 'spec_files'
spec_filter.each do |path| spec_filter.each { |path| add_path(path, type) }
@required_files << (file = RequiredFile.new(path, nil, self))
file.spec_file = true
@potential_files_to_filter << path
end end
end end
filtered_required_files = []
@required_files.each do |file|
if !filtered_required_files.any? { |other_file| other_file == file }
filtered_required_files << file
end
end
@required_files = filtered_required_files
end
def config? def config?
@options[:config] @options[:config]
end end
@ -228,8 +232,14 @@ module Jasmine::Headless
%r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$} %r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$}
end end
def add_file(file) def add_path(path, type)
@files << file asset = sprockets_environment.find_asset(path, :bundle => false)
@required_files << asset
if type == 'spec_files'
@potential_files_to_filter << path
end
end end
def include_spec_file?(file) def include_spec_file?(file)

View File

@ -0,0 +1,14 @@
require 'tilt/template'
module Jasmine::Headless
class JSTemplate < Tilt::Template
self.default_mime_type = 'application/javascript'
def prepare ; end
def evaluate(scope, locals, &block)
file ? %{<script type="text/javascript" src="#{file}"></script>} : data
end
end
end

View File

@ -1,34 +0,0 @@
require 'sprockets'
require 'forwardable'
module Jasmine::Headless
class PathSearcher
extend Forwardable
def_delegators :source, :search_paths, :extension_filter
attr_reader :source
def initialize(source)
@source = source
end
def find(file)
search_paths.each do |dir|
Dir[File.join(dir, "#{file}*")].find_all { |path| File.file?(path) }.each do |path|
root = path.gsub(%r{^#{dir}/}, '')
ok = (root == file)
ok ||= File.basename(path.gsub("#{file}.", '')).split('.').all? { |part| ".#{part}"[extension_filter] }
if ok
return [ File.expand_path(path), dir ]
end
end
end
false
end
end
end

View File

@ -1,121 +0,0 @@
require 'rainbow'
require 'sprockets'
require 'forwardable'
module Jasmine::Headless
class RequiredFile
extend Forwardable
def_delegators :parent, :path_searcher, :extension_filter
attr_reader :path, :source_root, :parent
attr_writer :spec_file
def initialize(path, source_root, parent)
@path, @source_root, @parent = path, source_root, parent
@spec_file = false
end
def spec_file?
@spec_file
end
def ==(other)
self.path == other.path
end
def to_html
process_data_by_filename(path)
end
def has_dependencies?
!dependencies.empty?
end
def includes?(path)
@path == path || dependencies.any? { |dependency| dependency.includes?(path) }
end
def file_paths
paths = dependencies.collect(&:file_paths).flatten
if @insert_after
paths.insert(paths.index(@insert_after) + 1, path)
else
paths << path
end
paths
end
def dependencies
return @dependencies if @dependencies
processor = Sprockets::DirectiveProcessor.new(path)
last_file_added = nil
@dependencies = processor.directives.collect do |line, type, name|
if name && name[%r{^\.}]
name = File.expand_path(File.join(File.dirname(path), name)).gsub(%r{^#{source_root}/}, '')
else
raise Sprockets::ArgumentError.new("require_tree needs a relative path: ./#{path}") if type == 'require_tree'
end
files = case type
when 'require'
[ name ]
when 'require_tree'
Dir[File.join(source_root, name, '**/*')].find_all { |found_path|
found_path != path && File.file?(found_path) && found_path[extension_filter]
}.sort.collect { |path| path.gsub(%r{^#{source_root}/}, '') }
when 'require_self'
@insert_after = last_file_added
[]
else
[]
end
files.collect do |file|
if result = path_searcher.find(file)
new_file = self.class.new(*[ result, self ].flatten)
last_file_added = new_file.path
new_file
else
raise Sprockets::FileNotFound.new("Could not find #{file}, referenced from #{path}:#{line}")
end
end
end.flatten
end
def logical_path
path.gsub(%r{^#{source_root}/}, '').gsub(%r{\..+$}, '')
end
private
def read
File.read(path)
end
def process_data_by_filename(path, data = nil)
case extension = File.extname(path)
when ''
data || ''
when '.js'
data || %{<script type="text/javascript" src="#{path}"></script>}
when '.css'
data || %{<link rel="stylesheet" href="#{path}" type="text/css" />}
else
if engine = Sprockets.engines(extension)
data = engine.new(path) { data || read }.render(self)
data = %{<script type="text/javascript">#{data}</script>} if extension == '.jst'
process_data_by_filename(path.gsub(%r{#{extension}$}, ''), data)
else
data || ''
end
end
end
end
end

View File

@ -14,7 +14,7 @@ module Jasmine::Headless
data = File.read(file) data = File.read(file)
if data.respond_to?(:encode) if data.respond_to?(:encode)
data.encode!('US-ASCII', 'UTF-8', :invalid => :replace) data.encode!('US-ASCII', 'UTF-8', :invalid => :replace, :undef => :replace)
else else
require 'iconv' require 'iconv'
ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII') ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII')

View File

@ -27,160 +27,8 @@ describe Jasmine::Headless::FilesList do
end end
end end
describe '#use_config' do it 'should have tests for #use_config!'
let(:files_list) { described_class.new(:config => config) } it 'should have tests for #add_files'
include FakeFS::SpecHelpers
no_default_files!
let(:src_dir) { 'src' }
let(:spec_dir) { 'spec' }
let(:first_file) { File.join(src_dir, 'js/first_file.js') }
let(:src_file) { File.join(src_dir, 'js/src_file.js') }
let(:spec_file) { File.join(spec_dir, 'spec_file_spec.js') }
let(:helper_file) { File.join(spec_dir, 'helper/helper_file.js') }
let(:stylesheet_file) { File.join(src_dir, 'stylesheet/blah.css') }
before do
[ first_file, src_file, spec_file, helper_file, stylesheet_file ].each do |file|
FileUtils.mkdir_p File.split(file).first
File.open(file, 'w')
end
end
shared_examples_for :reading_data do
let(:expected_files) do
[
File.expand_path(first_file),
File.expand_path(src_file),
File.expand_path(stylesheet_file),
File.expand_path(helper_file),
File.expand_path(spec_file)
]
end
it 'should read the data from the jasmine.yml file and add the files' do
files_list.files.should == expected_files
files_list.spec_files.should == [ File.expand_path(spec_file) ]
end
end
context 'with normal list' do
let(:config) { {
'src_dir' => src_dir,
'spec_dir' => spec_dir,
'src_files' => [ 'js/first_file.js', 'js/*.js' ],
'spec_files' => [ '*_spec.js' ],
'helpers' => [ 'helper/*.js' ],
'stylesheets' => [ 'stylesheet/*.css' ]
} }
it_should_behave_like :reading_data
end
context 'with multidimensional list' do
let(:config) { {
'src_dir' => src_dir,
'spec_dir' => spec_dir,
'src_files' => [ [ 'js/first_file.js', 'js/*.js' ] ],
'spec_files' => [ '*_spec.js' ],
'helpers' => [ 'helper/*.js' ],
'stylesheets' => [ 'stylesheet/*.css' ]
} }
it_should_behave_like :reading_data
end
context 'with multidimensional src dir' do
let(:config) { {
'src_dir' => [ src_dir ],
'spec_dir' => spec_dir,
'src_files' => [ [ 'js/first_file.js', 'js/*.js' ] ],
'spec_files' => [ '*_spec.js' ],
'helpers' => [ 'helper/*.js' ],
'stylesheets' => [ 'stylesheet/*.css' ]
} }
it_should_behave_like :reading_data
end
end
context 'with filtered specs' do
let(:files_list) { Jasmine::Headless::FilesList.new(:only => filter, :config => config) }
let(:spec_dir) { 'spec' }
include FakeFS::SpecHelpers
no_default_files!
let(:config) { {
'spec_files' => [ '*_spec.js' ],
'spec_dir' => spec_dir
} }
let(:spec_files) { %w{one_spec.js two_spec.js whatever.js} }
before do
spec_files.each do |file|
FileUtils.mkdir_p spec_dir
File.open(File.join(spec_dir, file), 'w')
end
end
context 'empty filter' do
let(:filter) { [] }
it 'should return all files for filtered and all files' do
files_list.files.any? { |file| file['two_spec.js'] }.should be_true
files_list.filtered?.should be_false
files_list.should_not have_spec_outside_scope
files_list.spec_files.sort.should == %w{one_spec.js two_spec.js}.sort.collect { |file| File.expand_path(File.join(spec_dir, file)) }
end
end
context 'filter with a file that is matchable' do
let(:filter) { [ File.expand_path('spec/one_spec.js') ] }
it 'should return all files for files' do
files_list.files.any? { |file| file['two_spec.js'] }.should be_true
files_list.filtered?.should be_true
files_list.should_not have_spec_outside_scope
files_list.spec_files.should == filter
end
it 'should return only filtered files for filtered_files' do
files_list.filtered_files.any? { |file| file['two_spec.js'] }.should be_false
files_list.should_not have_spec_outside_scope
end
end
context 'filter with a glob' do
let(:filter) { [ File.expand_path('spec/one*') ] }
it 'should return all files for files' do
files_list.files.any? { |file| file['two_spec.js'] }.should be_true
files_list.filtered?.should be_true
files_list.should_not have_spec_outside_scope
end
it 'should return only filtered files for filtered_files' do
files_list.filtered_files.any? { |file| file['two_spec.js'] }.should be_false
files_list.should_not have_spec_outside_scope
end
end
context 'filter with a file that is not even there' do
let(:filter) { [ File.expand_path('spec/whatever.js') ] }
it 'should use the provided file' do
files_list.filtered_files.any? { |file| file['whatever.js'] }.should be_true
files_list.should have_spec_outside_scope
end
end
end
describe '#spec_file_line_numbers' do describe '#spec_file_line_numbers' do
include FakeFS::SpecHelpers include FakeFS::SpecHelpers
@ -274,8 +122,12 @@ describe Jasmine::Headless::FilesList do
let(:path_two) { 'two' } let(:path_two) { 'two' }
let(:path_three) { 'three' } let(:path_three) { 'three' }
let(:file_one) { stub(:file_paths => [ path_one, path_two ] ) } let(:file_one) { stub(:required_assets => [ asset_one, asset_two ] ) }
let(:file_two) { stub(:file_paths => [ path_two, path_three ] ) } let(:file_two) { stub(:required_assets => [ asset_two, asset_three ] ) }
let(:asset_one) { stub(:pathname => Pathname(path_one)) }
let(:asset_two) { stub(:pathname => Pathname(path_two)) }
let(:asset_three) { stub(:pathname => Pathname(path_three)) }
before do before do
files_list.stubs(:required_files).returns([ file_one, file_two ]) files_list.stubs(:required_files).returns([ file_one, file_two ])
@ -323,21 +175,5 @@ describe Jasmine::Headless::FilesList do
it { should == [ file_one, file_two, file_four ] } it { should == [ file_one, file_two, file_four ] }
end end
end end
describe '#files_to_html' do
let(:file_one) { 'path/one' }
let(:file_two) { 'path/two' }
before do
files_list.stubs(:files).returns([ file_one, file_two ])
files_list.stubs(:search_paths).returns([ 'path' ])
Jasmine::Headless::RequiredFile.any_instance.stubs(:to_html).returns('made it')
end
it 'should render all the files' do
files_list.files_to_html.should == [ 'made it', 'made it' ]
end
end
end end

View File

@ -1,40 +0,0 @@
require 'spec_helper'
describe Jasmine::Headless::PathSearcher do
include FakeFS::SpecHelpers
let(:path) { File.expand_path('path') }
let(:paths) { [ path ] }
let(:source) { stub(:search_paths => paths, :extension_filter => %r{.*}) }
let(:path_searcher) { described_class.new(source) }
let(:filename) { 'file.js' }
let(:file) { File.join(path, filename) }
describe '#find' do
subject { path_searcher.find(search) }
before do
FileUtils.mkdir_p path
File.open(file, 'wb')
end
context 'found file' do
let(:search) { 'file' }
it 'should find the file' do
subject.should == [ File.expand_path(file), path ]
end
end
context 'not found file' do
let(:search) { 'other' }
it 'should not find the file' do
subject.should be_false
end
end
end
end

View File

@ -1,240 +0,0 @@
require 'spec_helper'
describe Jasmine::Headless::RequiredFile do
let(:source_root) { File.expand_path('source_root') }
let(:path) { File.join(source_root, 'path.js') }
let(:file) { described_class.new(path, source_root, files_list) }
let(:paths) { [ source_root ] }
let(:path_searcher) { stub }
let(:files_list) { stub(:path_searcher => path_searcher) }
subject { file }
its(:path) { should == path }
its(:source_root) { should == source_root }
its(:parent) { should == files_list }
describe '#has_dependencies?' do
it 'should have dependencies' do
file.instance_variable_set(:@dependencies, [ 1 ])
file.should have_dependencies
end
it 'should not have dependencies' do
file.instance_variable_set(:@dependencies, [])
file.should_not have_dependencies
end
end
describe '#includes?' do
it 'includes itself' do
file.includes?(path).should be_true
end
context 'with dependencies' do
let(:other_file) { stub }
let(:other_path) { 'other path' }
let(:third_path) { 'third path' }
before do
other_file.stubs(:includes?).with(other_path).returns(true)
other_file.stubs(:includes?).with(third_path).returns(false)
file.stubs(:dependencies).returns([ other_file ])
end
it 'checks dependencies' do
file.includes?(third_path).should be_false
file.includes?(other_path).should be_true
end
end
end
describe '#to_html' do
subject { file.to_html }
context '.js' do
let(:path) { 'path.js' }
it { should == %{<script type="text/javascript" src="#{path}"></script>} }
end
context '.css' do
let(:path) { 'path.css' }
it { should == %{<link rel="stylesheet" href="#{path}" type="text/css" />} }
end
context 'with tilt template' do
include FakeFS::SpecHelpers
let(:content) { 'content' }
before do
File.open(path, 'wb') { |fh| fh.print content }
end
let(:klass) do
Class.new(Tilt::Template) do
def prepare ; end
def evaluate(scope, locals, &block)
"#{file} made it #{data}"
end
end
end
let(:other_klass) do
Class.new(Tilt::Template) do
def prepare ; end
def evaluate(scope, locals, &block)
data
end
end
end
before do
Sprockets.stubs(:engines).with('.tilt').returns(klass)
Sprockets.stubs(:engines).with('.jst').returns(other_klass)
end
context '.tilt' do
let(:path) { 'path.tilt' }
it { should == %{#{path} made it #{content}} }
end
context '.tilt.tilt' do
let(:path) { 'path.tilt.tilt' }
it { should == %{path.tilt made it #{path} made it #{content}} }
end
context '.jst.tilt' do
let(:path) { 'path.jst.tilt' }
it { should == %{<script type="text/javascript">#{path} made it #{content}</script>} }
end
end
end
describe '#dependencies' do
include FakeFS::SpecHelpers
let(:directive) { 'require' }
let(:dirname) { 'subdir/subsubdir' }
let(:dir) { File.join(source_root, dirname) }
let(:path) { path_file }
let(:path_file) { File.join(dir, 'path.js') }
let(:req_file) { File.join(dir, "req.js") }
let(:other_file) { File.join(dir, "other.js") }
let(:content) { "//= #{directive} '#{req_name}'\njavascript" }
before do
FileUtils.mkdir_p dir
File.open(path_file, 'wb') { |fh| fh.print content }
File.open(req_file, 'wb')
File.open(other_file, 'wb')
end
subject { file.dependencies }
context 'absolute' do
context 'require' do
context 'file exists' do
let(:req_name) { File.join(dirname, 'req') }
before do
path_searcher.expects(:find).with(File.join(dirname, 'req')).returns([ req_file, source_root ])
end
it { should == [ described_class.new(req_file, source_root, file) ] }
end
context 'file does not exist' do
let(:req_name) { File.join(dirname, 'bad') }
before do
path_searcher.expects(:find).with(File.join(dirname, 'bad')).returns(false)
end
it 'should raise an exception' do
expect { subject }.to raise_error(Sprockets::FileNotFound)
end
end
end
end
context 'relative' do
context 'require' do
context 'file exists' do
let(:req_name) { './req' }
before do
path_searcher.expects(:find).with(File.join(dirname, 'req')).returns([ req_file, source_root ])
end
it { should == [ described_class.new(req_file, source_root, file) ] }
end
context 'file does not exist' do
let(:req_name) { './bad' }
before do
path_searcher.expects(:find).with(File.join(dirname, 'bad')).returns(false)
end
it 'should raise an exception' do
expect { subject }.to raise_error(Sprockets::FileNotFound)
end
end
end
end
context 'require_self' do
subject { file.file_paths }
let(:content) do
<<-ENDTXT
//= require #{dirname}/req
//= require_self
//= require #{dirname}/other
ENDTXT
end
before do
path_searcher.expects(:find).with(File.join(dirname, 'req')).returns([ req_file, source_root ])
path_searcher.expects(:find).with(File.join(dirname, 'other')).returns([ other_file, source_root ])
end
it { should == [
req_file,
path_file,
other_file
] }
end
end
describe '#file_paths' do
let(:other_path) { File.join(source_root, 'other_path.js') }
let(:other_file) { described_class.new(other_path, source_root, file) }
before do
file.stubs(:dependencies).returns([ other_file ])
other_file.stubs(:dependencies).returns([])
end
it 'should flatten all the paths in itself and descendents' do
file.file_paths.should == [ other_path, path ]
end
end
end

View File

@ -1,13 +1,16 @@
(function() {
window.HeadlessReporterResult = (function() { window.HeadlessReporterResult = (function() {
function HeadlessReporterResult(name, splitName) { function HeadlessReporterResult(name, splitName) {
this.name = name; this.name = name;
this.splitName = splitName; this.splitName = splitName;
this.results = []; this.results = [];
} }
HeadlessReporterResult.prototype.addResult = function(message) { HeadlessReporterResult.prototype.addResult = function(message) {
return this.results.push(message); return this.results.push(message);
}; };
HeadlessReporterResult.prototype.print = function() { HeadlessReporterResult.prototype.print = function() {
var bestChoice, output, result, _i, _len, _ref, _results; var bestChoice, output, result, _i, _len, _ref, _results;
output = this.name.foreground('red'); output = this.name.foreground('red');
@ -25,10 +28,15 @@
output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright(); output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright();
} }
JHW.stdout.puts(" " + output); JHW.stdout.puts(" " + output);
_results.push(result.line != null ? JHW.stdout.puts((" " + result.line).foreground('yellow')) : void 0); if (result.line != null) {
_results.push(JHW.stdout.puts((" " + result.line).foreground('yellow')));
} else {
_results.push(void 0);
}
} }
return _results; return _results;
}; };
HeadlessReporterResult.findSpecLine = function(splitName) { HeadlessReporterResult.findSpecLine = function(splitName) {
var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref; var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref;
bestChoice = { bestChoice = {
@ -49,9 +57,7 @@
for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) { for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) {
line = newLineNumberInfo[_i]; line = newLineNumberInfo[_i];
lastLine = line; lastLine = line;
if (line > lineNumber) { if (line > lineNumber) break;
break;
}
} }
lineNumber = lastLine; lineNumber = lastLine;
} }
@ -67,6 +73,7 @@
} }
return bestChoice; return bestChoice;
}; };
return HeadlessReporterResult; return HeadlessReporterResult;
})(); })();
}).call(this);

View File

@ -1,5 +1,6 @@
(function() { (function() {
var code, method, _ref; var code, method, _ref;
window.Intense = { window.Intense = {
colors: { colors: {
black: 0, black: 0,
@ -29,15 +30,15 @@
}, },
useColors: true, useColors: true,
moveBack: function(count) { moveBack: function(count) {
if (count == null) { if (count == null) count = 1;
count = 1;
}
return "\033[" + count + "D"; return "\033[" + count + "D";
} }
}; };
_ref = Intense.methods; _ref = Intense.methods;
for (method in _ref) { for (method in _ref) {
code = _ref[method]; code = _ref[method];
String.prototype[method] = code; String.prototype[method] = code;
} }
}).call(this); }).call(this);

View File

@ -1,9 +1,11 @@
(function() { (function() {
var generator, getSplitName, method, pauseAndRun, _i, _len, _ref; var generator, getSplitName, method, pauseAndRun, _i, _len, _ref;
var __slice = Array.prototype.slice; var __slice = Array.prototype.slice;
if (!(typeof jasmine !== "undefined" && jasmine !== null)) { if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
throw new Error("jasmine not laoded!"); throw new Error("jasmine not laoded!");
} }
if (window.JHW) { if (window.JHW) {
getSplitName = function(parts) { getSplitName = function(parts) {
parts.push(String(this.description).replace(/[\n\r]/g, ' ')); parts.push(String(this.description).replace(/[\n\r]/g, ' '));
@ -110,7 +112,11 @@
_results = []; _results = [];
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
reporter = _ref2[_j]; reporter = _ref2[_j];
_results.push(reporter[method] != null ? reporter[method].apply(reporter, args) : void 0); if (reporter[method] != null) {
_results.push(reporter[method].apply(reporter, args));
} else {
_results.push(void 0);
}
} }
return _results; return _results;
}; };
@ -119,4 +125,5 @@
} }
} }
} }
}).call(this); }).call(this);

View File

@ -1,9 +1,10 @@
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
if (!(typeof jasmine !== "undefined" && jasmine !== null)) { if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
throw new Error("jasmine not loaded!"); throw new Error("jasmine not loaded!");
} }
jasmine.HeadlessConsoleReporter = (function() { jasmine.HeadlessConsoleReporter = (function() {
function HeadlessConsoleReporter(callback) { function HeadlessConsoleReporter(callback) {
this.callback = callback != null ? callback : null; this.callback = callback != null ? callback : null;
this.results = []; this.results = [];
@ -13,11 +14,10 @@
this.position = 0; this.position = 0;
this.positions = "|/-\\"; this.positions = "|/-\\";
} }
HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) { HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) {
var output, result, resultLine, runtime, _i, _len, _ref; var output, result, resultLine, runtime, _i, _len, _ref;
if (this.hasError()) { if (this.hasError()) return;
return;
}
runtime = (new Date() - this.startTime) / 1000.0; runtime = (new Date() - this.startTime) / 1000.0;
JHW.stdout.print("\n"); JHW.stdout.print("\n");
resultLine = this._formatResultLine(runtime); resultLine = this._formatResultLine(runtime);
@ -34,22 +34,20 @@
result = _ref[_i]; result = _ref[_i];
result.print(); result.print();
} }
if (window.JHW) { if (window.JHW) window.onbeforeunload = null;
window.onbeforeunload = null;
}
return JHW.finishSuite(); return JHW.finishSuite();
}; };
HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) { HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) {
this.startTime = new Date(); this.startTime = new Date();
if (!this.hasError()) { if (!this.hasError()) {
return JHW.stdout.puts("\nRunning Jasmine specs...".bright()); return JHW.stdout.puts("\nRunning Jasmine specs...".bright());
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) { HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) {
var failureResult, foundLine, result, results, testCount, _i, _len, _ref; var failureResult, foundLine, result, results, testCount, _i, _len, _ref;
if (this.hasError()) { if (this.hasError()) return;
return;
}
JHW.ping(); JHW.ping();
results = spec.results(); results = spec.results();
this.length++; this.length++;
@ -76,35 +74,37 @@
return this.results.push(failureResult); return this.results.push(failureResult);
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) { HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) {
if (this.hasError()) { if (this.hasError()) {
spec.finish(); spec.finish();
return spec.suite.finish(); return spec.suite.finish();
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecWaiting = function() { HeadlessConsoleReporter.prototype.reportSpecWaiting = function() {
var first, runner; var first, runner;
var _this = this;
runner = null; runner = null;
if (!this.timer) { if (!this.timer) {
this.timer = true; this.timer = true;
first = true; first = true;
runner = __bind(function() { runner = function() {
return this.timer = setTimeout(__bind(function() { return _this.timer = setTimeout(function() {
if (this.timer) { if (_this.timer) {
if (!first) { if (!first) JHW.stdout.print(Intense.moveBack());
JHW.stdout.print(Intense.moveBack()); JHW.stdout.print(_this.positions.substr(_this.position, 1).foreground('yellow'));
} _this.position += 1;
JHW.stdout.print(this.positions.substr(this.position, 1).foreground('yellow')); _this.position %= _this.positions.length;
this.position += 1;
this.position %= this.positions.length;
first = false; first = false;
return runner(); return runner();
} }
}, this), 750); }, 750);
}, this); };
return runner(); return runner();
} }
}; };
HeadlessConsoleReporter.prototype.reportSpecRunning = function() { HeadlessConsoleReporter.prototype.reportSpecRunning = function() {
if (this.timer) { if (this.timer) {
clearTimeout(this.timer); clearTimeout(this.timer);
@ -112,10 +112,13 @@
return JHW.stdout.print(Intense.moveBack()); return JHW.stdout.print(Intense.moveBack());
} }
}; };
HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {}; HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {};
HeadlessConsoleReporter.prototype.hasError = function() { HeadlessConsoleReporter.prototype.hasError = function() {
return JHW._hasErrors; return JHW._hasErrors;
}; };
HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) { HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) {
var line; var line;
line = []; line = [];
@ -127,6 +130,7 @@
line.push((runtime === 1.0 ? "sec" : "secs") + '.'); line.push((runtime === 1.0 ? "sec" : "secs") + '.');
return line.join(' '); return line.join(' ');
}; };
return HeadlessConsoleReporter; return HeadlessConsoleReporter;
})(); })();
}).call(this);

View File

@ -1,5 +1,6 @@
(function() { (function() {
var createHandle, handle, _i, _len, _ref; var createHandle, handle, _i, _len, _ref;
if (window.JHW) { if (window.JHW) {
window.console = { window.console = {
log: function(data) { log: function(data) {
@ -40,9 +41,7 @@
e = e || window.event; e = e || window.event;
JHW.hasError(); JHW.hasError();
JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.'); JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.');
if (e) { if (e) e.returnValue = 'string';
e.returnValue = 'string';
}
return 'string'; return 'string';
}; };
window.confirm = function(message) { window.confirm = function(message) {
@ -84,6 +83,9 @@
return JHW.stdout.puts(msg); return JHW.stdout.puts(msg);
}; };
} }
window.CoffeeScriptToFilename = {}; window.CoffeeScriptToFilename = {};
window.CSTF = window.CoffeeScriptToFilename; window.CSTF = window.CoffeeScriptToFilename;
}).call(this); }).call(this);