mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-14 09:37:37 +02:00
test: subdirectory doc file linking
This commit is contained in:
parent
06e243a77f
commit
8835ec0d60
3 changed files with 46 additions and 0 deletions
9
v1/lib/server/__tests__/__fixtures__/subdir/doc3.md
Normal file
9
v1/lib/server/__tests__/__fixtures__/subdir/doc3.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
id: doc3
|
||||
title: Document 3
|
||||
---
|
||||
|
||||
Test subdirectory file
|
||||
|
||||
### Replace this
|
||||
- [doc3](subdir/doc3.md)
|
|
@ -1,5 +1,14 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`mdToHtmlify transform link even in subdirectory 1`] = `
|
||||
"
|
||||
Test subdirectory file
|
||||
|
||||
### Replace this
|
||||
- [doc3](/docs/subdir/doc3)
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`mdToHtmlify transform nothing 1`] = `
|
||||
"
|
||||
Docusaurus is the best :)
|
||||
|
|
|
@ -50,8 +50,14 @@ const doc2 = fs.readFileSync(
|
|||
'utf8',
|
||||
);
|
||||
|
||||
const doc3 = fs.readFileSync(
|
||||
path.join(__dirname, '__fixtures__', 'subdir', 'doc3.md'),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
const rawContent1 = metadataUtils.extractMetadata(doc1).rawContent;
|
||||
const rawContent2 = metadataUtils.extractMetadata(doc2).rawContent;
|
||||
const rawContent3 = metadataUtils.extractMetadata(doc3).rawContent;
|
||||
|
||||
describe('mdToHtmlify', () => {
|
||||
const mdToHtml = metadataUtils.mdToHtml(Metadata, '/');
|
||||
|
@ -77,6 +83,28 @@ describe('mdToHtmlify', () => {
|
|||
expect(content2).toMatchSnapshot();
|
||||
expect(content2).not.toEqual(rawContent2);
|
||||
});
|
||||
|
||||
test('transform link even in subdirectory', () => {
|
||||
const customMetadata = {
|
||||
'subdir-doc3': {
|
||||
id: 'subdir-doc3',
|
||||
title: 'Document 3',
|
||||
source: 'subdir/doc3.md',
|
||||
permalink: 'docs/subdir/doc3.html',
|
||||
language: 'en',
|
||||
},
|
||||
};
|
||||
const customMdToHtml = metadataUtils.mdToHtml(customMetadata, '/');
|
||||
const content3 = docs.mdToHtmlify(
|
||||
rawContent3,
|
||||
customMdToHtml,
|
||||
customMetadata['subdir-doc3'],
|
||||
);
|
||||
expect(content3).toContain('/docs/subdir/doc3');
|
||||
expect(content3).not.toContain('subdir/doc3.md');
|
||||
expect(content3).toMatchSnapshot();
|
||||
expect(content3).not.toEqual(rawContent3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFile', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue