Repository navigation
fix(core): ignore canary and prerelease versions in update notifier (#11013) #12747
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
Open
hardikkaurani
wants to merge
4
commits into
meta:main
Choose a base branch
from
hardikkaurani:fix/canary-update-check-11013
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+354
−72
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c519a8
fix(core): ignore canary and prerelease versions in update notifier
hardikkaurani cb093f4
test(core): add unit tests for ignoreUpdate in beforeCli
hardikkaurani 8d44563
fix(core): preserve node version check when ignoring updates
hardikkaurani ce96b5b
test(core): hoist update-notifier test mocks in beforeCli tests
hardikkaurani 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 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,276 @@ | ||
| /** | ||
| * 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 {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; | ||
| import {logger} from '@docusaurus/logger'; | ||
| import beforeCli, {ignoreUpdate} from '../beforeCli.mjs'; | ||
| import type {UpdateInfo} from 'update-notifier'; | ||
|
|
||
| const {mockNotifierConfig, mockState} = vi.hoisted(() => ({ | ||
| mockNotifierConfig: { | ||
| get: vi.fn(), | ||
| set: vi.fn(), | ||
| }, | ||
| mockState: { | ||
| update: undefined as UpdateInfo | undefined, | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock('update-notifier', () => ({ | ||
| default: vi.fn(() => ({ | ||
| config: mockNotifierConfig, | ||
| get update() { | ||
| return mockState.update; | ||
| }, | ||
| check: vi.fn(), | ||
| })), | ||
| })); | ||
|
|
||
| describe('beforeCli ignoreUpdate', () => { | ||
| it('returns false when update is undefined or current is missing', () => { | ||
| expect(ignoreUpdate(undefined)).toBe(false); | ||
| expect(ignoreUpdate({} as UpdateInfo)).toBe(false); | ||
| }); | ||
|
|
||
| it('ignores legacy 0.0.0 canary releases', () => { | ||
| expect( | ||
| ignoreUpdate({ | ||
| current: '0.0.0-1234', | ||
| latest: '3.7.0', | ||
| name: '@docusaurus/core', | ||
| type: 'major', | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('ignores versions with canary suffix (closes #11013)', () => { | ||
| expect( | ||
| ignoreUpdate({ | ||
| current: '3.7.0-canary-6264', | ||
| latest: '3.7.0', | ||
| name: '@docusaurus/core', | ||
| type: 'patch', | ||
| }), | ||
| ).toBe(true); | ||
| expect( | ||
| ignoreUpdate({ | ||
| current: '3.8.0-canary-7123+7b6826b', | ||
| latest: '3.8.0', | ||
| name: '@docusaurus/core', | ||
| type: 'patch', | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('ignores prerelease versions', () => { | ||
| expect( | ||
| ignoreUpdate({ | ||
| current: '4.0.0-alpha.0', | ||
| latest: '4.0.0', | ||
| name: '@docusaurus/core', | ||
| type: 'major', | ||
| }), | ||
| ).toBe(true); | ||
| expect( | ||
| ignoreUpdate({ | ||
| current: '4.0.0-beta.1', | ||
| latest: '4.0.0', | ||
| name: '@docusaurus/core', | ||
| type: 'major', | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('does not ignore regular stable versions', () => { | ||
| expect( | ||
| ignoreUpdate({ | ||
| current: '3.6.0', | ||
| latest: '3.7.0', | ||
| name: '@docusaurus/core', | ||
| type: 'minor', | ||
| }), | ||
| ).toBe(false); | ||
| expect( | ||
| ignoreUpdate({ | ||
| current: '3.7.0', | ||
| latest: '3.7.1', | ||
| name: '@docusaurus/core', | ||
| type: 'patch', | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('beforeCli control flow', () => { | ||
| const originalNodeVersion = process.version; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mockState.update = undefined; | ||
| Object.defineProperty(process, 'version', { | ||
| value: 'v26.0.0', | ||
| configurable: true, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| Object.defineProperty(process, 'version', { | ||
| value: originalNodeVersion, | ||
| configurable: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('suppresses update notification for canary installations while passing Node.js check', async () => { | ||
| const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
| const processExitSpy = vi | ||
| .spyOn(process, 'exit') | ||
| .mockImplementation((() => {}) as unknown as ( | ||
| code?: string | number | null | undefined, | ||
| ) => never); | ||
|
|
||
| mockState.update = { | ||
| current: '3.7.0-canary-6264', | ||
| latest: '3.7.0', | ||
| name: '@docusaurus/core', | ||
| type: 'patch', | ||
| }; | ||
|
|
||
| await beforeCli(); | ||
|
|
||
| expect(mockNotifierConfig.set).toHaveBeenCalledWith( | ||
| 'update', | ||
| mockState.update, | ||
| ); | ||
| expect(consoleLogSpy).not.toHaveBeenCalled(); | ||
| expect(processExitSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('displays update notification for stable outdated installations while passing Node.js check', async () => { | ||
| const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
| const processExitSpy = vi | ||
| .spyOn(process, 'exit') | ||
| .mockImplementation((() => {}) as unknown as ( | ||
| code?: string | number | null | undefined, | ||
| ) => never); | ||
|
|
||
| mockState.update = { | ||
| current: '3.6.0', | ||
| latest: '3.7.0', | ||
| name: '@docusaurus/core', | ||
| type: 'minor', | ||
| }; | ||
|
|
||
| await beforeCli(); | ||
|
|
||
| expect(mockNotifierConfig.set).toHaveBeenCalledWith( | ||
| 'update', | ||
| mockState.update, | ||
| ); | ||
| expect(consoleLogSpy).toHaveBeenCalled(); | ||
| expect(consoleLogSpy.mock.calls[0]?.[0]).toContain('Update available'); | ||
| expect(consoleLogSpy.mock.calls[0]?.[0]).toContain('3.6.0'); | ||
| expect(consoleLogSpy.mock.calls[0]?.[0]).toContain('3.7.0'); | ||
| expect(processExitSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not bypass minimum Node.js version validation when canary update is suppressed', async () => { | ||
| const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
| const loggerErrorSpy = vi | ||
| .spyOn(logger, 'error') | ||
| .mockImplementation(() => {}); | ||
| const loggerInfoSpy = vi.spyOn(logger, 'info').mockImplementation(() => {}); | ||
| const processExitSpy = vi | ||
| .spyOn(process, 'exit') | ||
| .mockImplementation((() => {}) as unknown as ( | ||
| code?: string | number | null | undefined, | ||
| ) => never); | ||
|
|
||
| mockState.update = { | ||
| current: '3.7.0-canary-6264', | ||
| latest: '3.7.0', | ||
| name: '@docusaurus/core', | ||
| type: 'patch', | ||
| }; | ||
|
|
||
| Object.defineProperty(process, 'version', { | ||
| value: 'v18.0.0', | ||
| configurable: true, | ||
| }); | ||
|
|
||
| await beforeCli(); | ||
|
|
||
| expect(consoleLogSpy).not.toHaveBeenCalled(); | ||
| expect(loggerErrorSpy).toHaveBeenCalledWith( | ||
| 'Minimum Node.js version not met :(', | ||
| ); | ||
| expect(loggerInfoSpy).toHaveBeenCalled(); | ||
| expect(processExitSpy).toHaveBeenCalledWith(1); | ||
| }); | ||
|
|
||
| it('does not bypass minimum Node.js version validation when prerelease update is suppressed', async () => { | ||
| const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
| const loggerErrorSpy = vi | ||
| .spyOn(logger, 'error') | ||
| .mockImplementation(() => {}); | ||
| const loggerInfoSpy = vi.spyOn(logger, 'info').mockImplementation(() => {}); | ||
| const processExitSpy = vi | ||
| .spyOn(process, 'exit') | ||
| .mockImplementation((() => {}) as unknown as ( | ||
| code?: string | number | null | undefined, | ||
| ) => never); | ||
|
|
||
| mockState.update = { | ||
| current: '4.0.0-alpha.0', | ||
| latest: '4.0.0', | ||
| name: '@docusaurus/core', | ||
| type: 'major', | ||
| }; | ||
|
|
||
| Object.defineProperty(process, 'version', { | ||
| value: 'v18.0.0', | ||
| configurable: true, | ||
| }); | ||
|
|
||
| await beforeCli(); | ||
|
|
||
| expect(consoleLogSpy).not.toHaveBeenCalled(); | ||
| expect(loggerErrorSpy).toHaveBeenCalledWith( | ||
| 'Minimum Node.js version not met :(', | ||
| ); | ||
| expect(loggerInfoSpy).toHaveBeenCalled(); | ||
| expect(processExitSpy).toHaveBeenCalledWith(1); | ||
| }); | ||
|
|
||
| it('triggers error and exit on unsupported Node.js versions even when no update is available', async () => { | ||
| const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
| const loggerErrorSpy = vi | ||
| .spyOn(logger, 'error') | ||
| .mockImplementation(() => {}); | ||
| const loggerInfoSpy = vi.spyOn(logger, 'info').mockImplementation(() => {}); | ||
| const processExitSpy = vi | ||
| .spyOn(process, 'exit') | ||
| .mockImplementation((() => {}) as unknown as ( | ||
| code?: string | number | null | undefined, | ||
| ) => never); | ||
|
|
||
| mockState.update = undefined; | ||
|
|
||
| Object.defineProperty(process, 'version', { | ||
| value: 'v18.0.0', | ||
| configurable: true, | ||
| }); | ||
|
|
||
| await beforeCli(); | ||
|
|
||
| expect(consoleLogSpy).not.toHaveBeenCalled(); | ||
| expect(loggerErrorSpy).toHaveBeenCalledWith( | ||
| 'Minimum Node.js version not met :(', | ||
| ); | ||
| expect(loggerInfoSpy).toHaveBeenCalled(); | ||
| expect(processExitSpy).toHaveBeenCalledWith(1); | ||
| }); | ||
| }); | ||
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.