-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat(config): docs.excludeModules — doc-only module exclusion independent of activation #3924
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
Merged
Merged
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
lib/helpers/tests/config.filterByDocExclusion.unit.tests.js
This file contains hidden or 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,104 @@ | ||
| /** | ||
| * Unit tests for filterByDocExclusion in config helper. | ||
| * | ||
| * filterByDocExclusion drops a module's doc files (OpenAPI YAML + guides) from | ||
| * the resolved file lists based on `config.docs.excludeModules`, independent of | ||
| * runtime module activation — so it works even for core modules. | ||
| */ | ||
| import configHelper from '../config.js'; | ||
|
|
||
| const { filterByDocExclusion } = configHelper; | ||
|
|
||
| describe('filterByDocExclusion', () => { | ||
| const files = [ | ||
| 'modules/core/doc/index.yml', | ||
| 'modules/home/doc/openapi.yml', | ||
| 'modules/home/doc/guides/00-welcome.md', | ||
| 'modules/home/doc/guides/01-quickstart.md', | ||
| 'modules/tasks/doc/tasks.yml', | ||
| 'modules/tasks/doc/guides/00-tasks.md', | ||
| 'modules/billing/doc/billing.yml', | ||
| ]; | ||
|
|
||
| it('should return all files unchanged when excludeModules is missing (no docs config)', () => { | ||
| expect(filterByDocExclusion(files, {})).toEqual(files); | ||
| }); | ||
|
|
||
| it('should return all files unchanged when docs exists but excludeModules is missing', () => { | ||
| expect(filterByDocExclusion(files, { docs: { guideSections: [] } })).toEqual(files); | ||
| }); | ||
|
|
||
| it('should return all files unchanged when excludeModules is empty (default)', () => { | ||
| expect(filterByDocExclusion(files, { docs: { excludeModules: [] } })).toEqual(files); | ||
| }); | ||
|
|
||
| it('should drop OpenAPI yml + guides of an excluded CORE module (no activation bypass)', () => { | ||
| const config = { docs: { excludeModules: ['home'] } }; | ||
| const result = filterByDocExclusion(files, config); | ||
| expect(result).not.toContain('modules/home/doc/openapi.yml'); | ||
| expect(result).not.toContain('modules/home/doc/guides/00-welcome.md'); | ||
| expect(result).not.toContain('modules/home/doc/guides/01-quickstart.md'); | ||
| // Other modules' docs untouched | ||
| expect(result).toContain('modules/core/doc/index.yml'); | ||
| expect(result).toContain('modules/tasks/doc/tasks.yml'); | ||
| expect(result).toContain('modules/billing/doc/billing.yml'); | ||
| }); | ||
|
|
||
| it('should drop docs of multiple excluded modules', () => { | ||
| const config = { docs: { excludeModules: ['home', 'tasks'] } }; | ||
| const result = filterByDocExclusion(files, config); | ||
| expect(result).not.toContain('modules/home/doc/openapi.yml'); | ||
| expect(result).not.toContain('modules/home/doc/guides/00-welcome.md'); | ||
| expect(result).not.toContain('modules/tasks/doc/tasks.yml'); | ||
| expect(result).not.toContain('modules/tasks/doc/guides/00-tasks.md'); | ||
| expect(result).toEqual([ | ||
| 'modules/core/doc/index.yml', | ||
| 'modules/billing/doc/billing.yml', | ||
| ]); | ||
| }); | ||
|
|
||
| it('should keep non-module files (no modules/ in path)', () => { | ||
| const mixedFiles = [ | ||
| 'config/defaults/development.config.js', | ||
| 'lib/helpers/config.js', | ||
| 'modules/home/doc/guides/00-welcome.md', | ||
| ]; | ||
| const config = { docs: { excludeModules: ['home'] } }; | ||
| const result = filterByDocExclusion(mixedFiles, config); | ||
| expect(result).toContain('config/defaults/development.config.js'); | ||
| expect(result).toContain('lib/helpers/config.js'); | ||
| expect(result).not.toContain('modules/home/doc/guides/00-welcome.md'); | ||
| }); | ||
|
|
||
| it('should be a no-op when excludeModules is not an array (defensive)', () => { | ||
| expect(filterByDocExclusion(files, { docs: { excludeModules: 'home' } })).toEqual(files); | ||
| expect(filterByDocExclusion(files, { docs: { excludeModules: null } })).toEqual(files); | ||
| }); | ||
|
|
||
| it('should not drop a module whose name is a prefix of an excluded name', () => { | ||
| const prefixFiles = ['modules/home-extras/doc/home-extras.yml']; | ||
| const config = { docs: { excludeModules: ['home'] } }; | ||
| expect(filterByDocExclusion(prefixFiles, config)).toEqual(prefixFiles); | ||
| }); | ||
|
|
||
| it('should only ever drop files under a module doc/ dir, never runtime files of an excluded module', () => { | ||
| const runtimeFiles = [ | ||
| 'modules/home/routes/home.route.js', | ||
| 'modules/home/models/home.mongoose.js', | ||
| 'modules/home/doc/openapi.yml', | ||
| 'modules/home/doc/guides/00-welcome.md', | ||
| ]; | ||
| const config = { docs: { excludeModules: ['home'] } }; | ||
| const result = filterByDocExclusion(runtimeFiles, config); | ||
| // runtime files of the excluded module are kept | ||
| expect(result).toContain('modules/home/routes/home.route.js'); | ||
| expect(result).toContain('modules/home/models/home.mongoose.js'); | ||
| // only its doc files are dropped | ||
| expect(result).not.toContain('modules/home/doc/openapi.yml'); | ||
| expect(result).not.toContain('modules/home/doc/guides/00-welcome.md'); | ||
| }); | ||
|
|
||
| it('should handle empty file array', () => { | ||
| expect(filterByDocExclusion([], { docs: { excludeModules: ['home'] } })).toEqual([]); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.