class LearnTest::Strategies::Mocha
Public Instance Methods
check_dependencies()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 18 def check_dependencies Dependencies::NodeJS.new.execute end
cleanup()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 26 def cleanup FileUtils.rm('.results.json') if File.exist?('.results.json') end
detect()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 12 def detect return false unless js_package (has_js_dependency?(:mocha) || in_browser?) ? true : false end
output()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 53 def output @output ||= File.exist?('.results.json') ? Oj.load(File.read('.results.json'), symbol_keys: true) : nil end
push_results?()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 30 def push_results? !in_browser? end
results()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 34 def results @results ||= { username: username, github_user_id: user_id, learn_oauth_token: learn_oauth_token, repo_name: runner.repo, build: { test_suite: [{ framework: 'mocha', formatted_output: output, duration: output[:stats] }] }, examples: output[:stats][:tests], passing_count: output[:stats][:passes], failure_count: output[:stats][:failures] } end
run()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 22 def run run_mocha end
service_endpoint()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 8 def service_endpoint '/e/flatiron_mocha' end
Private Instance Methods
in_IDE?()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 80 def in_IDE? ENV['IDE_CONTAINER'] == 'true' end
in_browser?()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 84 def in_browser? @in_browser ||= has_js_dependency?(:'learn-browser') end
install_mocha_multi()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 88 def install_mocha_multi return if File.exist?('node_modules/mocha-multi') run_install('npm install mocha-multi', npm_install: true) end
run_mocha()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 59 def run_mocha npm_install if in_browser? exec('npm test') else run_node_based_mocha end end
run_node_based_mocha()
click to toggle source
# File lib/learn_test/strategies/mocha.rb, line 69 def run_node_based_mocha command = if (js_package[:scripts] && js_package[:scripts][:test] || '').include?('.results.json') 'npm test' else install_mocha_multi 'node_modules/.bin/mocha -R mocha-multi --reporter-options spec=-,json=.results.json' end system(command) end