Skip to content

Commit 64c8412

Browse files
committed
Clean up test suite by removing duplicates and improving clarity
- Consolidate 3 redundant URL authority tests into 1 comprehensive test - Rename ambiguous test descriptions for better clarity - Reduce test count from 783 to 781 with no coverage loss - Maintain 100% code coverage across all metrics
1 parent 7aeee19 commit 64c8412

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

test/json-export.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('PackageURL JSON/dict export', () => {
240240
expect(partialPurl.subpath).toBeUndefined()
241241
})
242242

243-
it('should validate input and throw appropriate errors', () => {
243+
it('should validate object input and throw appropriate errors', () => {
244244
// Test non-object inputs
245245
expect(() => PackageURL.fromObject('not an object')).toThrow(
246246
'Object argument is required.',
@@ -290,7 +290,7 @@ describe('PackageURL JSON/dict export', () => {
290290
expect(completePurl.subpath).toBe('lib/fs.d.ts')
291291
})
292292

293-
it('should validate input and throw appropriate errors', () => {
293+
it('should validate JSON string input and throw appropriate errors', () => {
294294
// Test non-string inputs
295295
expect(() => PackageURL.fromJSON(123)).toThrow(
296296
'JSON string argument is required.',

test/package-url.test.mts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -921,42 +921,31 @@ describe('PackageURL', () => {
921921
)
922922
})
923923

924-
it('should reject URLs with authority components', () => {
924+
it('should reject all URL authority component combinations', () => {
925+
// Full credentials with host and port
925926
expect(() =>
926927
PackageURL.fromString('pkg://user:pass@host:8080/type/name'),
927928
).toThrow(/cannot contain a "user:pass@host:port"/)
929+
930+
// Username with host
928931
expect(() =>
929932
PackageURL.fromString('pkg://user@host/type/name'),
930933
).toThrow(/cannot contain a "user:pass@host:port"/)
931-
})
932934

933-
it('should reject URLs with password auth component', () => {
934-
// Test password-only auth (empty username, non-empty password)
935+
// Password only (empty username, non-empty password)
935936
expect(() =>
936937
PackageURL.fromString('pkg://:password@type/name'),
937938
).toThrow(/cannot contain a "user:pass@host:port"/)
938-
})
939939

940-
it('should reject all combinations of username and password auth', () => {
941-
// Test username only (already covered but for completeness)
940+
// Username only
942941
expect(() => PackageURL.fromString('pkg://user@type/name')).toThrow(
943942
/cannot contain a "user:pass@host:port"/,
944943
)
945944

946-
// Test password only (already covered but for completeness)
947-
expect(() =>
948-
PackageURL.fromString('pkg://:password@type/name'),
949-
).toThrow(/cannot contain a "user:pass@host:port"/)
950-
951-
// Test both username and password (full auth credentials)
945+
// Full credentials without host
952946
expect(() =>
953947
PackageURL.fromString('pkg://user:password@type/name'),
954948
).toThrow(/cannot contain a "user:pass@host:port"/)
955-
956-
// Test with host component too (complete authority format)
957-
expect(() =>
958-
PackageURL.fromString('pkg://user:pass@host:8080/type/name'),
959-
).toThrow(/cannot contain a "user:pass@host:port"/)
960949
})
961950

962951
it('should handle URL parsing failures gracefully', () => {

test/result.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ describe('PackageURL Result methods', () => {
300300
})
301301

302302
describe('tryParseString', () => {
303-
it('should return Ok for valid purl string', () => {
303+
it('should return Ok with parsed components for valid purl string', () => {
304304
const result = PackageURL.tryParseString('pkg:npm/[email protected]')
305305

306306
expect(result.isOk()).toBe(true)
@@ -314,7 +314,7 @@ describe('PackageURL Result methods', () => {
314314
expect(components[3]).toBe('4.17.21')
315315
})
316316

317-
it('should return Err for invalid purl string', () => {
317+
it('should return Err when parsing invalid purl string', () => {
318318
const result = PackageURL.tryParseString('invalid-purl')
319319

320320
expect(result.isErr()).toBe(true)

0 commit comments

Comments
 (0)