class SleepingKingStudios::Tasks::Ci::JestRunner

Service object to run Jest as an external process with the specified parameters.

Public Instance Methods

call(env: {}) click to toggle source
# File lib/sleeping_king_studios/tasks/ci/jest_runner.rb, line 12
def call env: {}, files: [], options: [], report: true
  report  = 'tmp/ci/jest.json' if report && !report.is_a?(String)
  command =
    build_command(
      :env     => env,
      :files   => files,
      :options => options,
      :report  => report
    )

  stream_process(command)

  report ? load_report(:report => report) : {}
end

Private Instance Methods

base_command() click to toggle source
# File lib/sleeping_king_studios/tasks/ci/jest_runner.rb, line 29
def base_command
  'yarn jest'
end
build_options(files:, options:, report:, **_kwargs) click to toggle source
# File lib/sleeping_king_studios/tasks/ci/jest_runner.rb, line 33
def build_options files:, options:, report:, **_kwargs
  options += ['--json', "--outputFile=#{report}"] if report

  super :files => files, :options => options
end
load_report(report: raw = File.read report) click to toggle source
# File lib/sleeping_king_studios/tasks/ci/jest_runner.rb, line 39
def load_report report:
  raw = File.read report

  return {} if raw.empty?

  JSON.parse raw
rescue
  # :nocov:
  {}
  # :nocov:
end