Commit da47cbe6 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'ps-remove-duplicaiton-markdown-processing-spec' into 'master'

Remove duplication in EE/CE markdown_processing_spec

See merge request gitlab-org/gitlab!76292
parents 359e45d5 c742f323
import path from 'path';
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.
describeMarkdownProcessing('EE markdown processing in ContentEditor', markdownYamlPath);
import path from 'path';
import {
createSharedExamples,
loadMarkdownApiExamples,
} from 'jest/content_editor/markdown_processing_spec_helper';
jest.mock('~/emoji');
// 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);
});
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# For EE, these files are used: # For EE, these files are used:
# EE Data: ee/spec/fixtures/markdown/markdown_golden_master_examples.yml # EE Data: ee/spec/fixtures/markdown/markdown_golden_master_examples.yml
# EE Backend: ee/spec/requests/api/markdown_golden_master_spec.rb # EE Backend: ee/spec/requests/api/markdown_golden_master_spec.rb
# EE Frontend: ee/spec/frontend/content_editor/markdown_processing_spec.js # EE Frontend: ee/spec/frontend/content_editor/ee_markdown_processing_spec.js
# #
# #
# Requirements: # Requirements:
......
import path from 'path'; 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'); 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. // See spec/fixtures/markdown/markdown_golden_master_examples.yml for documentation on how this spec works.
describe('markdown processing in ContentEditor', () => { describeMarkdownProcessing('CE markdown processing in ContentEditor', markdownYamlPath);
// 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);
});
...@@ -30,8 +30,7 @@ const getPendingReason = (pendingStringOrObject) => { ...@@ -30,8 +30,7 @@ const getPendingReason = (pendingStringOrObject) => {
return null; return null;
}; };
// eslint-disable-next-line jest/no-export const loadMarkdownApiExamples = (markdownYamlPath) => {
export const loadMarkdownApiExamples = (markdownYamlPath) => {
const apiMarkdownYamlText = fs.readFileSync(markdownYamlPath); const apiMarkdownYamlText = fs.readFileSync(markdownYamlPath);
const apiMarkdownExampleObjects = jsYaml.safeLoad(apiMarkdownYamlText); const apiMarkdownExampleObjects = jsYaml.safeLoad(apiMarkdownYamlText);
...@@ -59,17 +58,29 @@ const testSerializesHtmlToMarkdownForElement = async ({ markdown, html }) => { ...@@ -59,17 +58,29 @@ const testSerializesHtmlToMarkdownForElement = async ({ markdown, html }) => {
expect(serializedContent).toBe(markdown); 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 // eslint-disable-next-line jest/no-export
export const createSharedExamples = (name, { pendingReason, ...example }) => { export const describeMarkdownProcessing = (description, markdownYamlPath) => {
const exampleName = 'correctly serializes HTML to markdown'; const examples = loadMarkdownApiExamples(markdownYamlPath);
if (pendingReason) {
it.todo(`${exampleName}: ${pendingReason}`); describe(description, () => {
} else { describe.each(examples)('%s', (name, { pendingReason, ...example }) => {
it(exampleName, async () => { const exampleName = 'correctly serializes HTML to markdown';
if (name === 'frontmatter_toml') { if (pendingReason) {
setTestTimeoutOnce(2000); it.todo(`${exampleName}: ${pendingReason}`);
return;
} }
await testSerializesHtmlToMarkdownForElement(example);
it(exampleName, async () => {
if (name === 'frontmatter_toml') {
setTestTimeoutOnce(2000);
}
await testSerializesHtmlToMarkdownForElement(example);
});
}); });
} });
}; };
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