mumuki-html-runner 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/html_runner.rb +1 -0
- data/lib/test_dom_hook.rb +102 -0
- data/lib/test_hook.rb +24 -56
- data/lib/test_script_hook.rb +55 -0
- data/lib/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 745db41402dbb39adee5699159f786c4d190a10d2a4b0aeaac2241f6e197e9db
|
4
|
+
data.tar.gz: 58e82903357fdb43a4b9effeccb44459cac84cc58bfb279cb6f33229c9c1ab14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bc8bfa5b6411fa761ed9366424022aae0d3abf36c022c0a15068603397f5be33750c584d901fdfc72de50cdac3e1f53d19902a394e91975af4fedf9a5888c33
|
7
|
+
data.tar.gz: 4b5ad09dfeeb179ff8547217684430a769ae5f94649285d70db5e7b7e8a332cfe4905d90a93052e906a8f2ecf3bdd03fd0c43c831fc02e37e05dbbd7099882c3
|
data/lib/html_runner.rb
CHANGED
@@ -8,6 +8,7 @@ I18n.load_translations_path File.join(__dir__, 'locales', '*.yml')
|
|
8
8
|
|
9
9
|
Mumukit.runner_name = 'html'
|
10
10
|
Mumukit.configure do |config|
|
11
|
+
config.docker_image = 'mumuki/mumuki-html-worker:1.3'
|
11
12
|
config.content_type = 'html'
|
12
13
|
config.process_expectations_on_empty_content = true
|
13
14
|
config.run_test_hook_on_empty_test = true
|
@@ -0,0 +1,102 @@
|
|
1
|
+
class HtmlTestDomHook < Mumukit::Hook
|
2
|
+
def compile(request)
|
3
|
+
request
|
4
|
+
end
|
5
|
+
|
6
|
+
def run!(request)
|
7
|
+
options = request.options
|
8
|
+
expected = expected_html request
|
9
|
+
actual = compile_content request
|
10
|
+
|
11
|
+
if is_dom_ok expected, actual, options
|
12
|
+
[render_html(actual), :passed]
|
13
|
+
else
|
14
|
+
[render_fail_html(actual, expected), :failed]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def is_dom_ok(expected, actual, options)
|
21
|
+
expected.blank? || contents_match?(expected, actual, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def contents_match?(expected, actual, options)
|
25
|
+
comparable_hexp(expected, options) == comparable_hexp(actual, options)
|
26
|
+
rescue
|
27
|
+
expected == actual
|
28
|
+
end
|
29
|
+
|
30
|
+
def comparable_hexp(content, options)
|
31
|
+
html = transform_content content, options
|
32
|
+
|
33
|
+
hexp_without_blanks html
|
34
|
+
end
|
35
|
+
|
36
|
+
def transform_content(content, options)
|
37
|
+
return content unless options.present?
|
38
|
+
exp = hexp_without_blanks content
|
39
|
+
|
40
|
+
if options['output_ignore_scripts']
|
41
|
+
exp = exp.replace('script') { [] }
|
42
|
+
end
|
43
|
+
|
44
|
+
if options['output_ignore_styles']
|
45
|
+
exp = exp.replace('style') { [] }
|
46
|
+
end
|
47
|
+
|
48
|
+
exp.to_html
|
49
|
+
end
|
50
|
+
|
51
|
+
def hexp_without_blanks(content)
|
52
|
+
hexp %W(\r \n \t)
|
53
|
+
.reduce(content.strip) { |c, it| c.gsub(it, ' ') }
|
54
|
+
.squeeze(' ')
|
55
|
+
end
|
56
|
+
|
57
|
+
def hexp(squeezed_content)
|
58
|
+
Hexp.parse("<html>#{squeezed_content}</html>")
|
59
|
+
end
|
60
|
+
|
61
|
+
def render_html(actual)
|
62
|
+
build_iframe actual
|
63
|
+
end
|
64
|
+
|
65
|
+
def render_fail_html(actual, expected)
|
66
|
+
"#{build_result :actual, actual}#{build_result :expected, expected}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_result(name, content)
|
70
|
+
<<html
|
71
|
+
<br>
|
72
|
+
<strong>#{t name}</strong>
|
73
|
+
#{build_iframe content}
|
74
|
+
html
|
75
|
+
end
|
76
|
+
|
77
|
+
def page_title(dom)
|
78
|
+
title = dom.xpath('//title').first&.text
|
79
|
+
title.present? ? " data-title=\"#{title}\"" : ''
|
80
|
+
end
|
81
|
+
|
82
|
+
def page_favicon(dom)
|
83
|
+
dom.xpath("//link[@rel='icon' and @href]").first
|
84
|
+
.try { |tag| " data-favicon=\"#{tag['href']}\"" }
|
85
|
+
end
|
86
|
+
|
87
|
+
def build_iframe(content)
|
88
|
+
dom = hexp(content).to_dom
|
89
|
+
<<html
|
90
|
+
<div class="mu-browser"#{page_title dom}#{page_favicon dom} data-srcdoc="#{content.escape_html}">
|
91
|
+
</div>
|
92
|
+
html
|
93
|
+
end
|
94
|
+
|
95
|
+
def compile_content(request)
|
96
|
+
request.extra.presence || request.content
|
97
|
+
end
|
98
|
+
|
99
|
+
def expected_html(request)
|
100
|
+
request.test.is_a?(Hash) ? request.test['output'] : request.test
|
101
|
+
end
|
102
|
+
end
|
data/lib/test_hook.rb
CHANGED
@@ -1,71 +1,39 @@
|
|
1
|
+
require_relative './test_dom_hook'
|
2
|
+
require_relative './test_script_hook'
|
3
|
+
|
1
4
|
class HtmlTestHook < Mumukit::Hook
|
5
|
+
def initialize(config = nil)
|
6
|
+
super config
|
7
|
+
@dom_hook = HtmlTestDomHook.new
|
8
|
+
@script_hook = HtmlTestScriptHook.new
|
9
|
+
end
|
10
|
+
|
2
11
|
def compile(request)
|
3
|
-
request
|
12
|
+
request = struct request.to_h.merge options: options(request)
|
13
|
+
@script_hook.compile @dom_hook.compile(request)
|
4
14
|
end
|
5
15
|
|
6
16
|
def run!(request)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
17
|
+
dom_output, dom_status = @dom_hook.run! request
|
18
|
+
script_results = @script_hook.run!(request)
|
19
|
+
script_test_results = script_results&.first
|
20
|
+
return ["<pre>#{script_test_results}</pre>", :errored] if script_results&.last&.errored?
|
21
|
+
|
22
|
+
if script_test_results.blank?
|
23
|
+
[dom_output, dom_status]
|
11
24
|
else
|
12
|
-
[
|
25
|
+
[script_test_results, dom_output, dom_status]
|
13
26
|
end
|
14
27
|
end
|
15
28
|
|
16
29
|
private
|
17
30
|
|
18
|
-
def
|
19
|
-
|
20
|
-
rescue
|
21
|
-
expected == actual
|
22
|
-
end
|
23
|
-
|
24
|
-
def hexp_without_blanks(content)
|
25
|
-
hexp %W(\r \n \t)
|
26
|
-
.reduce(content.strip) { |c, it| c.gsub(it, ' ') }
|
27
|
-
.squeeze(' ')
|
28
|
-
end
|
29
|
-
|
30
|
-
def hexp(squeezed_content)
|
31
|
-
Hexp.parse("<html>#{squeezed_content}</html>")
|
32
|
-
end
|
33
|
-
|
34
|
-
def render_html(actual)
|
35
|
-
build_iframe actual
|
36
|
-
end
|
37
|
-
|
38
|
-
def render_fail_html(actual, expected)
|
39
|
-
"#{build_result :actual, actual}#{build_result :expected, expected}"
|
40
|
-
end
|
41
|
-
|
42
|
-
def build_result(name, content)
|
43
|
-
<<html
|
44
|
-
<br>
|
45
|
-
<strong>#{t name}</strong>
|
46
|
-
#{build_iframe content}
|
47
|
-
html
|
48
|
-
end
|
31
|
+
def options(request)
|
32
|
+
return {} unless request.test.is_a?(Hash)
|
49
33
|
|
50
|
-
|
51
|
-
|
52
|
-
title.present? ? " data-title=\"#{title}\"" : ''
|
53
|
-
end
|
54
|
-
|
55
|
-
def page_favicon(dom)
|
56
|
-
dom.xpath("//link[@rel='icon' and @href]").first
|
57
|
-
.try { |tag| " data-favicon=\"#{tag['href']}\"" }
|
58
|
-
end
|
59
|
-
|
60
|
-
def build_iframe(content)
|
61
|
-
dom = hexp(content).to_dom
|
62
|
-
<<html
|
63
|
-
<div class="mu-browser"#{page_title dom}#{page_favicon dom} data-srcdoc="#{content.escape_html}">
|
64
|
-
</div>
|
65
|
-
html
|
66
|
-
end
|
34
|
+
options_yaml = request.test['options']
|
35
|
+
return {} if options_yaml.blank?
|
67
36
|
|
68
|
-
|
69
|
-
request.extra.presence || request.content
|
37
|
+
YAML.load(options_yaml)
|
70
38
|
end
|
71
39
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class HtmlTestScriptHook < Mumukit::Templates::FileHook
|
2
|
+
isolated true
|
3
|
+
|
4
|
+
def compile(request)
|
5
|
+
return request if script_test(request).blank?
|
6
|
+
|
7
|
+
struct request.to_h.merge file: super(request)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run!(request)
|
11
|
+
return nil if script_test(request).blank?
|
12
|
+
|
13
|
+
super request.file
|
14
|
+
end
|
15
|
+
|
16
|
+
def command_line(filename)
|
17
|
+
"run-dom-tests #{filename}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def compile_file_content(request)
|
21
|
+
JSON.generate html: request.content,
|
22
|
+
tests: script_test(request)
|
23
|
+
end
|
24
|
+
|
25
|
+
def post_process_file(_file, result, status)
|
26
|
+
report = JSON.parse(result)
|
27
|
+
test_results = generate_test_results report
|
28
|
+
|
29
|
+
[test_results, :passed]
|
30
|
+
rescue
|
31
|
+
[result, :errored]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def generate_test_results(report)
|
37
|
+
report['tests'].map { |it|
|
38
|
+
[
|
39
|
+
it['fullTitle'],
|
40
|
+
it['err'].blank? ? :passed : :failed,
|
41
|
+
create_error_tag(it['err']&.dig('message'))
|
42
|
+
]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def script_test(request)
|
47
|
+
request.test.is_a?(Hash) ? request.test['tests'] : nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_error_tag(message)
|
51
|
+
return '' if message.blank?
|
52
|
+
|
53
|
+
"<pre>#{message}</pre>"
|
54
|
+
end
|
55
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-html-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumukit
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.28'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.28'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hexp
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,7 +153,9 @@ files:
|
|
153
153
|
- lib/locales/es.yml
|
154
154
|
- lib/metadata_hook.rb
|
155
155
|
- lib/precompile_hook.rb
|
156
|
+
- lib/test_dom_hook.rb
|
156
157
|
- lib/test_hook.rb
|
158
|
+
- lib/test_script_hook.rb
|
157
159
|
- lib/version.rb
|
158
160
|
homepage: http://github.com/mumuki/mumuki-html-server
|
159
161
|
licenses:
|
@@ -175,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
177
|
version: '0'
|
176
178
|
requirements: []
|
177
179
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.7.
|
180
|
+
rubygems_version: 2.7.8
|
179
181
|
signing_key:
|
180
182
|
specification_version: 4
|
181
183
|
summary: HTML Runner for Mumuki
|