class LearnLab::Test::Strategies::Mocha

Test strategy for Mocha.

Public Instance Methods

check_dependencies() click to toggle source
# File lib/learn_lab/test/strategies/mocha.rb, line 9
def check_dependencies
  msg = 'Please install NodeJS: https://nodejs.org/en/download'
  raise MissingDependencyError.new(msg) if `which node`.empty?
end
detect() click to toggle source
# File lib/learn_lab/test/strategies/mocha.rb, line 14
def detect
  js_dependency?(:mocha) || js_dependency?(:'learn-browser')
end
parser() click to toggle source
# File lib/learn_lab/test/strategies/mocha.rb, line 28
def parser
  @parser ||= LearnLab::Test::Parsers::Mocha.new(output)
end
run() click to toggle source
# File lib/learn_lab/test/strategies/mocha.rb, line 18
def run
  command = if js_dependency?(:'learn-browser') || js_test_script?
              'npm test'
            else
              'node_modules/.bin/mocha -R mocha-multi ' \
                "--reporter-options spec=-,json=#{result_filename}"
            end
  system(command)
end

Private Instance Methods

js_dependency?(dep) click to toggle source
# File lib/learn_lab/test/strategies/mocha.rb, line 41
def js_dependency?(dep)
  %i[dependencies devDependencies].any? do |key|
    js_package[key] && js_package[key][dep]
  end
end
js_package() click to toggle source
# File lib/learn_lab/test/strategies/mocha.rb, line 34
def js_package
  @js_package ||= begin
    path = fs.join(runner.working_directory, 'package.json')
    fs.read_json_file(path)
  end
end
js_test_script?() click to toggle source
# File lib/learn_lab/test/strategies/mocha.rb, line 47
def js_test_script?
  (js_package[:scripts] && js_package[:scripts][:test] || '') \
    .include?(result_filename)
end