Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed debug.pass_methods getting squashed regardless of log level #4

Merged
merged 1 commit into from

2 participants

@mleglise

debug.clear, debug.group, and all other "pass_methods" are currently getting removed from the compiled files, even when they should be left alone.

This patch fixes it and adds tests for debug.group and debug.groupEnd

@jeremygpeterson

Extra credit for adding tests, merging in.

@jeremygpeterson jeremygpeterson merged commit 3da634d into jeremygpeterson:master
@jeremygpeterson
@mleglise

Thanks for the fast turn-around Jeremy! This gem solves the JS logging problem rather elegantly, so I'm happy to help.

@jeremygpeterson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
10 lib/jsdebug/processor.rb
@@ -37,9 +37,13 @@ def evaluate(context, locals, &block)
data.each_line do |line|
index += 1
- if(is_jsdebug_allowed? && line.match(log_regex))
- cmd = line.scan(log_regex).first
- new_data << line.gsub(cmd, "#{cmd}'[#{name}::#{index}]', ")
+ if(is_jsdebug_allowed? && line.match(debug_regex))
+ if line.match(log_regex)
+ cmd = line.scan(log_regex).first
+ new_data << line.gsub(cmd, "#{cmd}'[#{name}::#{index}]', ")
+ else
+ new_data << line
+ end
else
if (!is_jsdebug_allowed?)
if line.match(/debug_start/)
View
4 test/fixtures/assets/pass_debugs.js
@@ -0,0 +1,4 @@
+debug.group('test');
+var foo = {},
+bar = {};
+debug.groupEnd();
View
10 test/test_debug_processor.rb
@@ -41,4 +41,14 @@ def setup
assert_equal "var str = \"Hello\";\n// debug_start\nstr = str + \" World!\";\ndebug.log('[block_debugs::4]', str);\n// debug_end\nvar str2 = \"Bye\";\n", @env['block_debugs.js'].to_s
end
+ test "javascript compiles without passthrough debug statements" do
+ @logger.stubs(:level).returns(1)
+ assert_equal "var foo = {},\nbar = {};\n", @env['pass_debugs.js'].to_s
+ end
+
+ test "javascript compiles with passthrough debug statements" do
+ @logger.stubs(:level).returns(0)
+ assert_equal "debug.group('test');\nvar foo = {},\nbar = {};\ndebug.groupEnd();\n", @env['pass_debugs.js'].to_s
+ end
+
end
Something went wrong with that request. Please try again.