diff --git a/src/scripts/pr-check.js b/src/scripts/pr-check.js index 677416b..7a8b145 100644 --- a/src/scripts/pr-check.js +++ b/src/scripts/pr-check.js @@ -99,10 +99,9 @@ export function validateRequiredFields(pkg) { console.log('Validating URLs...'); const urlFields = ['sourceUrl', 'homepage']; for (const field of urlFields) { - try { - new URL(pkg[field]); - } catch (error) { - throw new Error(`Package ${pkg.name} has invalid ${field} URL: ${pkg[field]}`); + const url = pkg[field]; + if (!url.startsWith('http://') && !url.startsWith('https://')) { + throw new Error(`Package ${pkg.name} has invalid ${field} URL: ${url} - must start with http:// or https://`); } } } diff --git a/src/scripts/pr-check.test.js b/src/scripts/pr-check.test.js new file mode 100644 index 0000000..1820136 --- /dev/null +++ b/src/scripts/pr-check.test.js @@ -0,0 +1,42 @@ +import { validateRequiredFields } from './pr-check.js'; + +describe('validateRequiredFields', () => { + test('accepts valid GitHub URLs', () => { + const pkg = { + name: 'test-package', + description: 'Test package', + vendor: 'Test Vendor', + sourceUrl: 'https://github.com/owner/repo', + homepage: 'https://github.com/owner/repo', + license: 'MIT', + runtime: 'node' + }; + expect(() => validateRequiredFields(pkg)).not.toThrow(); + }); + + test('rejects invalid URLs without protocol', () => { + const pkg = { + name: 'test-package', + description: 'Test package', + vendor: 'Test Vendor', + sourceUrl: 'github.com/owner/repo', + homepage: 'https://github.com/owner/repo', + license: 'MIT', + runtime: 'node' + }; + expect(() => validateRequiredFields(pkg)).toThrow(/invalid sourceUrl URL/); + }); + + test('accepts both http and https protocols', () => { + const pkg = { + name: 'test-package', + description: 'Test package', + vendor: 'Test Vendor', + sourceUrl: 'http://github.com/owner/repo', + homepage: 'https://github.com/owner/repo', + license: 'MIT', + runtime: 'node' + }; + expect(() => validateRequiredFields(pkg)).not.toThrow(); + }); +});