@diplodoc/cli-tests 5.9.5 → 5.10.1

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
+ });
@@ -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,30 @@ 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
+ // Here we sort the order of the included files after all processing
59
+ // This is necessary for better test stability
60
+ // We do not care in what order these files were received and processed
61
+ // We sort only the final list and put it in the snapshot
62
+ filesForSnapshot = filesForSnapshot.map(hashless).sort();
63
+
64
+ expect(JSON.stringify(filesForSnapshot, null, 2)).toMatchSnapshot('filelist');
27
65
 
28
66
  if (!ignoreFileContent) {
29
- filesFromOutput.filter(uselessFile).forEach((filePath) => {
30
- const content = getFileContent(resolve(outputPath, filePath));
67
+ filesFromOutput.filter(file => uselessFile(file, ['_assets/', ...SYSTEM_DIRS])).forEach((filePath) => {
68
+ let content = getFileContent(resolve(outputPath, filePath));
69
+
70
+ if (!checkBundle && filePath.endsWith('.html')) {
71
+ content = stripSystemLinks(content);
72
+ }
73
+
31
74
  expect(content).toMatchSnapshot();
32
75
  });
33
76
  }
@@ -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
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/cli-tests",
3
- "version": "5.9.5",
3
+ "version": "5.10.1",
4
4
  "bin": {
5
5
  "diplodoc-cli-test": "bin.mjs"
6
6
  },