Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1380ce73
Commit
1380ce73
authored
Feb 12, 2021
by
Brett Walker
Committed by
Mayra Cabrera
Feb 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for testing mermaid, platuml, kroki
in markdown feature spec
parent
8135412c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
165 additions
and
87 deletions
+165
-87
lib/banzai/filter/plantuml_filter.rb
lib/banzai/filter/plantuml_filter.rb
+1
-1
spec/benchmarks/banzai_benchmark.rb
spec/benchmarks/banzai_benchmark.rb
+96
-86
spec/features/markdown/markdown_spec.rb
spec/features/markdown/markdown_spec.rb
+27
-0
spec/fixtures/markdown.md.erb
spec/fixtures/markdown.md.erb
+14
-0
spec/support/matchers/markdown_matchers.rb
spec/support/matchers/markdown_matchers.rb
+27
-0
No files found.
lib/banzai/filter/plantuml_filter.rb
View file @
1380ce73
...
...
@@ -9,7 +9,7 @@ module Banzai
#
class
PlantumlFilter
<
HTML
::
Pipeline
::
Filter
def
call
return
doc
unless
doc
.
at
(
'pre > code[lang="plantuml"]'
)
&&
settings
.
plantuml_enabled
return
doc
unless
settings
.
plantuml_enabled?
&&
doc
.
at
(
'pre > code[lang="plantuml"]'
)
plantuml_setup
...
...
spec/benchmarks/banzai_benchmark.rb
View file @
1380ce73
# frozen_string_literal: true
if
ENV
.
key?
(
'BENCHMARK'
)
require
'spec_helper'
require
'erb'
require
'benchmark/ips'
# This benchmarks some of the Banzai pipelines and filters.
# They are not definitive, but can be used by a developer to
# get a rough idea how the changing or addition of a new filter
# will effect performance.
#
# Run by:
# BENCHMARK=1 rspec spec/benchmarks/banzai_benchmark.rb
# or
# rake benchmark:banzai
#
RSpec
.
describe
'GitLab Markdown Benchmark'
,
:aggregate_failures
do
return
unless
ENV
.
key?
(
'BENCHMARK'
)
require
'spec_helper'
require
'erb'
require
'benchmark/ips'
# This benchmarks some of the Banzai pipelines and filters.
# They are not definitive, but can be used by a developer to
# get a rough idea how the changing or addition of a new filter
# will effect performance.
#
# Run by:
# BENCHMARK=1 rspec spec/benchmarks/banzai_benchmark.rb
# or
# rake benchmark:banzai
#
# rubocop: disable RSpec/TopLevelDescribePath
RSpec
.
describe
'GitLab Markdown Benchmark'
,
:aggregate_failures
do
include
MarkupHelper
let_it_be
(
:feature
)
{
MarkdownFeature
.
new
}
...
...
@@ -24,6 +26,18 @@ if ENV.key?('BENCHMARK')
let_it_be
(
:wiki
)
{
feature
.
wiki
}
let_it_be
(
:wiki_page
)
{
feature
.
wiki_page
}
let_it_be
(
:markdown_text
)
{
feature
.
raw_markdown
}
let_it_be
(
:grafana_integration
)
{
create
(
:grafana_integration
,
project:
project
)
}
let_it_be
(
:default_context
)
do
{
project:
project
,
current_user:
current_user
,
suggestions_filter_enabled:
true
}
end
let
(
:context
)
do
Banzai
::
Filter
::
AssetProxyFilter
.
transform_context
(
default_context
)
end
let!
(
:render_context
)
{
Banzai
::
RenderContext
.
new
(
project
,
current_user
)
}
...
...
@@ -32,6 +46,8 @@ if ENV.key?('BENCHMARK')
stub_application_setting
(
asset_proxy_secret_key:
'shared-secret'
)
stub_application_setting
(
asset_proxy_url:
'https://assets.example.com'
)
stub_application_setting
(
asset_proxy_whitelist:
%w(gitlab.com *.mydomain.com)
)
stub_application_setting
(
plantuml_enabled:
true
,
plantuml_url:
'http://localhost:8080'
)
stub_application_setting
(
kroki_enabled:
true
,
kroki_url:
'http://localhost:8000'
)
Banzai
::
Filter
::
AssetProxyFilter
.
initialize_settings
end
...
...
@@ -48,9 +64,9 @@ if ENV.key?('BENCHMARK')
Benchmark
.
ips
do
|
x
|
x
.
config
(
time:
10
,
warmup:
2
)
x
.
report
(
'Full pipeline'
)
{
markdown
(
markdown_text
,
{
pipeline: :full
}
)
}
x
.
report
(
'Wiki pipeline'
)
{
markdown
(
markdown_text
,
{
pipeline: :wiki
,
wiki:
wiki
,
page_slug:
wiki_page
.
slug
}
)
}
x
.
report
(
'Plain pipeline'
)
{
markdown
(
markdown_text
,
{
pipeline: :plain_markdown
}
)
}
x
.
report
(
'Full pipeline'
)
{
Banzai
::
Pipeline
::
FullPipeline
.
call
(
markdown_text
,
context
)
}
x
.
report
(
'Wiki pipeline'
)
{
Banzai
::
Pipeline
::
WikiPipeline
.
call
(
markdown_text
,
context
.
merge
(
wiki:
wiki
,
page_slug:
wiki_page
.
slug
)
)
}
x
.
report
(
'Plain pipeline'
)
{
Banzai
::
Pipeline
::
PlainMarkdownPipeline
.
call
(
markdown_text
,
context
)
}
x
.
compare!
end
...
...
@@ -58,11 +74,6 @@ if ENV.key?('BENCHMARK')
end
context
'filters'
do
let
(
:context
)
do
tmp
=
{
project:
project
,
current_user:
current_user
,
render_context:
render_context
}
Banzai
::
Filter
::
AssetProxyFilter
.
transform_context
(
tmp
)
end
it
'benchmarks all filters in the FullPipeline'
do
benchmark_pipeline_filters
(
:full
)
end
...
...
@@ -110,5 +121,4 @@ if ENV.key?('BENCHMARK')
def
current_user
feature
.
user
end
end
end
spec/features/markdown/markdown_spec.rb
View file @
1380ce73
...
...
@@ -206,6 +206,9 @@ RSpec.describe 'GitLab Markdown', :aggregate_failures do
# `markdown` helper expects a `@project` and `@group` variable
@project
=
@feat
.
project
@group
=
@feat
.
group
stub_application_setting
(
plantuml_enabled:
true
,
plantuml_url:
'http://localhost:8080'
)
stub_application_setting
(
kroki_enabled:
true
,
kroki_url:
'http://localhost:8000'
)
end
let
(
:project
)
{
@feat
.
project
}
# Shadow this so matchers can use it
...
...
@@ -265,6 +268,18 @@ RSpec.describe 'GitLab Markdown', :aggregate_failures do
aggregate_failures
'ColorFilter'
do
expect
(
doc
).
to
parse_colors
end
aggregate_failures
'MermaidFilter'
do
expect
(
doc
).
to
parse_mermaid
end
aggregate_failures
'PlantumlFilter'
do
expect
(
doc
).
to
parse_plantuml
end
aggregate_failures
'KrokiFilter'
do
expect
(
doc
).
to
parse_kroki
end
end
end
...
...
@@ -338,6 +353,18 @@ RSpec.describe 'GitLab Markdown', :aggregate_failures do
aggregate_failures
'ColorFilter'
do
expect
(
doc
).
to
parse_colors
end
aggregate_failures
'MermaidFilter'
do
expect
(
doc
).
to
parse_mermaid
end
aggregate_failures
'PlantumlFilter'
do
expect
(
doc
).
to
parse_plantuml
end
aggregate_failures
'KrokiFilter'
do
expect
(
doc
).
to
parse_kroki
end
end
end
...
...
spec/fixtures/markdown.md.erb
View file @
1380ce73
...
...
@@ -358,3 +358,17 @@ For details see the [Mermaid official page][mermaid].
[mermaid]: https://mermaidjs.github.io/ "Mermaid website"
### PLantUML
```plantuml
Bob -> Sara : Hello
```
### Kroki
```nomnoml
[Pirate|eyeCount: Int|raid();pillage()|
[beard]--[parrot]
[beard]-:>[foul mouth]
]
```
spec/support/matchers/markdown_matchers.rb
View file @
1380ce73
...
...
@@ -246,6 +246,33 @@ module MarkdownMatchers
end
end
end
# MermaidFilter
matcher
:parse_mermaid
do
set_default_markdown_messages
match
do
|
actual
|
expect
(
actual
).
to
have_selector
(
'code.js-render-mermaid'
)
end
end
# PLantumlFilter
matcher
:parse_plantuml
do
set_default_markdown_messages
match
do
|
actual
|
expect
(
actual
).
to
have_link
(
href:
'http://localhost:8080/png/U9npoazIqBLJ24uiIbImKl18pSd9vm80EtS5lW00'
)
end
end
# KrokiFilter
matcher
:parse_kroki
do
set_default_markdown_messages
match
do
|
actual
|
expect
(
actual
).
to
have_link
(
href:
'http://localhost:8000/nomnoml/svg/eNqLDsgsSixJrUmtTHXOL80rsVLwzCupKUrMTNHQtC7IzMlJTE_V0KzhUlCITkpNLEqJ1dWNLkgsKsoviUUSs7KLTssvzVHIzS8tyYjligUAMhEd0g=='
)
end
end
end
# Monkeypatch the matcher DSL so that we can reduce some noisy duplication for
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment