Skip to content

Commit

Permalink
chore: rewrite e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Dec 21, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
edmorley Ed Morley
1 parent 57cef40 commit 107e487
Showing 77 changed files with 1,205 additions and 939 deletions.
4 changes: 4 additions & 0 deletions src/resolvers/md2html.ts
Original file line number Diff line number Diff line change
@@ -50,6 +50,10 @@ export async function resolveMd2HTML(options: ResolverOptions): Promise<ResolveM
const transformFn: Function = FileTransformer[fileExtension];
const {result} = transformFn(content, {path: inputPath});

if (result.html) {
result.html = result.html.replace(/\n+/gm, '');
}

const updatedMetadata =
metadata && metadata.isContributorsEnabled
? await getUpdatedMetadata(metadata, content, result?.meta)
2 changes: 1 addition & 1 deletion src/utils/markup.ts
Original file line number Diff line number Diff line change
@@ -137,7 +137,7 @@ export function joinSinglePageResults(
root: string,
tocDir: string,
): string {
const delimeter = `${сarriage}${сarriage}<hr class="yfm-page__delimeter">${сarriage}${сarriage}`;
const delimeter = `<hr class="yfm-page__delimeter">`;
return singlePageResults
.filter(({content}) => content)
.map(({content, path, title}) =>
8 changes: 0 additions & 8 deletions src/utils/path.ts
Original file line number Diff line number Diff line change
@@ -14,11 +14,3 @@ export function convertBackSlashToSlash(path: string): string {

return path;
}

export function convertSlashToWindowsBackSlashes(path: string): string {
if (process.platform === Platforms.WINDOWS) {
return path.replace(/\//g, '\\\\');
}

return path;
}
15 changes: 10 additions & 5 deletions src/utils/singlePage.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import {parse} from 'node-html-parser';
import {relative, resolve, sep} from 'path';
import {resolveRelativePath} from '@diplodoc/transform/lib/utilsFS';
import url from 'url';
import _ from 'lodash';
import escape from 'lodash/escapeRegExp';

import {isExternalHref} from './url';

@@ -22,6 +22,11 @@ interface PreprocessSinglePageOptions {

const HEADERS_SELECTOR = 'h1, h2, h3, h4, h5, h6';

function toUrl(path: string) {
// replace windows backslashes
return path.replace(new RegExp(escape(sep), 'g'), '/');
}

function getNewNode(options: ModifyNode): HTMLElement | null {
const {rawTagName, innerHTML, attrEntries} = options;

@@ -92,7 +97,7 @@ export function replaceLinks(rootEl: HTMLElement, options: PreprocessSinglePageO
}
}

node.setAttribute('href', preparedHref);
node.setAttribute('href', toUrl(preparedHref));
});
}

@@ -110,7 +115,7 @@ export function replaceImages(rootEl: HTMLElement, options: PreprocessSinglePage
const linkFullPath = resolveRelativePath(resolvedPath, href);
const preparedHref = relative(tocDir, linkFullPath);

node.setAttribute('src', preparedHref);
node.setAttribute('src', toUrl(preparedHref));
});
}

@@ -129,7 +134,7 @@ function prepareAnchorAttrs(node: HTMLElement, pageId: string) {
for (const [name, value] of Object.entries(node.attributes)) {
const preparedValue = prepareAnchorAttr(name, value, pageId);

node.setAttribute(name, preparedValue);
node.setAttribute(name, toUrl(preparedValue));
}
}

@@ -197,7 +202,7 @@ export function getSinglePageAnchorId(args: {
resultAnchor = resultAnchor
.replace(root, '')
.replace(/\.(md|ya?ml|html)$/i, '')
.replace(new RegExp(_.escapeRegExp(sep), 'gi'), '_');
.replace(new RegExp(escape(sep), 'gi'), '_');

if (hash) {
resultAnchor = resultAnchor + '_' + hash.slice(1);
63 changes: 63 additions & 0 deletions tests/e2e/__snapshots__/generate-map.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Generate map for project with external links in toc 1`] = `
"{
"files": [
"ru/folder1/folder2/a1",
"ru/folder1/a1",
"ru/",
"ru/settings",
"ru/plugins/",
"ru/project/"
]
}"
`;

exports[`Generate map for project with multiple language 1`] = `
"{
"files": [
"en/",
"en/settings",
"en/plugins/",
"en/plugins/import",
"en/project/",
"en/project/config",
"ru/",
"ru/settings",
"ru/plugins/",
"ru/plugins/import",
"ru/project/",
"ru/project/config"
]
}"
`;

exports[`Generate map for project with single language and toc include - only md2html 1`] = `
"{
"files": [
"ru/folder1/folder2/a1",
"ru/folder1/a1",
"ru/",
"ru/settings",
"ru/plugins/",
"ru/plugins/import",
"ru/project/",
"ru/project/config"
]
}"
`;

exports[`Generate map for project with single language and toc include 1`] = `
"{
"files": [
"ru/folder1/folder2/a1",
"ru/folder1/a1",
"ru/",
"ru/settings",
"ru/plugins/",
"ru/plugins/import",
"ru/project/",
"ru/project/config"
]
}"
`;
Loading

0 comments on commit 107e487

Please sign in to comment.