testing javascript files with jslint
This commit is contained in:
parent
969f834440
commit
c7d7be6ed2
|
@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Nick Gauthier"]
|
||||
s.date = %q{2010-05-10}
|
||||
s.date = %q{2010-05-24}
|
||||
s.description = %q{Spread your tests over multiple machines to test your code faster.}
|
||||
s.email = %q{nick@smartlogicsolutions.com}
|
||||
s.extra_rdoc_files = [
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -39,6 +39,8 @@ module Hydra #:nodoc:
|
|||
output = run_rspec_file(file)
|
||||
elsif file =~ /.feature$/
|
||||
output = run_cucumber_file(file)
|
||||
elsif file =~ /.js$/
|
||||
output = run_javascript_file(file)
|
||||
else
|
||||
output = run_test_unit_file(file)
|
||||
end
|
||||
|
@ -175,6 +177,48 @@ module Hydra #:nodoc:
|
|||
return hydra_response.read
|
||||
end
|
||||
|
||||
def run_javascript_file(file)
|
||||
puts "Running #{file}"
|
||||
errors = []
|
||||
require 'v8'
|
||||
require 'pp' #TODO REMOVE!
|
||||
V8::Context.open do |context|
|
||||
context.load(File.expand_path(File.join(File.dirname(__FILE__), 'js', 'lint.js')))
|
||||
context['input'] = lambda{
|
||||
File.read(file)
|
||||
}
|
||||
context['reportErrors'] = lambda{|js_errors|
|
||||
js_errors.each do |e|
|
||||
e = V8::To.ruby(e)
|
||||
errors << "Error at line #{e['line'].to_i + 1} " +
|
||||
"character #{e['character'].to_i + 1}: #{e['reason']}"
|
||||
errors << e['evidence']
|
||||
end
|
||||
}
|
||||
context.eval %{
|
||||
JSLINT(input(), {
|
||||
sub: true,
|
||||
onevar: true,
|
||||
eqeqeq: true,
|
||||
plusplus: true,
|
||||
bitwise: true,
|
||||
regexp: true,
|
||||
newcap: true,
|
||||
immed: true,
|
||||
strict: true,
|
||||
rhino: true
|
||||
});
|
||||
reportErrors(JSLINT.errors);
|
||||
}
|
||||
end
|
||||
|
||||
if errors.empty?
|
||||
return '.'
|
||||
else
|
||||
return errors.join("\n")
|
||||
end
|
||||
end
|
||||
|
||||
# find all the test unit classes in a given file, so we can run their suites
|
||||
def self.find_classes_in_file(f)
|
||||
code = ""
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
"use strict";
|
||||
var thisvar;
|
||||
var thatvar
|
||||
|
|
@ -37,6 +37,12 @@ class RunnerTest < Test::Unit::TestCase
|
|||
Process.wait(child)
|
||||
end
|
||||
|
||||
should "run a js lint file and find errors" do
|
||||
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
||||
results = runner.run_file(javascript_file)
|
||||
assert results =~ /Missing semicolon/
|
||||
end
|
||||
|
||||
should "run two rspec tests" do
|
||||
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
||||
runner.run_file(rspec_file)
|
||||
|
|
|
@ -42,6 +42,10 @@ class Test::Unit::TestCase
|
|||
def alternate_cucumber_feature_file
|
||||
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'features', 'write_alternate_file.feature'))
|
||||
end
|
||||
|
||||
def javascript_file
|
||||
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'js_file.js'))
|
||||
end
|
||||
end
|
||||
|
||||
module Hydra #:nodoc:
|
||||
|
|
Loading…
Reference in New Issue