Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions test/nuxt/composables/use-repository-url.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { describe, expect, it } from 'vitest'

/**
* Tests for useRepositoryUrl composable.
*
* Regression tests for GitHub issue #2233: monorepo packages with .git suffix
* in repository.url generated broken source links like:
* https://github.com/org/repo.git/tree/HEAD/packages/foo (404)
* instead of:
* https://github.com/org/repo/tree/HEAD/packages/foo
*/
describe('useRepositoryUrl', () => {
it('should strip .git from repository URL', () => {
const { repositoryUrl } = useRepositoryUrl(
ref({

Check failure on line 15 in test/nuxt/composables/use-repository-url.spec.ts

View workflow job for this annotation

GitHub Actions / 💪 Type check

Argument of type 'Ref<{ repository: { type: string; url: string; }; }, { repository: { type: string; url: string; }; } | { repository: { type: string; url: string; }; }>' is not assignable to parameter of type 'MaybeRefOrGetter<RequestedVersion>'.
repository: {
type: 'git',
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
},
}),
)

expect(repositoryUrl.value).toBe('https://github.com/agentmarkup/agentmarkup')
})

it('should append /tree/HEAD/{directory} for monorepo packages without .git', () => {
const { repositoryUrl } = useRepositoryUrl(
ref({

Check failure on line 28 in test/nuxt/composables/use-repository-url.spec.ts

View workflow job for this annotation

GitHub Actions / 💪 Type check

Argument of type 'Ref<{ repository: { type: string; url: string; directory: string; }; }, { repository: { type: string; url: string; directory: string; }; } | { repository: { type: string; url: string; directory: string; }; }>' is not assignable to parameter of type 'MaybeRefOrGetter<RequestedVersion>'.
repository: {
type: 'git',
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
directory: 'packages/vite',
},
}),
)

expect(repositoryUrl.value).toBe(
'https://github.com/agentmarkup/agentmarkup/tree/HEAD/packages/vite',
)
})

it('should return null when repository has no url', () => {
const { repositoryUrl } = useRepositoryUrl(
ref({

Check failure on line 44 in test/nuxt/composables/use-repository-url.spec.ts

View workflow job for this annotation

GitHub Actions / 💪 Type check

Argument of type 'Ref<{ repository: {}; }, { repository: {}; } | { repository: {}; }>' is not assignable to parameter of type 'MaybeRefOrGetter<RequestedVersion>'.
repository: {},
}),
)

expect(repositoryUrl.value).toBeNull()
})

it('should return null when no repository field', () => {
const { repositoryUrl } = useRepositoryUrl(ref({}))

Check failure on line 53 in test/nuxt/composables/use-repository-url.spec.ts

View workflow job for this annotation

GitHub Actions / 💪 Type check

Argument of type 'Ref<{}, {}>' is not assignable to parameter of type 'MaybeRefOrGetter<RequestedVersion>'.

expect(repositoryUrl.value).toBeNull()
})

it('should handle plain HTTPS URLs without .git suffix', () => {
const { repositoryUrl } = useRepositoryUrl(
ref({

Check failure on line 60 in test/nuxt/composables/use-repository-url.spec.ts

View workflow job for this annotation

GitHub Actions / 💪 Type check

Argument of type 'Ref<{ repository: { url: string; }; }, { repository: { url: string; }; } | { repository: { url: string; }; }>' is not assignable to parameter of type 'MaybeRefOrGetter<RequestedVersion>'.
repository: {
url: 'https://github.com/nuxt/ui',
},
}),
)

expect(repositoryUrl.value).toBe('https://github.com/nuxt/ui')
})

it('should handle directory with trailing slash', () => {
const { repositoryUrl } = useRepositoryUrl(
ref({

Check failure on line 72 in test/nuxt/composables/use-repository-url.spec.ts

View workflow job for this annotation

GitHub Actions / 💪 Type check

Argument of type 'Ref<{ repository: { url: string; directory: string; }; }, { repository: { url: string; directory: string; }; } | { repository: { url: string; directory: string; }; }>' is not assignable to parameter of type 'MaybeRefOrGetter<RequestedVersion>'.
repository: {
url: 'git+https://github.com/org/repo.git',
directory: 'packages/core/',
},
}),
)

expect(repositoryUrl.value).toBe('https://github.com/org/repo/tree/HEAD/packages/core/')
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})
Loading