Commit 9b8370a2 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-markdown-spec-performance' into 'master'

Combine multiple `it` blocks to improve Markdown feature spec times

Closes #47348

See merge request gitlab-org/gitlab-ce!19447
parents 4ccf4d33 9c3c198d
...@@ -24,7 +24,7 @@ require 'erb' ...@@ -24,7 +24,7 @@ require 'erb'
# #
# See the MarkdownFeature class for setup details. # See the MarkdownFeature class for setup details.
describe 'GitLab Markdown' do describe 'GitLab Markdown', :aggregate_failures do
include Capybara::Node::Matchers include Capybara::Node::Matchers
include MarkupHelper include MarkupHelper
include MarkdownMatchers include MarkdownMatchers
...@@ -44,112 +44,102 @@ describe 'GitLab Markdown' do ...@@ -44,112 +44,102 @@ describe 'GitLab Markdown' do
# Shared behavior that all pipelines should exhibit # Shared behavior that all pipelines should exhibit
shared_examples 'all pipelines' do shared_examples 'all pipelines' do
describe 'Redcarpet extensions' do it 'includes Redcarpet extensions' do
it 'does not parse emphasis inside of words' do aggregate_failures 'does not parse emphasis inside of words' do
expect(doc.to_html).not_to match('foo<em>bar</em>baz') expect(doc.to_html).not_to match('foo<em>bar</em>baz')
end end
it 'parses table Markdown' do aggregate_failures 'parses table Markdown' do
aggregate_failures do
expect(doc).to have_selector('th:contains("Header")') expect(doc).to have_selector('th:contains("Header")')
expect(doc).to have_selector('th:contains("Row")') expect(doc).to have_selector('th:contains("Row")')
expect(doc).to have_selector('th:contains("Example")') expect(doc).to have_selector('th:contains("Example")')
end end
end
it 'allows Markdown in tables' do aggregate_failures 'allows Markdown in tables' do
expect(doc.at_css('td:contains("Baz")').children.to_html) expect(doc.at_css('td:contains("Baz")').children.to_html)
.to eq '<strong>Baz</strong>' .to eq '<strong>Baz</strong>'
end end
it 'parses fenced code blocks' do aggregate_failures 'parses fenced code blocks' do
aggregate_failures do
expect(doc).to have_selector('pre.code.highlight.js-syntax-highlight.c') expect(doc).to have_selector('pre.code.highlight.js-syntax-highlight.c')
expect(doc).to have_selector('pre.code.highlight.js-syntax-highlight.python') expect(doc).to have_selector('pre.code.highlight.js-syntax-highlight.python')
end end
end
it 'parses mermaid code block' do aggregate_failures 'parses mermaid code block' do
aggregate_failures do
expect(doc).to have_selector('pre[lang=mermaid] > code.js-render-mermaid') expect(doc).to have_selector('pre[lang=mermaid] > code.js-render-mermaid')
end end
end
it 'parses strikethroughs' do aggregate_failures 'parses strikethroughs' do
expect(doc).to have_selector(%{del:contains("and this text doesn't")}) expect(doc).to have_selector(%{del:contains("and this text doesn't")})
end end
it 'parses superscript' do aggregate_failures 'parses superscript' do
expect(doc).to have_selector('sup', count: 2) expect(doc).to have_selector('sup', count: 2)
end end
end end
describe 'SanitizationFilter' do it 'includes SanitizationFilter' do
it 'permits b elements' do aggregate_failures 'permits b elements' do
expect(doc).to have_selector('b:contains("b tag")') expect(doc).to have_selector('b:contains("b tag")')
end end
it 'permits em elements' do aggregate_failures 'permits em elements' do
expect(doc).to have_selector('em:contains("em tag")') expect(doc).to have_selector('em:contains("em tag")')
end end
it 'permits code elements' do aggregate_failures 'permits code elements' do
expect(doc).to have_selector('code:contains("code tag")') expect(doc).to have_selector('code:contains("code tag")')
end end
it 'permits kbd elements' do aggregate_failures 'permits kbd elements' do
expect(doc).to have_selector('kbd:contains("s")') expect(doc).to have_selector('kbd:contains("s")')
end end
it 'permits strike elements' do aggregate_failures 'permits strike elements' do
expect(doc).to have_selector('strike:contains(Emoji)') expect(doc).to have_selector('strike:contains(Emoji)')
end end
it 'permits img elements' do aggregate_failures 'permits img elements' do
expect(doc).to have_selector('img[data-src*="smile.png"]') expect(doc).to have_selector('img[data-src*="smile.png"]')
end end
it 'permits br elements' do aggregate_failures 'permits br elements' do
expect(doc).to have_selector('br') expect(doc).to have_selector('br')
end end
it 'permits hr elements' do aggregate_failures 'permits hr elements' do
expect(doc).to have_selector('hr') expect(doc).to have_selector('hr')
end end
it 'permits span elements' do aggregate_failures 'permits span elements' do
expect(doc).to have_selector('span:contains("span tag")') expect(doc).to have_selector('span:contains("span tag")')
end end
it 'permits details elements' do aggregate_failures 'permits details elements' do
expect(doc).to have_selector('details:contains("Hiding the details")') expect(doc).to have_selector('details:contains("Hiding the details")')
end end
it 'permits summary elements' do aggregate_failures 'permits summary elements' do
expect(doc).to have_selector('details summary:contains("collapsible")') expect(doc).to have_selector('details summary:contains("collapsible")')
end end
it 'permits style attribute in th elements' do aggregate_failures 'permits style attribute in th elements' do
aggregate_failures do
expect(doc.at_css('th:contains("Header")')['style']).to eq 'text-align: center' expect(doc.at_css('th:contains("Header")')['style']).to eq 'text-align: center'
expect(doc.at_css('th:contains("Row")')['style']).to eq 'text-align: right' expect(doc.at_css('th:contains("Row")')['style']).to eq 'text-align: right'
expect(doc.at_css('th:contains("Example")')['style']).to eq 'text-align: left' expect(doc.at_css('th:contains("Example")')['style']).to eq 'text-align: left'
end end
end
it 'permits style attribute in td elements' do aggregate_failures 'permits style attribute in td elements' do
aggregate_failures do
expect(doc.at_css('td:contains("Foo")')['style']).to eq 'text-align: center' expect(doc.at_css('td:contains("Foo")')['style']).to eq 'text-align: center'
expect(doc.at_css('td:contains("Bar")')['style']).to eq 'text-align: right' expect(doc.at_css('td:contains("Bar")')['style']).to eq 'text-align: right'
expect(doc.at_css('td:contains("Baz")')['style']).to eq 'text-align: left' expect(doc.at_css('td:contains("Baz")')['style']).to eq 'text-align: left'
end end
end
it 'removes `rel` attribute from links' do aggregate_failures 'removes `rel` attribute from links' do
expect(doc).not_to have_selector('a[rel="bookmark"]') expect(doc).not_to have_selector('a[rel="bookmark"]')
end end
it "removes `href` from `a` elements if it's fishy" do aggregate_failures "removes `href` from `a` elements if it's fishy" do
expect(doc).not_to have_selector('a[href*="javascript"]') expect(doc).not_to have_selector('a[href*="javascript"]')
end end
end end
...@@ -176,26 +166,26 @@ describe 'GitLab Markdown' do ...@@ -176,26 +166,26 @@ describe 'GitLab Markdown' do
end end
end end
describe 'ExternalLinkFilter' do it 'includes ExternalLinkFilter' do
it 'adds nofollow to external link' do aggregate_failures 'adds nofollow to external link' do
link = doc.at_css('a:contains("Google")') link = doc.at_css('a:contains("Google")')
expect(link.attr('rel')).to include('nofollow') expect(link.attr('rel')).to include('nofollow')
end end
it 'adds noreferrer to external link' do aggregate_failures 'adds noreferrer to external link' do
link = doc.at_css('a:contains("Google")') link = doc.at_css('a:contains("Google")')
expect(link.attr('rel')).to include('noreferrer') expect(link.attr('rel')).to include('noreferrer')
end end
it 'adds _blank to target attribute for external links' do aggregate_failures 'adds _blank to target attribute for external links' do
link = doc.at_css('a:contains("Google")') link = doc.at_css('a:contains("Google")')
expect(link.attr('target')).to match('_blank') expect(link.attr('target')).to match('_blank')
end end
it 'ignores internal link' do aggregate_failures 'ignores internal link' do
link = doc.at_css('a:contains("GitLab Root")') link = doc.at_css('a:contains("GitLab Root")')
expect(link.attr('rel')).not_to match 'nofollow' expect(link.attr('rel')).not_to match 'nofollow'
...@@ -219,24 +209,24 @@ describe 'GitLab Markdown' do ...@@ -219,24 +209,24 @@ describe 'GitLab Markdown' do
it_behaves_like 'all pipelines' it_behaves_like 'all pipelines'
it 'includes RelativeLinkFilter' do it 'includes custom filters' do
aggregate_failures 'RelativeLinkFilter' do
expect(doc).to parse_relative_links expect(doc).to parse_relative_links
end end
it 'includes EmojiFilter' do aggregate_failures 'EmojiFilter' do
expect(doc).to parse_emoji expect(doc).to parse_emoji
end end
it 'includes TableOfContentsFilter' do aggregate_failures 'TableOfContentsFilter' do
expect(doc).to create_header_links expect(doc).to create_header_links
end end
it 'includes AutolinkFilter' do aggregate_failures 'AutolinkFilter' do
expect(doc).to create_autolinks expect(doc).to create_autolinks
end end
it 'includes all reference filters' do aggregate_failures 'all reference filters' do
aggregate_failures do
expect(doc).to reference_users expect(doc).to reference_users
expect(doc).to reference_issues expect(doc).to reference_issues
expect(doc).to reference_merge_requests expect(doc).to reference_merge_requests
...@@ -246,24 +236,24 @@ describe 'GitLab Markdown' do ...@@ -246,24 +236,24 @@ describe 'GitLab Markdown' do
expect(doc).to reference_labels expect(doc).to reference_labels
expect(doc).to reference_milestones expect(doc).to reference_milestones
end end
end
it 'includes TaskListFilter' do aggregate_failures 'TaskListFilter' do
expect(doc).to parse_task_lists expect(doc).to parse_task_lists
end end
it 'includes InlineDiffFilter' do aggregate_failures 'InlineDiffFilter' do
expect(doc).to parse_inline_diffs expect(doc).to parse_inline_diffs
end end
it 'includes VideoLinkFilter' do aggregate_failures 'VideoLinkFilter' do
expect(doc).to parse_video_links expect(doc).to parse_video_links
end end
it 'includes ColorFilter' do aggregate_failures 'ColorFilter' do
expect(doc).to parse_colors expect(doc).to parse_colors
end end
end end
end
context 'wiki pipeline' do context 'wiki pipeline' do
before do before do
...@@ -280,24 +270,24 @@ describe 'GitLab Markdown' do ...@@ -280,24 +270,24 @@ describe 'GitLab Markdown' do
it_behaves_like 'all pipelines' it_behaves_like 'all pipelines'
it 'includes RelativeLinkFilter' do it 'includes custom filters' do
aggregate_failures 'RelativeLinkFilter' do
expect(doc).not_to parse_relative_links expect(doc).not_to parse_relative_links
end end
it 'includes EmojiFilter' do aggregate_failures 'EmojiFilter' do
expect(doc).to parse_emoji expect(doc).to parse_emoji
end end
it 'includes TableOfContentsFilter' do aggregate_failures 'TableOfContentsFilter' do
expect(doc).to create_header_links expect(doc).to create_header_links
end end
it 'includes AutolinkFilter' do aggregate_failures 'AutolinkFilter' do
expect(doc).to create_autolinks expect(doc).to create_autolinks
end end
it 'includes all reference filters' do aggregate_failures 'all reference filters' do
aggregate_failures do
expect(doc).to reference_users expect(doc).to reference_users
expect(doc).to reference_issues expect(doc).to reference_issues
expect(doc).to reference_merge_requests expect(doc).to reference_merge_requests
...@@ -307,28 +297,28 @@ describe 'GitLab Markdown' do ...@@ -307,28 +297,28 @@ describe 'GitLab Markdown' do
expect(doc).to reference_labels expect(doc).to reference_labels
expect(doc).to reference_milestones expect(doc).to reference_milestones
end end
end
it 'includes TaskListFilter' do aggregate_failures 'TaskListFilter' do
expect(doc).to parse_task_lists expect(doc).to parse_task_lists
end end
it 'includes GollumTagsFilter' do aggregate_failures 'GollumTagsFilter' do
expect(doc).to parse_gollum_tags expect(doc).to parse_gollum_tags
end end
it 'includes InlineDiffFilter' do aggregate_failures 'InlineDiffFilter' do
expect(doc).to parse_inline_diffs expect(doc).to parse_inline_diffs
end end
it 'includes VideoLinkFilter' do aggregate_failures 'VideoLinkFilter' do
expect(doc).to parse_video_links expect(doc).to parse_video_links
end end
it 'includes ColorFilter' do aggregate_failures 'ColorFilter' do
expect(doc).to parse_colors expect(doc).to parse_colors
end end
end end
end
# Fake a `current_user` helper # Fake a `current_user` helper
def current_user def current_user
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment