Created
August 24, 2010 09:21
-
-
Save cjohansen/547258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Sometimes massive failure can cause JsTestDriver to hang | |
# To debug those cases, it's easier to run test cases one by one | |
# to track which test case is causing trouble. | |
# | |
# This script also helps test less capable browsers such as IE6, | |
# which can get overwhelmed while trying to run too many tests too | |
# rapidly. | |
# | |
def red(msg) | |
"\033[31m#{msg}\033[39m" | |
end | |
def green(msg) | |
"\033[32m#{msg}\033[39m" | |
end | |
def ok | |
green("OK") | |
end | |
args = "" | |
prefix = Dir.pwd | |
verbosity = 0 | |
ARGV.join(" ").split("--").reject { |a| a.strip!; a == "" }.each do |arg| | |
pieces = arg.split(" ") | |
config = pieces.shift | |
if config == "prefix" | |
prefix = pieces.join(" ") | |
elsif config == "verbose" | |
verbosity += 1 | |
else | |
args += " --#{config} #{pieces.join(' ')}" | |
end | |
end | |
def browser(str) | |
str.gsub("Microsoft Internet Explorer", "MSIE").gsub("Windows", "Win") | |
end | |
problems = [] | |
puts "jstestdriver --reset#{args}" | |
print "Resetting" | |
`jstestdriver --reset#{args}` | |
print " - #{ok}\n" | |
(Dir.glob(File.join(prefix, "**/*.js")).collect do |test| | |
File.read(test).scan(/estCase\("(.+)"/) | |
end).flatten.sort.each do |testCase| | |
print testCase | |
output = `jstestdriver --tests #{testCase}#{args}` | |
output =~ /Fails: (\d+); Errors: (\d+)/ | |
if $1.to_i > 0 || $2.to_i > 0 | |
problems << testCase | |
print " - " + red("#{$1} failures, #{$2} errors") | |
else | |
print " - #{ok}" | |
end | |
browsers = output.scan(/ ([^\s][^:\n]*): Run/).flatten | |
print " - #{browsers.count} browsers" | |
if verbosity == 1 | |
print ": #{browser(browsers.join(', '))}" | |
logs = output.scan(/ (\[[A-Z]+\] .*)/).flatten | |
print "\n " + logs.join("\n ") if logs.count > 0 | |
end | |
print "\n#{output}" if verbosity > 1 | |
print "\n" | |
end | |
if problems.count > 0 | |
puts red("Some test cases had failures and/or errors") | |
puts problems.join("\n") | |
else | |
puts green("No problems") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment