Compare commits

...

44 Commits

Author SHA1 Message Date
John Bintz
f7384d684c It's been fun. Use Karma instead. 2014-05-14 15:34:21 -04:00
John Bintz
1055dc1016 Merge pull request #177 from jeremy-brenner/master
Qt 4.8 fix
2013-03-15 10:59:23 -07:00
Jeremy Brenner
c1e786f3c5 Added compiler directive to include getopt.h on qt versions >= 4.8 2013-03-15 11:23:50 -05:00
John Bintz
aa1d989a90 message about looking for new maintainer 2012-07-30 11:15:32 -04:00
John Bintz
30e1ff8e51 bump version 2012-04-23 11:08:17 -04:00
John Bintz
9b41a36841 fix a bad commit and fix multijson deprecation warnings 2012-04-23 09:30:56 -04:00
John Bintz
65137186c8 Merge pull request #142 from pungoyal/master
fixing multi_json 1.3.2 issue #140
2012-04-18 08:05:08 -07:00
Puneet Goyal
a89682f771 Update vendor/assets/javascripts/intense.coffee 2012-04-18 20:24:20 +05:30
Puneet Goyal
3815a47d07 fixing multi_json 1.3.2 issue 2012-04-18 20:22:14 +05:30
John Bintz
724541a2cb Merge pull request #135 from tddium/master
Sort order in directory globs
2012-04-03 06:50:51 -07:00
William Josephson
1c81ea7286 Most filesystems don't guarantee directory listing order, so sort glob results. 2012-04-02 22:12:45 -04:00
John Bintz
8c6a792960 Merge pull request #132 from doitian/master
Do not populate the global Sprockets environment
2012-03-23 11:48:33 -07:00
Ian Yang
1aac97ea1f do not populate the global Sprockets environment 2012-03-23 22:52:54 +08:00
John Bintz
21590a9a19 Merge pull request #111 from rossta/register_custom_template_hook
Ability to register custom template engines...
2012-03-22 04:17:13 -07:00
John Bintz
68683e4b6c Merge pull request #131 from pmcelhaney/patch-1
Great price and record fast shipping time!!! Would request again. :)
2012-03-20 11:12:14 -07:00
Patrick McElhaney
181f4e286a Removed log messages from spec runner. 2012-03-19 17:05:51 -03:00
John Bintz
d572b0d6fe Merge pull request #130 from pmcelhaney/patch-1
Fixed getLastModified callback firing three times
2012-03-19 12:11:28 -07:00
Patrick McElhaney
af20af8524 Fixed getLastModified callback firing three times (once for every readyState change). 2012-03-19 15:28:41 -03:00
John Bintz
0064595dea remove the specification of the qmakespec, maybe help fix #59 2012-02-21 09:19:33 -05:00
John Bintz
2e2651d11a may fix #119, file paths on windows 2012-02-21 09:04:00 -05:00
John Bintz
c96cbd4aac move sprockets gem finding to separate gem that enforces rubygems version, implements #116 in a different way 2012-02-08 09:07:54 -05:00
John Bintz
4f11cba073 some fixes for bad things. i'm sad 2012-02-03 15:12:28 -05:00
John Bintz
bad6839760 rc version bump 2012-01-27 09:19:44 -05:00
John Bintz
453f439271 forgot a change 2012-01-24 14:47:31 -05:00
John Bintz
142a0c974b make sure src_files can also be loaded from other asset paths, should fix problem found by @christiannelson 2012-01-24 14:38:10 -05:00
Ross Kaffenberger
75dce5b66b Ability to register custom template engines via Jasmine::Headless.register_engine hook 2012-01-22 18:40:13 -05:00
John Bintz
0d4550524f crazy crazy changes for server running and outside browser usage and other *magic* 2012-01-18 18:04:36 -05:00
John Bintz
47b8d10d56 server runner updated 2012-01-17 13:32:57 -05:00
John Bintz
d3c3e7bd7d don't reinvent the wheel 2012-01-13 07:45:27 -05:00
John Bintz
f51f041b85 webrick seems to need log write locations or things get weird 2012-01-12 18:40:25 -05:00
John Bintz
8de1bd8cf0 clean up some fixes 2012-01-12 18:07:08 -05:00
John Bintz
09842c0539 fix a few verbose reporter bugs 2012-01-12 16:47:36 -05:00
John Bintz
5d43eb2193 let's run with a server, like all the cool kids do nowadays\! 2012-01-12 15:02:32 -05:00
John Bintz
ed4590ee44 ensure assets with same logical_path but different pathnames are included, fixes #110 2012-01-12 14:16:16 -05:00
John Bintz
b7553062bd rearrange js 2012-01-11 15:41:27 -05:00
John Bintz
ed76916205 more cleanup 2012-01-11 14:24:09 -05:00
John Bintz
b9b4648a24 update reporter 2012-01-11 11:37:25 -05:00
John Bintz
282ed40264 merge 2012-01-11 09:58:47 -05:00
John Bintz
1f56031d8b -q to silence some noisy things, fixes #97 2012-01-11 08:44:28 -05:00
John Bintz
da59a48025 add verbose reporter 2012-01-10 17:14:37 -05:00
John Bintz
81f561282a make sure window.promot doesn't get called, fixes #106 2012-01-09 13:20:58 -05:00
John Bintz
dfe1bece2c make sure window.promot doesn't get called, fixes #106 2012-01-09 11:09:34 -05:00
John Bintz
7587381e1e qt 4.8 webkit doesn't use working dir to resolve local file urls anymore, fixes #101 2012-01-03 10:47:18 -05:00
John Bintz
df83a61cb5 add help options 2011-12-30 15:33:06 -05:00
77 changed files with 888 additions and 735 deletions

1
.gitignore vendored
View File

@ -16,3 +16,4 @@ _site/
jhw.*.html jhw.*.html
coverage/ coverage/
tmp/ tmp/
cache dir/

17
Gemfile
View File

@ -12,16 +12,19 @@ gem 'guard-shell'
gem 'guard-coffeescript' gem 'guard-coffeescript'
gem 'guard-cucumber' gem 'guard-cucumber'
gem 'growl' require 'rbconfig'
gem 'rake', '0.8.7' case RbConfig::CONFIG['host_os']
gem 'mocha', '0.9.12' when /darwin/
gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-jasmine-headless-webkit.git' when /linux/
gem 'facter' gem 'libnotify'
end
gem 'mocha'
gem 'cucumber' gem 'cucumber'
gem 'jquery-rails' gem 'jquery-rails', '~> 1.0.0'
gem 'ejs' gem 'ejs'
gem 'simplecov' gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-jasmine-headless-webkit.git'

View File

@ -1,3 +1,5 @@
_This project is dead. You should use [Karma](http://karma-runner.github.io/) instead. I do._
# Jasmine Headless WebKit runner # Jasmine Headless WebKit runner
Run your specs at sonic boom speed! No pesky reload button or page rendering slowdowns! Run your specs at sonic boom speed! No pesky reload button or page rendering slowdowns!

View File

@ -14,7 +14,7 @@ require 'jasmine/headless/task'
Jasmine::Headless::Task.new Jasmine::Headless::Task.new
PLATFORMS = %w{1.8.7 1.9.2 ree 1.9.3-rc1} PLATFORMS = %w{1.9.2 1.9.3}
def rvm_bundle(command = '') def rvm_bundle(command = '')
Bundler.with_clean_env do Bundler.with_clean_env do

2
config/cucumber.yml Normal file
View File

@ -0,0 +1,2 @@
default: -r features

View File

@ -11,6 +11,5 @@ void Page::javaScriptConsoleMessage(const QString & message, int lineNumber, con
} }
void Page::javaScriptAlert(QWebFrame *, const QString &) {} void Page::javaScriptAlert(QWebFrame *, const QString &) {}
bool Page::javaScriptConfirm(QWebFrame *, const QString &) { bool Page::javaScriptConfirm(QWebFrame *, const QString &) { return false; }
return false; bool Page::javaScriptPrompt(QWebFrame *, const QString &, const QString &, QString *) { return false; }
}

View File

@ -12,6 +12,7 @@ class Page: public QWebPage {
void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID);
void javaScriptAlert(QWebFrame *, const QString &); void javaScriptAlert(QWebFrame *, const QString &);
bool javaScriptConfirm(QWebFrame *, const QString &); bool javaScriptConfirm(QWebFrame *, const QString &);
bool javaScriptPrompt(QWebFrame *, const QString &, const QString &, QString *);
signals: signals:
void handleError(const QString & message, int lineNumber, const QString & sourceID); void handleError(const QString & message, int lineNumber, const QString & sourceID);
}; };

View File

@ -18,6 +18,7 @@ Runner::Runner() : QObject()
, usedConsole(false) , usedConsole(false)
, isFinished(false) , isFinished(false)
, useColors(false) , useColors(false)
, quiet(false)
{ {
page.settings()->enablePersistentStorage(); page.settings()->enablePersistentStorage();
ticker.setInterval(TIMER_TICK); ticker.setInterval(TIMER_TICK);
@ -70,7 +71,9 @@ void Runner::loadSpec()
outputFiles.enqueue(outputFile); outputFiles.enqueue(outputFile);
} }
page.mainFrame()->load(runnerFiles.dequeue()); QString runnerFile = runnerFiles.dequeue();
page.mainFrame()->load(runnerFile);
ticker.start(); ticker.start();
} }
@ -122,10 +125,18 @@ void Runner::setSeed(QString s) {
seed = s; seed = s;
} }
void Runner::setQuiet(bool q) {
quiet = q;
}
QString Runner::getSeed() { QString Runner::getSeed() {
return seed; return seed;
} }
bool Runner::isQuiet() {
return quiet;
}
void Runner::print(const QString &fh, const QString &content) { void Runner::print(const QString &fh, const QString &content) {
if (fh == "stdout") { if (fh == "stdout") {
std::cout << qPrintable(content); std::cout << qPrintable(content);

View File

@ -7,7 +7,9 @@
#include <QTextStream> #include <QTextStream>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream>
#include <QQueue> #include <QQueue>
#include <QApplication>
#include "Page.h" #include "Page.h"
@ -22,6 +24,7 @@ class Runner: public QObject {
void setColors(bool colors); void setColors(bool colors);
void setReportFiles(QStack<QString> &files); void setReportFiles(QStack<QString> &files);
void setSeed(QString s); void setSeed(QString s);
void setQuiet(bool q);
void addFile(const QString &spec); void addFile(const QString &spec);
void go(); void go();
@ -33,6 +36,7 @@ class Runner: public QObject {
void hasError(); void hasError();
void hasSpecFailure(); void hasSpecFailure();
bool isQuiet();
QString getSeed(); QString getSeed();
void print(const QString &fh, const QString &content); void print(const QString &fh, const QString &content);
@ -54,6 +58,7 @@ class Runner: public QObject {
bool usedConsole; bool usedConsole;
bool isFinished; bool isFinished;
bool useColors; bool useColors;
bool quiet;
QString seed; QString seed;

View File

@ -1,7 +1,6 @@
TEMPLATE = app TEMPLATE = app
CONFIG -= app_bundle CONFIG -= app_bundle
QMAKE_INFO_PLIST = Info.plist QMAKE_INFO_PLIST = Info.plist
QMAKESPEC = macx-g++
QT += network webkit QT += network webkit
SOURCES = Page.cpp Runner.cpp SOURCES = Page.cpp Runner.cpp

View File

@ -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

View File

@ -23,6 +23,10 @@
#include "Runner.h" #include "Runner.h"
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
#include <getopt.h>
#endif
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) #if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
#error Use Qt 4.7 or later version #error Use Qt 4.7 or later version
#endif #endif
@ -30,17 +34,20 @@
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
bool showColors = false; bool showColors = false;
bool isQuiet = false;
QString seed; QString seed;
QStack<QString> reporterFiles; QStack<QString> reporterFiles;
int c, index; int c, index;
while ((c = getopt(argc, argv, "cr:s:")) != -1) { while ((c = getopt(argc, argv, "cr:s:q")) != -1) {
switch(c) { switch(c) {
case 'c': case 'c':
showColors = true; showColors = true;
break; break;
case 'q':
isQuiet = true;
break;
case 'r': case 'r':
reporterFiles.push(QString(optarg)); reporterFiles.push(QString(optarg));
break; break;
@ -61,6 +68,7 @@ int main(int argc, char** argv)
Runner runner; Runner runner;
runner.setColors(showColors); runner.setColors(showColors);
runner.setQuiet(isQuiet);
runner.setReportFiles(reporterFiles); runner.setReportFiles(reporterFiles);
runner.setSeed(seed); runner.setSeed(seed);

View File

@ -0,0 +1,7 @@
Feature: Bin - Help
Scenario: Display the Help
Given I have a test suite
When I run `bin/jasmine-headless-webkit -h`
Then I should get help output
And the exit status should be 0

View File

@ -0,0 +1,8 @@
Feature: Bin - Quiet Messages
Scenario: Run a test that would cause a lot of messages to be displayed and silence them all
Given I have a test suite
When I run `bin/jasmine-headless-webkit -q -j spec/jasmine/noisy/noisy.yml`
Then the exit status should be 0
And the output should not include "[Skipping File]"
And the output should not include "You should mock"

View File

@ -0,0 +1,7 @@
Feature: Bin - Two spec files with same basename
Scenario: Run both files
Given there is no existing "spec/report.txt" file
When I run `bin/jasmine-headless-webkit -j spec/jasmine/two_spec_files_same_basename/jasmine.yml -f File:spec/report.txt`
Then the exit status should be 0
And the report file "spec/report.txt" should have 2 total, 0 failures, no console usage

View 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 |

View 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

View File

@ -0,0 +1,7 @@
Feature: Bin - With window.prompt()
Scenario: Alert the user that window.prompt() needs to be stubbed
Given I have a test suite
When I run `bin/jasmine-headless-webkit -j spec/jasmine/window_prompt/window_prompt.yml`
Then the exit status should be 0
And the output should include "You should mock window.prompt"

View 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

View File

@ -0,0 +1,4 @@
Then /^I should get help output$/ do
@output.should include("Usage:")
end

View File

@ -0,0 +1,4 @@
Then /^the output should not include "([^"]*)"$/ do |string|
@output.should_not include(string)
end

View File

@ -20,9 +20,11 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"] 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 'coffee-script'
s.add_runtime_dependency 'rainbow' s.add_runtime_dependency 'rainbow'
s.add_runtime_dependency 'multi_json' s.add_runtime_dependency 'multi_json', '>= 1.2.0'
s.add_runtime_dependency 'sprockets', '~> 2' s.add_runtime_dependency 'sprockets'
s.add_runtime_dependency 'sprockets-vendor_gems'
end end

View File

@ -1,20 +0,0 @@
module Digest
class JasmineTest
def self.file(file)
new
end
def file(file)
self
end
def hexdigest
'test'
end
def update(prefix)
self
end
end
end

View File

@ -1,7 +1,3 @@
require 'jasmine/headless' require 'jasmine/headless'
require 'jasmine/headless/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3 require 'jasmine/headless/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
module Digest
autoload :JasmineTest, 'digest/jasmine_test'
end

View File

@ -35,6 +35,24 @@ module Jasmine
def root def root
@root ||= Pathname(File.expand_path('../../..', __FILE__)) @root ||= Pathname(File.expand_path('../../..', __FILE__))
end end
def warn(message)
output.puts message if show_warnings?
end
def show_warnings=(show)
@show_warnings = show
end
def show_warnings?
@show_warnings = true if @show_warnings.nil?
@show_warnings
end
def output
$stdout
end
end end
end end
end end

View File

@ -54,7 +54,11 @@ module Jasmine::Headless
end end
def cache_file 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 end
def fresh? def fresh?

View File

@ -1,14 +1,18 @@
module Jasmine::Headless::FileChecker module Jasmine::Headless::FileChecker
def excluded_formats
::Jasmine::Headless::EXCLUDED_FORMATS
end
def bad_format?(file) def bad_format?(file)
return if file.nil? return if file.nil?
::Jasmine::Headless::EXCLUDED_FORMATS.any? do |format| excluded_formats.any? do |format|
file[%r{\.#{format}(\.|$)}] file[%r{\.#{format}(\.|$)}]
end end
end end
def alert_bad_format(file) def alert_bad_format(file)
puts "[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ] Jasmine::Headless.warn("[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ])
end end
def alert_if_bad_format?(file) def alert_if_bad_format?(file)

View File

@ -4,6 +4,7 @@ require 'multi_json'
require 'set' require 'set'
require 'sprockets' require 'sprockets'
require 'sprockets/engines' require 'sprockets/engines'
require 'sprockets-vendor_gems'
module Jasmine::Headless module Jasmine::Headless
class FilesList class FilesList
@ -11,33 +12,12 @@ module Jasmine::Headless
class << self class << self
def asset_paths def asset_paths
return @asset_paths if @asset_paths @asset_paths ||= Sprockets.find_gem_vendor_paths(:for => 'javascripts')
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
end end
def reset! def reset!
@asset_paths = nil @asset_paths = nil
@registered_engines = {}
# register haml-sprockets and handlebars_assets if it's available... # register haml-sprockets and handlebars_assets if it's available...
%w{haml-sprockets handlebars_assets}.each do |library| %w{haml-sprockets handlebars_assets}.each do |library|
@ -56,22 +36,27 @@ module Jasmine::Headless
end end
end end
# ...and unregister ones we don't want/need @sprockets_environment = nil
Sprockets.instance_eval do end
EXCLUDED_FORMATS.each do |extension|
register_engine ".#{extension}", Jasmine::Headless::NilTemplate
end
register_engine '.coffee', Jasmine::Headless::CoffeeTemplate def registered_engines
register_engine '.js', Jasmine::Headless::JSTemplate @registered_engines ||= {}
register_engine '.css', Jasmine::Headless::CSSTemplate end
register_engine '.jst', Jasmine::Headless::JSTTemplate
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
end end
def default_files def default_files
%w{jasmine.js jasmine-html jasmine.css jasmine-extensions %w{jasmine.js jasmine-html jasmine.css jasmine-extensions
intense headless_reporter_result jasmine.HeadlessReporter intense headless_reporter_result jasmine.HeadlessReporter
jasmine.HeadlessReporter.ConsoleBase
jsDump beautify-html} jsDump beautify-html}
end end
@ -94,11 +79,21 @@ module Jasmine::Headless
@required_files = UniqueAssetList.new @required_files = UniqueAssetList.new
@potential_files_to_filter = [] @potential_files_to_filter = []
register_engines!
load_initial_assets load_initial_assets
use_config if config? use_config if config?
end end
def register_engines!
begin
require spec_helper
rescue LoadError
end
self.class.register_engines!
end
def load_initial_assets def load_initial_assets
self.class.default_files.each do |file| self.class.default_files.each do |file|
begin begin
@ -136,6 +131,7 @@ module Jasmine::Headless
@search_paths += asset_paths.collect { |dir| File.expand_path(dir) } @search_paths += asset_paths.collect { |dir| File.expand_path(dir) }
@search_paths += spec_dir.collect { |dir| File.expand_path(dir) } @search_paths += spec_dir.collect { |dir| File.expand_path(dir) }
@search_paths.uniq!
@search_paths @search_paths
end end
@ -146,6 +142,19 @@ module Jasmine::Headless
search_paths.each { |path| @sprockets_environment.append_path(path) } search_paths.each { |path| @sprockets_environment.append_path(path) }
@sprockets_environment.unregister_postprocessor('application/javascript', Sprockets::SafetyColons) @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 @sprockets_environment
end end
@ -226,13 +235,13 @@ module Jasmine::Headless
end end
def add_files(patterns, type, dirs) def add_files(patterns, type, dirs)
dirs.product(patterns).each do |search| patterns.each do |pattern|
files = expanded_dir(File.join(*search)) 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.sort! { |a, b| Kernel.rand(3) - 1 } if type == 'spec_files' files.each do |path|
add_path(path, type)
files.each do |path| end
add_path(path, type)
end end
end end
@ -246,7 +255,8 @@ module Jasmine::Headless
end end
def expanded_dir(path) 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) file[extension_filter] && !alert_if_bad_format?(file)
}.collect { }.collect {
|file| File.expand_path(file) |file| File.expand_path(file)
@ -270,7 +280,7 @@ module Jasmine::Headless
end end
def src_dir def src_dir
@src_dir ||= config_dir_or_pwd('src_dir') @src_dir ||= config_dir_or_pwd('src_dir') + asset_paths
end end
def spec_dir def spec_dir
@ -278,7 +288,7 @@ module Jasmine::Headless
end end
def asset_paths def asset_paths
@asset_paths ||= config_dir_or_pwd('asset_paths') @asset_paths ||= config_dir('asset_paths')
end end
def spec_file_searches def spec_file_searches
@ -286,9 +296,15 @@ module Jasmine::Headless
end end
def config_dir_or_pwd(dir) 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 end
def filter_for_requested_specs(files) def filter_for_requested_specs(files)
@ -300,5 +316,17 @@ module Jasmine::Headless
end end
end 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
end end

View File

@ -17,9 +17,10 @@ module Jasmine
:full_run => true, :full_run => true,
:enable_cache => true, :enable_cache => true,
:files => [], :files => [],
:reporters => [ :reporters => [ [ 'Console' ] ],
[ 'Console' ] :quiet => false,
] :use_server => false,
:server_port => nil
} }
DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit') DEFAULTS_FILE = File.join(Dir.pwd, '.jasmine-headless-webkit')
@ -39,6 +40,7 @@ module Jasmine
srand srand
@options[:seed] = rand(10000) @options[:seed] = rand(10000)
read_defaults_files read_defaults_files
opts.each { |k, v| @options[k] = v if v } opts.each { |k, v| @options[k] = v if v }
end end
@ -69,12 +71,22 @@ module Jasmine
@options[:full_run] = false @options[:full_run] = false
when '--list', '-l' when '--list', '-l'
@options[:do_list] = true @options[:do_list] = true
when '--quiet', '-q'
@options[:quiet] = true
when '--seed' when '--seed'
@options[:seed] = arg.to_i @options[:seed] = arg.to_i
when '--format', '-f' when '--format', '-f'
add_reporter(arg) add_reporter(arg)
when '--use-server'
@options[:use_server] = true
when '--server-port'
@options[:server_port] = arg.to_i
when '--out' when '--out'
add_reporter_file(arg) add_reporter_file(arg)
when '-h', '--help'
print_help
exit
end end
end end
@ -100,7 +112,11 @@ module Jasmine
[ '--list', '-l', GetoptLong::NO_ARGUMENT ], [ '--list', '-l', GetoptLong::NO_ARGUMENT ],
[ '--seed', GetoptLong::REQUIRED_ARGUMENT ], [ '--seed', GetoptLong::REQUIRED_ARGUMENT ],
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ], [ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
[ '--out', 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 ]
) )
command_line_args.each { |*args| process_option(*args) } command_line_args.each { |*args| process_option(*args) }
@ -146,6 +162,44 @@ module Jasmine
def add_reporter_file(file) def add_reporter_file(file)
@options[:reporters].last << file @options[:reporters].last << file
end end
def print_help
options = [
[ '-c, --colors', 'Enable colors (default: disabled)' ],
[ '-nc, --no-colors', 'Disable colors' ],
[ '--cache', 'Enable cache (default: enabled)' ],
[ '--no-cache', 'Disable cache' ],
[ '--keep', 'Keep runner files on failure' ],
[ '--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 <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" ],
[ '-h, --help', "You're looking at it" ]
]
longest_length = options.collect(&:first).collect(&:length).max
puts <<-HELP
Usage: #{$0} [ options ] [ spec files ]
Options:
#{options.collect { |option, description| " #{option.ljust(longest_length)} #{description}" }.join("\n")}
Available reporters:
Console Write out spec results to the console in a progress format (default)
Verbose Write out spec results to the console in a verbose format
File Write spec results in jasmine-headless-webkit ReportFile format
Tap Write spec results in TAP format
Add reporters to the jasmine.HeadlessReporter object to access them
(ex: jasmine.HeadlessReporter.Teamcity for the Teamcity reporter)
HELP
end
end end
end end
end end

View File

@ -7,9 +7,26 @@ require 'yaml'
require 'erb' require 'erb'
require 'sprockets' require 'sprockets'
module Jasmine module Jasmine
module Headless 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 class Runner
JASMINE_DEFAULTS = { JASMINE_DEFAULTS = {
'spec_files' => [ '**/*[sS]pec.js' ], 'spec_files' => [ '**/*[sS]pec.js' ],
@ -26,9 +43,103 @@ module Jasmine
attr_reader :options attr_reader :options
class << self def self.run(options = {})
def run(options = {}) new(options).run
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
end end
@ -57,23 +168,26 @@ module Jasmine
command << "-s #{options[:seed]}" command << "-s #{options[:seed]}"
command << '-c' if options[:colors] command << '-c' if options[:colors]
command << '-q' if options[:quiet]
options.file_reporters.each do |reporter, identifier, file| options.file_reporters.each do |reporter, identifier, file|
command << "-r #{file}" command << "-r #{file}"
end end
command += targets command += targets
command.compact.join(' ') command.compact.join(' ')
end end
def run def run
Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache] Jasmine::Headless::CacheableAction.enabled = @options[:enable_cache]
Jasmine::Headless.show_warnings = !@options[:quiet]
FilesList.reset! FilesList.reset!
self.class.server_port = options[:server_port]
@_targets = template_writer.write @_targets = template_writer.write
run_targets = @_targets.dup run_targets = absolute_run_targets(@_targets.dup)
if run_targets.length == 2 if run_targets.length == 2
if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope? if (!@options[:full_run] && files_list.filtered?) || files_list.has_spec_outside_scope?
@ -81,7 +195,13 @@ module Jasmine
end end
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 @_status = $?.exitstatus
ensure ensure
@ -90,6 +210,17 @@ module Jasmine
end end
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 def runner_filename
options[:runner_output_filename] || begin options[:runner_output_filename] || begin
if (runner_output = jasmine_config['runner_output']) && !runner_output.empty? if (runner_output = jasmine_config['runner_output']) && !runner_output.empty?
@ -109,6 +240,15 @@ module Jasmine
) )
end 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 private
def jasmine_config_data def jasmine_config_data
raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config]) raise JasmineConfigNotFound.new("Jasmine config not found. I tried #{@options[:jasmine_config]}.") if !File.file?(@options[:jasmine_config])

View File

@ -33,11 +33,11 @@ module Jasmine::Headless
end end
def serialize(data) def serialize(data)
MultiJson.encode(data) MultiJson.dump(data)
end end
def unserialize(data) def unserialize(data)
MultiJson.decode(data) MultiJson.load(data)
end end
end end
end end

View File

@ -14,23 +14,9 @@ module Jasmine
desc 'Run Jasmine specs headlessly' desc 'Run Jasmine specs headlessly'
task(name) { run_rake_task } task(name) { run_rake_task }
create_rails_compliant_task if defined?(Rails)
end end
private private
def create_rails_compliant_task
if Rails.respond_to?(:version) && Rails.version >= "3.1.0"
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
end
end
end
def run_rake_task def run_rake_task
case Jasmine::Headless::Runner.run( case Jasmine::Headless::Runner.run(
:colors => colors, :colors => colors,

View File

@ -24,7 +24,9 @@ module Jasmine::Headless
output.unshift([filtered_tests_filename, files_list.filtered_files_to_html ]) if files_list.filtered? output.unshift([filtered_tests_filename, files_list.filtered_files_to_html ]) if files_list.filtered?
output.each do |name, files| 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 end
output.collect(&:first) output.collect(&:first)

View File

@ -3,7 +3,7 @@ module Jasmine::Headless
def <<(asset) def <<(asset)
raise InvalidUniqueAsset.new("Not an asset: #{asset.inspect}") if !asset.respond_to?(:logical_path) raise InvalidUniqueAsset.new("Not an asset: #{asset.inspect}") if !asset.respond_to?(:logical_path)
super if !self.any? { |other| asset.logical_path == other.logical_path } super if !self.any? { |other| asset.pathname == other.pathname }
end end
def flatten def flatten

View File

@ -1,5 +1,5 @@
module Jasmine module Jasmine
module Headless module Headless
VERSION = "0.8.4" VERSION = "0.9.0.rc.2"
end end
end end

4
script/hooks/post-commit Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
penchant gemfile remote --switch-back

View File

@ -2,9 +2,9 @@
OLD_GIT_DIR=$GIT_DIR OLD_GIT_DIR=$GIT_DIR
if [ "$(penchant gemfile-env)" != "remote" ]; then if [ "$(penchant gemfile-env)" != "remote deployment" ]; then
unset GIT_DIR unset GIT_DIR
penchant gemfile remote penchant gemfile remote --deployment
GIT_DIR=$OLD_GIT_DIR GIT_DIR=$OLD_GIT_DIR
git add Gemfile* git add Gemfile*
fi fi

View File

@ -5,7 +5,7 @@ if File.file?('Gemfile.erb')
Dir.chdir '..' do Dir.chdir '..' do
File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line| File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
repo = line[%r{:git => (['"])(.*)\1}, 2] repo = line[%r{:git => (['"])([^'"]+)\1}, 2]
puts "Installing #{repo}" puts "Installing #{repo}"
system %{git clone #{repo}} system %{git clone #{repo}}

View File

@ -6,7 +6,7 @@
<script type="text/javascript" src="<%= Jasmine::Headless.root.join('vendor/assets/javascripts/prolog.js') %>"></script> <script type="text/javascript" src="<%= Jasmine::Headless.root.join('vendor/assets/javascripts/prolog.js') %>"></script>
<%= files.join("\n") %> <%= files.join("\n") %>
<script type="text/javascript"> <script type="text/javascript">
if (window.JHW) { HeadlessReporterResult.specLineNumbers = <%= MultiJson.encode(spec_lines) %>; } if (window.JHW) { HeadlessReporterResult.specLineNumbers = <%= MultiJson.dump(spec_lines) %>; }
</script> </script>
</head> </head>
<body> <body>
@ -34,6 +34,39 @@
break; 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(); jasmine.getEnv().execute();

View File

View File

@ -0,0 +1,8 @@
src_dir: spec/jasmine/noisy
src_files:
- '**/*'
spec_dir: spec/jasmine/noisy
spec_files:
- '**/*'

View File

@ -0,0 +1,2 @@
window.prompt("hello");

View File

@ -0,0 +1,2 @@
//= require app-file
//

View 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' ]

View File

@ -0,0 +1,2 @@
//= require vendor-file
//

View File

@ -0,0 +1,6 @@
src_dir: spec/jasmine/two_spec_files_same_basename
src_files: []
spec_dir: spec/jasmine/two_spec_files_same_basename
spec_files: [ "**/*.{js,coffee}" ]

View File

@ -0,0 +1,4 @@
describe 'two', ->
it 'should pass', ->
expect(true).toEqual(true)

View File

@ -0,0 +1,6 @@
describe("one", function() {
it('should pass', function() {
expect(true).toEqual(true);
});
});

View File

@ -0,0 +1,2 @@
window.prompt("Yes! Hi!");

View File

@ -0,0 +1,4 @@
src_dir: spec/jasmine/window_prompt
src_files:
- '**/*.js'

View File

@ -0,0 +1,35 @@
describe 'jasmine.HeadlessReporter.ConsoleBase', ->
reporter = null
beforeEach ->
reporter = new jasmine.HeadlessReporter.ConsoleBase()
describe '#formatResultLine', ->
context 'length = 1', ->
it 'should format', ->
reporter.length = 1
expect(reporter.formatResultLine(0)).toMatch(/test,/)
context 'length != 1', ->
it 'should format', ->
reporter.length = 2
expect(reporter.formatResultLine(0)).toMatch(/tests,/)
context 'failedCount = 1', ->
it 'should format', ->
reporter.failedCount = 1
expect(reporter.formatResultLine(0)).toMatch(/failure,/)
context 'failedCount != 1', ->
it 'should format', ->
reporter.failedCount = 0
expect(reporter.formatResultLine(0)).toMatch(/failures,/)
context 'runtime = 1', ->
it 'should format', ->
expect(reporter.formatResultLine(1)).toMatch(/sec./)
context 'runtime != 1', ->
it 'should format', ->
expect(reporter.formatResultLine(0)).toMatch(/secs./)

View File

@ -1,35 +1,3 @@
describe 'jasmine.HeadlessReporter', -> describe 'jasmine.HeadlessReporter.Console', ->
reporter = null describe '#reportSpecResults', ->
beforeEach ->
reporter = new jasmine.HeadlessReporter.Console()
describe '#formatResultLine', ->
context 'length = 1', ->
it 'should format', ->
reporter.length = 1
expect(reporter.formatResultLine(0)).toMatch(/test,/)
context 'length != 1', ->
it 'should format', ->
reporter.length = 2
expect(reporter.formatResultLine(0)).toMatch(/tests,/)
context 'failedCount = 1', ->
it 'should format', ->
reporter.failedCount = 1
expect(reporter.formatResultLine(0)).toMatch(/failure,/)
context 'failedCount != 1', ->
it 'should format', ->
reporter.failedCount = 0
expect(reporter.formatResultLine(0)).toMatch(/failures,/)
context 'runtime = 1', ->
it 'should format', ->
expect(reporter.formatResultLine(1)).toMatch(/sec./)
context 'runtime != 1', ->
it 'should format', ->
expect(reporter.formatResultLine(0)).toMatch(/secs./)

View File

@ -95,5 +95,28 @@ describe Jasmine::Headless::CacheableAction do
end end
end 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 end

View File

@ -1,25 +1,41 @@
require 'spec_helper' require 'spec_helper'
describe Jasmine::Headless::FileChecker do describe Jasmine::Headless::FileChecker do
include FakeFS::SpecHelpers
let(:test_class) do let(:test_class) do
object = Object.new object = Object.new
object.class.send(:include, Jasmine::Headless::FileChecker) object.class.send(:include, Jasmine::Headless::FileChecker)
object object
end end
context "bad_format?" do describe "#bad_format?" do
it "should return false wth correct format" do subject { test_class.bad_format?(file) }
test_class.bad_format?('foobar.js').should be_false
before do
test_class.stubs(:excluded_formats).returns(%w{erb string})
end end
it "should return false wth wrong format" do context 'nil' do
test_class.bad_format?('foobar.js.erb').should be_true let(:file) { nil }
it { should be_nil }
end end
it "should check for the whole extension" do context 'allowed format' do
test_class.bad_format?('foobar.string.js').should be_false let(:file) { 'foobar.js' }
it { should be_false }
end
context 'unallowed format' do
let(:file) { 'foobar.erb' }
it { should be_true }
end
context 'check whole extension' do
let(:file) { 'foobar.string.js' }
it { should be_true }
end end
end end
end end

View File

@ -5,50 +5,6 @@ require 'coffee-script'
describe Jasmine::Headless::FilesList do describe Jasmine::Headless::FilesList do
let(:files_list) { described_class.new } 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 describe '#initialize' do
before do before do
described_class.any_instance.stubs(:load_initial_assets) 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 files_list.files.any? { |file| file['.erb'] }.should be_false
end end
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
end end

View File

@ -91,6 +91,15 @@ describe Jasmine::Headless::Runner do
it_should_have_basics it_should_have_basics
it { should include("-r #{file}") } it { should include("-r #{file}") }
end end
context 'quiet' do
before do
options[:quiet] = true
end
it_should_have_basics
it { should include("-q") }
end
end end
describe '#runner_filename' do describe '#runner_filename' do
@ -185,4 +194,54 @@ describe Jasmine::Headless::Runner do
subject.options[:reporters].should == reporters subject.options[:reporters].should == reporters
end end
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 end

View File

@ -3,9 +3,9 @@ require 'spec_helper'
describe Jasmine::Headless::UniqueAssetList do describe Jasmine::Headless::UniqueAssetList do
let(:list) { described_class.new } let(:list) { described_class.new }
let(:first) { stub(:logical_path => 'one') } let(:first) { stub(:logical_path => 'one', :pathname => 'one') }
let(:second) { stub(:logical_path => 'two') } let(:second) { stub(:logical_path => 'two', :pathname => 'two') }
let(:third) { stub(:logical_path => 'two') } let(:third) { stub(:logical_path => 'two', :pathname => 'two') }
it 'should raise an exception on a non-asset' do it 'should raise an exception on a non-asset' do
expect { list << "whatever" }.to raise_error(StandardError) expect { list << "whatever" }.to raise_error(StandardError)

View File

@ -1,2 +1,38 @@
require 'spec_helper' require 'spec_helper'
describe Jasmine::Headless do
describe '.warn' do
let(:output) { StringIO.new }
before do
described_class.stubs(:output).returns(output)
end
context 'warnings enabled' do
before do
described_class.stubs(:show_warnings?).returns(true)
end
it 'should work' do
described_class.warn("warning")
output.rewind
output.read.should == "warning\n"
end
end
context 'warnings disabled' do
before do
described_class.stubs(:show_warnings?).returns(false)
end
it 'should work' do
described_class.warn("warning")
output.rewind
output.read.should == ""
end
end
end
end

View File

@ -29,12 +29,15 @@ if window.JHW
puts = (message) -> puts = (message) ->
JHW.print('stdout', message + "\n") JHW.print('stdout', message + "\n")
warn = (message) ->
puts(message) if !JHW.isQuiet()
# handle unloading # handle unloading
window.onbeforeunload = (e) -> window.onbeforeunload = (e) ->
e = e || window.event e = e || window.event
JHW.hasError() JHW.hasError()
puts "The code tried to leave the test page. Check for unhandled form submits and link clicks." warn "The code tried to leave the test page. Check for unhandled form submits and link clicks."
e.returnValue = 'string' if e e.returnValue = 'string' if e
@ -48,13 +51,18 @@ if window.JHW
false false
# dialogs # dialogs
window.confirm = (message) -> window.confirm = ->
puts "#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true." warn "#{"[confirm]".foreground('red')} You should mock window.confirm. Returning true."
true
window.prompt = ->
warn "#{"[prompt]".foreground('red')} You should mock window.prompt. Returning true."
true true
window.alert = (message) -> window.alert = (message) ->
puts "[alert] ".foreground('red') + message warn "[alert] ".foreground('red') + message
# color support # color support
JHW._setColors = (useColors) -> Intense.useColors = useColors JHW._setColors = (useColors) -> Intense.useColors = useColors
@ -71,6 +79,22 @@ if window.JHW
puts msg puts msg
JHW.createCoffeeScriptFileException = (e) ->
if e and e.sourceURL
filename = e.sourceURL.split('/').pop()
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
window.CoffeeScriptToFilename = {} window.CoffeeScriptToFilename = {}
window.CSTF = window.CoffeeScriptToFilename window.CSTF = window.CoffeeScriptToFilename

View File

@ -1,3 +1,4 @@
(function() {
window.HeadlessReporterResult = (function() { window.HeadlessReporterResult = (function() {
@ -74,3 +75,5 @@
return HeadlessReporterResult; return HeadlessReporterResult;
})(); })();
}).call(this);

View File

@ -11,16 +11,16 @@ window.Intense = {
methods: methods:
foreground: (color) -> foreground: (color) ->
if Intense.useColors if Intense.useColors
"\033[3#{Intense.colors[color]}m#{this}\033[0m" '\x1b' + "[3#{Intense.colors[color]}m#{this}" + '\x1b' + "[0m"
else else
this this
bright: -> bright: ->
if Intense.useColors if Intense.useColors
"\033[1m#{this}\033[0m" '\x1b' + "[1m#{this}" + '\x1b' + "[0m"
else else
this this
useColors: true useColors: true
moveBack: (count = 1) -> "\033[#{count}D" moveBack: (count = 1) -> '\x1b' + "[#{count}D"
} }
for method, code of Intense.methods for method, code of Intense.methods

View File

@ -1,44 +0,0 @@
(function() {
var code, method, _ref;
window.Intense = {
colors: {
black: 0,
red: 1,
green: 2,
yellow: 3,
blue: 4,
magenta: 5,
cyan: 6,
white: 7
},
methods: {
foreground: function(color) {
if (Intense.useColors) {
return "\033[3" + Intense.colors[color] + "m" + this + "\033[0m";
} else {
return this;
}
},
bright: function() {
if (Intense.useColors) {
return "\033[1m" + this + "\033[0m";
} else {
return this;
}
}
},
useColors: true,
moveBack: function(count) {
if (count == null) count = 1;
return "\033[" + count + "D";
}
};
_ref = Intense.methods;
for (method in _ref) {
code = _ref[method];
String.prototype[method] = code;
}
}).call(this);

View File

@ -30,15 +30,7 @@ if window.JHW
this.env.reporter.reportSpecResults(this) this.env.reporter.reportSpecResults(this)
jasmine.Spec.prototype.fail = (e) -> jasmine.Spec.prototype.fail = (e) ->
if e and e.sourceURL and window.CoffeeScriptToFilename e = JHW.createCoffeeScriptFileException(e)
filename = e.sourceURL.split('/').pop()
if realFilename = window.CoffeeScriptToFilename[filename]
e = {
name: e.name,
message: e.message,
lineNumber: "~" + String(e.line),
sourceURL: realFilename
}
expectationResult = new jasmine.ExpectationResult({ expectationResult = new jasmine.ExpectationResult({
passed: false, passed: false,
@ -47,6 +39,8 @@ if window.JHW
}) })
@results_.addResult(expectationResult) @results_.addResult(expectationResult)
this.env.reporter.reportException(e)
jasmine.NestedResults.isValidSpecLine = (line) -> jasmine.NestedResults.isValidSpecLine = (line) ->
line.match(/^\s*expect/) != null || line.match(/^\s*return\s*expect/) != null line.match(/^\s*expect/) != null || line.match(/^\s*return\s*expect/) != null
@ -92,7 +86,7 @@ if window.JHW
this.addResult_(result) this.addResult_(result)
for method in [ "reportSpecWaiting", "reportSpecRunning" ] for method in [ "reportSpecWaiting", "reportSpecRunning", "reportException" ]
generator = (method) -> generator = (method) ->
(args...) -> (args...) ->
for reporter in @subReporters_ for reporter in @subReporters_

View File

@ -1,129 +0,0 @@
(function() {
var generator, getSplitName, method, pauseAndRun, _i, _len, _ref;
var __slice = Array.prototype.slice;
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, ' '));
return parts;
};
jasmine.Suite.prototype.getSuiteSplitName = function() {
return this.getSplitName(this.parentSuite ? this.parentSuite.getSuiteSplitName() : []);
};
jasmine.Spec.prototype.getSpecSplitName = function() {
return this.getSplitName(this.suite.getSuiteSplitName());
};
jasmine.Suite.prototype.getSplitName = getSplitName;
jasmine.Spec.prototype.getSplitName = getSplitName;
jasmine.Spec.prototype.getJHWSpecInformation = function() {
var parts, specLineInfo;
parts = this.getSpecSplitName();
specLineInfo = HeadlessReporterResult.findSpecLine(parts);
if (specLineInfo.file) {
parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber);
} else {
parts.push('');
}
return parts.join("||");
};
jasmine.Spec.prototype.finishCallback = function() {
JHW.ping();
return this.env.reporter.reportSpecResults(this);
};
jasmine.Spec.prototype.fail = function(e) {
var expectationResult, filename, realFilename;
if (e && e.sourceURL && window.CoffeeScriptToFilename) {
filename = e.sourceURL.split('/').pop();
if (realFilename = window.CoffeeScriptToFilename[filename]) {
e = {
name: e.name,
message: e.message,
lineNumber: "~" + String(e.line),
sourceURL: realFilename
};
}
}
expectationResult = new jasmine.ExpectationResult({
passed: false,
message: e ? jasmine.util.formatException(e) : 'Exception',
trace: {
stack: e.stack
}
});
return this.results_.addResult(expectationResult);
};
jasmine.NestedResults.isValidSpecLine = function(line) {
return line.match(/^\s*expect/) !== null || line.match(/^\s*return\s*expect/) !== null;
};
jasmine.NestedResults.parseFunction = function(func) {
var line, lineCount, lines, _i, _len, _ref;
lines = [];
lineCount = 0;
_ref = func.split("\n");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
if (jasmine.NestedResults.isValidSpecLine(line)) {
line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, '');
lines.push([line, lineCount]);
}
lineCount += 1;
}
return lines;
};
jasmine.NestedResults.parseAndStore = function(func) {
if (!jasmine.NestedResults.ParsedFunctions[func]) {
jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func);
}
return jasmine.NestedResults.ParsedFunctions[func];
};
jasmine.NestedResults.ParsedFunctions = [];
if (!jasmine.WaitsBlock.prototype._execute) {
jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute;
jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute;
pauseAndRun = function(onComplete) {
JHW.timerPause();
jasmine.getEnv().reporter.reportSpecWaiting();
return this._execute(function() {
jasmine.getEnv().reporter.reportSpecRunning();
JHW.timerDone();
return onComplete();
});
};
jasmine.WaitsBlock.prototype.execute = pauseAndRun;
jasmine.WaitsForBlock.prototype.execute = pauseAndRun;
jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult;
jasmine.NestedResults.prototype.addResult = function(result) {
result.expectations = [];
result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString());
return this.addResult_(result);
};
_ref = ["reportSpecWaiting", "reportSpecRunning"];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
method = _ref[_i];
generator = function(method) {
return function() {
var args, reporter, _j, _len2, _ref2, _results;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
_ref2 = this.subReporters_;
_results = [];
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
reporter = _ref2[_j];
if (reporter[method] != null) {
_results.push(reporter[method].apply(reporter, args));
} else {
_results.push(void 0);
}
}
return _results;
};
};
jasmine.MultiReporter.prototype[method] = generator(method);
}
}
}
}).call(this);

View File

@ -0,0 +1,8 @@
#= require jasmine.HeadlessReporter.ConsoleBase
#
class jasmine.HeadlessReporter.Console extends jasmine.HeadlessReporter.ConsoleBase
displaySuccess: (spec) =>
this.print('.'.foreground('green'))
displayFailure: (spec) =>
this.print('F'.foreground('red'))

View File

@ -1,115 +0,0 @@
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
jasmine.HeadlessReporter.Console = (function() {
__extends(Console, jasmine.HeadlessReporter);
function Console(callback) {
this.callback = callback != null ? callback : null;
this._waitRunner = __bind(this._waitRunner, this);
Console.__super__.constructor.call(this, this.callback);
this.position = 0;
this.positions = "|/-\\";
}
Console.prototype.reportRunnerResults = function(runner) {
var result, resultLine, _i, _len, _ref;
Console.__super__.reportRunnerResults.call(this);
this.print("\n");
resultLine = this.formatResultLine(this._runtime());
if (this.failedCount === 0) {
this.puts(("PASS: " + resultLine).foreground('green'));
} else {
this.puts(("FAIL: " + resultLine).foreground('red'));
}
_ref = this.results;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
this.puts(result.toString());
}
return this.puts("\nTest ordering seed: --seed " + (JHW.getSeed()));
};
Console.prototype.reportRunnerStarting = function(runner) {
Console.__super__.reportRunnerStarting.call(this, runner);
if (!this.hasError()) {
return this.puts("\nRunning Jasmine specs...".bright());
}
};
Console.prototype.reportSpecResults = function(spec) {
var _this = this;
Console.__super__.reportSpecResults.call(this, spec);
return this._reportSpecResult(spec, {
success: function(results) {
return _this.print('.'.foreground('green'));
},
failure: function(results) {
var failureResult, foundLine, result, testCount, _i, _len, _ref;
_this.print('F'.foreground('red'));
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName());
testCount = 1;
_ref = results.getItems();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
result = _ref[_i];
if (result.type === 'expect' && !result.passed_) {
if (foundLine = result.expectations[testCount - 1]) {
result.line = foundLine[0], result.lineNumber = foundLine[1];
}
failureResult.addResult(result);
}
testCount += 1;
}
return _this.results.push(failureResult);
}
});
};
Console.prototype.reportSpecWaiting = function() {
if (!this.timer) {
this.timer = true;
this.first = true;
return this._waitRunner();
}
};
Console.prototype.reportSpecRunning = function() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
return this.print(Intense.moveBack());
}
};
Console.prototype.formatResultLine = function(runtime) {
var line;
line = [];
line.push(this.length);
line.push((this.length === 1 ? "test" : "tests") + ',');
line.push(this.failedCount);
line.push((this.failedCount === 1 ? "failure" : "failures") + ',');
line.push(runtime);
line.push((runtime === 1.0 ? "sec" : "secs") + '.');
return line.join(' ');
};
Console.prototype._waitRunner = function() {
var _this = this;
return this.timer = setTimeout(function() {
if (_this.timer) {
if (!_this.first) _this.print(Intense.moveBack());
_this.print(_this.positions.substr(_this.position, 1).foreground('yellow'));
_this.position += 1;
_this.position %= _this.positions.length;
_this.first = false;
return _this._waitRunner();
}
}, 750);
};
return Console;
})();
}).call(this);

View File

@ -1,12 +1,25 @@
#= require jasmine.HeadlessReporter.js #= require jasmine.HeadlessReporter
#
class jasmine.HeadlessReporter.Console extends jasmine.HeadlessReporter class jasmine.HeadlessReporter.ConsoleBase extends jasmine.HeadlessReporter
constructor: (@callback = null) -> constructor: (@callback = null) ->
super(@callback) super(@callback)
@position = 0 @position = 0
@positions = "|/-\\" @positions = "|/-\\"
formatResultLine: (runtime) ->
line = []
line.push(@length)
line.push((if @length == 1 then "test" else "tests") + ',')
line.push(@failedCount)
line.push((if @failedCount == 1 then "failure" else "failures") + ',')
line.push(runtime)
line.push((if runtime == 1.0 then "sec" else "secs") + '.')
line.join(' ')
reportRunnerResults: (runner) -> reportRunnerResults: (runner) ->
super() super()
@ -28,27 +41,6 @@ class jasmine.HeadlessReporter.Console extends jasmine.HeadlessReporter
super(runner) super(runner)
this.puts("\nRunning Jasmine specs...".bright()) if !this.hasError() this.puts("\nRunning Jasmine specs...".bright()) if !this.hasError()
reportSpecResults: (spec) ->
super(spec)
this._reportSpecResult(spec, {
success: (results) =>
this.print('.'.foreground('green'))
failure: (results) =>
this.print('F'.foreground('red'))
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName())
testCount = 1
for result in results.getItems()
if result.type == 'expect' and !result.passed_
if foundLine = result.expectations[testCount - 1]
[ result.line, result.lineNumber ] = foundLine
failureResult.addResult(result)
testCount += 1
@results.push(failureResult)
})
reportSpecWaiting: -> reportSpecWaiting: ->
if !@timer if !@timer
@timer = true @timer = true
@ -62,18 +54,28 @@ class jasmine.HeadlessReporter.Console extends jasmine.HeadlessReporter
@timer = null @timer = null
this.print(Intense.moveBack()) this.print(Intense.moveBack())
formatResultLine: (runtime) -> reportSpecResults: (spec) ->
line = [] super(spec)
line.push(@length)
line.push((if @length == 1 then "test" else "tests") + ',')
line.push(@failedCount) this._reportSpecResult(spec, {
line.push((if @failedCount == 1 then "failure" else "failures") + ',') success: (results) =>
this.displaySuccess(spec)
failure: (results) =>
this.displayFailure(spec)
line.push(runtime) this.reportFailureResult(results, new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()))
line.push((if runtime == 1.0 then "sec" else "secs") + '.') })
line.join(' ') reportFailureResult: (results, failureResult) ->
testCount = 1
for result in results.getItems()
if result.type == 'expect' and !result.passed_
if foundLine = result.expectations[testCount - 1]
[ result.line, result.lineNumber ] = foundLine
failureResult.addResult(result)
testCount += 1
@results.push(failureResult)
_waitRunner: => _waitRunner: =>
@timer = setTimeout( @timer = setTimeout(
@ -87,3 +89,4 @@ class jasmine.HeadlessReporter.Console extends jasmine.HeadlessReporter
this._waitRunner() this._waitRunner()
, 750 , 750
) )

View File

@ -1,4 +1,4 @@
#= require jasmine.HeadlessReporter.js #= require jasmine.HeadlessReporter
# #
class jasmine.HeadlessReporter.File extends jasmine.HeadlessReporter class jasmine.HeadlessReporter.File extends jasmine.HeadlessReporter
reportRunnerResults: (runner) -> reportRunnerResults: (runner) ->

View File

@ -1,41 +0,0 @@
(function() {
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
jasmine.HeadlessReporter.File = (function() {
__extends(File, jasmine.HeadlessReporter);
function File() {
File.__super__.constructor.apply(this, arguments);
}
File.prototype.reportRunnerResults = function(runner) {
var output;
File.__super__.reportRunnerResults.call(this, runner);
output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + (this._runtime()) + "||" + (JHW._hasErrors ? "T" : "F");
this.puts(output);
return this.puts("SEED||" + (JHW.getSeed()));
};
File.prototype.consoleLogUsed = function(msg) {
return this.puts("CONSOLE||" + msg);
};
File.prototype.reportSpecResults = function(spec) {
var _this = this;
File.__super__.reportSpecResults.call(this, spec);
return this._reportSpecResult(spec, {
success: function(results) {
return _this.puts("PASS||" + spec.getJHWSpecInformation());
},
failure: function(results) {
return _this.puts("FAIL||" + spec.getJHWSpecInformation());
}
});
};
return File;
})();
}).call(this);

View File

@ -1,4 +1,4 @@
#= require jasmine.HeadlessReporter.js #= require jasmine.HeadlessReporter
class jasmine.HeadlessReporter.Tap extends jasmine.HeadlessReporter class jasmine.HeadlessReporter.Tap extends jasmine.HeadlessReporter
constructor: (@outputTarget = null) -> constructor: (@outputTarget = null) ->

View File

@ -1,40 +0,0 @@
(function() {
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
jasmine.HeadlessReporter.Tap = (function() {
__extends(Tap, jasmine.HeadlessReporter);
function Tap(outputTarget) {
this.outputTarget = outputTarget != null ? outputTarget : null;
Tap.__super__.constructor.call(this, this.outputTarget);
this.output = [];
}
Tap.prototype.reportRunnerResults = function(runner) {
Tap.__super__.reportRunnerResults.call(this, runner);
if (this.output.length > 0) this.output.unshift("1.." + this.output.length);
return this.puts(this.output.join("\n"));
};
Tap.prototype.reportSpecResults = function(spec) {
var description, index;
var _this = this;
Tap.__super__.reportSpecResults.call(this, spec);
index = this.output.length + 1;
description = spec.getSpecSplitName().join(' ');
return this._reportSpecResult(spec, {
success: function(results) {
return _this.output.push("ok " + index + " " + description);
},
failure: function(results) {
return _this.output.push("not ok " + index + " " + description);
}
});
};
return Tap;
})();
}).call(this);

View File

@ -0,0 +1,64 @@
#= require jasmine.HeadlessReporter.ConsoleBase
#
class jasmine.HeadlessReporter.Verbose extends jasmine.HeadlessReporter.ConsoleBase
@prereport = false
displaySuccess: (spec) =>
this.displaySpec(spec, 'green')
displayFailure: (spec) =>
this.displaySpec(spec, 'red')
displaySpec: (spec, color) =>
currentLastNames = (@lastNames || []).slice(0)
@lastNames = spec.getSpecSplitName()
for line in this.indentSpec(@lastNames, currentLastNames, color)
if line? and !_.isEmpty(line)
this.puts(line)
indentSpec: (current, last, color) =>
last = last.slice(0)
lines = []
for name in current
if last.shift() != name
lines.push(name)
else
lines.push(null)
this.indentLines(lines, color)
indentLines: (lines, color) =>
indent = ''
output = []
for line in lines
if line?
outputLine = indent
outputLine += this.colorLine(line, color)
output.push(outputLine)
indent += ' '
output
colorLine: (line, color) =>
line.foreground(color)
reportSpecStarting: (spec) =>
if jasmine.HeadlessReporter.Verbose.prereport
this.puts(spec.getSpecSplitName().join(' '))
reportException: (e) =>
e = JHW.createCoffeeScriptFileException(e)
if e.sourceURL && e.lineNumber
output = "#{e.sourceURL}:#{e.lineNumber} #{e.message}"
else
output = e.message ? e
this.puts(output.foreground('yellow'))

View File

@ -1,77 +0,0 @@
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
throw new Error("jasmine not loaded!");
}
jasmine.HeadlessReporter = (function() {
function HeadlessReporter(outputTarget) {
this.outputTarget = outputTarget != null ? outputTarget : null;
this.puts = __bind(this.puts, this);
this.print = __bind(this.print, this);
this.results = [];
this.failedCount = 0;
this.length = 0;
this.timer = null;
}
HeadlessReporter.prototype.hasError = function() {
return JHW._hasErrors;
};
HeadlessReporter.prototype.reportSpecStarting = function(spec) {
if (this.hasError()) {
spec.finish();
return spec.suite.finish();
}
};
HeadlessReporter.prototype.reportSuiteResults = function(suite) {};
HeadlessReporter.prototype.reportRunnerStarting = function(runner) {
return this.startTime = new Date();
};
HeadlessReporter.prototype.reportRunnerResults = function(runner) {
if (this.hasError()) return;
if (this.failedCount !== 0) JHW.hasSpecFailure();
JHW.finishSuite();
if (window.JHW) return window.onbeforeunload = null;
};
HeadlessReporter.prototype.reportSpecResults = function(spec) {
if (this.hasError()) return;
return JHW.ping();
};
HeadlessReporter.prototype._reportSpecResult = function(spec, options) {
var results;
results = spec.results();
this.length++;
if (results.passed()) {
return options.success(results, spec);
} else {
this.failedCount++;
return options.failure(results, spec);
}
};
HeadlessReporter.prototype._runtime = function() {
return (new Date() - this.startTime) / 1000.0;
};
HeadlessReporter.prototype.print = function(output) {
return JHW.print(this.outputTarget, output);
};
HeadlessReporter.prototype.puts = function(output) {
return JHW.print(this.outputTarget, output + "\n");
};
return HeadlessReporter;
})();
}).call(this);

View File

@ -1,5 +1,5 @@
(function() { (function() {
var puts; var puts, warn;
if (window.JHW) { if (window.JHW) {
window.console = { window.console = {
@ -40,10 +40,13 @@
puts = function(message) { puts = function(message) {
return JHW.print('stdout', message + "\n"); return JHW.print('stdout', message + "\n");
}; };
warn = function(message) {
if (!JHW.isQuiet()) return puts(message);
};
window.onbeforeunload = function(e) { window.onbeforeunload = function(e) {
e = e || window.event; e = e || window.event;
JHW.hasError(); JHW.hasError();
puts("The code tried to leave the test page. Check for unhandled form submits and link clicks."); warn("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'; return 'string';
}; };
@ -53,12 +56,16 @@
JHW._hasErrors = true; JHW._hasErrors = true;
return false; return false;
}; };
window.confirm = function(message) { window.confirm = function() {
puts("" + ("[confirm]".foreground('red')) + " jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true."); warn("" + ("[confirm]".foreground('red')) + " You should mock window.confirm. Returning true.");
return true;
};
window.prompt = function() {
warn("" + ("[prompt]".foreground('red')) + " You should mock window.prompt. Returning true.");
return true; return true;
}; };
window.alert = function(message) { window.alert = function(message) {
return puts("[alert] ".foreground('red') + message); return warn("[alert] ".foreground('red') + message);
}; };
JHW._setColors = function(useColors) { JHW._setColors = function(useColors) {
return Intense.useColors = useColors; return Intense.useColors = useColors;
@ -75,6 +82,23 @@
JHW._usedConsole = true; JHW._usedConsole = true;
return puts(msg); return puts(msg);
}; };
JHW.createCoffeeScriptFileException = function(e) {
var filename, realFilename;
if (e && e.sourceURL) {
filename = e.sourceURL.split('/').pop();
e = {
name: e.name,
message: e.message,
sourceURL: e.sourceURL,
lineNumber: e.line
};
if (window.CoffeeScriptToFilename && (realFilename = window.CoffeeScriptToFilename[filename])) {
e.sourceURL = realFilename;
e.lineNumber = "~" + String(e.line);
}
}
return e;
};
} }
window.CoffeeScriptToFilename = {}; window.CoffeeScriptToFilename = {};