mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 00:57:53 +02:00
refactor(v2): add typing for docs plugin (#1811)
* refactor(v2): add typing for docs plugin * nits
This commit is contained in:
parent
f671e6b437
commit
1591128cdd
25 changed files with 304 additions and 131 deletions
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import path from 'path';
|
||||
import pluginContentDocs from '../index';
|
||||
import {LoadContext} from '@docusaurus/types';
|
||||
|
||||
describe('loadDocs', () => {
|
||||
test('simple website', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'website');
|
||||
const siteConfig = {
|
||||
title: 'Hello',
|
||||
baseUrl: '/',
|
||||
url: 'https://docusaurus.io',
|
||||
};
|
||||
const context = {
|
||||
siteDir,
|
||||
siteConfig,
|
||||
} as LoadContext;
|
||||
const sidebarPath = path.join(siteDir, 'sidebars.json');
|
||||
const pluginPath = 'docs';
|
||||
const plugin = pluginContentDocs(context, {
|
||||
path: 'docs',
|
||||
sidebarPath,
|
||||
});
|
||||
const {docs: docsMetadata} = await plugin.loadContent();
|
||||
|
||||
expect(docsMetadata.hello).toEqual({
|
||||
category: 'Guides',
|
||||
id: 'hello',
|
||||
permalink: '/docs/hello',
|
||||
previous: 'foo/baz',
|
||||
previous_title: 'baz',
|
||||
sidebar: 'docs',
|
||||
source: path.join('@site', pluginPath, 'hello.md'),
|
||||
title: 'Hello, World !',
|
||||
description: `Hi, Endilie here :)`,
|
||||
});
|
||||
|
||||
expect(docsMetadata['foo/bar']).toEqual({
|
||||
category: 'Test',
|
||||
id: 'foo/bar',
|
||||
next: 'foo/baz',
|
||||
next_title: 'baz',
|
||||
permalink: '/docs/foo/bar',
|
||||
sidebar: 'docs',
|
||||
source: path.join('@site', pluginPath, 'foo', 'bar.md'),
|
||||
title: 'Bar',
|
||||
description: 'This is custom description',
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue