Skip to content

Commit

Permalink
fix(cli): don't crash when checking for updates from integration vers…
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Nov 10, 2022
1 parent 2a7f323 commit 43580a8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions packages/cli/src/__tests__/printUpdateMessage.test.ts
@@ -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
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

0 comments on commit 43580a8

Please sign in to comment.