@diplodoc/cli-tests 5.19.3 → 5.19.5
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/bin.mjs +39 -14
- package/e2e/__snapshots__/pdf-page.spec.ts.snap +35 -2
- package/e2e/errors.spec.ts +18 -2
- package/e2e/pdf-page.spec.ts +38 -0
- package/mocks/errors/max-asset-size/input/_images/large-image.png +0 -0
- package/mocks/errors/max-asset-size/input/index.md +5 -0
- package/mocks/errors/max-asset-size/input/toc.yaml +1 -0
- package/mocks/pdf-page/title-pages/input/.yfm +3 -0
- package/mocks/pdf-page/title-pages/input/__assets/start-page.css +4 -2
- package/mocks/pdf-page/title-pages/input/index.md +1 -1
- package/mocks/pdf-page/title-pages/input/pdf-titles/pdf-title-page2.md +0 -3
- package/package.json +1 -1
package/bin.mjs
CHANGED
|
@@ -7,22 +7,47 @@ import {createRequire} from 'node:module';
|
|
|
7
7
|
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
9
|
const vitestPath = require.resolve('vitest');
|
|
10
|
+
const configPath = resolve(dirname(fileURLToPath(import.meta.url)), 'vitest.config.ts');
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
let stdout = '';
|
|
13
|
+
let stderr = '';
|
|
14
|
+
|
|
15
|
+
const childProcess = execa(
|
|
12
16
|
join(dirname(vitestPath), 'vitest.mjs'),
|
|
13
|
-
[
|
|
14
|
-
'run',
|
|
15
|
-
'--config',
|
|
16
|
-
resolve(dirname(fileURLToPath(import.meta.url)), 'vitest.config.ts'),
|
|
17
|
-
...process.argv.slice(2),
|
|
18
|
-
],
|
|
17
|
+
['run', '--config', configPath, ...process.argv.slice(2)],
|
|
19
18
|
{
|
|
20
|
-
stdio: 'inherit',
|
|
21
|
-
env: {
|
|
22
|
-
|
|
23
|
-
NODE_ENV: 'test',
|
|
24
|
-
},
|
|
19
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
20
|
+
env: {...process.env, NODE_ENV: 'test'},
|
|
21
|
+
reject: false,
|
|
25
22
|
},
|
|
26
|
-
)
|
|
27
|
-
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
childProcess.stdout.on('data', (chunk) => {
|
|
26
|
+
const text = chunk.toString();
|
|
27
|
+
stdout += text;
|
|
28
|
+
process.stdout.write(chunk);
|
|
28
29
|
});
|
|
30
|
+
|
|
31
|
+
childProcess.stderr.on('data', (chunk) => {
|
|
32
|
+
const text = chunk.toString();
|
|
33
|
+
stderr += text;
|
|
34
|
+
process.stderr.write(chunk);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const result = await childProcess;
|
|
38
|
+
|
|
39
|
+
if (result.exitCode !== 0) {
|
|
40
|
+
const output = stdout + stderr;
|
|
41
|
+
const hasTimeout = /Test timed out|timed out in \d+ms/gi.test(output);
|
|
42
|
+
const exitCode = hasTimeout ? 124 : result.exitCode || 1;
|
|
43
|
+
|
|
44
|
+
const error = new Error(`Command failed with exit code ${result.exitCode}`);
|
|
45
|
+
error.exitCode = exitCode;
|
|
46
|
+
|
|
47
|
+
if (hasTimeout) {
|
|
48
|
+
const timeoutCount = (output.match(/Test timed out|timed out in \d+ms/gi) || []).length;
|
|
49
|
+
error.message += ` (${timeoutCount} timeout${timeoutCount > 1 ? 's' : ''} detected)`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
process.exit(exitCode);
|
|
53
|
+
}
|
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
+
exports[`Pdf generation with md2md phase, only files structure > Generates md2md content, then uses it for md2html render with pdf when .yfm options is specified > filelist 1`] = `
|
|
4
|
+
"[
|
|
5
|
+
".yfm",
|
|
6
|
+
"__assets/start-page.css",
|
|
7
|
+
"__images/mountain.jpg",
|
|
8
|
+
"__includes/include1-hash.md",
|
|
9
|
+
"index.md",
|
|
10
|
+
"page1.md",
|
|
11
|
+
"page2.md",
|
|
12
|
+
"pdf-titles/pdf-title-page1.md",
|
|
13
|
+
"pdf-titles/pdf-title-page2.md",
|
|
14
|
+
"toc.yaml"
|
|
15
|
+
]"
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
exports[`Pdf generation with md2md phase, only files structure > Generates md2md content, then uses it for md2html render with pdf when .yfm options is specified > filelist 2`] = `
|
|
19
|
+
"[
|
|
20
|
+
".yfm",
|
|
21
|
+
"__assets/start-page.css",
|
|
22
|
+
"__images/mountain.jpg",
|
|
23
|
+
"index.html",
|
|
24
|
+
"page1.html",
|
|
25
|
+
"page2.html",
|
|
26
|
+
"pdf/pdf-page-toc.js",
|
|
27
|
+
"pdf/pdf-page.html",
|
|
28
|
+
"pdf/pdf-page.json",
|
|
29
|
+
"toc.js"
|
|
30
|
+
]"
|
|
31
|
+
`;
|
|
32
|
+
|
|
3
33
|
exports[`Pdf page mode > creates a pdf folder when the .yfm option is specified > filelist 1`] = `
|
|
4
34
|
"[
|
|
5
35
|
"pdf-page-toc.js",
|
|
@@ -105,7 +135,7 @@ exports[`Pdf page with titles > Generates content for pdf genrator with title pa
|
|
|
105
135
|
<body class="g-root g-root_theme_light">
|
|
106
136
|
<div id="root"></div>
|
|
107
137
|
<script type="application/json" id="diplodoc-state">
|
|
108
|
-
{"data":{"leading":false,"pdfTitlePages":{"content":"<div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 id=\\"pdf-titles_pdf-title-page1_pdf-title-page-1\\" data-original-article=\\"./pdf-titles/pdf-title-page1.html\\"><a href=\\"#pdf-titles_pdf-title-page1_pdf-title-page-1\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Pdf title page 1</span></a>Pdf title page 1<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#pdf-titles_pdf-title-page1\\" id=\\"pdf-titles_pdf-title-page1\\"></a></h2>/n<p>Should be able to use variables pdf</p>/n<p>Should be able to use link to other pages <a href=\\"#page1\\">test</a></p>/n<p>Should be able to use inlcudes</p>/n<h4 id=\\"pdf-titles_pdf-title-page1_include-pdf-title\\"><a href=\\"#pdf-titles_pdf-title-page1_include-pdf-title\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Include Pdf title</span></a>Include Pdf title</h4>/n<p>Should be able to resolve liquid syntax</p>/n<p>should be visible</p>/n</div><div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><
|
|
138
|
+
{"data":{"leading":false,"pdfTitlePages":{"content":"<div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 id=\\"pdf-titles_pdf-title-page1_pdf-title-page-1\\" data-original-article=\\"./pdf-titles/pdf-title-page1.html\\"><a href=\\"#pdf-titles_pdf-title-page1_pdf-title-page-1\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Pdf title page 1</span></a>Pdf title page 1<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#pdf-titles_pdf-title-page1\\" id=\\"pdf-titles_pdf-title-page1\\"></a></h2>/n<p>Should be able to use variables pdf</p>/n<p>Should be able to use link to other pages <a href=\\"#page1\\">test</a></p>/n<p>Should be able to use inlcudes</p>/n<h4 id=\\"pdf-titles_pdf-title-page1_include-pdf-title\\"><a href=\\"#pdf-titles_pdf-title-page1_include-pdf-title\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Include Pdf title</span></a>Include Pdf title</h4>/n<p>Should be able to resolve liquid syntax</p>/n<p>should be visible</p>/n</div><div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><div class=\\"pdf-title-page-wrapper\\">/n <p>Lorem ipsum title page with var pdf</p>/n</div></div>","pageCount":2},"cssLink":["_bundle/search-css-0","_bundle/app-css-1","_bundle/search-css-2","_bundle/search-css-3","_bundle/search-css-4"],"html":"<div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 data-original-article=\\"page1.html\\">Page 1<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#page1\\" id=\\"page1\\"></a></h2><p>Page 1 content</p>/n</div><div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 data-original-article=\\"page2.html\\">Page 2<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#page2\\" id=\\"page2\\"></a></h2><p>Page 2 content</p>/n</div>","headings":[],"meta":{"metadata":[{"name":"generator","content":"Diplodoc Platform vDIPLODOC-VERSION"}],"style":["__assets/start-page.css"]},"title":"Pdf title pages"},"router":{"pathname":"pdf-page","depth":1,"base":"./"},"lang":"ru","langs":["ru"],"viewerInterface":{"toc":true,"search":true,"feedback":true}}
|
|
109
139
|
</script>
|
|
110
140
|
<script type="application/javascript">
|
|
111
141
|
const data = document.querySelector('script#diplodoc-state');
|
|
@@ -119,7 +149,7 @@ exports[`Pdf page with titles > Generates content for pdf genrator with title pa
|
|
|
119
149
|
</html>"
|
|
120
150
|
`;
|
|
121
151
|
|
|
122
|
-
exports[`Pdf page with titles > Generates content for pdf genrator with title pages 3`] = `"{"data":{"leading":false,"pdfTitlePages":{"content":"<div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 id=\\"pdf-titles_pdf-title-page1_pdf-title-page-1\\" data-original-article=\\"./pdf-titles/pdf-title-page1.html\\"><a href=\\"#pdf-titles_pdf-title-page1_pdf-title-page-1\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Pdf title page 1</span></a>Pdf title page 1<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#pdf-titles_pdf-title-page1\\" id=\\"pdf-titles_pdf-title-page1\\"></a></h2>/n<p>Should be able to use variables pdf</p>/n<p>Should be able to use link to other pages <a href=\\"#page1\\">test</a></p>/n<p>Should be able to use inlcudes</p>/n<h4 id=\\"pdf-titles_pdf-title-page1_include-pdf-title\\"><a href=\\"#pdf-titles_pdf-title-page1_include-pdf-title\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Include Pdf title</span></a>Include Pdf title</h4>/n<p>Should be able to resolve liquid syntax</p>/n<p>should be visible</p>/n</div><div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><
|
|
152
|
+
exports[`Pdf page with titles > Generates content for pdf genrator with title pages 3`] = `"{"data":{"leading":false,"pdfTitlePages":{"content":"<div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 id=\\"pdf-titles_pdf-title-page1_pdf-title-page-1\\" data-original-article=\\"./pdf-titles/pdf-title-page1.html\\"><a href=\\"#pdf-titles_pdf-title-page1_pdf-title-page-1\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Pdf title page 1</span></a>Pdf title page 1<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#pdf-titles_pdf-title-page1\\" id=\\"pdf-titles_pdf-title-page1\\"></a></h2>/n<p>Should be able to use variables pdf</p>/n<p>Should be able to use link to other pages <a href=\\"#page1\\">test</a></p>/n<p>Should be able to use inlcudes</p>/n<h4 id=\\"pdf-titles_pdf-title-page1_include-pdf-title\\"><a href=\\"#pdf-titles_pdf-title-page1_include-pdf-title\\" class=\\"yfm-anchor\\" aria-hidden=\\"true\\"><span class=\\"visually-hidden\\" data-no-index=\\"true\\">Include Pdf title</span></a>Include Pdf title</h4>/n<p>Should be able to resolve liquid syntax</p>/n<p>should be visible</p>/n</div><div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><div class=\\"pdf-title-page-wrapper\\">/n <p>Lorem ipsum title page with var pdf</p>/n</div></div>","pageCount":2},"cssLink":["_bundle/search-css-0","_bundle/app-css-1","_bundle/search-css-2","_bundle/search-css-3","_bundle/search-css-4"],"html":"<div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 data-original-article=\\"page1.html\\">Page 1<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#page1\\" id=\\"page1\\"></a></h2><p>Page 1 content</p>/n</div><div class=\\"pdf-page-wrapper\\" data-page-break=\\"true\\"><h2 data-original-article=\\"page2.html\\">Page 2<a class=\\"yfm-anchor\\" aria-hidden=\\"true\\" href=\\"#page2\\" id=\\"page2\\"></a></h2><p>Page 2 content</p>/n</div>","headings":[],"meta":{"metadata":[{"name":"generator","content":"Diplodoc Platform vDIPLODOC-VERSION"}],"style":["__assets/start-page.css"]},"title":"Pdf title pages","toc":{"title":"Pdf title pages","href":"index.html","pdf":{"startPages":["./pdf-titles/pdf-title-page1.md","./pdf-titles/pdf-title-page2.md"]},"items":[{"name":"Title 1","href":"page1.html","id":"UUID"},{"name":"Title 2","href":"page2.html","id":"UUID"}],"path":"toc.yaml","id":"UUID"}},"router":{"pathname":"pdf-page","depth":1,"base":"./"},"lang":"ru","langs":["ru"],"viewerInterface":{"toc":true,"search":true,"feedback":true}}"`;
|
|
123
153
|
|
|
124
154
|
exports[`Pdf page with titles > Generates pdf title pages as regular entries for debug purpose > filelist 1`] = `
|
|
125
155
|
"[
|
|
@@ -131,6 +161,9 @@ exports[`Pdf page with titles > Generates pdf title pages as regular entries for
|
|
|
131
161
|
"page2.html",
|
|
132
162
|
"pdf-titles/pdf-title-page1.html",
|
|
133
163
|
"pdf-titles/pdf-title-page2.html",
|
|
164
|
+
"pdf/pdf-page-toc.js",
|
|
165
|
+
"pdf/pdf-page.html",
|
|
166
|
+
"pdf/pdf-page.json",
|
|
134
167
|
"toc.js"
|
|
135
168
|
]"
|
|
136
169
|
`;
|
package/e2e/errors.spec.ts
CHANGED
|
@@ -9,15 +9,21 @@ type TestResult = {
|
|
|
9
9
|
html: Report;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
function test(path: string, expect: Function) {
|
|
12
|
+
function test(path: string, expect: Function, additionalArgs: string[] = []) {
|
|
13
13
|
it(path, async () => {
|
|
14
14
|
const {inputPath, outputPath} = getTestPaths(path);
|
|
15
15
|
|
|
16
|
-
const md = await TestAdapter.build.run(inputPath, outputPath, [
|
|
16
|
+
const md = await TestAdapter.build.run(inputPath, outputPath, [
|
|
17
|
+
'-j2',
|
|
18
|
+
'-f',
|
|
19
|
+
'md',
|
|
20
|
+
...additionalArgs,
|
|
21
|
+
]);
|
|
17
22
|
const html = await TestAdapter.build.run(inputPath, outputPath + '-html', [
|
|
18
23
|
'-j2',
|
|
19
24
|
'-f',
|
|
20
25
|
'html',
|
|
26
|
+
...additionalArgs,
|
|
21
27
|
]);
|
|
22
28
|
return expect({md, html});
|
|
23
29
|
});
|
|
@@ -42,6 +48,16 @@ describe('Errors', () => {
|
|
|
42
48
|
]);
|
|
43
49
|
});
|
|
44
50
|
|
|
51
|
+
test(
|
|
52
|
+
'mocks/errors/max-asset-size',
|
|
53
|
+
({md}: TestResult) => {
|
|
54
|
+
expectErrors(md, [
|
|
55
|
+
'ERR YFM013 _images/large-image.png: YFM013 / File asset limit exceeded: 3057 (limit is 2048)',
|
|
56
|
+
]);
|
|
57
|
+
},
|
|
58
|
+
['--max-asset-size', '2K'],
|
|
59
|
+
);
|
|
60
|
+
|
|
45
61
|
it('translate extract with filtered links', async () => {
|
|
46
62
|
const {inputPath, outputPath} = getTestPaths('mocks/errors/extract-filtered-link');
|
|
47
63
|
|
package/e2e/pdf-page.spec.ts
CHANGED
|
@@ -23,6 +23,37 @@ const generateMapTestTemplate = (
|
|
|
23
23
|
});
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
const generateMd2mdTestTemplate = async (testTitle: string, testRootPath: string) => {
|
|
27
|
+
test(testTitle, async () => {
|
|
28
|
+
const {inputPath, outputPath} = getTestPaths(testRootPath);
|
|
29
|
+
|
|
30
|
+
await TestAdapter.testBuildPass(inputPath, outputPath, {
|
|
31
|
+
md2md: true,
|
|
32
|
+
md2html: false,
|
|
33
|
+
args: '--allow-custom-resources', // this is common arg in arc ci for md2md
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await compareDirectories(outputPath, true);
|
|
37
|
+
|
|
38
|
+
const midOutputFolder = 'final-output';
|
|
39
|
+
const finalOutputPath = outputPath
|
|
40
|
+
.split('/')
|
|
41
|
+
.slice(0, -1)
|
|
42
|
+
.concat(midOutputFolder)
|
|
43
|
+
.join('/');
|
|
44
|
+
|
|
45
|
+
await TestAdapter.testBuildPass(outputPath, finalOutputPath, {
|
|
46
|
+
md2md: false,
|
|
47
|
+
md2html: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await compareDirectories(finalOutputPath, true);
|
|
51
|
+
|
|
52
|
+
await cleanupDirectory(outputPath);
|
|
53
|
+
await cleanupDirectory(finalOutputPath);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
26
57
|
describe('Pdf page mode', () => {
|
|
27
58
|
generateMapTestTemplate(
|
|
28
59
|
'creates a pdf folder when the --pdf flag is specified',
|
|
@@ -52,3 +83,10 @@ describe('Pdf page with titles', () => {
|
|
|
52
83
|
true,
|
|
53
84
|
);
|
|
54
85
|
});
|
|
86
|
+
|
|
87
|
+
describe('Pdf generation with md2md phase, only files structure', () => {
|
|
88
|
+
generateMd2mdTestTemplate(
|
|
89
|
+
'Generates md2md content, then uses it for md2html render with pdf when .yfm options is specified',
|
|
90
|
+
'mocks/pdf-page/title-pages',
|
|
91
|
+
);
|
|
92
|
+
});
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
href: index.md
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
align-items: center;
|
|
6
6
|
background-color: grey;
|
|
7
7
|
padding: 20px;
|
|
8
|
-
height:
|
|
8
|
+
height: 100vh;
|
|
9
|
+
background-image: url(../__images/mountain.jpg);
|
|
10
|
+
background-size: cover;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
img {
|
|
12
14
|
width: 100px;
|
|
13
15
|
height: 100px;
|
|
14
|
-
}
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
# PDF mock index
|
|
1
|
+
# PDF mock index
|