Skip to content

Commit 0103106

Browse files
committed
fix: type errors
1 parent 89509f7 commit 0103106

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

test/nuxt/composables/use-repository-url.spec.ts

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
import { describe, expect, it } from 'vitest'
22

3+
type RequestedVersion = Exclude<SlimPackument['requestedVersion'], null>
4+
5+
function mockPackage(repository: RequestedVersion['repository']): RequestedVersion {
6+
return {
7+
_id: 'foo',
8+
name: 'foo',
9+
dist: { shasum: 'foo', signatures: [], tarball: '' },
10+
_npmVersion: '',
11+
version: '0.1.0',
12+
repository,
13+
}
14+
}
15+
316
describe('useRepositoryUrl', () => {
417
it('should strip .git from repository URL', () => {
518
const { repositoryUrl } = useRepositoryUrl(
6-
ref({
7-
repository: {
8-
type: 'git',
9-
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
10-
},
11-
} as any),
19+
mockPackage({
20+
type: 'git',
21+
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
22+
}),
1223
)
1324

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

1728
it('should append /tree/HEAD/{directory} for monorepo packages without .git', () => {
1829
const { repositoryUrl } = useRepositoryUrl(
19-
ref({
20-
repository: {
21-
type: 'git',
22-
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
23-
directory: 'packages/vite',
24-
},
25-
} as any),
30+
mockPackage({
31+
type: 'git',
32+
url: 'git+https://github.com/agentmarkup/agentmarkup.git',
33+
directory: 'packages/vite',
34+
}),
2635
)
2736

2837
expect(repositoryUrl.value).toBe(
@@ -31,41 +40,28 @@ describe('useRepositoryUrl', () => {
3140
})
3241

3342
it('should return null when repository has no url', () => {
34-
const { repositoryUrl } = useRepositoryUrl(
35-
ref({
36-
repository: {},
37-
} as any),
38-
)
39-
43+
// @ts-expect-error tests
44+
const { repositoryUrl } = useRepositoryUrl(mockPackage({}))
4045
expect(repositoryUrl.value).toBeNull()
4146
})
4247

4348
it('should return null when no repository field', () => {
44-
const { repositoryUrl } = useRepositoryUrl(ref({} as any))
45-
49+
// @ts-expect-error tests
50+
const { repositoryUrl } = useRepositoryUrl(mockPackage())
4651
expect(repositoryUrl.value).toBeNull()
4752
})
4853

4954
it('should handle plain HTTPS URLs without .git suffix', () => {
50-
const { repositoryUrl } = useRepositoryUrl(
51-
ref({
52-
repository: {
53-
url: 'https://github.com/nuxt/ui',
54-
},
55-
} as any),
56-
)
57-
55+
const { repositoryUrl } = useRepositoryUrl(mockPackage({ url: 'https://github.com/nuxt/ui' }))
5856
expect(repositoryUrl.value).toBe('https://github.com/nuxt/ui')
5957
})
6058

6159
it('should handle directory with trailing slash', () => {
6260
const { repositoryUrl } = useRepositoryUrl(
63-
ref({
64-
repository: {
65-
url: 'git+https://github.com/org/repo.git',
66-
directory: 'packages/core/',
67-
},
68-
} as any),
61+
mockPackage({
62+
url: 'git+https://github.com/org/repo.git',
63+
directory: 'packages/core/',
64+
}),
6965
)
7066

7167
expect(repositoryUrl.value).toBe('https://github.com/org/repo/tree/HEAD/packages/core/')

0 commit comments

Comments
 (0)