|
| 1 | +require 'rubygems' |
| 2 | + |
| 3 | +RUNNER_DIR = Dir.pwd.gsub(/\/tests$/,"") + "/" |
| 4 | +def execute(cmd) |
| 5 | + `#{cmd}` |
| 6 | +end |
| 7 | + |
| 8 | +def runBg(cmd, linestomatch, genre, test_strings) |
| 9 | + pid = Process.fork { |
| 10 | + counter = 0 |
| 11 | + matched_counter = 0 |
| 12 | + IO.popen(cmd) {|io| |
| 13 | + io.each {|line| |
| 14 | + if line.match(/Completed in /) |
| 15 | + counter += 1 |
| 16 | + puts "[#{genre.upcase}] : " + line |
| 17 | + test_strings.each do |test_string| |
| 18 | + matched_counter += 1 if line.match(/#{test_string}/) |
| 19 | + end |
| 20 | + end |
| 21 | + if counter >= linestomatch |
| 22 | + if matched_counter != counter |
| 23 | + puts "\n####\n#{genre.upcase} FAILED\n####\n" |
| 24 | + end |
| 25 | + execute("ps -ef | grep #{io.pid} | grep -v grep | awk '{print $2}' | xargs kill -9") |
| 26 | + end |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + pid |
| 31 | +end |
| 32 | + |
| 33 | +class Test |
| 34 | + def run_project |
| 35 | + end |
| 36 | + |
| 37 | + def qunit |
| 38 | + repo_path = "#{RUNNER_DIR}tests/external-repos/" |
| 39 | + conf_path = "#{RUNNER_DIR}tests/conf/" |
| 40 | + execute("cd #{repo_path}underscorejs && npm install") |
| 41 | + execute("cd #{repo_path}underscorejs && cp #{conf_path}underscorejs.json #{repo_path}underscorejs/browserstack.json") |
| 42 | + pid = runBg("cd #{repo_path}underscorejs && ../../../bin/cli.js", 1, "qunit-underscorejs", ["631 of 631 passed"]) |
| 43 | + execute("open http://localhost:8888/test/index.html") |
| 44 | + Process.wait(pid) |
| 45 | + sleep(1) |
| 46 | + |
| 47 | + execute("cd #{repo_path}Modernizr && npm install") |
| 48 | + execute("cd #{repo_path}Modernizr && cp #{conf_path}Modernizr.json #{repo_path}Modernizr/browserstack.json") |
| 49 | + pid2 = runBg("cd #{repo_path}Modernizr && ../../../bin/cli.js", 1, "qunit-Modernizr", ["20 of 41 passed"]) |
| 50 | + execute("open http://localhost:8888/test/index.html") |
| 51 | + Process.wait(pid2) |
| 52 | + |
| 53 | + # https://github.com/bitovi/funcunit/ |
| 54 | + # https://github.com/twbs/bootstrap |
| 55 | + end |
| 56 | + |
| 57 | + def mocha |
| 58 | + repo_path = "#{RUNNER_DIR}tests/external-repos/" |
| 59 | + conf_path = "#{RUNNER_DIR}tests/conf/" |
| 60 | + |
| 61 | + execute("cd #{repo_path}url.js && npm install") |
| 62 | + execute("cd #{repo_path}url.js && cp #{conf_path}url.js.json #{repo_path}url.js/browserstack.json") |
| 63 | + pid = runBg("cd #{repo_path}url.js && ../../../bin/cli.js", 1, "mocha-urlJs", ["35 of 35 passed"]) |
| 64 | + execute("open http://localhost:8888/test.html") |
| 65 | + Process.wait(pid) |
| 66 | + sleep(1) |
| 67 | + |
| 68 | + # https://github.com/browserstack/microjungle |
| 69 | + # https://github.com/dhimil/mocha |
| 70 | + # https://github.com/auth0/auth0.js |
| 71 | + end |
| 72 | + |
| 73 | + def jasmine |
| 74 | + repo_path = "#{RUNNER_DIR}tests/external-repos/" |
| 75 | + conf_path = "#{RUNNER_DIR}tests/conf/" |
| 76 | + |
| 77 | + execute("cd #{repo_path}mout && npm install") |
| 78 | + execute("cd #{repo_path}mout && cp #{conf_path}mout.json #{repo_path}mout/browserstack.json") |
| 79 | + pid = runBg("cd #{repo_path}mout && ../../../bin/cli.js", 1, "jasmine-mout", ["978 of 978 passed"]) |
| 80 | + execute("open http://localhost:8888/tests/runner.html") |
| 81 | + Process.wait(pid) |
| 82 | + sleep(1) |
| 83 | + end |
| 84 | + |
| 85 | + def run |
| 86 | + execute("cd #{RUNNER_DIR} && git submodule init && git submodule update") |
| 87 | + qunit |
| 88 | + mocha |
| 89 | + jasmine |
| 90 | + end |
| 91 | +end |
| 92 | + |
| 93 | +Test.new.run |
0 commit comments