Skip to content

Commit 0f565bf

Browse files
committed
Add integration tests using isolatePackage helper
- Test package installation in isolated environment - Verify all entry points load correctly - Test PackageURL, PackageURLBuilder, and UrlConverter functionality - Use correct dist/ import paths per package.json exports
1 parent adb599b commit 0f565bf

File tree

3 files changed

+101
-6
lines changed

3 files changed

+101
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"@dotenvx/dotenvx": "1.49.0",
7676
"@eslint/compat": "1.3.2",
7777
"@eslint/js": "9.35.0",
78-
"@socketsecurity/registry": "1.4.6",
78+
"@socketsecurity/registry": "1.5.0",
7979
"@types/node": "24.5.2",
8080
"@typescript/native-preview": "7.0.0-dev.20250926.1",
8181
"@vitest/coverage-v8": "3.2.4",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration.test.mts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @fileoverview Integration tests using socket-registry test helpers.
3+
* Tests the package in an isolated environment with installed dependencies.
4+
*/
5+
6+
import path from 'node:path'
7+
import { fileURLToPath } from 'node:url'
8+
9+
import { describe, expect, it } from 'vitest'
10+
11+
import { isolatePackage } from '../../socket-registry/test/utils/test-helpers.mjs'
12+
13+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
14+
const packagePath = path.resolve(__dirname, '..')
15+
16+
describe('Integration tests', () => {
17+
it('should install and load package successfully', async () => {
18+
const { pkgPath } = await isolatePackage(packagePath)
19+
20+
// Test that we can import the package
21+
const { PackageURL } = await import(`${pkgPath}/dist/package-url.js`)
22+
expect(PackageURL).toBeDefined()
23+
expect(typeof PackageURL).toBe('function')
24+
25+
// Test basic functionality
26+
const purl = new PackageURL('npm', undefined, 'lodash', '4.17.21')
27+
expect(purl.toString()).toBe('pkg:npm/[email protected]')
28+
})
29+
30+
it('should load PackageURLBuilder and work correctly', async () => {
31+
const { pkgPath } = await isolatePackage(packagePath)
32+
33+
const { PackageURLBuilder } = await import(`${pkgPath}/dist/package-url.js`)
34+
expect(PackageURLBuilder).toBeDefined()
35+
expect(typeof PackageURLBuilder.create).toBe('function')
36+
37+
// Test basic functionality
38+
const purl = PackageURLBuilder.create()
39+
.type('npm')
40+
.name('lodash')
41+
.version('4.17.21')
42+
.build()
43+
expect(purl.toString()).toBe('pkg:npm/[email protected]')
44+
})
45+
46+
it('should load UrlConverter and work correctly', async () => {
47+
const { pkgPath } = await isolatePackage(packagePath)
48+
49+
const { UrlConverter } = await import(`${pkgPath}/dist/url-converter.js`)
50+
const { PackageURL } = await import(`${pkgPath}/dist/package-url.js`)
51+
52+
expect(UrlConverter).toBeDefined()
53+
expect(typeof UrlConverter.toRepositoryUrl).toBe('function')
54+
55+
// Test basic functionality
56+
const purl = new PackageURL('npm', undefined, 'lodash', '4.17.21')
57+
const result = UrlConverter.toRepositoryUrl(purl)
58+
expect(result).toEqual({
59+
url: 'https://npmjs.com/package/lodash',
60+
type: 'web',
61+
})
62+
})
63+
64+
it('should have all entry points working together', async () => {
65+
const { pkgPath } = await isolatePackage(packagePath)
66+
67+
const { PackageURL, PackageURLBuilder } = await import(
68+
`${pkgPath}/dist/package-url.js`
69+
)
70+
const { UrlConverter } = await import(`${pkgPath}/dist/url-converter.js`)
71+
72+
// Build a purl
73+
const purl = PackageURLBuilder.create()
74+
.type('npm')
75+
.namespace('@types')
76+
.name('node')
77+
.version('16.11.7')
78+
.build()
79+
80+
// Convert to string (namespace @ is URL-encoded as %40)
81+
expect(purl.toString()).toBe('pkg:npm/%40types/[email protected]')
82+
83+
// Get URLs
84+
const urls = UrlConverter.getAllUrls(purl)
85+
expect(urls.repository).toBeDefined()
86+
expect(urls.download).toBeDefined()
87+
88+
// Parse back
89+
const parsed = PackageURL.fromString(purl.toString())
90+
expect(parsed.type).toBe('npm')
91+
expect(parsed.namespace).toBe('@types')
92+
expect(parsed.name).toBe('node')
93+
expect(parsed.version).toBe('16.11.7')
94+
})
95+
})

0 commit comments

Comments
 (0)