Skip to content
This repository

Report js syntax errors #72

Closed
wants to merge 2 commits into from

3 participants

Christian Williams Rajan Agaskar Davis W. Frank
Christian Williams

No description provided.

Brian Donova... and others added some commits January 13, 2012
Rajan Agaskar
Collaborator

We'll add this after we finish asset pipeline cleanup.

Thanks!

Rajan Agaskar
Collaborator

This pull is too old to apply at this point. I think we still want syntax error checking, but we'll need to rethink how we get it.

Rajan Agaskar ragaskar closed this September 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 2 authors.

Jan 13, 2012
Fail if a JS file has a syntax error. 7dfe0f0
Jan 16, 2012
Christian Williams Move syntax error reporting mostly in to jasmine-core. 211bb27
This page is out of date. Refresh to see the latest.
10  lib/jasmine/run.html.erb
@@ -39,14 +39,20 @@
39 39
       function execJasmine() {
40 40
         jasmineEnv.execute();
41 41
       }
42  
-
43 42
     })();
44 43
   </script>
45 44
 
46 45
   <% js_files.each do |js_file| %>
47  
-  <script src="<%= js_file %>" type="text/javascript"></script>
  46
+    <script type="text/javascript">jasmineEnv.aboutToLoad(<%= js_file.inspect %>, function(onError) { var old = window.onerror; window.onerror = onError; return old; });</script>
  47
+    <script src="<%= js_file %>" type="text/javascript"></script>
  48
+    <script type="text/javascript">jasmineEnv.generateFileLoadErrors();</script>
48 49
   <% end %>
49 50
 
  51
+  <script type="text/javascript">
  52
+    if (window.onerror == jasmine._runner_.onError) {
  53
+      window.onerror = jasmine._runner_.oldOnError;
  54
+    }
  55
+  </script>
50 56
 </head>
51 57
 <body>
52 58
 <div id="jasmine_content"></div>
34  lib/jasmine/server.rb
@@ -71,9 +71,43 @@ def call(env)
71 71
     end
72 72
   end
73 73
 
  74
+  class JasmineLoadFlag
  75
+    def initialize(app)
  76
+      @app = app
  77
+    end
  78
+
  79
+    def call(env)
  80
+      code, headers, body = @app.call(env)
  81
+
  82
+      if code == 200 && (headers['Content-Type'] && headers['Content-Type'].include?('javascript'))
  83
+        body = JsFileFlagAppender.new(body)
  84
+        headers.delete('Content-Length')
  85
+      end
  86
+
  87
+      [code, headers, body]
  88
+    end
  89
+  end
  90
+
  91
+  class JsFileFlagAppender
  92
+    def initialize(body)
  93
+      @body = body
  94
+    end
  95
+
  96
+    def each(&block)
  97
+      @body.each(&block)
  98
+      block.call("\n\njasmineEnv.finishedLoading();")
  99
+    end
  100
+
  101
+    def close
  102
+      @body.close if @body.respond_to?(:close)
  103
+    end
  104
+  end
  105
+
74 106
   def self.app(config)
75 107
     Rack::Builder.app do
76 108
       use Rack::Head
  109
+      use JasmineLoadFlag
  110
+
77 111
       if Jasmine::Dependencies.rails_3_asset_pipeline?
78 112
         map('/assets') do
79 113
           run Rails.application.assets
4  spec/fixture/spec/example_spec.js
... ...
@@ -1,5 +1,5 @@
1 1
 describe("example_spec", function() {
2 2
   it("should be here for path loading tests", function() {
3 3
     expect(true).toBe(true);
4  
-  }
5  
-})
  4
+  });
  5
+});
0  spec/fixture/spec/example_with_syntax_error_spec.js
No changes.
14  spec/server_spec.rb
@@ -2,6 +2,8 @@
2 2
 require 'rack/test'
3 3
 
4 4
 describe "Jasmine.app" do
  5
+  LOADED_FLAG = "\n\njasmineEnv.finishedLoading();"
  6
+
5 7
   include Rack::Test::Methods
6 8
 
7 9
   def app
@@ -15,25 +17,25 @@ def app
15 17
     Jasmine.app(config)
16 18
   end
17 19
 
18  
-  it "should serve static files from spec dir under __spec__" do
  20
+  it "should serve static files from spec dir under __spec__ with loaded flag appended" do
19 21
     get "/__spec__/example_spec.js"
20 22
     last_response.status.should == 200
21 23
     last_response.content_type.should == "application/javascript"
22  
-    last_response.body.should == File.read(File.join(@root, "fixture/spec/example_spec.js"))
  24
+    last_response.body.should == File.read(File.join(@root, "fixture/spec/example_spec.js")) + LOADED_FLAG
23 25
     end
24 26
 
25  
-  it "should serve static files from root dir under __root__" do
  27
+  it "should serve static files from root dir under __root__ with loaded flag appended" do
26 28
     get "/__root__/fixture/src/example.js"
27 29
     last_response.status.should == 200
28 30
     last_response.content_type.should == "application/javascript"
29  
-    last_response.body.should == File.read(File.join(@root, "fixture/src/example.js"))
  31
+    last_response.body.should == File.read(File.join(@root, "fixture/src/example.js")) + LOADED_FLAG
30 32
   end
31 33
 
32  
-  it "should serve static files from src dir under /" do
  34
+  it "should serve static files from src dir under / with loaded flag appended" do
33 35
     get "/example.js"
34 36
     last_response.status.should == 200
35 37
     last_response.content_type.should == "application/javascript"
36  
-    last_response.body.should == File.read(File.join(@root, "fixture/src/example.js"))
  38
+    last_response.body.should == File.read(File.join(@root, "fixture/src/example.js")) + LOADED_FLAG
37 39
   end
38 40
 
39 41
   it "should serve Jasmine static files under /__JASMINE_ROOT__/" do
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.