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
011d0c35
Commit
011d0c35
authored
Dec 07, 2021
by
Paul Slaughter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplication in EE/CE markdown_processing_spec
parent
b990ab0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
43 deletions
+55
-43
ee/spec/frontend/content_editor/markdown_processing_spec.js
ee/spec/frontend/content_editor/markdown_processing_spec.js
+11
-17
spec/frontend/content_editor/markdown_processing_spec.js
spec/frontend/content_editor/markdown_processing_spec.js
+11
-14
spec/frontend/content_editor/markdown_processing_spec_helper.js
...rontend/content_editor/markdown_processing_spec_helper.js
+33
-12
No files found.
ee/spec/frontend/content_editor/markdown_processing_spec.js
View file @
011d0c35
import
path
from
'
path
'
;
import
{
createSharedExamples
,
loadMarkdownApiExamples
,
}
from
'
jest/content_editor/markdown_processing_spec_helper
'
;
import
{
describeMarkdownProcessing
}
from
'
jest/content_editor/markdown_processing_spec_helper
'
;
jest
.
mock
(
'
~/emoji
'
);
const
markdownYamlPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
..
'
,
'
fixtures
'
,
'
markdown
'
,
'
markdown_golden_master_examples.yml
'
,
);
// See spec/fixtures/markdown/markdown_golden_master_examples.yml for documentation on how this spec works.
describe
(
'
EE markdown processing in ContentEditor
'
,
()
=>
{
// Ensure we generate same markdown that was provided to Markdown API.
const
markdownYamlPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
..
'
,
'
fixtures
'
,
'
markdown
'
,
'
markdown_golden_master_examples.yml
'
,
);
// eslint-disable-next-line jest/valid-describe
describe
.
each
(
loadMarkdownApiExamples
(
markdownYamlPath
))(
'
%s
'
,
createSharedExamples
);
});
describeMarkdownProcessing
(
'
EE markdown processing in ContentEditor
'
,
markdownYamlPath
);
spec/frontend/content_editor/markdown_processing_spec.js
View file @
011d0c35
import
path
from
'
path
'
;
import
{
createSharedExamples
,
loadMarkdownApiExamples
}
from
'
.
/markdown_processing_spec_helper
'
;
import
{
describeMarkdownProcessing
}
from
'
jest/content_editor
/markdown_processing_spec_helper
'
;
jest
.
mock
(
'
~/emoji
'
);
const
markdownYamlPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
..
'
,
'
fixtures
'
,
'
markdown
'
,
'
markdown_golden_master_examples.yml
'
,
);
// See spec/fixtures/markdown/markdown_golden_master_examples.yml for documentation on how this spec works.
describe
(
'
markdown processing in ContentEditor
'
,
()
=>
{
// Ensure we generate same markdown that was provided to Markdown API.
const
markdownYamlPath
=
path
.
join
(
__dirname
,
'
..
'
,
'
..
'
,
'
fixtures
'
,
'
markdown
'
,
'
markdown_golden_master_examples.yml
'
,
);
// eslint-disable-next-line jest/valid-describe
describe
.
each
(
loadMarkdownApiExamples
(
markdownYamlPath
))(
'
%s
'
,
createSharedExamples
);
});
describeMarkdownProcessing
(
'
CE markdown processing in ContentEditor
'
,
markdownYamlPath
);
spec/frontend/content_editor/markdown_processing_spec_helper.js
View file @
011d0c35
...
...
@@ -30,8 +30,7 @@ const getPendingReason = (pendingStringOrObject) => {
return
null
;
};
// eslint-disable-next-line jest/no-export
export
const
loadMarkdownApiExamples
=
(
markdownYamlPath
)
=>
{
const
loadMarkdownApiExamples
=
(
markdownYamlPath
)
=>
{
const
apiMarkdownYamlText
=
fs
.
readFileSync
(
markdownYamlPath
);
const
apiMarkdownExampleObjects
=
jsYaml
.
safeLoad
(
apiMarkdownYamlText
);
...
...
@@ -59,17 +58,39 @@ const testSerializesHtmlToMarkdownForElement = async ({ markdown, html }) => {
expect
(
serializedContent
).
toBe
(
markdown
);
};
// describeMarkdownProcesssing
//
// This is used to dynamically generate examples (for both CE and EE) to ensure
// we generate same markdown that was provided to Markdown API.
//
// eslint-disable-next-line jest/no-export
export
const
createSharedExamples
=
(
name
,
{
pendingReason
,
...
example
})
=>
{
const
exampleName
=
'
correctly serializes HTML to markdown
'
;
if
(
pendingReason
)
{
it
.
todo
(
`
${
exampleName
}
:
${
pendingReason
}
`
);
}
else
{
it
(
exampleName
,
async
()
=>
{
if
(
name
===
'
frontmatter_toml
'
)
{
setTestTimeoutOnce
(
2000
);
}
await
testSerializesHtmlToMarkdownForElement
(
example
);
export
const
describeMarkdownProcessing
=
(
description
,
markdownYamlPath
)
=>
{
const
examples
=
loadMarkdownApiExamples
(
markdownYamlPath
);
// If examples were filtered out, we need to create at least one dummy test
// so Jest doesn't blow up.
if
(
!
examples
.
length
)
{
describe
(
description
,
()
=>
{
// eslint-disable-next-line jest/no-disabled-tests
it
.
skip
(
'
skipped because no examples matched filter
'
,
()
=>
{});
});
return
;
}
describe
(
description
,
()
=>
{
describe
.
each
(
examples
)(
'
%s
'
,
(
name
,
{
pendingReason
,
...
example
})
=>
{
const
exampleName
=
'
correctly serializes HTML to markdown
'
;
if
(
pendingReason
)
{
it
.
todo
(
`
${
exampleName
}
:
${
pendingReason
}
`
);
return
;
}
it
(
exampleName
,
async
()
=>
{
if
(
name
===
'
frontmatter_toml
'
)
{
setTestTimeoutOnce
(
2000
);
}
await
testSerializesHtmlToMarkdownForElement
(
example
);
});
});
});
};
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