@diplodoc/cli-tests 5.12.1 → 5.12.3
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.
- package/e2e/__snapshots__/alternates.test.ts.snap +2 -2
- package/e2e/__snapshots__/pdf-page.spec.ts.snap +137 -0
- package/e2e/__snapshots__/preprocess.test.ts.snap +279 -21
- package/e2e/__snapshots__/rtl.spec.ts.snap +4 -4
- package/e2e/alternates.test.ts +1 -0
- package/e2e/bundles.spec.ts +1 -0
- package/e2e/errors.spec.ts +18 -8
- package/e2e/generate-map.spec.ts +6 -2
- package/e2e/include-toc.test.ts +1 -0
- package/e2e/load-custom-resources.spec.ts +1 -0
- package/e2e/metadata.spec.ts +1 -0
- package/e2e/pdf-page.spec.ts +16 -0
- package/e2e/plugin-corner-cases.spec.ts +1 -0
- package/e2e/preprocess.test.ts +8 -5
- package/e2e/redirects-validation.spec.ts +5 -4
- package/e2e/regression.test.ts +1 -0
- package/e2e/restricted-access.test.ts +3 -5
- package/e2e/rtl.spec.ts +1 -0
- package/e2e/search.test.ts +1 -0
- package/e2e/single-page.spec.ts +1 -0
- package/e2e/skip-html-extension.spec.ts +1 -0
- package/e2e/translation.spec.ts +17 -6
- package/fixtures/cliAdapter.ts +7 -3
- package/fixtures/globals.d.ts +1 -1
- package/fixtures/runners/binary.ts +5 -2
- package/fixtures/runners/index.ts +2 -1
- package/fixtures/runners/source.ts +1 -1
- package/fixtures/utils/file.ts +20 -16
- package/fixtures/utils/test.ts +19 -19
- package/mocks/pdf-page/input/.yfm +7 -0
- package/mocks/pdf-page/input/index.md +6 -0
- package/mocks/pdf-page/input/page1.md +3 -0
- package/mocks/pdf-page/input/page2.md +5 -0
- package/mocks/pdf-page/input/page3.md +1 -0
- package/mocks/pdf-page/input/toc.yaml +15 -0
- package/mocks/preprocess/input/autotitle.md +3 -0
- package/mocks/preprocess/input/includes/level1.md +9 -0
- package/mocks/preprocess/input/includes/level11.md +1 -0
- package/mocks/preprocess/input/includes/sub/level2.md +7 -0
- package/mocks/preprocess/input/level0.md +7 -0
- package/mocks/preprocess/input/level1/level1.md +7 -0
- package/mocks/preprocess/input/level1/level2/level2.md +6 -0
- package/mocks/preprocess/input/level1/toc.yaml +5 -0
- package/mocks/preprocess/input/toc.yaml +8 -0
- package/package.json +1 -1
package/e2e/metadata.spec.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {describe, it} from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {TestAdapter, compareDirectories, getTestPaths} from '../fixtures';
|
|
4
|
+
|
|
5
|
+
describe('Pdf page mode', () => {
|
|
6
|
+
it('transforms links correctly', async () => {
|
|
7
|
+
const {inputPath, outputPath} = getTestPaths('mocks/pdf-page');
|
|
8
|
+
|
|
9
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
10
|
+
md2md: false,
|
|
11
|
+
md2html: true,
|
|
12
|
+
args: '-j2',
|
|
13
|
+
});
|
|
14
|
+
await compareDirectories(outputPath);
|
|
15
|
+
});
|
|
16
|
+
});
|
package/e2e/preprocess.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, test} from 'vitest';
|
|
2
|
+
|
|
2
3
|
import {TestAdapter, compareDirectories, getTestPaths} from '../fixtures';
|
|
3
4
|
|
|
4
5
|
const generateFilesYamlTestTemplate = (
|
|
@@ -9,7 +10,7 @@ const generateFilesYamlTestTemplate = (
|
|
|
9
10
|
test(testTitle, async () => {
|
|
10
11
|
const {inputPath, outputPath} = getTestPaths(testRootPath);
|
|
11
12
|
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
12
|
-
md2md:true,
|
|
13
|
+
md2md: true,
|
|
13
14
|
md2html: false,
|
|
14
15
|
args: args.join(' '),
|
|
15
16
|
});
|
|
@@ -24,14 +25,16 @@ const generateFilesYamlTestTemplate = (
|
|
|
24
25
|
|
|
25
26
|
describe('Preprocess', () => {
|
|
26
27
|
generateFilesYamlTestTemplate('HashIncludes=true,Autotitles=false', 'mocks/preprocess', [
|
|
27
|
-
'--no-merge-autotitles'
|
|
28
|
+
'--no-merge-autotitles',
|
|
28
29
|
]);
|
|
29
30
|
|
|
30
31
|
generateFilesYamlTestTemplate('HashIncludes=true,Autotitles=true', 'mocks/preprocess');
|
|
31
32
|
|
|
32
|
-
generateFilesYamlTestTemplate(
|
|
33
|
-
'
|
|
34
|
-
|
|
33
|
+
generateFilesYamlTestTemplate(
|
|
34
|
+
'HashIncludes=true,Autotitles=true,Svg=true',
|
|
35
|
+
'mocks/preprocess',
|
|
36
|
+
['--merge-svg'],
|
|
37
|
+
);
|
|
35
38
|
|
|
36
39
|
// generateFilesYamlTestTemplate('Nested toc restricted access', 'mocks/preprocess/test3');
|
|
37
40
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest';
|
|
2
|
+
|
|
2
3
|
import {TestAdapter, getTestPaths} from '../fixtures';
|
|
3
4
|
|
|
4
5
|
describe('Redirects validation', () => {
|
|
@@ -38,7 +39,9 @@ describe('Redirects validation', () => {
|
|
|
38
39
|
});
|
|
39
40
|
|
|
40
41
|
it('should emit an error when a redirect is malformed', async () => {
|
|
41
|
-
const {inputPath, outputPath} = getTestPaths(
|
|
42
|
+
const {inputPath, outputPath} = getTestPaths(
|
|
43
|
+
'mocks/redirects-validation/malformed-redirect',
|
|
44
|
+
);
|
|
42
45
|
|
|
43
46
|
const report = await TestAdapter.build.run(inputPath, outputPath, ['-f', 'md']);
|
|
44
47
|
|
|
@@ -54,8 +57,6 @@ describe('Redirects validation', () => {
|
|
|
54
57
|
const report = await TestAdapter.build.run(inputPath, outputPath, ['-f', 'md']);
|
|
55
58
|
|
|
56
59
|
expect(report.code).toBe(1);
|
|
57
|
-
expect(report.errors).toContainEqual(
|
|
58
|
-
expect.stringMatching(/Parameters must be different/),
|
|
59
|
-
);
|
|
60
|
+
expect(report.errors).toContainEqual(expect.stringMatching(/Parameters must be different/));
|
|
60
61
|
});
|
|
61
62
|
});
|
package/e2e/regression.test.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import {describe, test} from 'vitest';
|
|
2
|
+
|
|
2
3
|
import {TestAdapter, compareDirectories, getTestPaths} from '../fixtures';
|
|
3
4
|
|
|
4
|
-
const generateFilesYamlTestTemplate = (
|
|
5
|
-
testTitle: string,
|
|
6
|
-
testRootPath: string
|
|
7
|
-
) => {
|
|
5
|
+
const generateFilesYamlTestTemplate = (testTitle: string, testRootPath: string) => {
|
|
8
6
|
test(testTitle, async () => {
|
|
9
7
|
const {inputPath, outputPath} = getTestPaths(testRootPath);
|
|
10
|
-
await TestAdapter.testBuildPass(inputPath, outputPath, {md2md:true});
|
|
8
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {md2md: true});
|
|
11
9
|
await compareDirectories(outputPath);
|
|
12
10
|
});
|
|
13
11
|
};
|
package/e2e/rtl.spec.ts
CHANGED
package/e2e/search.test.ts
CHANGED
package/e2e/single-page.spec.ts
CHANGED
package/e2e/translation.spec.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type {TranslateRunArgs} from '../fixtures';
|
|
2
|
+
|
|
1
3
|
import {describe, test} from 'vitest';
|
|
2
|
-
|
|
4
|
+
|
|
5
|
+
import {TestAdapter, compareDirectories, getTestPaths} from '../fixtures';
|
|
3
6
|
|
|
4
7
|
const generateMapTestTemplate = (
|
|
5
8
|
testTitle: string,
|
|
@@ -46,9 +49,17 @@ const buildFilesYamlTestTemplate = (
|
|
|
46
49
|
};
|
|
47
50
|
|
|
48
51
|
describe('Translate command', () => {
|
|
49
|
-
buildFilesYamlTestTemplate(
|
|
52
|
+
buildFilesYamlTestTemplate(
|
|
53
|
+
'build translated md files and remove no-translate directives',
|
|
54
|
+
'mocks/translation/no-translate',
|
|
55
|
+
{md2md: true},
|
|
56
|
+
);
|
|
50
57
|
|
|
51
|
-
buildFilesYamlTestTemplate(
|
|
58
|
+
buildFilesYamlTestTemplate(
|
|
59
|
+
'build translated static files and remove no-translate directives',
|
|
60
|
+
'mocks/translation/no-translate',
|
|
61
|
+
{md2html: true},
|
|
62
|
+
);
|
|
52
63
|
|
|
53
64
|
generateFilesYamlTestTemplate('extract openapi spec files', 'mocks/translation/openapi', {
|
|
54
65
|
subcommand: 'extract',
|
|
@@ -66,7 +77,7 @@ describe('Translate command', () => {
|
|
|
66
77
|
subcommand: 'extract',
|
|
67
78
|
source: 'ru-RU',
|
|
68
79
|
target: 'es-ES',
|
|
69
|
-
additionalArgs: '--filter'
|
|
80
|
+
additionalArgs: '--filter',
|
|
70
81
|
});
|
|
71
82
|
|
|
72
83
|
generateMapTestTemplate(
|
|
@@ -80,7 +91,7 @@ describe('Translate command', () => {
|
|
|
80
91
|
},
|
|
81
92
|
);
|
|
82
93
|
|
|
83
|
-
const vars = {skip: 'prod'}
|
|
94
|
+
const vars = {skip: 'prod'};
|
|
84
95
|
generateMapTestTemplate(
|
|
85
96
|
'filter files on extract with extra vars option',
|
|
86
97
|
'mocks/translation/dir-files',
|
|
@@ -98,7 +109,7 @@ describe('Translate command', () => {
|
|
|
98
109
|
{
|
|
99
110
|
subcommand: 'extract',
|
|
100
111
|
source: 'ru-RU',
|
|
101
|
-
target: 'es-ES',
|
|
112
|
+
target: 'es-ES',
|
|
102
113
|
},
|
|
103
114
|
false,
|
|
104
115
|
);
|
package/fixtures/cliAdapter.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {Runner
|
|
1
|
+
import type {Runner} from './runners';
|
|
2
|
+
|
|
3
|
+
import {createRunner} from './runners';
|
|
2
4
|
import {cleanupDirectory} from './utils/file';
|
|
3
5
|
|
|
4
6
|
export interface BuildRunArgs {
|
|
@@ -76,8 +78,10 @@ export class CliTestAdapter {
|
|
|
76
78
|
const tasks = [];
|
|
77
79
|
|
|
78
80
|
if (md2md && md2html) {
|
|
79
|
-
tasks.push(() => this.build.run(inputPath, outputPath,[...baseArgs, '-f', 'md']));
|
|
80
|
-
tasks.push(() =>
|
|
81
|
+
tasks.push(() => this.build.run(inputPath, outputPath, [...baseArgs, '-f', 'md']));
|
|
82
|
+
tasks.push(() =>
|
|
83
|
+
this.build.run(inputPath, `${outputPath}-html`, [...baseArgs, '-f', 'html']),
|
|
84
|
+
);
|
|
81
85
|
} else if (md2md) {
|
|
82
86
|
tasks.push(() => this.build.run(inputPath, outputPath, [...baseArgs, '-f', 'md']));
|
|
83
87
|
} else {
|
package/fixtures/globals.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {Runner} from './types';
|
|
1
|
+
import type {Runner} from './types';
|
|
2
|
+
|
|
2
3
|
import {execa} from 'execa';
|
|
3
4
|
import strip from 'strip-ansi';
|
|
4
5
|
|
|
@@ -20,6 +21,7 @@ export class BinaryRunner implements Runner {
|
|
|
20
21
|
const restLog = fillLog(/^(?!INFO|WARN|ERR)/, stderr);
|
|
21
22
|
if (restLog.length) {
|
|
22
23
|
for (const line of restLog) {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
23
25
|
console.log(line);
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -29,7 +31,8 @@ export class BinaryRunner implements Runner {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
function fillLog(filter: RegExp, source: string) {
|
|
32
|
-
return source
|
|
34
|
+
return source
|
|
35
|
+
.split('\n')
|
|
33
36
|
.map((line) => strip(line).trim())
|
|
34
37
|
.filter(Boolean)
|
|
35
38
|
.filter((line) => line.match(filter));
|
|
@@ -7,7 +7,8 @@ import {Runner} from './types';
|
|
|
7
7
|
export {Runner};
|
|
8
8
|
|
|
9
9
|
export function createRunner(): Runner {
|
|
10
|
-
const binaryPath =
|
|
10
|
+
const binaryPath =
|
|
11
|
+
process.env.DIPLODOC_BINARY_PATH || resolve(__dirname, '../../../build/index.js');
|
|
11
12
|
|
|
12
13
|
if (binaryPath) {
|
|
13
14
|
return new BinaryRunner(binaryPath);
|
package/fixtures/utils/file.ts
CHANGED
|
@@ -2,29 +2,29 @@ import {readFileSync} from 'node:fs';
|
|
|
2
2
|
import {rm} from 'node:fs/promises';
|
|
3
3
|
import {join, resolve} from 'node:path';
|
|
4
4
|
import {glob} from 'glob';
|
|
5
|
-
import {bundleless, hashless, platformless} from './test';
|
|
6
5
|
import {expect} from 'vitest';
|
|
7
6
|
|
|
7
|
+
import {bundleless, hashless, platformless} from './test';
|
|
8
|
+
|
|
8
9
|
const SYSTEM_DIRS = ['_bundle/', '_search/'];
|
|
9
10
|
|
|
10
11
|
export function getFileContent(filePath: string) {
|
|
11
12
|
return platformless(bundleless(readFileSync(filePath, 'utf8')));
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
const uselessFile = (file: string, dirs: string[]) =>
|
|
15
|
-
!dirs.some((part) => file.includes(part));
|
|
15
|
+
const uselessFile = (file: string, dirs: string[]) => !dirs.some((part) => file.includes(part));
|
|
16
16
|
|
|
17
17
|
export function stripSystemLinks(content: string) {
|
|
18
|
-
const dirPattern = SYSTEM_DIRS.map(d => d.replace('/', '\\/')).join('|');
|
|
18
|
+
const dirPattern = SYSTEM_DIRS.map((d) => d.replace('/', '\\/')).join('|');
|
|
19
19
|
|
|
20
20
|
content = content.replace(
|
|
21
21
|
new RegExp(`<script[^>]+src="(?:${dirPattern})[^"]*"[^>]*></script>`, 'g'),
|
|
22
|
-
''
|
|
22
|
+
'',
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
content = content.replace(
|
|
26
26
|
new RegExp(`<link[^>]+href="(?:${dirPattern})[^"]*"[^>]*\\/?>`, 'g'),
|
|
27
|
-
''
|
|
27
|
+
'',
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
content = content.replace(/^[ \t]*\r?\n/gm, '');
|
|
@@ -45,34 +45,38 @@ export async function compareDirectories(
|
|
|
45
45
|
nodir: true,
|
|
46
46
|
posix: true,
|
|
47
47
|
})
|
|
48
|
-
)
|
|
48
|
+
)
|
|
49
|
+
.map(bundleless)
|
|
50
|
+
.sort();
|
|
49
51
|
|
|
50
52
|
let filesForSnapshot;
|
|
51
53
|
|
|
52
54
|
if (checkBundle) {
|
|
53
55
|
filesForSnapshot = filesFromOutput;
|
|
54
56
|
} else {
|
|
55
|
-
filesForSnapshot = filesFromOutput.filter(file => uselessFile(file, SYSTEM_DIRS));
|
|
57
|
+
filesForSnapshot = filesFromOutput.filter((file) => uselessFile(file, SYSTEM_DIRS));
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
// Here we sort the order of the included files after all processing
|
|
59
61
|
// This is necessary for better test stability
|
|
60
62
|
// We do not care in what order these files were received and processed
|
|
61
63
|
// We sort only the final list and put it in the snapshot
|
|
62
|
-
filesForSnapshot = filesForSnapshot.map(hashless).sort();
|
|
64
|
+
filesForSnapshot = filesForSnapshot.map(hashless).sort();
|
|
63
65
|
|
|
64
66
|
expect(JSON.stringify(filesForSnapshot, null, 2)).toMatchSnapshot('filelist');
|
|
65
67
|
|
|
66
68
|
if (!ignoreFileContent) {
|
|
67
|
-
filesFromOutput
|
|
68
|
-
|
|
69
|
+
filesFromOutput
|
|
70
|
+
.filter((file) => uselessFile(file, ['_assets/', ...SYSTEM_DIRS]))
|
|
71
|
+
.forEach((filePath) => {
|
|
72
|
+
let content = getFileContent(resolve(outputPath, filePath));
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
if (!checkBundle && filePath.endsWith('.html')) {
|
|
75
|
+
content = stripSystemLinks(content);
|
|
76
|
+
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
expect(content).toMatchSnapshot();
|
|
79
|
+
});
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
package/fixtures/utils/test.ts
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
|
|
2
1
|
import assets from '@diplodoc/cli/manifest';
|
|
3
2
|
|
|
4
3
|
export function platformless(text: string): string {
|
|
5
4
|
let index = 1;
|
|
6
5
|
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
return (
|
|
7
|
+
hashless(text)
|
|
8
|
+
.replace(/\r\n/g, '\n')
|
|
9
|
+
// Fix for XML equiv-text attributes in Windows - handle various patterns
|
|
10
|
+
.replace(/equiv-text="[\r\n]+ "/g, 'equiv-text=" "')
|
|
11
|
+
.replace(/equiv-text="[\r\n]+&#10;"/g, 'equiv-text="&#10;"')
|
|
12
|
+
// Also normalize any other attributes that might have line ending issues
|
|
13
|
+
.replace(/(ctype|id)="[\r\n]+(.*?)"/g, '$1="$2"')
|
|
14
|
+
.replace(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/g, 'UUID')
|
|
15
|
+
.replace(
|
|
16
|
+
/(content"?[:=]{1}[" ]{1}Diplodoc.*? )v\d+\.\d+\.\d+(?:-[\w-]+)?/g,
|
|
17
|
+
`$1vDIPLODOC-VERSION`,
|
|
18
|
+
)
|
|
19
|
+
.replace(/(\\(?![/"'])){1,2}/g, '/')
|
|
20
|
+
.replace(
|
|
21
|
+
/id=\\"inline-code-id-[a-zA-Z0-9]{8}\\"/g,
|
|
22
|
+
() => `id="inline-code-id-${index++}"`,
|
|
23
|
+
)
|
|
24
|
+
);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export function hashless(text: string): string {
|
|
@@ -45,4 +46,3 @@ export function bundleless(text: string): string {
|
|
|
45
46
|
|
|
46
47
|
return text;
|
|
47
48
|
}
|
|
48
|
-
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Page 3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Level 11 svg header 
|