mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-31 07:18:59 +02:00
test: improve test coverage; properly test core client APIs (#6905)
* test: improve test coverage * fix
This commit is contained in:
parent
76cb012209
commit
d85cee576d
41 changed files with 1400 additions and 753 deletions
|
@ -0,0 +1,43 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`toGlobalDataVersion generates the right docs, sidebars, and metadata 1`] = `
|
||||
Object {
|
||||
"docs": Array [
|
||||
Object {
|
||||
"id": "main",
|
||||
"path": "/current/main",
|
||||
"sidebar": "tutorial",
|
||||
},
|
||||
Object {
|
||||
"id": "doc",
|
||||
"path": "/current/doc",
|
||||
"sidebar": "tutorial",
|
||||
},
|
||||
Object {
|
||||
"id": "/current/generated",
|
||||
"path": "/current/generated",
|
||||
"sidebar": "tutorial",
|
||||
},
|
||||
],
|
||||
"isLast": true,
|
||||
"label": "Label",
|
||||
"mainDocId": "main",
|
||||
"name": "current",
|
||||
"path": "/current",
|
||||
"sidebars": Object {
|
||||
"another": Object {
|
||||
"link": Object {
|
||||
"label": "Generated",
|
||||
"path": "/current/generated",
|
||||
},
|
||||
},
|
||||
"links": Object {},
|
||||
"tutorial": Object {
|
||||
"link": Object {
|
||||
"label": "main",
|
||||
"path": "/current/main",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
|
@ -0,0 +1,100 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {toGlobalDataVersion} from '../globalData';
|
||||
|
||||
describe('toGlobalDataVersion', () => {
|
||||
it('generates the right docs, sidebars, and metadata', () => {
|
||||
expect(
|
||||
toGlobalDataVersion({
|
||||
versionName: 'current',
|
||||
versionLabel: 'Label',
|
||||
isLast: true,
|
||||
versionPath: '/current',
|
||||
mainDocId: 'main',
|
||||
docs: [
|
||||
{
|
||||
unversionedId: 'main',
|
||||
permalink: '/current/main',
|
||||
sidebar: 'tutorial',
|
||||
},
|
||||
{
|
||||
unversionedId: 'doc',
|
||||
permalink: '/current/doc',
|
||||
sidebar: 'tutorial',
|
||||
},
|
||||
],
|
||||
sidebars: {
|
||||
another: [
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Generated',
|
||||
link: {
|
||||
type: 'generated-index',
|
||||
permalink: '/current/generated',
|
||||
},
|
||||
items: [
|
||||
{
|
||||
type: 'doc',
|
||||
id: 'doc',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
tutorial: [
|
||||
{
|
||||
type: 'doc',
|
||||
id: 'main',
|
||||
},
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Generated',
|
||||
link: {
|
||||
type: 'generated-index',
|
||||
permalink: '/current/generated',
|
||||
},
|
||||
items: [
|
||||
{
|
||||
type: 'doc',
|
||||
id: 'doc',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
links: [
|
||||
{
|
||||
type: 'link',
|
||||
href: 'foo',
|
||||
label: 'Foo',
|
||||
},
|
||||
{
|
||||
type: 'link',
|
||||
href: 'bar',
|
||||
label: 'Bar',
|
||||
},
|
||||
],
|
||||
},
|
||||
categoryGeneratedIndices: [
|
||||
{
|
||||
title: 'Generated',
|
||||
slug: '/current/generated',
|
||||
permalink: '/current/generated',
|
||||
sidebar: 'tutorial',
|
||||
},
|
||||
],
|
||||
versionBanner: 'unreleased',
|
||||
versionBadge: true,
|
||||
versionClassName: 'current-cls',
|
||||
tagsPath: '/current/tags',
|
||||
contentPath: '',
|
||||
contentPathLocalized: '',
|
||||
sidebarFilePath: '',
|
||||
routePriority: 0.5,
|
||||
}),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
|
@ -111,6 +111,27 @@ describe('getSlug', () => {
|
|||
).toBe('/dir with spâce/hey $hello/my dôc');
|
||||
});
|
||||
|
||||
it('throws for invalid routes', () => {
|
||||
expect(() =>
|
||||
getSlug({
|
||||
baseID: 'my dôc',
|
||||
source: '@site/docs/dir with spâce/hey $hello/doc.md',
|
||||
sourceDirName: '/dir with spâce/hey $hello',
|
||||
frontMatterSlug: '//',
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
"We couldn't compute a valid slug for document with ID \\"my dôc\\" in \\"/dir with spâce/hey $hello\\" directory.
|
||||
The slug we computed looks invalid: //.
|
||||
Maybe your slug front matter is incorrect or there are special characters in the file path?
|
||||
By using front matter to set a custom slug, you should be able to fix this error:
|
||||
|
||||
---
|
||||
slug: /my/customDocPath
|
||||
---
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
it('handles current dir', () => {
|
||||
expect(
|
||||
getSlug({baseID: 'doc', source: '@site/docs/doc.md', sourceDirName: '.'}),
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue