Commit 011d0c35 authored by Paul Slaughter's avatar Paul Slaughter

Remove duplication in EE/CE markdown_processing_spec

parent b990ab0b
import path from 'path'; import path from 'path';
import { import { describeMarkdownProcessing } from 'jest/content_editor/markdown_processing_spec_helper';
createSharedExamples,
loadMarkdownApiExamples,
} 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('EE markdown processing in ContentEditor', () => { describeMarkdownProcessing('EE 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);
});
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,39 @@ const testSerializesHtmlToMarkdownForElement = async ({ markdown, html }) => { ...@@ -59,17 +58,39 @@ 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}`); // If examples were filtered out, we need to create at least one dummy test
} else { // so Jest doesn't blow up.
it(exampleName, async () => { if (!examples.length) {
if (name === 'frontmatter_toml') { describe(description, () => {
setTestTimeoutOnce(2000); // eslint-disable-next-line jest/no-disabled-tests
} it.skip('skipped because no examples matched filter', () => {});
await testSerializesHtmlToMarkdownForElement(example);
}); });
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);
});
});
});
}; };
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