class Opal::Test::Unit::Runner
Public Class Methods
new(directory, **options)
click to toggle source
# File lib/opal/test/unit/runner.rb, line 7 def initialize(directory, **options) @directory = directory @options = options end
Public Instance Methods
run()
click to toggle source
# File lib/opal/test/unit/runner.rb, line 12 def run tmpfile_path = "#{Dir.tmpdir}/tmp.rb" File.open(tmpfile_path, "w") do |tmpfile| Dir.glob("#{@directory}/**/*test.rb").each do |filename| tmpfile.write("require \"#{filename.sub(/^#{@directory}\//, "")}\"\n") end tmpfile.write(<<~SRC) require "opal/platform" run_test = Proc.new do result = Opal::Test::Unit::TestCase.run Opal::Test::Unit::ResultPrinter.print_summary(result) if result.failure_messages.count > 0 || result.errors.count > 0 exit 1 end end %x( var isNode = (typeof process !== "undefined" && typeof require !== "undefined"); if (isNode) { run_test(); } else { window.onload = run_test; } ) SRC end run_on_opal @directory, tmpfile_path File.delete tmpfile_path puts "Done." end
run_on_opal(dir, filename)
click to toggle source
# File lib/opal/test/unit/runner.rb, line 47 def run_on_opal(dir, filename) options_hash = { file: File.open(filename), filename: File.basename(filename), load_paths: $LOAD_PATH + ["./lib", dir] }.merge(@options) cli = Opal::CLI.new options_hash begin cli.run exit cli.exit_status rescue Opal::CliRunners::RunnerError => e $stderr.puts e.message exit 72 end end