-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathtest_img_graph.rb
89 lines (73 loc) · 1.91 KB
/
test_img_graph.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true
require 'test_helper'
require 'review/htmlbuilder'
require 'review/img_graph'
class ImgGraphTest < Test::Unit::TestCase
def setup
@config = ReVIEW::Configure.values
@tmpdir = Dir.mktmpdir
@playwright_path = install_playwright
@config['imagedir'] = @tmpdir
@config['playwright_options']['playwright_path'] = @playwright_path
@img_graph = ReVIEW::ImgGraph.new(@config, 'latex')
end
def teardown
@img_graph.cleanup_graphimg
FileUtils.rm_rf(@tmpdir)
end
def install_playwright
begin
`npm -v`
rescue StandardError
return nil
end
json = <<-EOB
{
"name": "imggraph-test",
"dependencies": {
"playwright": "^1.32.2"
}
}
EOB
File.write(File.join(@tmpdir, 'package.json'), json)
Dir.chdir(@tmpdir) do
system('npm install')
system('npx playwright install chromium')
end
File.join(@tmpdir, 'node_modules', '.bin', 'playwright')
end
def prepare_mermaid_data
content = <<-EOB
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server1]
B --> D[Server2]
EOB
@img_graph.defer_mermaid_image(content, 'testid1')
end
def test_make_mermaid_pdf
unless @playwright_path
$stderr.puts 'skip test_make_mermaid_pdf (cannot find playwright)'
return true
end
prepare_mermaid_data
@img_graph.make_mermaid_images
assert File.size(File.join(@tmpdir, 'latex', 'testid1.pdf')) > 0
end
def test_make_mermaid_svg
unless @playwright_path
$stderr.puts 'skip test_make_mermaid_svg (cannot find playwright)'
return true
end
begin
`pdftocairo -v`
rescue StandardError
$stderr.puts 'skip test_make_mermaid_svg (cannot find pdftocairo)'
return true
end
@img_graph = ReVIEW::ImgGraph.new(@config, 'html')
prepare_mermaid_data
@img_graph.make_mermaid_images
assert File.size(File.join(@tmpdir, 'html', 'testid1.svg')) > 0
end
end