-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(v2): Fix MDX docs being considered as partials when siteDir match…
… the _ prefix convention (#5199) * Add _ to dogfood docs folder to cover against edge case * Fix edge case with MDX partials when site / content dir contains a _ prefix * add globUtils tests * proper dogfooding folder re-organization, all content plugins being used * refactor dogfooding folder + expose /tests page index * fix page plugin ignoring options.routeBasePath
- Loading branch information
Showing
28 changed files
with
271 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/docusaurus-utils/src/__tests__/globUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* 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 { | ||
GlobExcludeDefault, | ||
createMatcher, | ||
createAbsoluteFilePathMatcher, | ||
} from '../globUtils'; | ||
|
||
describe('createMatcher', () => { | ||
const matcher = createMatcher(GlobExcludeDefault); | ||
|
||
test('match default exclude MD/MDX partials correctly', () => { | ||
expect(matcher('doc.md')).toEqual(false); | ||
expect(matcher('category/doc.md')).toEqual(false); | ||
expect(matcher('category/subcategory/doc.md')).toEqual(false); | ||
// | ||
expect(matcher('doc.mdx')).toEqual(false); | ||
expect(matcher('category/doc.mdx')).toEqual(false); | ||
expect(matcher('category/subcategory/doc.mdx')).toEqual(false); | ||
// | ||
expect(matcher('_doc.md')).toEqual(true); | ||
expect(matcher('category/_doc.md')).toEqual(true); | ||
expect(matcher('category/subcategory/_doc.md')).toEqual(true); | ||
expect(matcher('_category/doc.md')).toEqual(true); | ||
expect(matcher('_category/subcategory/doc.md')).toEqual(true); | ||
expect(matcher('category/_subcategory/doc.md')).toEqual(true); | ||
}); | ||
|
||
test('match default exclude tests correctly', () => { | ||
expect(matcher('xyz.js')).toEqual(false); | ||
expect(matcher('xyz.ts')).toEqual(false); | ||
expect(matcher('xyz.jsx')).toEqual(false); | ||
expect(matcher('xyz.tsx')).toEqual(false); | ||
expect(matcher('folder/xyz.js')).toEqual(false); | ||
expect(matcher('folder/xyz.ts')).toEqual(false); | ||
expect(matcher('folder/xyz.jsx')).toEqual(false); | ||
expect(matcher('folder/xyz.tsx')).toEqual(false); | ||
// | ||
expect(matcher('xyz.test.js')).toEqual(true); | ||
expect(matcher('xyz.test.ts')).toEqual(true); | ||
expect(matcher('xyz.test.jsx')).toEqual(true); | ||
expect(matcher('xyz.test.tsx')).toEqual(true); | ||
expect(matcher('folder/xyz.test.js')).toEqual(true); | ||
expect(matcher('folder/xyz.test.ts')).toEqual(true); | ||
expect(matcher('folder/xyz.test.jsx')).toEqual(true); | ||
expect(matcher('folder/xyz.test.tsx')).toEqual(true); | ||
expect(matcher('folder/subfolder/xyz.test.js')).toEqual(true); | ||
expect(matcher('folder/subfolder/xyz.test.ts')).toEqual(true); | ||
expect(matcher('folder/subfolder/xyz.test.jsx')).toEqual(true); | ||
expect(matcher('folder/subfolder/xyz.test.tsx')).toEqual(true); | ||
// | ||
expect(matcher('__tests__/subfolder/xyz.js')).toEqual(true); | ||
expect(matcher('__tests__/subfolder/xyz.ts')).toEqual(true); | ||
expect(matcher('__tests__/subfolder/xyz.jsx')).toEqual(true); | ||
expect(matcher('__tests__/subfolder/xyz.tsx')).toEqual(true); | ||
expect(matcher('folder/__tests__/xyz.js')).toEqual(true); | ||
expect(matcher('folder/__tests__/xyz.ts')).toEqual(true); | ||
expect(matcher('folder/__tests__/xyz.jsx')).toEqual(true); | ||
expect(matcher('folder/__tests__/xyz.tsx')).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('createAbsoluteFilePathMatcher', () => { | ||
const rootFolders = ['/_root/docs', '/root/_docs/', '/__test__/website/src']; | ||
|
||
const matcher = createAbsoluteFilePathMatcher( | ||
GlobExcludeDefault, | ||
rootFolders, | ||
); | ||
|
||
test('match default exclude MD/MDX partials correctly', () => { | ||
expect(matcher('/_root/docs/myDoc.md')).toEqual(false); | ||
expect(matcher('/_root/docs/myDoc.mdx')).toEqual(false); | ||
expect(matcher('/root/_docs/myDoc.md')).toEqual(false); | ||
expect(matcher('/root/_docs/myDoc.mdx')).toEqual(false); | ||
expect(matcher('/_root/docs/category/myDoc.md')).toEqual(false); | ||
expect(matcher('/_root/docs/category/myDoc.mdx')).toEqual(false); | ||
expect(matcher('/root/_docs/category/myDoc.md')).toEqual(false); | ||
expect(matcher('/root/_docs/category/myDoc.mdx')).toEqual(false); | ||
// | ||
expect(matcher('/_root/docs/_myDoc.md')).toEqual(true); | ||
expect(matcher('/_root/docs/_myDoc.mdx')).toEqual(true); | ||
expect(matcher('/root/_docs/_myDoc.md')).toEqual(true); | ||
expect(matcher('/root/_docs/_myDoc.mdx')).toEqual(true); | ||
expect(matcher('/_root/docs/_category/myDoc.md')).toEqual(true); | ||
expect(matcher('/_root/docs/_category/myDoc.mdx')).toEqual(true); | ||
expect(matcher('/root/_docs/_category/myDoc.md')).toEqual(true); | ||
expect(matcher('/root/_docs/_category/myDoc.mdx')).toEqual(true); | ||
}); | ||
|
||
test('match default exclude tests correctly', () => { | ||
expect(matcher('/__test__/website/src/xyz.js')).toEqual(false); | ||
expect(matcher('/__test__/website/src/__test__/xyz.js')).toEqual(true); | ||
expect(matcher('/__test__/website/src/xyz.test.js')).toEqual(true); | ||
}); | ||
|
||
test('throw if file is not contained in any root doc', () => { | ||
expect(() => | ||
matcher('/bad/path/myDoc.md'), | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=/bad/path/myDoc.md was not contained in any of the root folders [\\"/_root/docs\\",\\"/root/_docs/\\",\\"/__test__/website/src\\"]"`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Docusaurus website dogfooding | ||
|
||
This is where we test edge cases of Docusaurus by using fancy configs, ensuring they all don't fail during a real site build. | ||
|
||
Eventually, we could move these tests later so another test site? Note there is value to keep seeing the live result of those tests. | ||
|
||
Fancy things we can test for here: | ||
|
||
- Plugin Multi-instance | ||
- Symlinks support | ||
- Webpack configs | ||
- \_ prefix convention | ||
- Huge sidebars impact |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Page partial content | ||
|
||
This is text coming from a page partial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Page | ||
|
||
Let's import some MDX partial: | ||
|
||
```mdx-code-block | ||
import PagePartial from "./_pagePartial.md" | ||
<PagePartial /> | ||
``` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_docs-tests |
Oops, something went wrong.