Class: LearnTest::Strategies::Protractor

Inherits:
LearnTest::Strategy show all
Defined in:
lib/learn_test/strategies/protractor.rb

Instance Attribute Summary

Attributes inherited from LearnTest::Strategy

#options, #runner

Instance Method Summary collapse

Methods inherited from LearnTest::Strategy

#argv, #configure, #die, #initialize, #learn_oauth_token, #push_results?, #run_install, #user_id, #username

Constructor Details

This class inherits a constructor from LearnTest::Strategy

Instance Method Details

#check_dependenciesObject



14
15
16
17
# File 'lib/learn_test/strategies/protractor.rb', line 14

def check_dependencies
  Dependencies::NodeJS.new.execute
  Dependencies::Protractor.new.execute
end

#cleanupObject



83
84
85
# File 'lib/learn_test/strategies/protractor.rb', line 83

def cleanup
  FileUtils.rm('.results.json') if File.exist?('.results.json')
end

#detectObject



10
11
12
# File 'lib/learn_test/strategies/protractor.rb', line 10

def detect
  runner.files.include?('conf.js')
end

#outputObject



60
61
62
# File 'lib/learn_test/strategies/protractor.rb', line 60

def output
  File.exists?('.results.json') ? Oj.load(File.read('.results.json'), symbol_keys: true) : nil
end

#resultsObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/learn_test/strategies/protractor.rb', line 64

def results
  @results ||= {
    username: username,
    github_user_id: user_id,
    learn_oauth_token: learn_oauth_token,
    repo_name: runner.repo,
    build: {
      test_suite: [{
        framework: 'protractor',
        formatted_output: output,
        duration: duration
      }]
    },
    examples: passing_count + failure_count,
    passing_count: passing_count,
    failure_count: failure_count
  }
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/learn_test/strategies/protractor.rb', line 19

def run
  if !selenium_running?
    stdin, stdout, stderr, wait_thr = Open3.popen3('webdriver-manager start')
    @pid = wait_thr.pid

    @server_started = false

    while !@server_started && line = stderr.gets do
      puts line
      if line.include?('Selenium Server is up and running')
        @server_started = true
        stdin.close
        stdout.close
        stderr.close
      end
    end
  end

  Open3.popen3('protractor conf.js --resultJsonOutputFile .results.json') do |stdin, stdout, stderr, wait_thr|
    while line = stdout.gets do
      if line.include?('Error: Cannot find module')
        @modules_missing = true
      end
      puts line
    end

    while stderr_line = stderr.gets do
      puts stderr_line
    end

    if wait_thr.value.exitstatus != 0
      if @modules_missing
        die("You appear to be missing npm dependencies. Try running `npm install`\nIf the issue persists, check the package.json")
      end
    end
  end

  safe_kill(@pid)
  safe_kill(@selenium_pid) if selenium_running?
end

#service_endpointObject



6
7
8
# File 'lib/learn_test/strategies/protractor.rb', line 6

def service_endpoint
  '/e/flatiron_protractor'
end