From 61e3fb09fdc3f313eb5944323a4d2706ce96c377 Mon Sep 17 00:00:00 2001 From: Jorens Merenjanu Date: Fri, 6 Oct 2023 14:55:49 +0000 Subject: [PATCH 1/3] feat(errors): throw error instead of just logging it when checking plugin versions additionally remove import for logger because it is not needed. --- packages/docusaurus/src/server/siteMetadata.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus/src/server/siteMetadata.ts b/packages/docusaurus/src/server/siteMetadata.ts index affcbf7183ec..faedab4fcfdb 100644 --- a/packages/docusaurus/src/server/siteMetadata.ts +++ b/packages/docusaurus/src/server/siteMetadata.ts @@ -7,7 +7,6 @@ import fs from 'fs-extra'; import path from 'path'; -import logger from '@docusaurus/logger'; import {DOCUSAURUS_VERSION} from '@docusaurus/utils'; import type { LoadedPlugin, @@ -82,10 +81,9 @@ function checkDocusaurusPackagesVersion(siteMetadata: SiteMetadata) { versionInfo.version && versionInfo.version !== docusaurusVersion ) { - // Should we throw instead? It still could work with different versions - logger.error`Invalid name=${plugin} version number=${versionInfo.version}. + throw new Error(`Invalid name=${plugin} version number=${versionInfo.version}. All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}). -Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`; +Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`); } }, ); From 51d995463e7a439350d56409384307d64f39afd5 Mon Sep 17 00:00:00 2001 From: Jorens Merenjanu Date: Sun, 8 Oct 2023 07:08:49 +0000 Subject: [PATCH 2/3] test: update test for loadSiteMetadata() --- .../src/server/__tests__/siteMetadata.test.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts b/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts index 3985173a03b8..cf5557ecb496 100644 --- a/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts +++ b/packages/docusaurus/src/server/__tests__/siteMetadata.test.ts @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -import {jest} from '@jest/globals'; import path from 'path'; +import {DOCUSAURUS_VERSION} from '@docusaurus/utils'; import {getPluginVersion, loadSiteMetadata} from '../siteMetadata'; import type {LoadedPlugin} from '@docusaurus/types'; @@ -37,10 +37,7 @@ describe('getPluginVersion', () => { }); describe('loadSiteMetadata', () => { - it('warns about plugin version mismatch', async () => { - const consoleMock = jest - .spyOn(console, 'error') - .mockImplementation(() => {}); + it('throws if plugin versions mismatch', async () => { await expect( loadSiteMetadata({ plugins: [ @@ -55,11 +52,9 @@ describe('loadSiteMetadata', () => { ] as LoadedPlugin[], siteDir: path.join(__dirname, '__fixtures__/siteMetadata'), }), - ).resolves.toMatchSnapshot(); - expect(consoleMock.mock.calls[0]![0]).toMatchInlineSnapshot(` - "[ERROR] Invalid docusaurus-plugin-content-docs version 1.0.0. - All official @docusaurus/* packages should have the exact same version as @docusaurus/core (). - Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?" - `); + ).rejects + .toThrow(`Invalid name=docusaurus-plugin-content-docs version number=1.0.0. +All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${DOCUSAURUS_VERSION}). +Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`); }); }); From cc7fdd43c1293162812bb3cd8920d71b7f0813f6 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Sun, 8 Oct 2023 18:29:55 +0200 Subject: [PATCH 3/3] remove useless snapshot --- .../__snapshots__/siteMetadata.test.ts.snap | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 packages/docusaurus/src/server/__tests__/__snapshots__/siteMetadata.test.ts.snap diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/siteMetadata.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/siteMetadata.test.ts.snap deleted file mode 100644 index 667dc1216ad9..000000000000 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/siteMetadata.test.ts.snap +++ /dev/null @@ -1,15 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`loadSiteMetadata warns about plugin version mismatch 1`] = ` -{ - "docusaurusVersion": "", - "pluginVersions": { - "docusaurus-plugin-content-docs": { - "name": "@docusaurus/plugin-content-docs", - "type": "package", - "version": "1.0.0", - }, - }, - "siteVersion": "random-version", -} -`;