Skip to content

Commit

Permalink
fix(v2): docs plugin stability improvement (100% test coverage) (#1912)
Browse files Browse the repository at this point in the history
* update jest config

* add more tests on docs plugin

* fix(v2): docs plugin should not add routes if there are no docs

* fix

* rm -rf coverage

* nits

* update
  • Loading branch information
endiliey authored and yangshun committed Oct 29, 2019
1 parent ad22c9f commit a8826b9
Show file tree
Hide file tree
Showing 26 changed files with 465 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Prioritize `@docusaurus/core` dependencies/ node_modules over user's node_modules. This fix a bug whereby if user has core-js@3 on its own node_modules but docusaurus depends on core-js@2, we previously encounter `Module not found: core-js/modules/xxxx` (because core-js@3 doesn't have that).
Another example is if user installed webpack@3 but docusaurus depends on webpack@4.
- Added code block line highlighting feature (thanks @lex111)! If you have previously swizzled the `CodeBlock` theme component, it is recommended to update your source code to have this feature.
- Fix a bug where docs plugin add `/docs` route even if docs folder is empty. We also improved docs plugin test coverage to 100% for stability before working on docs versioning.

## 2.0.0-alpha.31

Expand Down
21 changes: 12 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@

const path = require('path');

const ignorePatterns = [
'/node_modules/',
'__fixtures__',
'/packages/docusaurus/lib',
'/packages/docusaurus-utils/lib',
'/packages/docusaurus-plugin-content-blog/lib',
'/packages/docusaurus-plugin-content-docs/lib',
'/packages/docusaurus-plugin-content-pages/lib',
];

module.exports = {
rootDir: path.resolve(__dirname),
verbose: true,
testURL: 'http://localhost/',
testEnvironment: 'node',
testPathIgnorePatterns: [
'/node_modules/',
'__fixtures__',
'/packages/docusaurus/lib',
'/packages/docusaurus-utils/lib',
'/packages/docusaurus-plugin-content-blog/lib',
'/packages/docusaurus-plugin-content-docs-legacy/lib',
'/packages/docusaurus-plugin-content-pages/lib',
],
testPathIgnorePatterns: ignorePatterns,
coveragePathIgnorePatterns: ignorePatterns,
transform: {
'^.+\\.[jt]sx?$': 'babel-jest',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
id: hello/super
---

Lorem
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 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.
*/

module.exports = {
title: 'My Site',
tagline: 'The tagline of my site',
url: 'https://your-docusaurus-test-site.com',
baseUrl: '/',
favicon: 'img/favicon.ico',
organizationName: 'facebook', // Usually your GitHub org/user name.
projectName: 'docusaurus', // Usually your repo name.
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"docs": {
"Test": [
{
"type": "category",
"label": "Category Label",
"items": "doc1"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"docs": {
"Test": [
"foo/bar",
"foo/baz",
{
"type": "category",
"label": "category",
"href": "https://github.com"
},
{
"type": "ref",
"id": "hello"
}
],
"Guides": [
"hello"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
id: lorem
custom_edit_url: https://github.com/customUrl/docs/lorem.md
---

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 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.
*/

module.exports = {
title: 'My Site',
tagline: 'The tagline of my site',
url: 'https://your-docusaurus-test-site.com',
baseUrl: '/',
favicon: 'img/favicon.ico',
organizationName: 'facebook', // Usually your GitHub org/user name.
projectName: 'docusaurus', // Usually your repo name.
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"docs": {
"Test": [
{
"type": "category",
"label": "foo",
"items": ["foo/bar", "foo/baz"]
},
{
"type": "link",
"label": "Github",
"href": "https://github.com"
},
{
"type": "ref",
"id": "hello"
}
],
"Guides": [
"hello"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"docs": {
"Test": [
"goku"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`simple website content 1`] = `
Object {
"docs": Array [
Object {
"items": Array [
Object {
"items": Array [
Object {
"href": "/docs/foo/bar",
"label": "Bar",
"type": "link",
},
Object {
"href": "/docs/foo/baz",
"label": "baz",
"type": "link",
},
],
"label": "foo",
"type": "category",
},
Object {
"href": "https://github.com",
"label": "Github",
"type": "link",
},
Object {
"href": "/docs/hello",
"label": "Hello, World !",
"type": "link",
},
],
"label": "Test",
"type": "category",
},
Object {
"items": Array [
Object {
"href": "/docs/hello",
"label": "Hello, World !",
"type": "link",
},
],
"label": "Guides",
"type": "category",
},
],
}
`;

exports[`simple website content 2`] = `
Array [
Object {
"component": "@theme/DocPage",
"modules": Object {
"docsMetadata": "@docusaurus-plugin-content-docs/docs-b5f.json",
},
"path": "/docs",
"routes": Array [
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/permalink.md",
"metadata": "@docusaurus-plugin-content-docs/docs-endiliey-permalink-086.json",
},
"path": "/docs/endiliey/permalink",
},
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/foo/bar.md",
"metadata": "@docusaurus-plugin-content-docs/docs-foo-bar-cef.json",
},
"path": "/docs/foo/bar",
},
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/foo/baz.md",
"metadata": "@docusaurus-plugin-content-docs/docs-foo-baz-dd9.json",
},
"path": "/docs/foo/baz",
},
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/hello.md",
"metadata": "@docusaurus-plugin-content-docs/docs-hello-da2.json",
},
"path": "/docs/hello",
},
Object {
"component": "@theme/DocItem",
"exact": true,
"modules": Object {
"content": "@site/docs/lorem.md",
"metadata": "@docusaurus-plugin-content-docs/docs-lorem-17b.json",
},
"path": "/docs/lorem",
},
],
},
]
`;
Loading

0 comments on commit a8826b9

Please sign in to comment.