more sprockets improvements
This commit is contained in:
parent
e04d692d26
commit
61c8ed8828
@ -2,31 +2,9 @@
|
||||
|
||||
require 'rubygems'
|
||||
|
||||
def gem_dir
|
||||
File.expand_path('../..', __FILE__)
|
||||
end
|
||||
|
||||
$:.unshift(File.join(gem_dir, 'lib'))
|
||||
$: << File.expand_path('../../lib', __FILE__)
|
||||
|
||||
require 'jasmine-headless-webkit'
|
||||
require 'coffee-script'
|
||||
require 'rainbow'
|
||||
|
||||
begin
|
||||
options = Jasmine::Headless::Options.from_command_line
|
||||
runner = Jasmine::Headless::Runner.new(options)
|
||||
|
||||
if options[:do_list]
|
||||
files_list = Jasmine::Headless::FilesList.new(:config => runner.jasmine_config)
|
||||
files_list.files.each { |file| puts file }
|
||||
else
|
||||
exit runner.run
|
||||
end
|
||||
rescue CoffeeScript::CompilationError
|
||||
exit 1
|
||||
rescue StandardError => e
|
||||
$stderr.puts "[%s] %s (%s)" % [ "jasmine-headless-webkit".color(:red), e.message.color(:white), e.class.name.color(:yellow) ]
|
||||
$stderr.puts e.backtrace.collect { |line| " #{line}" }.join("\n")
|
||||
exit 1
|
||||
end
|
||||
Jasmine::Headless::CommandLine.run!
|
||||
|
||||
|
@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
||||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
s.add_dependency 'jasmine-core', '~>1.1.beta'
|
||||
s.add_dependency 'coffee-script', '>= 2.2'
|
||||
s.add_dependency 'rainbow'
|
||||
s.add_dependency 'multi_json'
|
||||
s.add_dependency 'sprockets', '>= 2.0'
|
||||
s.add_runtime_dependency 'jasmine-core', '~> 1.1'
|
||||
s.add_runtime_dependency 'coffee-script'
|
||||
s.add_runtime_dependency 'rainbow'
|
||||
s.add_runtime_dependency 'multi_json'
|
||||
s.add_runtime_dependency 'sprockets', '~> 2'
|
||||
end
|
||||
|
@ -2,6 +2,8 @@ require 'pathname'
|
||||
require 'sprockets'
|
||||
|
||||
module Jasmine::Headless
|
||||
autoload :CommandLine, 'jasmine/headless/command_line'
|
||||
|
||||
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
|
||||
autoload :SpecFileAnalyzer, 'jasmine/headless/spec_file_analyzer'
|
||||
autoload :CacheableAction, 'jasmine/headless/cacheable_action'
|
||||
|
29
lib/jasmine/headless/command_line.rb
Normal file
29
lib/jasmine/headless/command_line.rb
Normal file
@ -0,0 +1,29 @@
|
||||
module Jasmine::Headless
|
||||
class CommandLine
|
||||
class << self
|
||||
def run!
|
||||
require 'coffee-script'
|
||||
require 'rainbow'
|
||||
|
||||
begin
|
||||
options = Options.from_command_line
|
||||
runner = Runner.new(options)
|
||||
|
||||
if options[:do_list]
|
||||
files_list = FilesList.new(:config => runner.jasmine_config)
|
||||
files_list.files.each { |file| puts file }
|
||||
else
|
||||
exit runner.run
|
||||
end
|
||||
rescue CoffeeScript::CompilationError
|
||||
exit 1
|
||||
rescue StandardError => e
|
||||
$stderr.puts "[%s] %s (%s)" % [ "jasmine-headless-webkit".color(:red), e.message.color(:white), e.class.name.color(:yellow) ]
|
||||
$stderr.puts e.backtrace.collect { |line| " #{line}" }.join("\n")
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -57,7 +57,14 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def search_paths
|
||||
@search_paths ||= [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir) ] + self.class.vendor_asset_paths
|
||||
return @search_paths if @search_paths
|
||||
|
||||
@search_paths = [ Jasmine::Core.path ]
|
||||
@search_paths += [ src_dir ].flatten.collect { |dir| File.expand_path(dir) }
|
||||
@search_paths << File.expand_path(spec_dir)
|
||||
@search_paths += self.class.vendor_asset_paths
|
||||
|
||||
@search_paths
|
||||
end
|
||||
|
||||
def has_spec_outside_scope?
|
||||
@ -111,14 +118,13 @@ module Jasmine::Headless
|
||||
|
||||
def find_dependency(file)
|
||||
search_paths.each do |dir|
|
||||
if file[EXTENSION_FILTER]
|
||||
if File.file?(path = File.join(dir, file))
|
||||
return [ File.expand_path(path), File.expand_path(dir) ]
|
||||
end
|
||||
else
|
||||
if path = Dir[File.join(dir, "#{file}.*")].first
|
||||
return [ File.expand_path(path), File.expand_path(dir) ]
|
||||
end
|
||||
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] }
|
||||
|
||||
return [ File.expand_path(path), File.expand_path(dir) ] if ok
|
||||
end
|
||||
end
|
||||
|
||||
@ -176,15 +182,16 @@ module Jasmine::Headless
|
||||
|
||||
def add_files(searches, type)
|
||||
searches.each do |search|
|
||||
dir = @config[SEARCH_ROOTS[type]] || Dir.pwd
|
||||
dir = File.expand_path(dir)
|
||||
[ @config[SEARCH_ROOTS[type]] || Dir.pwd ].flatten.each do |dir|
|
||||
dir = File.expand_path(dir)
|
||||
|
||||
path = File.expand_path(File.join(dir, search))
|
||||
path = File.expand_path(File.join(dir, search))
|
||||
|
||||
found_files = expanded_dir(path) - files
|
||||
found_files = expanded_dir(path) - files
|
||||
|
||||
found_files.each do |file|
|
||||
type == 'spec_files' ? add_spec_file(file) : add_file(file, dir)
|
||||
found_files.each do |file|
|
||||
type == 'spec_files' ? add_spec_file(file) : add_file(file, dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,6 +43,8 @@ module Jasmine
|
||||
if Rails.respond_to?(:version) && Rails.version >= "3.1.0"
|
||||
desc 'Force generate static assets without an MD5 hash, all assets end with -test.<ext>'
|
||||
task 'assets:precompile:for_testing' => :environment do
|
||||
$stderr.puts "This task is deprecated and will be removed after 2012-01-01"
|
||||
|
||||
Rails.application.assets.digest_class = Digest::JasmineTest
|
||||
|
||||
Rake::Task['assets:precompile'].invoke
|
||||
|
@ -50,6 +50,7 @@ module Jasmine::Headless
|
||||
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
|
||||
|
@ -0,0 +1 @@
|
||||
'hello'
|
@ -0,0 +1,2 @@
|
||||
'hello'
|
||||
|
@ -87,6 +87,19 @@ describe Jasmine::Headless::FilesList do
|
||||
|
||||
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
|
||||
@ -246,11 +259,11 @@ describe Jasmine::Headless::FilesList do
|
||||
let(:spec_dir) { 'spec dir' }
|
||||
let(:path) { 'path' }
|
||||
|
||||
context 'no vendored gem paths' do
|
||||
before do
|
||||
Jasmine::Headless::FilesList.stubs(:vendor_asset_paths).returns([])
|
||||
end
|
||||
before do
|
||||
Jasmine::Headless::FilesList.stubs(:vendor_asset_paths).returns([])
|
||||
end
|
||||
|
||||
context 'no vendored gem paths' do
|
||||
it 'should take the src dir and spec dirs' do
|
||||
files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
|
||||
end
|
||||
@ -265,6 +278,17 @@ describe Jasmine::Headless::FilesList do
|
||||
files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir), path ]
|
||||
end
|
||||
end
|
||||
|
||||
context 'src_dir is an array' do
|
||||
let(:dir_1) { 'dir 1' }
|
||||
let(:dir_2) { 'dir 2' }
|
||||
|
||||
let(:src_dir) { [ dir_1, dir_2 ] }
|
||||
|
||||
it 'should take the src dir and spec dirs' do
|
||||
files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(dir_1), File.expand_path(dir_2), File.expand_path(spec_dir) ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.vendor_asset_paths' do
|
||||
@ -293,31 +317,38 @@ describe Jasmine::Headless::FilesList do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
let(:dir) { File.expand_path('dir') }
|
||||
|
||||
let(:filename) { 'file' }
|
||||
let(:file) { "#{filename}.js" }
|
||||
|
||||
before do
|
||||
files_list.stubs(:search_paths).returns([ dir ])
|
||||
|
||||
FileUtils.mkdir_p dir
|
||||
|
||||
%w{file.sub.js file.js.coffee}.each do |file|
|
||||
File.open(File.join(dir, file), 'wb')
|
||||
end
|
||||
|
||||
files_list.stubs(:search_paths).returns([ dir ])
|
||||
end
|
||||
|
||||
context 'does not exist' do
|
||||
it 'should not be found' do
|
||||
files_list.find_dependency(file).should be_false
|
||||
end
|
||||
subject { files_list.find_dependency(search) }
|
||||
|
||||
context 'bad' do
|
||||
let(:search) { 'bad' }
|
||||
|
||||
it { should be_false }
|
||||
end
|
||||
|
||||
context 'exists' do
|
||||
let(:path) { File.join(dir, file) }
|
||||
context 'file' do
|
||||
let(:search) { 'file' }
|
||||
|
||||
before do
|
||||
File.open(path, 'wb')
|
||||
end
|
||||
it { should == [ File.join(dir, 'file.js.coffee'), dir ] }
|
||||
end
|
||||
|
||||
it 'should be found' do
|
||||
files_list.find_dependency(filename).should == [ File.expand_path(path), dir ]
|
||||
end
|
||||
context 'file.sub' do
|
||||
let(:search) { 'file.sub' }
|
||||
|
||||
it { should == [ File.join(dir, 'file.sub.js'), dir ] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -44,26 +44,37 @@ describe Jasmine::Headless::TestFile do
|
||||
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}" }
|
||||
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}" }
|
||||
it { should == %{path.tilt made it #{path} made it #{content}} }
|
||||
end
|
||||
|
||||
context '.js.tilt' do
|
||||
let(:path) { 'path.js.tilt' }
|
||||
context '.jst.tilt' do
|
||||
let(:path) { 'path.jst.tilt' }
|
||||
|
||||
it { should == "#{path} made it #{content}" }
|
||||
it { should == %{<script type="text/javascript">#{path} made it #{content}</script>} }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,13 +1,16 @@
|
||||
(function() {
|
||||
|
||||
window.HeadlessReporterResult = (function() {
|
||||
|
||||
function HeadlessReporterResult(name, splitName) {
|
||||
this.name = name;
|
||||
this.splitName = splitName;
|
||||
this.results = [];
|
||||
}
|
||||
|
||||
HeadlessReporterResult.prototype.addResult = function(message) {
|
||||
return this.results.push(message);
|
||||
};
|
||||
|
||||
HeadlessReporterResult.prototype.print = function() {
|
||||
var bestChoice, output, result, _i, _len, _ref, _results;
|
||||
output = this.name.foreground('red');
|
||||
@ -25,10 +28,15 @@
|
||||
output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright();
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
HeadlessReporterResult.findSpecLine = function(splitName) {
|
||||
var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref;
|
||||
bestChoice = {
|
||||
@ -49,9 +57,7 @@
|
||||
for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) {
|
||||
line = newLineNumberInfo[_i];
|
||||
lastLine = line;
|
||||
if (line > lineNumber) {
|
||||
break;
|
||||
}
|
||||
if (line > lineNumber) break;
|
||||
}
|
||||
lineNumber = lastLine;
|
||||
}
|
||||
@ -67,6 +73,7 @@
|
||||
}
|
||||
return bestChoice;
|
||||
};
|
||||
|
||||
return HeadlessReporterResult;
|
||||
|
||||
})();
|
||||
}).call(this);
|
||||
|
3
vendor/assets/javascripts/intense.js
vendored
3
vendor/assets/javascripts/intense.js
vendored
@ -1,5 +1,6 @@
|
||||
(function() {
|
||||
var code, method, _ref;
|
||||
|
||||
window.Intense = {
|
||||
colors: {
|
||||
black: 0,
|
||||
@ -29,9 +30,11 @@
|
||||
},
|
||||
useColors: true
|
||||
};
|
||||
|
||||
_ref = Intense.methods;
|
||||
for (method in _ref) {
|
||||
code = _ref[method];
|
||||
String.prototype[method] = code;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
@ -1,8 +1,10 @@
|
||||
(function() {
|
||||
var getSplitName, pauseAndRun;
|
||||
|
||||
if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
|
||||
throw new Error("jasmine not laoded!");
|
||||
}
|
||||
|
||||
if (window.JHW) {
|
||||
getSplitName = function(parts) {
|
||||
parts.push(String(this.description).replace(/[\n\r]/g, ' '));
|
||||
@ -98,4 +100,5 @@
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
|
@ -1,19 +1,20 @@
|
||||
(function() {
|
||||
|
||||
if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
|
||||
throw new Error("jasmine not loaded!");
|
||||
}
|
||||
|
||||
jasmine.HeadlessConsoleReporter = (function() {
|
||||
|
||||
function HeadlessConsoleReporter(callback) {
|
||||
this.callback = callback != null ? callback : null;
|
||||
this.results = [];
|
||||
this.failedCount = 0;
|
||||
this.length = 0;
|
||||
}
|
||||
|
||||
HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) {
|
||||
var output, result, resultLine, runtime, _i, _len, _ref;
|
||||
if (this.hasError()) {
|
||||
return;
|
||||
}
|
||||
if (this.hasError()) return;
|
||||
runtime = (new Date() - this.startTime) / 1000.0;
|
||||
JHW.stdout.print("\n");
|
||||
resultLine = this._formatResultLine(runtime);
|
||||
@ -30,20 +31,18 @@
|
||||
result = _ref[_i];
|
||||
result.print();
|
||||
}
|
||||
if (window.JHW) {
|
||||
window.onbeforeunload = null;
|
||||
}
|
||||
if (window.JHW) window.onbeforeunload = null;
|
||||
return JHW.finishSuite();
|
||||
};
|
||||
|
||||
HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
this.startTime = new Date();
|
||||
return JHW.stdout.puts("\nRunning Jasmine specs...".bright());
|
||||
};
|
||||
|
||||
HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) {
|
||||
var failureResult, foundLine, result, results, testCount, _i, _len, _ref;
|
||||
if (this.hasError()) {
|
||||
return;
|
||||
}
|
||||
if (this.hasError()) return;
|
||||
JHW.ping();
|
||||
results = spec.results();
|
||||
this.length++;
|
||||
@ -70,16 +69,20 @@
|
||||
return this.results.push(failureResult);
|
||||
}
|
||||
};
|
||||
|
||||
HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) {
|
||||
if (this.hasError()) {
|
||||
spec.finish();
|
||||
return spec.suite.finish();
|
||||
}
|
||||
};
|
||||
|
||||
HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {};
|
||||
|
||||
HeadlessConsoleReporter.prototype.hasError = function() {
|
||||
return JHW._hasErrors;
|
||||
};
|
||||
|
||||
HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) {
|
||||
var line;
|
||||
line = [];
|
||||
@ -91,6 +94,7 @@
|
||||
line.push((runtime === 1.0 ? "sec" : "secs") + '.');
|
||||
return line.join(' ');
|
||||
};
|
||||
|
||||
return HeadlessConsoleReporter;
|
||||
|
||||
})();
|
||||
}).call(this);
|
||||
|
8
vendor/assets/javascripts/prolog.js
vendored
8
vendor/assets/javascripts/prolog.js
vendored
@ -1,5 +1,6 @@
|
||||
(function() {
|
||||
var createHandle, handle, _i, _len, _ref;
|
||||
|
||||
if (window.JHW) {
|
||||
window.console = {
|
||||
log: function(data) {
|
||||
@ -40,9 +41,7 @@
|
||||
e = e || window.event;
|
||||
JHW.hasError();
|
||||
JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.');
|
||||
if (e) {
|
||||
e.returnValue = 'string';
|
||||
}
|
||||
if (e) e.returnValue = 'string';
|
||||
return 'string';
|
||||
};
|
||||
window.confirm = function(message) {
|
||||
@ -84,6 +83,9 @@
|
||||
return JHW.stdout.puts(msg);
|
||||
};
|
||||
}
|
||||
|
||||
window.CoffeeScriptToFilename = {};
|
||||
|
||||
window.CSTF = window.CoffeeScriptToFilename;
|
||||
|
||||
}).call(this);
|
||||
|
Loading…
Reference in New Issue
Block a user