Skip to content
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(cli): don't crash when checking for updates from integration version with a long name #16227

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions packages/cli/src/__tests__/printUpdateMessage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { printUpdateMessage } from '../utils/printUpdateMessage'

function printUpdateMessageFromTo(from: string, to: string): void {
printUpdateMessage({
status: 'ok',
data: {
client_event_id: '',
previous_client_event_id: '',
product: '',
cli_path_hash: '',
local_timestamp: '',
previous_version: from,
current_version: to,
current_release_date: Date.now(),
current_download_url: '',
current_changelog_url: '',
package: 'prisma',
release_tag: to,
install_command: '',
project_website: '',
outdated: true,
alerts: [],
},
})
}

const consoleErrorMock = jest.spyOn(console, 'error').mockImplementation()

afterEach(() => {
consoleErrorMock.mockReset()
})

test('normal release', () => {
printUpdateMessageFromTo('4.5.0', '4.6.0')
expect(consoleErrorMock.mock.calls[0][0]).toMatchInlineSnapshot(`
┌─────────────────────────────────────────────────────────┐
│ Update available 4.5.0 -> 4.6.0 │
│ Run the following to update │
│ npm i --save-dev prisma@4.6.0 │
│ npm i @prisma/client@4.6.0 │
└─────────────────────────────────────────────────────────┘
`)
})

test('integration version with long name', () => {
printUpdateMessageFromTo('4.5.0-integration-use-keep-alive-for-node-fetch.1', '4.6.0')
expect(consoleErrorMock.mock.calls[0][0]).toMatchInlineSnapshot(`
┌───────────────────────────────────────────────────────────────────────────────┐
│ Update available 4.5.0-integration-use-keep-alive-for-node-fetch.1 -> 4.6.0 │
│ Run the following to update │
│ npm i --save-dev prisma@4.6.0 │
│ npm i @prisma/client@4.6.0 │
└───────────────────────────────────────────────────────────────────────────────┘
`)
})
2 changes: 1 addition & 1 deletion packages/internals/src/utils/drawBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function maxLineLength(str: string): number {

export function drawBox({ title, width, height, str, horizontalPadding }: BoxOptions): string {
horizontalPadding = horizontalPadding || 0
width = width || maxLineLength(str) + horizontalPadding * 2
width = Math.max(width, maxLineLength(str) + horizontalPadding * 2)
const topLine = title
? chalk.grey(chars.topLeft + chars.horizontal) +
' ' +
Expand Down