Merge branch 'master' of git://github.com/johnbintz/jasmine-headless-webkit
This commit is contained in:
commit
d462bd11b1
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,3 +16,4 @@ _site/
|
||||
jhw.*.html
|
||||
coverage/
|
||||
tmp/
|
||||
cache dir/
|
||||
|
1
Gemfile
1
Gemfile
@ -15,7 +15,6 @@ gem 'guard-cucumber'
|
||||
require 'rbconfig'
|
||||
case RbConfig::CONFIG['host_os']
|
||||
when /darwin/
|
||||
gem 'rb-fsevent'
|
||||
when /linux/
|
||||
gem 'libnotify'
|
||||
end
|
||||
|
@ -1,3 +1,5 @@
|
||||
_I am looking for a new maintainer for this project. Please contact me via GitHub if you're interested._
|
||||
|
||||
# Jasmine Headless WebKit runner
|
||||
|
||||
Run your specs at sonic boom speed! No pesky reload button or page rendering slowdowns!
|
||||
|
2
Rakefile
2
Rakefile
@ -14,7 +14,7 @@ require 'jasmine/headless/task'
|
||||
|
||||
Jasmine::Headless::Task.new
|
||||
|
||||
PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3}
|
||||
PLATFORMS = %w{1.9.2 1.9.3}
|
||||
|
||||
def rvm_bundle(command = '')
|
||||
Bundler.with_clean_env do
|
||||
|
2
config/cucumber.yml
Normal file
2
config/cucumber.yml
Normal file
@ -0,0 +1,2 @@
|
||||
default: -r features
|
||||
|
@ -71,7 +71,9 @@ void Runner::loadSpec()
|
||||
outputFiles.enqueue(outputFile);
|
||||
}
|
||||
|
||||
page.mainFrame()->load(QUrl::fromLocalFile(runnerFiles.dequeue()));
|
||||
QString runnerFile = runnerFiles.dequeue();
|
||||
|
||||
page.mainFrame()->load(runnerFile);
|
||||
ticker.start();
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,9 @@
|
||||
#include <QTextStream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <QQueue>
|
||||
#include <QApplication>
|
||||
|
||||
#include "Page.h"
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
TEMPLATE = app
|
||||
CONFIG -= app_bundle
|
||||
QMAKE_INFO_PLIST = Info.plist
|
||||
QMAKESPEC = macx-g++
|
||||
QT += network webkit
|
||||
|
||||
SOURCES = Page.cpp Runner.cpp
|
||||
|
@ -1,19 +0,0 @@
|
||||
######################################################################
|
||||
# Automatically generated by qmake (2.01a) Tue Aug 2 10:37:48 2011
|
||||
######################################################################
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET =
|
||||
DEPENDPATH += . HeadlessSpecRunner Test
|
||||
INCLUDEPATH += . HeadlessSpecRunner Test
|
||||
|
||||
# Input
|
||||
HEADERS += HeadlessSpecRunner/ConsoleOutput.h \
|
||||
HeadlessSpecRunner/Page.h \
|
||||
HeadlessSpecRunner/Runner.h \
|
||||
Test/Page_test.h
|
||||
SOURCES += specrunner.cpp \
|
||||
HeadlessSpecRunner/ConsoleOutput.cpp \
|
||||
HeadlessSpecRunner/Page.cpp \
|
||||
HeadlessSpecRunner/Runner.cpp \
|
||||
Test/Page_test.cpp
|
11
features/bin/two_files_from_src_files.feature
Normal file
11
features/bin/two_files_from_src_files.feature
Normal file
@ -0,0 +1,11 @@
|
||||
Feature: Two files from source files
|
||||
Scenario: Files are ordered directly
|
||||
Given I have a test suite
|
||||
When I run `bin/jasmine-headless-webkit -j spec/jasmine/two_files_from_src_files/jasmine.yml -l`
|
||||
Then the exit status should be 0
|
||||
And the following files should be loaded in order:
|
||||
| vendor/vendor-file.js |
|
||||
| vendor/vendor.js |
|
||||
| app/app-file.js |
|
||||
| app/app.js |
|
||||
|
7
features/bin/with_server.feature
Normal file
7
features/bin/with_server.feature
Normal file
@ -0,0 +1,7 @@
|
||||
Feature: Bin - With Server
|
||||
Scenario: Run using an HTTP server
|
||||
Given there is no existing "spec/report.txt" file
|
||||
When I run `bin/jasmine-headless-webkit --use-server -j spec/jasmine/success/success.yml -f File:spec/report.txt`
|
||||
Then the exit status should be 0
|
||||
And the report file "spec/report.txt" should have 1 total, 0 failures, no console usage
|
||||
|
10
features/steps/then/bin/following_files_loaded_in_order.rb
Normal file
10
features/steps/then/bin/following_files_loaded_in_order.rb
Normal file
@ -0,0 +1,10 @@
|
||||
Then /^the following files should be loaded in order:$/ do |table|
|
||||
files = table.raw.flatten
|
||||
|
||||
@output.lines.collect(&:strip).each do |line|
|
||||
files.shift if line[files.first]
|
||||
end
|
||||
|
||||
files.should be_empty
|
||||
end
|
||||
|
@ -20,9 +20,11 @@ Gem::Specification.new do |s|
|
||||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
s.add_runtime_dependency 'jasmine-core', '~> 1.1'
|
||||
s.add_runtime_dependency 'jasmine-core'
|
||||
s.add_runtime_dependency 'coffee-script'
|
||||
s.add_runtime_dependency 'rainbow'
|
||||
s.add_runtime_dependency 'multi_json'
|
||||
s.add_runtime_dependency 'sprockets', '~> 2'
|
||||
s.add_runtime_dependency 'multi_json', '>= 1.2.0'
|
||||
s.add_runtime_dependency 'sprockets'
|
||||
s.add_runtime_dependency 'sprockets-vendor_gems'
|
||||
end
|
||||
|
||||
|
@ -54,7 +54,11 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def cache_file
|
||||
@cache_file ||= File.expand_path(File.join(self.class.cache_dir, self.class.cache_type, file)) + '.js'
|
||||
@cache_file ||= File.expand_path(relative_cache_file) + '.js'
|
||||
end
|
||||
|
||||
def relative_cache_file
|
||||
File.join(self.class.cache_dir, self.class.cache_type, file.gsub(Dir.pwd + '/', ''))
|
||||
end
|
||||
|
||||
def fresh?
|
||||
|
@ -4,6 +4,7 @@ require 'multi_json'
|
||||
require 'set'
|
||||
require 'sprockets'
|
||||
require 'sprockets/engines'
|
||||
require 'sprockets-vendor_gems'
|
||||
|
||||
module Jasmine::Headless
|
||||
class FilesList
|
||||
@ -11,33 +12,12 @@ module Jasmine::Headless
|
||||
|
||||
class << self
|
||||
def asset_paths
|
||||
return @asset_paths if @asset_paths
|
||||
|
||||
require 'rubygems'
|
||||
|
||||
raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:each)
|
||||
|
||||
@asset_paths = []
|
||||
|
||||
Gem::Specification.each { |gemspec| @asset_paths += get_paths_from_gemspec(gemspec) }
|
||||
|
||||
@asset_paths
|
||||
end
|
||||
|
||||
def get_paths_from_gemspec(gemspec)
|
||||
%w{vendor lib app}.collect do |dir|
|
||||
path = File.join(gemspec.gem_dir, dir, "assets/javascripts")
|
||||
|
||||
if File.directory?(path) && !@asset_paths.include?(path)
|
||||
path
|
||||
else
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
@asset_paths ||= Sprockets.find_gem_vendor_paths(:for => 'javascripts')
|
||||
end
|
||||
|
||||
def reset!
|
||||
@asset_paths = nil
|
||||
@registered_engines = {}
|
||||
|
||||
# register haml-sprockets and handlebars_assets if it's available...
|
||||
%w{haml-sprockets handlebars_assets}.each do |library|
|
||||
@ -56,16 +36,20 @@ module Jasmine::Headless
|
||||
end
|
||||
end
|
||||
|
||||
# ...and unregister ones we don't want/need
|
||||
Sprockets.instance_eval do
|
||||
EXCLUDED_FORMATS.each do |extension|
|
||||
register_engine ".#{extension}", Jasmine::Headless::NilTemplate
|
||||
@sprockets_environment = nil
|
||||
end
|
||||
|
||||
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
|
||||
register_engine '.js', Jasmine::Headless::JSTemplate
|
||||
register_engine '.css', Jasmine::Headless::CSSTemplate
|
||||
register_engine '.jst', Jasmine::Headless::JSTTemplate
|
||||
def registered_engines
|
||||
@registered_engines ||= {}
|
||||
end
|
||||
|
||||
def register_engine(file_extension, template_class)
|
||||
registered_engines[file_extension] = template_class
|
||||
end
|
||||
|
||||
def register_engines!
|
||||
registered_engines.each do |file_extension, template_class|
|
||||
Sprockets.register_engine file_extension, template_class
|
||||
end
|
||||
end
|
||||
|
||||
@ -95,11 +79,21 @@ module Jasmine::Headless
|
||||
@required_files = UniqueAssetList.new
|
||||
@potential_files_to_filter = []
|
||||
|
||||
register_engines!
|
||||
|
||||
load_initial_assets
|
||||
|
||||
use_config if config?
|
||||
end
|
||||
|
||||
def register_engines!
|
||||
begin
|
||||
require spec_helper
|
||||
rescue LoadError
|
||||
end
|
||||
self.class.register_engines!
|
||||
end
|
||||
|
||||
def load_initial_assets
|
||||
self.class.default_files.each do |file|
|
||||
begin
|
||||
@ -137,6 +131,7 @@ module Jasmine::Headless
|
||||
@search_paths += asset_paths.collect { |dir| File.expand_path(dir) }
|
||||
@search_paths += spec_dir.collect { |dir| File.expand_path(dir) }
|
||||
|
||||
@search_paths.uniq!
|
||||
@search_paths
|
||||
end
|
||||
|
||||
@ -147,6 +142,19 @@ module Jasmine::Headless
|
||||
search_paths.each { |path| @sprockets_environment.append_path(path) }
|
||||
|
||||
@sprockets_environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons)
|
||||
|
||||
# ...and unregister ones we don't want/need
|
||||
@sprockets_environment.instance_eval do
|
||||
EXCLUDED_FORMATS.each do |extension|
|
||||
register_engine ".#{extension}", Jasmine::Headless::NilTemplate
|
||||
end
|
||||
|
||||
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate
|
||||
register_engine '.js', Jasmine::Headless::JSTemplate
|
||||
register_engine '.css', Jasmine::Headless::CSSTemplate
|
||||
register_engine '.jst', Jasmine::Headless::JSTTemplate
|
||||
end
|
||||
|
||||
@sprockets_environment
|
||||
end
|
||||
|
||||
@ -227,15 +235,15 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def add_files(patterns, type, dirs)
|
||||
dirs.product(patterns).each do |search|
|
||||
files = expanded_dir(File.join(*search))
|
||||
|
||||
patterns.each do |pattern|
|
||||
dirs.collect { |dir| expanded_dir(File.join(dir, pattern)) }.each do |files|
|
||||
files.sort! { |a, b| Kernel.rand(3) - 1 } if type == 'spec_files'
|
||||
|
||||
files.each do |path|
|
||||
add_path(path, type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if type == 'spec_files'
|
||||
spec_filter.each { |path| add_path(path, type) }
|
||||
@ -247,7 +255,8 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def expanded_dir(path)
|
||||
Dir[path].find_all { |file|
|
||||
file_list = Dir.glob(path).sort
|
||||
file_list.find_all { |file|
|
||||
file[extension_filter] && !alert_if_bad_format?(file)
|
||||
}.collect {
|
||||
|file| File.expand_path(file)
|
||||
@ -271,7 +280,7 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def src_dir
|
||||
@src_dir ||= config_dir_or_pwd('src_dir')
|
||||
@src_dir ||= config_dir_or_pwd('src_dir') + asset_paths
|
||||
end
|
||||
|
||||
def spec_dir
|
||||
@ -279,7 +288,7 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def asset_paths
|
||||
@asset_paths ||= config_dir_or_pwd('asset_paths')
|
||||
@asset_paths ||= config_dir('asset_paths')
|
||||
end
|
||||
|
||||
def spec_file_searches
|
||||
@ -287,9 +296,15 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def config_dir_or_pwd(dir)
|
||||
found_dir = (@options[:config] && @options[:config][dir]) || Dir.pwd
|
||||
if (found = config_dir(dir)).empty?
|
||||
found = [ Dir.pwd ]
|
||||
end
|
||||
|
||||
[ found_dir ].flatten.collect { |dir| File.expand_path(dir) }
|
||||
found
|
||||
end
|
||||
|
||||
def config_dir(dir)
|
||||
[ @options[:config] && @options[:config][dir] ].flatten.compact.collect { |dir| File.expand_path(dir) }
|
||||
end
|
||||
|
||||
def filter_for_requested_specs(files)
|
||||
@ -301,5 +316,17 @@ module Jasmine::Headless
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def spec_helper
|
||||
File.join(spec_dir, "helpers", "spec_helper")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Jasmine::Headless
|
||||
extend self
|
||||
|
||||
def register_engine(file_extension, template_class)
|
||||
Jasmine::Headless::FilesList.register_engine(file_extension, template_class)
|
||||
end
|
||||
end
|
||||
|
@ -18,7 +18,9 @@ module Jasmine
|
||||
:enable_cache => true,
|
||||
:files => [],
|
||||
:reporters => [ [ 'Console' ] ],
|
||||
:quiet => false
|
||||
:quiet => false,
|
||||
:use_server => false,
|
||||
:server_port => nil
|
||||
}
|
||||
|
||||
DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit')
|
||||
@ -75,6 +77,10 @@ module Jasmine
|
||||
@options[:seed] = arg.to_i
|
||||
when '--format', '-f'
|
||||
add_reporter(arg)
|
||||
when '--use-server'
|
||||
@options[:use_server] = true
|
||||
when '--server-port'
|
||||
@options[:server_port] = arg.to_i
|
||||
when '--out'
|
||||
add_reporter_file(arg)
|
||||
when '-h', '--help'
|
||||
@ -107,6 +113,8 @@ module Jasmine
|
||||
[ '--seed', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--out', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '--use-server', GetoptLong::NO_ARGUMENT ],
|
||||
[ '--server-port', GetoptLong::REQUIRED_ARGUMENT ],
|
||||
[ '-h', '--help', GetoptLong::NO_ARGUMENT ],
|
||||
[ '-q', '--quiet', GetoptLong::NO_ARGUMENT ]
|
||||
)
|
||||
@ -165,8 +173,9 @@ module Jasmine
|
||||
[ '--runner-out <filename>', 'Write runner to specified filename' ],
|
||||
[ '-j, --jasmine-config <config file>', 'Jasmine Yaml config to use' ],
|
||||
[ '--no-full-run', 'Do not perform a full spec run after a successful targeted spec run' ],
|
||||
[ '--use-server', 'Load tests from an HTTP server instead of from filesystem' ],
|
||||
[ '-l, --list', 'List files in the order they will be required' ],
|
||||
[ '--seed', 'Random order seed for spec file ordering' ],
|
||||
[ '--seed <seed>', 'Random order seed for spec file ordering' ],
|
||||
[ '-f, --format <reporter<:filename>>', 'Specify an output reporter and possibly output filename' ],
|
||||
[ '--out <filename>', 'Specify output filename for last defined reporter' ],
|
||||
[ '-q, --quiet', "Silence most non-test related warnings" ],
|
||||
|
@ -7,9 +7,26 @@ require 'yaml'
|
||||
require 'erb'
|
||||
require 'sprockets'
|
||||
|
||||
|
||||
module Jasmine
|
||||
module Headless
|
||||
class IndexHandler
|
||||
class << self
|
||||
attr_accessor :index
|
||||
end
|
||||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
if env['PATH_INFO'] == '/'
|
||||
return [ 302, { 'Location' => self.class.index }, [ 'Redirecting...' ] ]
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
class Runner
|
||||
JASMINE_DEFAULTS = {
|
||||
'spec_files' => [ '**/*[sS]pec.js' ],
|
||||
@ -26,10 +43,104 @@ module Jasmine
|
||||
|
||||
attr_reader :options
|
||||
|
||||
class << self
|
||||
def run(options = {})
|
||||
def self.run(options = {})
|
||||
new(options).run
|
||||
end
|
||||
|
||||
def self.server_port
|
||||
return @server_port if @server_port
|
||||
|
||||
require 'socket'
|
||||
|
||||
count = 100
|
||||
begin
|
||||
port = select_server_port
|
||||
|
||||
socket = TCPSocket.new(server_interface, port)
|
||||
socket.close
|
||||
|
||||
count -= 1
|
||||
|
||||
raise "Could not create server port after 100 attempts!" if count == 0
|
||||
rescue Errno::ECONNREFUSED
|
||||
@server_port = port
|
||||
|
||||
break
|
||||
ensure
|
||||
begin
|
||||
socket.close if socket
|
||||
rescue IOError
|
||||
end
|
||||
end while true
|
||||
|
||||
@server_port
|
||||
end
|
||||
|
||||
def self.server_port=(port)
|
||||
@server_port = port
|
||||
end
|
||||
|
||||
def self.select_server_port
|
||||
21000 + rand(10000)
|
||||
end
|
||||
|
||||
def self.server_interface
|
||||
'127.0.0.1'
|
||||
end
|
||||
|
||||
def self.server_uri
|
||||
"http://#{server_interface}:#{server_port}"
|
||||
end
|
||||
|
||||
def self.server_spec_path
|
||||
self.server_uri + '/__JHW__/'
|
||||
end
|
||||
|
||||
def self.ensure_server(options)
|
||||
return if @server
|
||||
|
||||
require 'webrick'
|
||||
require 'thread'
|
||||
require 'rack'
|
||||
require 'net/http'
|
||||
|
||||
port = server_port
|
||||
|
||||
@server = Thread.new do
|
||||
Jasmine::Headless.warn "Powering up!"
|
||||
|
||||
app = Rack::Builder.new do
|
||||
use IndexHandler
|
||||
|
||||
map '/__JHW__' do
|
||||
run Rack::File.new(Dir.pwd)
|
||||
end
|
||||
|
||||
map '/' do
|
||||
run Rack::File.new('/')
|
||||
end
|
||||
end
|
||||
|
||||
Rack::Handler::WEBrick.run(
|
||||
app,
|
||||
:Port => port,
|
||||
:Logger => Logger.new(StringIO.new),
|
||||
:AccessLog => [
|
||||
[ StringIO.new, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
|
||||
[ StringIO.new, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
while true do
|
||||
begin
|
||||
Net::HTTP.get(URI(server_uri))
|
||||
break
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
end
|
||||
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options)
|
||||
@ -63,8 +174,7 @@ module Jasmine
|
||||
command << "-r #{file}"
|
||||
end
|
||||
|
||||
command += targets.flatten.collect { |target| File.expand_path(target) }
|
||||
|
||||
command += targets
|
||||
command.compact.join(' ')
|
||||
end
|
||||
|
||||
@ -73,9 +183,11 @@ module Jasmine
|
||||
Jasmine::Headless.show_warnings = !@options[:quiet]
|
||||
FilesList.reset!
|
||||
|
||||
self.class.server_port = options[:server_port]
|
||||
|
||||
@_targets = template_writer.write
|
||||
|
||||
run_targets = @_targets.dup
|
||||
run_targets = absolute_run_targets(@_targets.dup)
|
||||
|
||||
if run_targets.length == 2
|
||||
if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope?
|
||||
@ -83,7 +195,13 @@ module Jasmine
|
||||
end
|
||||
end
|
||||
|
||||
system jasmine_command(run_targets)
|
||||
runner = lambda { system jasmine_command(run_targets) }
|
||||
|
||||
if options[:use_server]
|
||||
wrap_in_server(run_targets, &runner)
|
||||
else
|
||||
runner.call
|
||||
end
|
||||
|
||||
@_status = $?.exitstatus
|
||||
ensure
|
||||
@ -92,6 +210,17 @@ module Jasmine
|
||||
end
|
||||
end
|
||||
|
||||
def absolute_run_targets(targets)
|
||||
targets.flatten.collect do |target|
|
||||
if options[:use_server]
|
||||
target = self.class.server_spec_path + target
|
||||
else
|
||||
target = "file://" + File.expand_path(target)
|
||||
end
|
||||
target
|
||||
end
|
||||
end
|
||||
|
||||
def runner_filename
|
||||
options[:runner_output_filename] || begin
|
||||
if (runner_output = jasmine_config['runner_output']) && !runner_output.empty?
|
||||
@ -111,6 +240,15 @@ module Jasmine
|
||||
)
|
||||
end
|
||||
|
||||
def wrap_in_server(run_targets)
|
||||
self.class.ensure_server(options)
|
||||
IndexHandler.index = run_targets.last
|
||||
|
||||
Jasmine::Headless.warn "HTTP powered specs! Located at #{run_targets.join(' ')}"
|
||||
|
||||
yield
|
||||
end
|
||||
|
||||
private
|
||||
def jasmine_config_data
|
||||
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])
|
||||
|
@ -33,11 +33,11 @@ module Jasmine::Headless
|
||||
end
|
||||
|
||||
def serialize(data)
|
||||
MultiJson.encode(data)
|
||||
MultiJson.dump(data)
|
||||
end
|
||||
|
||||
def unserialize(data)
|
||||
MultiJson.decode(data)
|
||||
MultiJson.load(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,7 +24,9 @@ module Jasmine::Headless
|
||||
output.unshift([filtered_tests_filename, files_list.filtered_files_to_html ]) if files_list.filtered?
|
||||
|
||||
output.each do |name, files|
|
||||
File.open(name, 'w') { |fh| fh.print template_for(files) }
|
||||
template = template_for(files)
|
||||
|
||||
File.open(name, 'wb') { |fh| fh.print template }
|
||||
end
|
||||
|
||||
output.collect(&:first)
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Jasmine
|
||||
module Headless
|
||||
VERSION = "0.8.4"
|
||||
VERSION = "0.9.0.rc.2"
|
||||
end
|
||||
end
|
||||
|
@ -6,7 +6,7 @@
|
||||
<script type="text/javascript" src="<%= Jasmine::Headless.root.join('vendor/assets/javascripts/prolog.js') %>"></script>
|
||||
<%= files.join("\n") %>
|
||||
<script type="text/javascript">
|
||||
if (window.JHW) { HeadlessReporterResult.specLineNumbers = <%= MultiJson.encode(spec_lines) %>; }
|
||||
if (window.JHW) { HeadlessReporterResult.specLineNumbers = <%= MultiJson.dump(spec_lines) %>; }
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
@ -34,6 +34,39 @@
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var location = window.location.href;
|
||||
|
||||
var getLastModified = function(callback) {
|
||||
var http = new XMLHttpRequest();
|
||||
var header;
|
||||
|
||||
http.open('HEAD', location, true);
|
||||
|
||||
http.onreadystatechange = function() {
|
||||
if(http.readyState === http.DONE) {
|
||||
callback(http.getResponseHeader('Last-Modified'));
|
||||
}
|
||||
};
|
||||
http.send();
|
||||
}
|
||||
|
||||
getLastModified(function(currentLastModified) {
|
||||
var checker;
|
||||
checker = function() {
|
||||
setTimeout(function() {
|
||||
getLastModified(function(newLastModified) {
|
||||
if (currentLastModified != newLastModified) {
|
||||
setTimeout(function() { window.location.reload(); }, 1000);
|
||||
} else {
|
||||
checker();
|
||||
}
|
||||
});
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
checker();
|
||||
});
|
||||
}
|
||||
|
||||
jasmine.getEnv().execute();
|
||||
|
2
spec/jasmine/two_files_from_src_files/app/app.js
Normal file
2
spec/jasmine/two_files_from_src_files/app/app.js
Normal file
@ -0,0 +1,2 @@
|
||||
//= require app-file
|
||||
//
|
7
spec/jasmine/two_files_from_src_files/jasmine.yml
Normal file
7
spec/jasmine/two_files_from_src_files/jasmine.yml
Normal file
@ -0,0 +1,7 @@
|
||||
src_dir: spec/jasmine/two_files_from_src_files/app
|
||||
|
||||
asset_paths:
|
||||
- "spec/jasmine/two_files_from_src_files/vendor"
|
||||
|
||||
src_files: [ 'vendor.js', 'app.js' ]
|
||||
|
0
spec/jasmine/two_files_from_src_files/vendor/vendor-file.js
vendored
Normal file
0
spec/jasmine/two_files_from_src_files/vendor/vendor-file.js
vendored
Normal file
2
spec/jasmine/two_files_from_src_files/vendor/vendor.js
vendored
Normal file
2
spec/jasmine/two_files_from_src_files/vendor/vendor.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
//= require vendor-file
|
||||
//
|
@ -95,5 +95,28 @@ describe Jasmine::Headless::CacheableAction do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#relative_cache_file' do
|
||||
context 'file is an absolute windows file' do
|
||||
let(:current_path) { 'C:/path' }
|
||||
let(:filename) { "file.coffee" }
|
||||
let(:windows_path) { File.join(current_path, filename) }
|
||||
let(:cache_dir) { 'cache dir' }
|
||||
let(:cache_type) { 'cache type' }
|
||||
|
||||
before do
|
||||
cache_object.stubs(:file).returns(windows_path)
|
||||
|
||||
described_class.stubs(:cache_dir).returns(cache_dir)
|
||||
described_class.stubs(:cache_type).returns(cache_type)
|
||||
|
||||
Dir.stubs(:pwd).returns(current_path)
|
||||
end
|
||||
|
||||
subject { cache_object.relative_cache_file }
|
||||
|
||||
it { should == File.join(cache_dir, cache_type, filename) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,50 +5,6 @@ require 'coffee-script'
|
||||
describe Jasmine::Headless::FilesList do
|
||||
let(:files_list) { described_class.new }
|
||||
|
||||
describe '.get_paths_from_gemspec' do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
let(:gem_dir) { "dir" }
|
||||
let(:gemspec) { stub(:gem_dir => gem_dir) }
|
||||
|
||||
let(:paths) do
|
||||
%w{vendor lib app}.collect do |dir|
|
||||
File.join(gem_dir, dir, 'assets/javascripts')
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
paths.each { |path| FileUtils.mkdir_p path }
|
||||
|
||||
described_class.instance_variable_set(:@asset_paths, [])
|
||||
end
|
||||
|
||||
subject { described_class.get_paths_from_gemspec(gemspec) }
|
||||
|
||||
it { should =~ paths }
|
||||
end
|
||||
|
||||
describe '.asset_paths' do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
let(:dir_one) { 'dir_one' }
|
||||
let(:dir_two) { 'dir_two' }
|
||||
|
||||
let(:gem_one) { stub(:gem_dir => dir_one) }
|
||||
let(:gem_two) { stub(:gem_dir => dir_two) }
|
||||
|
||||
before do
|
||||
described_class.instance_variable_set(:@asset_paths, nil)
|
||||
FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
|
||||
|
||||
Gem::Specification.stubs(:_all).returns([gem_one, gem_two])
|
||||
end
|
||||
|
||||
it 'should return all matching gems with vendor/assets/javascripts directories' do
|
||||
described_class.asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
before do
|
||||
described_class.any_instance.stubs(:load_initial_assets)
|
||||
@ -218,6 +174,21 @@ describe Jasmine::Headless::FilesList do
|
||||
files_list.files.any? { |file| file['.erb'] }.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#register_engine!" do
|
||||
|
||||
before(:each) do
|
||||
Jasmine::Headless::FilesList.reset!
|
||||
end
|
||||
|
||||
it "should register code added via configure blocks" do
|
||||
template_class = mock()
|
||||
described_class.register_engine ".foo", template_class
|
||||
Sprockets.expects(:register_engine).with(".foo", template_class)
|
||||
described_class.new
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -194,4 +194,54 @@ describe Jasmine::Headless::Runner do
|
||||
subject.options[:reporters].should == reporters
|
||||
end
|
||||
end
|
||||
|
||||
describe '.server_port' do
|
||||
before do
|
||||
described_class.instance_variable_set(:@server_port, nil)
|
||||
end
|
||||
|
||||
context 'port in use' do
|
||||
require 'socket'
|
||||
|
||||
before do
|
||||
described_class.stubs(:select_server_port).returns(5000, 5001)
|
||||
end
|
||||
|
||||
it 'should try another port' do
|
||||
server = TCPServer.new(described_class.server_interface, 5000)
|
||||
|
||||
described_class.server_port.should == 5001
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#absolute_run_targets' do
|
||||
let(:opts) { {} }
|
||||
|
||||
subject { runner.absolute_run_targets(targets) }
|
||||
|
||||
let(:targets) { [ target ] }
|
||||
let(:target) { 'target' }
|
||||
|
||||
before do
|
||||
runner.stubs(:options).returns(:use_server => use_server)
|
||||
end
|
||||
|
||||
context 'server' do
|
||||
let(:use_server) { true }
|
||||
let(:server_spec_path) { 'server spec path' }
|
||||
|
||||
before do
|
||||
described_class.stubs(:server_spec_path).returns(server_spec_path)
|
||||
end
|
||||
|
||||
it { should == [ server_spec_path + target ] }
|
||||
end
|
||||
|
||||
context 'no server' do
|
||||
let(:use_server) { false }
|
||||
|
||||
it { should == [ 'file://' + File.expand_path(target) ] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
19
vendor/assets/coffeescripts/prolog.coffee
vendored
19
vendor/assets/coffeescripts/prolog.coffee
vendored
@ -80,15 +80,18 @@ if window.JHW
|
||||
puts msg
|
||||
|
||||
JHW.createCoffeeScriptFileException = (e) ->
|
||||
if e and e.sourceURL and window.CoffeeScriptToFilename
|
||||
if e and e.sourceURL
|
||||
filename = e.sourceURL.split('/').pop()
|
||||
if realFilename = window.CoffeeScriptToFilename[filename]
|
||||
e = {
|
||||
name: e.name,
|
||||
message: e.message,
|
||||
lineNumber: "~" + String(e.line),
|
||||
sourceURL: realFilename
|
||||
}
|
||||
|
||||
e =
|
||||
name: e.name
|
||||
message: e.message
|
||||
sourceURL: e.sourceURL
|
||||
lineNumber: e.line
|
||||
|
||||
if window.CoffeeScriptToFilename and realFilename = window.CoffeeScriptToFilename[filename]
|
||||
e.sourceURL = realFilename
|
||||
e.lineNumber = "~" + String(e.line)
|
||||
|
||||
e
|
||||
|
||||
|
6
vendor/assets/javascripts/intense.coffee
vendored
6
vendor/assets/javascripts/intense.coffee
vendored
@ -11,16 +11,16 @@ window.Intense = {
|
||||
methods:
|
||||
foreground: (color) ->
|
||||
if Intense.useColors
|
||||
"\033[3#{Intense.colors[color]}m#{this}\033[0m"
|
||||
'\x1b' + "[3#{Intense.colors[color]}m#{this}" + '\x1b' + "[0m"
|
||||
else
|
||||
this
|
||||
bright: ->
|
||||
if Intense.useColors
|
||||
"\033[1m#{this}\033[0m"
|
||||
'\x1b' + "[1m#{this}" + '\x1b' + "[0m"
|
||||
else
|
||||
this
|
||||
useColors: true
|
||||
moveBack: (count = 1) -> "\033[#{count}D"
|
||||
moveBack: (count = 1) -> '\x1b' + "[#{count}D"
|
||||
}
|
||||
|
||||
for method, code of Intense.methods
|
||||
|
@ -1,6 +1,8 @@
|
||||
#= require jasmine.HeadlessReporter.ConsoleBase
|
||||
#
|
||||
class jasmine.HeadlessReporter.Verbose extends jasmine.HeadlessReporter.ConsoleBase
|
||||
@prereport = false
|
||||
|
||||
displaySuccess: (spec) =>
|
||||
this.displaySpec(spec, 'green')
|
||||
|
||||
@ -46,12 +48,17 @@ class jasmine.HeadlessReporter.Verbose extends jasmine.HeadlessReporter.ConsoleB
|
||||
colorLine: (line, color) =>
|
||||
line.foreground(color)
|
||||
|
||||
reportSpecStarting: (spec) =>
|
||||
if jasmine.HeadlessReporter.Verbose.prereport
|
||||
this.puts(spec.getSpecSplitName().join(' '))
|
||||
|
||||
reportException: (e) =>
|
||||
e = JHW.createCoffeeScriptFileException(e)
|
||||
|
||||
output = e.message
|
||||
if e.sourceURL && e.lineNumber
|
||||
output = "#{e.sourceURL}:~#{e.lineNumber} #{output}"
|
||||
output = "#{e.sourceURL}:#{e.lineNumber} #{e.message}"
|
||||
else
|
||||
output = e.message ? e
|
||||
|
||||
this.puts(output.foreground('yellow'))
|
||||
|
||||
|
10
vendor/assets/javascripts/prolog.js
vendored
10
vendor/assets/javascripts/prolog.js
vendored
@ -84,15 +84,17 @@
|
||||
};
|
||||
JHW.createCoffeeScriptFileException = function(e) {
|
||||
var filename, realFilename;
|
||||
if (e && e.sourceURL && window.CoffeeScriptToFilename) {
|
||||
if (e && e.sourceURL) {
|
||||
filename = e.sourceURL.split('/').pop();
|
||||
if (realFilename = window.CoffeeScriptToFilename[filename]) {
|
||||
e = {
|
||||
name: e.name,
|
||||
message: e.message,
|
||||
lineNumber: "~" + String(e.line),
|
||||
sourceURL: realFilename
|
||||
sourceURL: e.sourceURL,
|
||||
lineNumber: e.line
|
||||
};
|
||||
if (window.CoffeeScriptToFilename && (realFilename = window.CoffeeScriptToFilename[filename])) {
|
||||
e.sourceURL = realFilename;
|
||||
e.lineNumber = "~" + String(e.line);
|
||||
}
|
||||
}
|
||||
return e;
|
||||
|
Loading…
Reference in New Issue
Block a user