Skip to content

Commit cc22507

Browse files
committed
Split out TestRun from ci/qunit-selenium-runner to separate file
This makes it easy to separate code that is not ours and include the license at the top and document it's origin on the class.
1 parent b56e6af commit cc22507

File tree

2 files changed

+73
-73
lines changed

2 files changed

+73
-73
lines changed

ci/qunit-selenium-runner.rb

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,7 @@
11
# frozen_string_literal: true
22

33
require "webdrivers"
4-
5-
# This class based on https://github.com/smontanari/qunit-selenium, with a few tweaks to make it easier to read output.
6-
# The license from https://github.com/smontanari/qunit-selenium is enclosed:
7-
#
8-
# The MIT License (MIT)
9-
#
10-
# Copyright (c) 2014 Silvio Montanari
11-
#
12-
# Permission is hereby granted, free of charge, to any person obtaining a copy
13-
# of this software and associated documentation files (the "Software"), to deal
14-
# in the Software without restriction, including without limitation the rights
15-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16-
# copies of the Software, and to permit persons to whom the Software is
17-
# furnished to do so, subject to the following conditions:
18-
#
19-
# The above copyright notice and this permission notice shall be included in all
20-
# copies or substantial portions of the Software.
21-
#
22-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28-
# SOFTWARE.
29-
30-
class TestRun
31-
TestResult = Struct.new(:tests, :assertions, :duration, :raw_output)
32-
33-
ID_TESTRESULT = "qunit-testresult"
34-
ID_TESTS = "qunit-tests"
35-
36-
def initialize(driver)
37-
@qunit_testresult = driver[ID_TESTRESULT]
38-
@qunit_tests = driver[ID_TESTS]
39-
end
40-
41-
def completed?
42-
@qunit_testresult.text =~ /Tests completed/
43-
end
44-
45-
def result
46-
assertions = { total: total_assertions, passed: passed_assertions, failed: failed_assertions }
47-
tests = { total: total_tests, passed: pass_tests, failed: fail_tests }
48-
TestResult.new(tests, assertions, duration, raw_output)
49-
end
50-
51-
private
52-
def raw_output
53-
@qunit_tests.text
54-
end
55-
56-
def duration
57-
match = /Tests completed in (?<milliseconds>\d+) milliseconds/.match @qunit_testresult.text
58-
match[:milliseconds].to_i / 1000
59-
end
60-
61-
%w(total passed failed).each do |result|
62-
define_method("#{result}_assertions".to_sym) do
63-
@qunit_testresult.find_elements(:class, result).first.text.to_i
64-
end
65-
end
66-
67-
def total_tests
68-
@qunit_tests.find_elements(:css, "##{ID_TESTS} > *").count
69-
end
70-
71-
%w(pass fail).each do |result|
72-
define_method("#{result}_tests".to_sym) do
73-
@qunit_tests.find_elements(:css, "##{ID_TESTS} > .#{result}").count
74-
end
75-
end
76-
end
4+
require_relative "test_run"
775

786
driver = if ARGV[1]
797
::Selenium::WebDriver.for(:remote, url: ARGV[1], desired_capabilities: :chrome)

ci/test_run.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# frozen_string_literal: true
2+
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2014 Silvio Montanari
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
# This class based on https://github.com/smontanari/qunit-selenium, with a few tweaks to make it easier to read output.
26+
class TestRun
27+
TestResult = Struct.new(:tests, :assertions, :duration, :raw_output)
28+
29+
ID_TESTRESULT = "qunit-testresult"
30+
ID_TESTS = "qunit-tests"
31+
32+
def initialize(driver)
33+
@qunit_testresult = driver[ID_TESTRESULT]
34+
@qunit_tests = driver[ID_TESTS]
35+
end
36+
37+
def completed?
38+
@qunit_testresult.text =~ /Tests completed/
39+
end
40+
41+
def result
42+
assertions = { total: total_assertions, passed: passed_assertions, failed: failed_assertions }
43+
tests = { total: total_tests, passed: pass_tests, failed: fail_tests }
44+
TestResult.new(tests, assertions, duration, raw_output)
45+
end
46+
47+
private
48+
def raw_output
49+
@qunit_tests.text
50+
end
51+
52+
def duration
53+
match = /Tests completed in (?<milliseconds>\d+) milliseconds/.match @qunit_testresult.text
54+
match[:milliseconds].to_i / 1000
55+
end
56+
57+
%w(total passed failed).each do |result|
58+
define_method("#{result}_assertions".to_sym) do
59+
@qunit_testresult.find_elements(:class, result).first.text.to_i
60+
end
61+
end
62+
63+
def total_tests
64+
@qunit_tests.find_elements(:css, "##{ID_TESTS} > *").count
65+
end
66+
67+
%w(pass fail).each do |result|
68+
define_method("#{result}_tests".to_sym) do
69+
@qunit_tests.find_elements(:css, "##{ID_TESTS} > .#{result}").count
70+
end
71+
end
72+
end

0 commit comments

Comments
 (0)