From 3e93fe1bd4ce0776fd517fc2eed232592d707afe Mon Sep 17 00:00:00 2001 From: Jack Murray Date: Tue, 23 Jan 2024 10:56:53 +0000 Subject: [PATCH] add a failing test to repro the problem Signed-off-by: Jack Murray <115712715+jackmtpt@users.noreply.github.com> --- ...cs_with_additional_plugins_with_config.yml | 9 ++++++ .../src/stages/generate/helpers.test.ts | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_with_additional_plugins_with_config.yml diff --git a/plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_with_additional_plugins_with_config.yml b/plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_with_additional_plugins_with_config.yml new file mode 100644 index 0000000000..6c945162d7 --- /dev/null +++ b/plugins/techdocs-node/src/stages/generate/__fixtures__/mkdocs_with_additional_plugins_with_config.yml @@ -0,0 +1,9 @@ +site_name: Test site name +site_description: Test site description +docs_dir: docs/ +plugins: + - not-techdocs-core + - also-not-techdocs-core + - custom-plugin: + with: + configuration: 1 diff --git a/plugins/techdocs-node/src/stages/generate/helpers.test.ts b/plugins/techdocs-node/src/stages/generate/helpers.test.ts index 24d9b3effb..1b47cfb05c 100644 --- a/plugins/techdocs-node/src/stages/generate/helpers.test.ts +++ b/plugins/techdocs-node/src/stages/generate/helpers.test.ts @@ -81,6 +81,12 @@ const mkdocsYmlWithoutPlugins = fs.readFileSync( const mkdocsYmlWithAdditionalPlugins = fs.readFileSync( resolvePath(__filename, '../__fixtures__/mkdocs_with_additional_plugins.yml'), ); +const mkdocsYmlWithAdditionalPluginsWithConfig = fs.readFileSync( + resolvePath( + __filename, + '../__fixtures__/mkdocs_with_additional_plugins_with_config.yml', + ), +); const mkdocsYmlWithEnvTag = fs.readFileSync( resolvePath(__filename, '../__fixtures__/mkdocs_with_env_tag.yml'), ); @@ -321,6 +327,8 @@ describe('helpers', () => { 'mkdocs_with_techdocs_plugin.yml': mkdocsYmlWithTechdocsPlugins, 'mkdocs_without_plugins.yml': mkdocsYmlWithoutPlugins, 'mkdocs_with_additional_plugins.yml': mkdocsYmlWithAdditionalPlugins, + 'mkdocs_with_additional_plugins_with_config.yml': + mkdocsYmlWithAdditionalPluginsWithConfig, }); }); it('should not add additional plugins if techdocs exists already in mkdocs file', async () => { @@ -386,6 +394,28 @@ describe('helpers', () => { expect(parsedYml.plugins).toContain('techdocs-core'); expect(parsedYml.plugins).toContain('custom-plugin'); }); + it('should not overwrite config when defaults are added', async () => { + await patchMkdocsYmlWithPlugins( + mockDir.resolve('mkdocs_with_additional_plugins_with_config.yml'), + mockLogger, + ['techdocs-core', 'custom-plugin'], + ); + + const updatedMkdocsYml = await fs.readFile( + mockDir.resolve('mkdocs_with_additional_plugins_with_config.yml'), + ); + const parsedYml = yaml.load(updatedMkdocsYml.toString()) as { + plugins: object[]; + }; + expect(parsedYml.plugins).toHaveLength(4); + expect(parsedYml.plugins).toContain('techdocs-core'); + // we want our original object with its properties to be preserved, and for the basic string form of the plugin + // to NOT be added as well. + expect(parsedYml.plugins).not.toContain('custom-plugin'); + expect(parsedYml.plugins).toContainEqual({ + 'custom-plugin': { with: { configuration: 1 } }, + }); + }); }); describe('patchIndexPreBuild', () => {