|
| 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