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 @@
# For EE, these files are used:
# EE Data: ee/spec/fixtures/markdown/markdown_golden_master_examples.yml
# 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:
......
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');
// 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(
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);
});
);
// See spec/fixtures/markdown/markdown_golden_master_examples.yml for documentation on how this spec works.
describeMarkdownProcessing('CE markdown processing in ContentEditor', markdownYamlPath);
......@@ -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,29 @@ 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 }) => {
export const describeMarkdownProcessing = (description, markdownYamlPath) => {
const examples = loadMarkdownApiExamples(markdownYamlPath);
describe(description, () => {
describe.each(examples)('%s', (name, { pendingReason, ...example }) => {
const exampleName = 'correctly serializes HTML to markdown';
if (pendingReason) {
it.todo(`${exampleName}: ${pendingReason}`);
} else {
return;
}
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