@diplodoc/cli-tests 5.9.4 → 5.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ import {describe, it} from 'vitest';
2
+ import {TestAdapter, compareDirectories, getTestPaths} from '../fixtures';
3
+
4
+ describe('Check bundles', () => {
5
+ it('bundles list is correct', async () => {
6
+ const {inputPath, outputPath} = getTestPaths('mocks/bundles');
7
+
8
+ await TestAdapter.testBuildPass(inputPath, outputPath, {
9
+ md2md: false,
10
+ md2html: true,
11
+ args: '-j2',
12
+ });
13
+ await compareDirectories(outputPath, false, true);
14
+ });
15
+ });
@@ -0,0 +1,22 @@
1
+ import {describe, test} from 'vitest';
2
+ import {TestAdapter, compareDirectories, getTestPaths} from '../fixtures';
3
+
4
+ const generateMapTestSinglePageTemplate = (
5
+ testTitle: string,
6
+ testRootPath: string,
7
+ {md2md = true, md2html = true, args = '--single-page'},
8
+ ) => {
9
+ test(testTitle, async () => {
10
+ const {inputPath, outputPath} = getTestPaths(testRootPath);
11
+ await TestAdapter.testBuildPass(inputPath, outputPath, {md2md, md2html, args});
12
+ await compareDirectories(outputPath);
13
+ });
14
+ };
15
+
16
+ describe('Single page mode', () => {
17
+ generateMapTestSinglePageTemplate(
18
+ 'simple md2html single page with lang dirs',
19
+ 'mocks/single-page',
20
+ {md2md: false},
21
+ );
22
+ });
@@ -5,14 +5,38 @@ import {glob} from 'glob';
5
5
  import {bundleless, hashless, platformless} from './test';
6
6
  import {expect} from 'vitest';
7
7
 
8
+ const SYSTEM_DIRS = ['_bundle/', '_search/'];
9
+
8
10
  export function getFileContent(filePath: string) {
9
11
  return platformless(bundleless(readFileSync(filePath, 'utf8')));
10
12
  }
11
13
 
12
- const uselessFile = (file: string) =>
13
- !['_bundle/', '_assets/', '_search/'].some((part) => file.includes(part));
14
+ const uselessFile = (file: string, dirs: string[]) =>
15
+ !dirs.some((part) => file.includes(part));
16
+
17
+ export function stripSystemLinks(content: string) {
18
+ const dirPattern = SYSTEM_DIRS.map(d => d.replace('/', '\\/')).join('|');
19
+
20
+ content = content.replace(
21
+ new RegExp(`<script[^>]+src="(?:${dirPattern})[^"]*"[^>]*></script>`, 'g'),
22
+ ''
23
+ );
24
+
25
+ content = content.replace(
26
+ new RegExp(`<link[^>]+href="(?:${dirPattern})[^"]*"[^>]*\\/?>`, 'g'),
27
+ ''
28
+ );
29
+
30
+ content = content.replace(/^[ \t]*\r?\n/gm, '');
31
+
32
+ return content;
33
+ }
14
34
 
15
- export async function compareDirectories(outputPath: string, ignoreFileContent = false) {
35
+ export async function compareDirectories(
36
+ outputPath: string,
37
+ ignoreFileContent = false,
38
+ checkBundle = false,
39
+ ) {
16
40
  const filesFromOutput = (
17
41
  await glob(`**/*`, {
18
42
  cwd: outputPath,
@@ -23,11 +47,24 @@ export async function compareDirectories(outputPath: string, ignoreFileContent =
23
47
  })
24
48
  ).map(bundleless).sort();
25
49
 
26
- expect(hashless(JSON.stringify(filesFromOutput, null, 2))).toMatchSnapshot('filelist');
50
+ let filesForSnapshot;
51
+
52
+ if (checkBundle) {
53
+ filesForSnapshot = filesFromOutput;
54
+ } else {
55
+ filesForSnapshot = filesFromOutput.filter(file => uselessFile(file, SYSTEM_DIRS));
56
+ }
57
+
58
+ expect(hashless(JSON.stringify(filesForSnapshot, null, 2))).toMatchSnapshot('filelist');
27
59
 
28
60
  if (!ignoreFileContent) {
29
- filesFromOutput.filter(uselessFile).forEach((filePath) => {
30
- const content = getFileContent(resolve(outputPath, filePath));
61
+ filesFromOutput.filter(file => uselessFile(file, ['_assets/', ...SYSTEM_DIRS])).forEach((filePath) => {
62
+ let content = getFileContent(resolve(outputPath, filePath));
63
+
64
+ if (!checkBundle && filePath.endsWith('.html')) {
65
+ content = stripSystemLinks(content);
66
+ }
67
+
31
68
  expect(content).toMatchSnapshot();
32
69
  });
33
70
  }
@@ -0,0 +1,13 @@
1
+ allowHTML: true
2
+
3
+ meta:
4
+ rootPath: http://127.0.0.1:5000/
5
+
6
+ interface:
7
+ toc-header: false
8
+ favicon-src: https://storage.yandexcloud.net/diplodoc-www-assets/favicon/favicon.ico
9
+
10
+ search:
11
+ provider: local
12
+ tolerance: 2
13
+ confidense: phrased
@@ -0,0 +1,12 @@
1
+ ---
2
+ availableLangs:
3
+ - en
4
+ - ru
5
+ ---
6
+
7
+ # Header
8
+
9
+ Content
10
+
11
+ [Link 1](page1.md)
12
+ [Link 2](page2.md)
@@ -0,0 +1,3 @@
1
+ # Page 1
2
+
3
+ [Link](page2.md#hash)
@@ -0,0 +1,5 @@
1
+ # Page 2
2
+
3
+ ## hash
4
+
5
+ [External link](https://example.com)
@@ -0,0 +1,9 @@
1
+ title: Skip html extension
2
+ href: index.md
3
+
4
+ items:
5
+ - name: Title 1
6
+ href: page1.md
7
+ - name: Title 2
8
+ href: page2.md
9
+
@@ -0,0 +1,9 @@
1
+ title: Documentation
2
+ description: ""
3
+ meta:
4
+ title: Documentation
5
+ noIndex: true
6
+ links:
7
+ - title: Getting started with Documentation
8
+ description: This guide will show you the basics of working with Documentation
9
+ href: page.md
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: Page Title
3
+ description: Some test description
4
+
5
+ interface:
6
+ toc: false
7
+ favicon-src: /favicon.ico
8
+
9
+ metadata:
10
+ - name: yfm
11
+ content: builder in page
12
+ ---
13
+
14
+ Lorem
@@ -0,0 +1,7 @@
1
+ title: Documentation
2
+ href: index.yaml
3
+ items:
4
+ - name: Documentation
5
+ href: page.md
6
+ - name: Config
7
+ href: project/config.md
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/cli-tests",
3
- "version": "5.9.4",
3
+ "version": "5.10.0",
4
4
  "bin": {
5
5
  "diplodoc-cli-test": "bin.mjs"
6
6
  },