Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Extracting reporter from run.html.erb into a separate javascript file #113

Closed
wants to merge 3 commits into from

1 participant

@GreyKn

Implementing TODO of extracting the reporter setup from run.html.erb into a separate javascript file.

This can be a breaking change due to the dependency on the newly extracted jasmine-reporter.js file.

10/12/30: I noticed that travis failed for this pull request, but it looks like a transient error. All builds except 47.10 passed, and the log makes it look like it borked while booting a server.

@GreyKn GreyKn closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 26, 2012
  1. @GreyKn

    Extracted reporter js from page erb. Now a config setting that allows…

    GreyKn authored
    … custom reporters to be added
  2. @GreyKn

    Cleaning up jasmine yml files

    GreyKn authored
Commits on Nov 15, 2012
  1. @GreyKn

    Spacing fixes

    GreyKn authored
This page is out of date. Refresh to see the latest.
View
4 generators/jasmine/jasmine_generator.rb
@@ -14,6 +14,10 @@ def manifest
m.directory "spec/javascripts/support"
m.file "spec/javascripts/support/jasmine-rails.yml", "spec/javascripts/support/jasmine.yml"
+
+ m.directory "spec/javascripts/support/reporters"
+ m.file "spec/javascripts/support/reporters/jasmine-reporter.js", "spec/javascripts/support/reporters/jasmine-reporter.js"
+
m.readme "INSTALL"
m.directory "lib/tasks"
View
14 generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml
@@ -58,6 +58,20 @@ helpers:
spec_files:
- '**/*[sS]pec.js'
+
+# reporters
+#
+# Return an array of filepaths relative to spec_dir + /support/reporters to include.
+# Default: ["**/*.js"]
+#
+# EXAMPLE:
+#
+# resporters:
+# - '**/*.js'
+#
+reporters:
+ - '**/*.js'
+
# src_dir
#
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
View
13 generators/jasmine/templates/spec/javascripts/support/jasmine.yml
@@ -50,6 +50,19 @@ helpers:
#
spec_files:
+# reporters
+#
+# Return an array of filepaths relative to spec_dir + /support/reporters to include.
+# Default: ["**/*.js"]
+#
+# EXAMPLE:
+#
+# resporters:
+# - '**/*.js'
+#
+reporters:
+ - '**/*.js'
+
# src_dir
#
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
View
28 generators/jasmine/templates/spec/javascripts/support/reporters/jasmine-reporter.js
@@ -0,0 +1,28 @@
+var jsApiReporter;
+(function() {
+ var jasmineEnv = jasmine.getEnv();
+
+ jsApiReporter = new jasmine.JsApiReporter();
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(jsApiReporter);
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+
+})();
View
13 lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml
@@ -53,6 +53,19 @@ helpers:
spec_files:
- '**/*[sS]pec.js'
+# reporters
+#
+# Return an array of filepaths relative to spec_dir + /support/reporters to include.
+# Default: ["**/*.js"]
+#
+# EXAMPLE:
+#
+# resporters:
+# - '**/*.js'
+#
+reporters:
+ - '**/*.js'
+
# src_dir
#
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
View
28 lib/generators/jasmine/install/templates/spec/javascripts/support/reporters/jasmine-reporter.js
@@ -0,0 +1,28 @@
+var jsApiReporter;
+(function() {
+ var jasmineEnv = jasmine.getEnv();
+
+ jsApiReporter = new jasmine.JsApiReporter();
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(jsApiReporter);
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+
+})();
View
1  lib/jasmine/application.rb
@@ -28,6 +28,7 @@ def self.app(config = Jasmine::RunnerConfig.new)
#TODO: These path mappings should come from the config.
map('/__JASMINE_ROOT__') { run Rack::File.new(Jasmine::Core.path) }
+ map(config.reporters_path) { run Rack::File.new(config.reporters_dir) }
map(config.spec_path) { run Rack::File.new(config.spec_dir) }
map(config.root_path) { run Rack::File.new(config.project_root) }
View
2  lib/jasmine/command_line_tool.rb
@@ -29,12 +29,14 @@ def process(argv)
FileUtils.makedirs('public/javascripts')
FileUtils.makedirs('spec/javascripts')
FileUtils.makedirs('spec/javascripts/support')
+ FileUtils.makedirs('spec/javascripts/support/reporters')
FileUtils.makedirs('spec/javascripts/helpers')
copy_unless_exists('jasmine-example/src/Player.js', 'public/javascripts/Player.js')
copy_unless_exists('jasmine-example/src/Song.js', 'public/javascripts/Song.js')
copy_unless_exists('jasmine-example/spec/PlayerSpec.js', 'spec/javascripts/PlayerSpec.js')
copy_unless_exists('jasmine-example/spec/SpecHelper.js', 'spec/javascripts/helpers/SpecHelper.js')
+ copy_unless_exists('spec/javascripts/support/reporters/jasmine-reporter.js', 'spec/javascripts/support/reporters/jasmine-reporter.js')
rails_tasks_dir = dest_path('lib/tasks')
if File.exist?(rails_tasks_dir)
View
20 lib/jasmine/config.rb
@@ -31,6 +31,14 @@ def spec_path
def root_path
"/__root__"
end
+
+ def reporters_path
+ "/__reporters__"
+ end
+
+ def reporters_files
+ reporters.collect {|f| File.join(reporters_path, f) }
+ end
def js_files(spec_filter = nil)
spec_files_to_include = spec_filter.nil? ? spec_files : match_files(spec_dir, [spec_filter])
@@ -61,6 +69,10 @@ def src_dir
end
end
+ def reporters_dir
+ File.join(spec_dir, ['support/reporters'])
+ end
+
def spec_dir
if simple_config['spec_dir']
File.join(project_root, simple_config['spec_dir'])
@@ -77,6 +89,14 @@ def helpers
end
end
+ def reporters
+ if simple_config['reporters']
+ match_files(reporters_dir, simple_config['reporters'])
+ else
+ match_files(reporters_dir, ["**/*.js"])
+ end
+ end
+
def src_files
return [] unless simple_config['src_files']
View
34 lib/jasmine/run.html.erb
@@ -12,37 +12,9 @@
<script src="<%= jasmine_file %>" type="text/javascript"></script>
<% end %>
- <script type="text/javascript">
- //TODO: make this a js file that gets passed in, then iterate over only js_files
- var jsApiReporter;
- (function() {
- var jasmineEnv = jasmine.getEnv();
-
- jsApiReporter = new jasmine.JsApiReporter();
- var htmlReporter = new jasmine.HtmlReporter();
-
- jasmineEnv.addReporter(jsApiReporter);
- jasmineEnv.addReporter(htmlReporter);
-
- jasmineEnv.specFilter = function(spec) {
- return htmlReporter.specFilter(spec);
- };
-
- var currentWindowOnload = window.onload;
-
- window.onload = function() {
- if (currentWindowOnload) {
- currentWindowOnload();
- }
- execJasmine();
- };
-
- function execJasmine() {
- jasmineEnv.execute();
- }
-
- })();
- </script>
+ <% reporters_files.each do |reporters_file| %>
+ <script src="<%= reporters_file %>" type="text/javascript"></script>
+ <% end %>
<% js_files.each do |js_file| %>
<script src="<%= js_file %>" type="text/javascript"></script>
View
12 lib/jasmine/runner_config.rb
@@ -12,6 +12,18 @@ def jasmine_files
@config.jasmine_javascripts
end
+ def reporters_path
+ @config.reporters_path
+ end
+
+ def reporters_dir
+ @config.reporters_dir
+ end
+
+ def reporters_files
+ @config.reporters_files
+ end
+
def js_files
@config.js_files
end
View
18 spec/application_spec.rb
@@ -11,6 +11,9 @@ def app
:spec_dir => File.join(@root, "fixture", "spec"),
:spec_path => "/__spec__",
:root_path => "/__root__",
+ :reporters_path => "/__reporters__",
+ :reporters_dir => File.join(@root, "fixture", "reporters"),
+ :reporters_files => ["example.js"],
:css_files => [],
:jasmine_files => [],
:js_files => ["path/file1.js", "path/file2.js"],
@@ -26,12 +29,25 @@ def app
last_response.headers["Cache-Control"].should == "max-age=0, private, must-revalidate"
end
+ it "includes no-cache headers for reporters" do
+ get "/__reporters__/example.js"
+ last_response.headers.should have_key("Cache-Control")
+ last_response.headers["Cache-Control"].should == "max-age=0, private, must-revalidate"
+ end
+
it "should serve static files from spec dir under __spec__" do
get "/__spec__/example_spec.js"
last_response.status.should == 200
last_response.content_type.should == "application/javascript"
last_response.body.should == File.read(File.join(@root, "fixture/spec/example_spec.js"))
- end
+ end
+
+ it "should serve static files from spec dir under __reporters__" do
+ get "/__reporters__/example.js"
+ last_response.status.should == 200
+ last_response.content_type.should == "application/javascript"
+ last_response.body.should == File.read(File.join(@root, "fixture/reporters/example.js"))
+ end
it "should serve static files from root dir under __root__" do
get "/__root__/fixture/src/example.js"
View
5 spec/config_spec.rb
@@ -57,6 +57,10 @@
@config.stylesheets.should == []
end
+ it "should find the reporter files" do
+ @config.reporters.should == ['jasmine-reporter.js']
+ end
+
it "should find the spec files" do
@config.spec_files.should == ['PlayerSpec.js']
end
@@ -206,6 +210,7 @@
@config.stub!(:simple_config_file).and_return(File.join(@template_dir, 'spec/javascripts/support/jasmine-rails.yml'))
+ @config.reporters_files.should == ['/__reporters__/jasmine-reporter.js']
@config.spec_files.should == ['PlayerSpec.js']
@config.helpers.should == ['helpers/SpecHelper.js']
@config.src_files.should == ['public/javascripts/prototype.js',
View
3  spec/fixture/reporters/example.js
@@ -0,0 +1,3 @@
+function Example() {
+ this.is_here = "for path loading tests";
+}
View
8 spec/jasmine_self_test_config.rb
@@ -13,7 +13,15 @@ def spec_dir
Jasmine::Core.path
end
+ def reporters_dir
+ File.join(project_root, 'lib/generators/jasmine/install/templates/spec/javascripts/support/reporters')
+ end
+
def spec_files
Jasmine::Core.html_spec_files + Jasmine::Core.core_spec_files
end
+
+ def reporters_files
+ ['__reporters__/jasmine-reporter.js']
+ end
end
View
5 spec/page_spec.rb
@@ -6,7 +6,8 @@
describe "#render" do
subject { Nokogiri::HTML(page.render) }
let(:fake_config) do
- OpenStruct.new(:js_files => ["file1.js", "file2.js"],
+ OpenStruct.new(:reporters_files => ["filea.js","fileb.js"],
+ :js_files => ["file1.js", "file2.js"],
:css_files => ["file1.css", "file2.css"],
:jasmine_files => ["jasmine_file1.js", "jasmine_file2.js"])
end
@@ -14,7 +15,7 @@
let(:page) { Jasmine::Page.new(context) }
it "should render javascript files in the correct order" do
js_files = subject.css("script")
- js_files.map { |file| file["src"] }.compact.should == ["jasmine_file1.js", "jasmine_file2.js", "file1.js", "file2.js"]
+ js_files.map { |file| file["src"] }.compact.should == ["jasmine_file1.js", "jasmine_file2.js", "filea.js", "fileb.js" ,"file1.js", "file2.js"]
end
it "should render css files in the correct order" do
View
24 spec/runner_config_spec.rb
@@ -19,6 +19,30 @@
end
end
+ describe "reporters_files" do
+ it "should return the user reporter files from the config" do
+ reporters_files = ['some/file']
+ user_config = double('config', :reporters_files => reporters_files)
+ Jasmine::RunnerConfig.new(user_config).reporters_files.should == reporters_files
+ end
+ end
+
+ describe "reporters_path" do
+ it "should return the user reporters_path from the config" do
+ reporters_path = ['some/path']
+ user_config = double('config', :reporters_path => reporters_path)
+ Jasmine::RunnerConfig.new(user_config).reporters_path.should == reporters_path
+ end
+ end
+
+ describe "reporters_dir" do
+ it "should return the user reporters_dir from the config" do
+ reporters_dir = ['some/dir']
+ user_config = double('config', :reporters_dir => reporters_dir)
+ Jasmine::RunnerConfig.new(user_config).reporters_dir.should == reporters_dir
+ end
+ end
+
describe "js_files" do
it "should return the user js files from the config" do
js_files = ['some/file']
Something went wrong with that request. Please try again.