Class: Funicular::Testing::NodeRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/funicular/testing/node_runner.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

RESULT_MARKER =
"__FUNICULAR_TEST_RESULTS_JSON__="
DEFAULT_TEST_GLOB =
"test/funicular/client/**/*_picotest.rb"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_root: nil, source_dir: nil, test_glob: DEFAULT_TEST_GLOB, runtime_dir: nil, node: nil, timeout_ms: 5000) ⇒ NodeRunner

Returns a new instance of NodeRunner.



70
71
72
73
74
75
76
77
78
# File 'lib/funicular/testing/node_runner.rb', line 70

def initialize(app_root: nil, source_dir: nil, test_glob: DEFAULT_TEST_GLOB,
               runtime_dir: nil, node: nil, timeout_ms: 5000)
  @app_root = File.expand_path(app_root || rails_root || Dir.pwd)
  @source_dir = File.expand_path(source_dir || File.join(@app_root, "app", "funicular"))
  @test_glob = test_glob
  @runtime_dir = File.expand_path(runtime_dir || default_runtime_dir)
  @node = node || ENV["NODE"] || "node"
  @timeout_ms = timeout_ms
end

Instance Attribute Details

#app_rootObject (readonly)

Returns the value of attribute app_root.



68
69
70
# File 'lib/funicular/testing/node_runner.rb', line 68

def app_root
  @app_root
end

#nodeObject (readonly)

Returns the value of attribute node.



68
69
70
# File 'lib/funicular/testing/node_runner.rb', line 68

def node
  @node
end

#runtime_dirObject (readonly)

Returns the value of attribute runtime_dir.



68
69
70
# File 'lib/funicular/testing/node_runner.rb', line 68

def runtime_dir
  @runtime_dir
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



68
69
70
# File 'lib/funicular/testing/node_runner.rb', line 68

def source_dir
  @source_dir
end

#test_globObject (readonly)

Returns the value of attribute test_glob.



68
69
70
# File 'lib/funicular/testing/node_runner.rb', line 68

def test_glob
  @test_glob
end

#timeout_msObject (readonly)

Returns the value of attribute timeout_ms.



68
69
70
# File 'lib/funicular/testing/node_runner.rb', line 68

def timeout_ms
  @timeout_ms
end

Instance Method Details

#runObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/funicular/testing/node_runner.rb', line 80

def run
  manifest = build_manifest
  with_manifest_file(manifest) do |path|
    stdout, stderr, status = Open3.capture3(node, runner_js, path, chdir: app_root)
    stdout = strip_ansi(stdout)
    stderr = strip_ansi(stderr)
    results, stdout = extract_picotest_results(stdout)
    Result.new(status: status, stdout: stdout, stderr: stderr, picotest_results: results)
  end
end