@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.
- package/e2e/__snapshots__/bundles.spec.ts.snap +168 -0
- package/e2e/__snapshots__/load-custom-resources.spec.ts.snap +0 -94
- package/e2e/__snapshots__/metadata.spec.ts.snap +0 -43
- package/e2e/__snapshots__/regression.test.ts.snap +0 -191
- package/e2e/__snapshots__/rtl.spec.ts.snap +0 -98
- package/e2e/__snapshots__/search.test.ts.snap +0 -30
- package/e2e/__snapshots__/single-page.spec.ts.snap +0 -57
- package/e2e/__snapshots__/skip-html-extension.spec.ts.snap +0 -59
- package/e2e/__snapshots__/translation.spec.ts.snap +163 -1263
- package/e2e/bundles.spec.ts +15 -0
- package/fixtures/utils/file.ts +49 -6
- package/mocks/bundles/input/.yfm +13 -0
- package/mocks/bundles/input/index.md +12 -0
- package/mocks/bundles/input/page1.md +3 -0
- package/mocks/bundles/input/page2.md +5 -0
- package/mocks/bundles/input/toc.yaml +9 -0
- package/package.json +1 -1
|
@@ -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
|
+
});
|
package/fixtures/utils/file.ts
CHANGED
|
@@ -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
|
-
!
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|