Welcome to mirror list, hosted at ThFree Co, Russian Federation.

markdown_processing_examples.js « content_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3aabfeb145b2427b9689fab0beff8b53ed2556c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import fs from 'fs';
import path from 'path';
import jsYaml from 'js-yaml';
import { getJSONFixture } from 'helpers/fixtures';

export const loadMarkdownApiResult = (testName) => {
  const fixturePathPrefix = `api/markdown/${testName}.json`;

  const fixture = getJSONFixture(fixturePathPrefix);
  return fixture.body || fixture.html;
};

export const loadMarkdownApiExamples = () => {
  const apiMarkdownYamlPath = path.join(__dirname, '..', 'fixtures', 'api_markdown.yml');
  const apiMarkdownYamlText = fs.readFileSync(apiMarkdownYamlPath);
  const apiMarkdownExampleObjects = jsYaml.safeLoad(apiMarkdownYamlText);

  return apiMarkdownExampleObjects.map(({ name, context, markdown }) => [name, context, markdown]);
};

export const loadMarkdownApiExample = (testName) => {
  return loadMarkdownApiExamples().find(([name, context]) => {
    return (context ? `${context}_${name}` : name) === testName;
  })[2];
};