Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
Update packages/next/src/client/components/react-dev-overlay/internal/helpers/get-socket-url.ts

Update packages/next/src/shared/lib/normalized-asset-prefix.test.ts
  • Loading branch information
devjiwonchoi committed Aug 6, 2024
1 parent c360163 commit 59e4a9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export function getSocketUrl(assetPrefix: string | undefined): string {
const protocol = getSocketProtocol(assetPrefix || '')

if (URL.canParse(prefix)) {
// since normalized asset prefix is ensured to be a URL format,
// we can safely replace the protocol
// since normalized asset prefix is ensured to be in URL format,
// we can trust to simply replace the protocol
return prefix.replace(/^http/, 'ws')
}

Expand Down
9 changes: 7 additions & 2 deletions packages/next/src/shared/lib/normalized-asset-prefix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ describe('normalizedAssetPrefix', () => {
expect(normalizedAssetPrefix('')).toBe('')
})

it('should return an empty string when assetPrefix is a single slash', () => {
expect(normalizedAssetPrefix('/')).toBe('')
})

// we expect an empty string because it could be an unnecessary trailing slash
it('should remove leading slash(es) when assetPrefix has more than one', () => {
expect(normalizedAssetPrefix('///path/to/asset')).toBe('/path/to/asset')
})
Expand All @@ -21,9 +26,9 @@ describe('normalizedAssetPrefix', () => {
expect(normalizedAssetPrefix('path/to/asset')).toBe('/path/to/asset')
})

it('should return a pathname when assetPrefix is a URL', () => {
it('should return the URL when assetPrefix is a URL', () => {
expect(normalizedAssetPrefix('https://example.com/path/to/asset')).toBe(
'/path/to/asset'
'https://example.com/path/to/asset'
)
})
})

0 comments on commit 59e4a9a

Please sign in to comment.