Skip to content

Commit eaeb2a1

Browse files
committed
Update test files for consistency and improve assertions
1 parent 188f795 commit eaeb2a1

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

test/json-export.test.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ describe('PackageURL JSON/dict export', () => {
9696
const obj = purl.toObject()
9797

9898
expect(obj.qualifiers).toEqual(qualifiers)
99-
expect(obj.qualifiers).not.toBe(qualifiers) // Should be a copy, not the same reference
99+
// Should be a copy, not the same reference
100+
expect(obj.qualifiers).not.toBe(qualifiers)
100101
})
101102
})
102103

test/package-url.test.mts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,7 @@ describe('PackageURL', () => {
771771
const isBuiltin = npmBuiltinNames.includes(id)
772772
const isMixedCased = /[A-Z]/.test(id)
773773
const containsIllegalCharacters = /[~'!()*]/.test(id)
774-
expect(
775-
isBuiltin || isMixedCased || containsIllegalCharacters,
774+
expect(isBuiltin || isMixedCased || containsIllegalCharacters,
776775
`assert for ${legacyName}`,
777776
)
778777
}
@@ -1572,7 +1571,8 @@ describe('PackageURL', () => {
15721571
// Test npm type edge cases with long names
15731572
it('should validate npm namespace+name length limit', () => {
15741573
const namespace = '@' + 'a'.repeat(100)
1575-
const name = 'b'.repeat(115) // This makes namespace + name > 214 chars
1574+
// This makes namespace + name > 214 chars
1575+
const name = 'b'.repeat(115)
15761576

15771577
expect(() => new PackageURL('npm', namespace, name, '1.0.0')).toThrow(
15781578
/npm "namespace" and "name" components can not collectively be more than 214 characters/,
@@ -1924,7 +1924,8 @@ describe('PackageURL', () => {
19241924
name: 'パッケージ',
19251925
expectedError:
19261926
/npm "name" component can only contain URL-friendly characters/,
1927-
}, // Non-ASCII characters
1927+
// Non-ASCII characters
1928+
},
19281929
]
19291930

19301931
testCases.forEach(({ expectedError, name }) => {
@@ -1947,7 +1948,8 @@ describe('PackageURL', () => {
19471948
]
19481949
validNames.forEach(name => {
19491950
const comp = { namespace: '', name }
1950-
const result = PurlType.npm.validate(comp, true) // Should not throw
1951+
// Should not throw
1952+
const result = PurlType.npm.validate(comp, true)
19511953
expect(result).toBe(true)
19521954
})
19531955
})
@@ -2491,7 +2493,8 @@ describe('PackageURL', () => {
24912493
expect(result1).toBe('Invalid purl: a')
24922494

24932495
// Test character just outside range
2494-
const result2 = formatPurlErrorMessage('[') // Character after Z
2496+
// Character after Z
2497+
const result2 = formatPurlErrorMessage('[')
24952498
expect(result2).toBe('Invalid purl: [')
24962499
})
24972500

@@ -2625,10 +2628,12 @@ describe('PackageURL', () => {
26252628
)
26262629
expect(formatPurlErrorMessage('[ message')).toBe(
26272630
'Invalid purl: [ message',
2628-
) // After Z
2631+
// After Z
2632+
)
26292633
expect(formatPurlErrorMessage('@ message')).toBe(
26302634
'Invalid purl: @ message',
2631-
) // Before A
2635+
// Before A
2636+
)
26322637

26332638
// Test normalize.js line 7 - namespace filter
26342639
// Import already at top of file
@@ -2842,10 +2847,14 @@ describe('PackageURL', () => {
28422847

28432848
const frozen = recursiveFreeze(arr)
28442849
expect(Object.isFrozen(frozen)).toBe(true)
2845-
expect(Object.isFrozen(frozen[0])).toBe(true) // func1
2846-
expect(Object.isFrozen(frozen[1])).toBe(true) // object containing func2
2847-
expect(Object.isFrozen(frozen[2])).toBe(true) // func2
2848-
expect(Object.isFrozen(frozen[2].nested)).toBe(true) // func2's nested object
2850+
// func1
2851+
expect(Object.isFrozen(frozen[0])).toBe(true)
2852+
// object containing func2
2853+
expect(Object.isFrozen(frozen[1])).toBe(true)
2854+
// func2
2855+
expect(Object.isFrozen(frozen[2])).toBe(true)
2856+
// func2's nested object
2857+
expect(Object.isFrozen(frozen[2].nested)).toBe(true)
28492858
})
28502859

28512860
it('should handle purl with type but no slash', () => {

test/result.test.mts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,12 @@ describe('PackageURL Result methods', () => {
323323
expect(result.isOk()).toBe(true)
324324
const components = result.unwrap()
325325
expect(components).toHaveLength(6)
326-
expect(components[0]).toBe('npm') // type
327-
expect(components[2]).toBe('lodash') // name
328-
expect(components[3]).toBe('4.17.21') // version
326+
// type
327+
expect(components[0]).toBe('npm')
328+
// name
329+
expect(components[2]).toBe('lodash')
330+
// version
331+
expect(components[3]).toBe('4.17.21')
329332
})
330333

331334
it('should return Err for invalid purl string', () => {

0 commit comments

Comments
 (0)