-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(docs): avoid duplicating manual documentation #3766
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import { mockBuildCtx, mockCompilerCtx, mockModule, mockValidatedConfig } from '@stencil/core/testing'; | ||
|
||
import type * as d from '../../../declarations'; | ||
import { getComponentsFromModules } from '../../output-targets/output-utils'; | ||
import { stubComponentCompilerMeta } from '../../types/tests/ComponentCompilerMeta.stub'; | ||
import { AUTO_GENERATE_COMMENT } from '../constants'; | ||
import { generateDocData } from '../generate-doc-data'; | ||
|
||
describe('generate-doc-data', () => { | ||
describe('getDocsComponents', () => { | ||
let moduleCmpWithJsdoc: d.Module; | ||
let moduleCmpNoJsdoc: d.Module; | ||
|
||
beforeEach(() => { | ||
moduleCmpWithJsdoc = mockModule({ | ||
cmps: [ | ||
stubComponentCompilerMeta({ | ||
docs: { | ||
tags: [], | ||
text: 'This is the overview of `my-component`', | ||
}, | ||
}), | ||
], | ||
}); | ||
moduleCmpNoJsdoc = mockModule({ | ||
cmps: [ | ||
stubComponentCompilerMeta({ | ||
docs: { | ||
tags: [], | ||
text: '', | ||
}, | ||
}), | ||
], | ||
}); | ||
}); | ||
|
||
/** | ||
* Setup function for the {@link generateDocData} function exported by the module under test | ||
* @param moduleMap a map of {@link d.ModuleMap} entities to add to the returned compiler and build contexts | ||
* @returns the arguments required to invoke the method under test | ||
*/ | ||
const setup = ( | ||
moduleMap: d.ModuleMap | ||
): { validatedConfig: d.ValidatedConfig; compilerCtx: d.CompilerCtx; buildCtx: d.BuildCtx } => { | ||
const validatedConfig: d.ValidatedConfig = mockValidatedConfig(); | ||
|
||
const compilerCtx: d.CompilerCtx = mockCompilerCtx(validatedConfig); | ||
compilerCtx.moduleMap = moduleMap; | ||
|
||
const modules = Array.from(compilerCtx.moduleMap.values()); | ||
const buildCtx: d.BuildCtx = mockBuildCtx(validatedConfig, compilerCtx); | ||
buildCtx.moduleFiles = modules; | ||
buildCtx.components = getComponentsFromModules(modules); | ||
|
||
return { validatedConfig, compilerCtx, buildCtx }; | ||
}; | ||
|
||
describe('component JSDoc overview', () => { | ||
it("takes the value from the component's JSDoc", async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpWithJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.overview).toBe('This is the overview of `my-component`'); | ||
}); | ||
|
||
it('sets the value to the empty string when there is no JSDoc', async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpNoJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.overview).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('docs content', () => { | ||
it("sets the field's contents to the jsdoc text if present", async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpWithJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.docs).toBe('This is the overview of `my-component`'); | ||
}); | ||
|
||
it("sets the field's contents to an empty string if neither the readme, nor jsdoc are set", async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpNoJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.docs).toBe(''); | ||
}); | ||
|
||
it("sets the field's contents to an empty string if the readme doesn't contain the autogenerated comment", async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpNoJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
await compilerCtx.fs.writeFile('readme.md', 'this is manually generated user content'); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.docs).toBe(''); | ||
}); | ||
|
||
it("sets the field's contents to manually generated content when the autogenerated comment is present", async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpNoJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
await compilerCtx.fs.writeFile( | ||
'readme.md', | ||
`this is manually generated user content\n${AUTO_GENERATE_COMMENT}\nauto-generated content` | ||
); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.docs).toBe('this is manually generated user content'); | ||
}); | ||
|
||
it("sets the field's contents to a subset of the manually generated content", async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpNoJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
const readmeContent = ` | ||
this is manually generated user content | ||
|
||
# user header | ||
user content | ||
|
||
# another user header | ||
more user content | ||
|
||
${AUTO_GENERATE_COMMENT} | ||
|
||
#some-header | ||
|
||
auto-generated content | ||
`; | ||
await compilerCtx.fs.writeFile('readme.md', readmeContent); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.docs).toBe('this is manually generated user content'); | ||
}); | ||
|
||
it("sets the field's contents to a an empty string when the manually generated content starts with a '#'", async () => { | ||
const moduleMap: d.ModuleMap = new Map(); | ||
moduleMap.set('path/to/component.tsx', moduleCmpNoJsdoc); | ||
const { validatedConfig, compilerCtx, buildCtx } = setup(moduleMap); | ||
|
||
const readmeContent = ` | ||
# header that leads to skipping | ||
this is manually generated user content | ||
|
||
# user header | ||
user content | ||
|
||
# another user header | ||
more user content | ||
|
||
${AUTO_GENERATE_COMMENT} | ||
|
||
#some-header | ||
|
||
auto-generated content | ||
`; | ||
await compilerCtx.fs.writeFile('readme.md', readmeContent); | ||
|
||
const generatedDocData = await generateDocData(validatedConfig, compilerCtx, buildCtx); | ||
|
||
expect(generatedDocData.components).toHaveLength(1); | ||
const componentDocData = generatedDocData.components[0]; | ||
expect(componentDocData.docs).toBe(''); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bah! How did I miss this? I'll put a tiny followup PR for this. Sorry about that!