start basic JS instrumentation, so alpha it hurts
This commit is contained in:
parent
d4b14f2036
commit
e28703b047
@ -21,7 +21,11 @@ Flowerbox =
|
|||||||
message = Flowerbox.messageQueue.shift()
|
message = Flowerbox.messageQueue.shift()
|
||||||
Flowerbox.socket.send(JSON.stringify(message))
|
Flowerbox.socket.send(JSON.stringify(message))
|
||||||
|
|
||||||
Flowerbox.done = true if url == 'results'
|
if url == 'results'
|
||||||
|
if __$instrument?
|
||||||
|
Flowerbox.socket.send(JSON.stringify(['instrument', __$instrument]))
|
||||||
|
|
||||||
|
Flowerbox.done = true
|
||||||
|
|
||||||
started: false
|
started: false
|
||||||
done: false
|
done: false
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
require 'flowerbox/reporter_list'
|
require 'flowerbox/reporter_list'
|
||||||
|
require 'flowerbox/instrumented_files_list'
|
||||||
|
|
||||||
module Flowerbox
|
module Flowerbox
|
||||||
class Configuration
|
class Configuration
|
||||||
attr_writer :reporters, :backtrace_filter
|
attr_writer :reporters, :backtrace_filter, :instrument_js
|
||||||
attr_accessor :port
|
attr_accessor :port
|
||||||
|
|
||||||
attr_accessor :test_environment, :runner_environment, :bare_coffeescript
|
attr_accessor :test_environment, :runner_environment, :bare_coffeescript
|
||||||
@ -27,6 +28,14 @@ module Flowerbox
|
|||||||
@backtrace_filter ||= []
|
@backtrace_filter ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def instrument_files
|
||||||
|
@instrument_files ||= Flowerbox::InstrumentedFilesList.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def instrument_js?
|
||||||
|
!@instrument_files.empty?
|
||||||
|
end
|
||||||
|
|
||||||
def test_with(what)
|
def test_with(what)
|
||||||
self.test_environment = Flowerbox::TestEnvironment.for(what)
|
self.test_environment = Flowerbox::TestEnvironment.for(what)
|
||||||
end
|
end
|
||||||
|
22
lib/flowerbox/instrumented_files_list.rb
Normal file
22
lib/flowerbox/instrumented_files_list.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
require 'forwardable'
|
||||||
|
|
||||||
|
module Flowerbox
|
||||||
|
class InstrumentedFilesList
|
||||||
|
extend Forwardable
|
||||||
|
|
||||||
|
def_delegators :@files_list, :empty?
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@files_list = []
|
||||||
|
end
|
||||||
|
|
||||||
|
def <<(pattern)
|
||||||
|
@files_list << pattern
|
||||||
|
end
|
||||||
|
|
||||||
|
def include?(filename)
|
||||||
|
@files_list.any? { |pattern| filename[pattern] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -36,6 +36,9 @@ module Flowerbox
|
|||||||
sprockets.find_asset(file.first, :bundle => false).body
|
sprockets.find_asset(file.first, :bundle => false).body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def instrument(data)
|
||||||
|
end
|
||||||
|
|
||||||
def ensure_alive
|
def ensure_alive
|
||||||
while @count < MAX_COUNT && !finished?
|
while @count < MAX_COUNT && !finished?
|
||||||
@count += 1 if @timer_running
|
@count += 1 if @timer_running
|
||||||
@ -92,8 +95,13 @@ module Flowerbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
@results
|
@results
|
||||||
rescue ExecJS::RuntimeError => e
|
rescue => e
|
||||||
|
case e
|
||||||
|
when ExecJS::RuntimeError, ExecJS::ProgramError
|
||||||
handle_coffeescript_compilation_error(e)
|
handle_coffeescript_compilation_error(e)
|
||||||
|
else
|
||||||
|
raise e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def configured?
|
def configured?
|
||||||
|
@ -40,6 +40,12 @@ module Flowerbox
|
|||||||
@environment = Sprockets::Environment.new
|
@environment = Sprockets::Environment.new
|
||||||
@environment.cache = cache
|
@environment.cache = cache
|
||||||
|
|
||||||
|
if Flowerbox.instrument_js?
|
||||||
|
require 'flowerbox/tilt/instrument_js'
|
||||||
|
|
||||||
|
@environment.register_postprocessor 'application/javascript', Flowerbox::Tilt::InstrumentJS
|
||||||
|
end
|
||||||
|
|
||||||
default_asset_paths.each { |path| @environment.append_path(path) }
|
default_asset_paths.each { |path| @environment.append_path(path) }
|
||||||
|
|
||||||
@environment
|
@environment
|
||||||
|
42
lib/flowerbox/tilt/instrument_js.rb
Normal file
42
lib/flowerbox/tilt/instrument_js.rb
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
require 'tilt'
|
||||||
|
|
||||||
|
module Flowerbox
|
||||||
|
module Tilt
|
||||||
|
class InstrumentJS < ::Tilt::Template
|
||||||
|
def prepare ; end
|
||||||
|
|
||||||
|
def evaluate(scope, locals, &block)
|
||||||
|
if Flowerbox.instrument_files.include?(file)
|
||||||
|
block_comment = false
|
||||||
|
|
||||||
|
lines = data.lines.to_a
|
||||||
|
|
||||||
|
output = [
|
||||||
|
'if (typeof __$instrument == "undefined") { __$instrument = {} }',
|
||||||
|
"__$instrument['#{file}'] = [];",
|
||||||
|
"__$instrument['#{file}'][#{lines.length - 1}] = 0;"
|
||||||
|
]
|
||||||
|
|
||||||
|
prior_comma_end = comma_end = false
|
||||||
|
|
||||||
|
lines.each_with_index do |line, index|
|
||||||
|
line.rstrip!
|
||||||
|
|
||||||
|
instrument = "__$instrument['#{file}'][#{index}] = 1;"
|
||||||
|
|
||||||
|
if line[%r{; *$}]
|
||||||
|
line = line + instrument
|
||||||
|
end
|
||||||
|
|
||||||
|
output << line
|
||||||
|
end
|
||||||
|
|
||||||
|
output.join("\n")
|
||||||
|
else
|
||||||
|
data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user