[READ-ONLY] a fast, modern browser for the npm registry

test: reorganise npm unit tests (#876)

authored by

James Garbutt and committed by
GitHub
b569b707 4124003f

+29 -53
-52
test/unit/app/utils/npm.spec.ts
··· 1 - import { describe, expect, it } from 'vitest' 2 - 3 - import { buildScopeTeam } from '../../../../app/utils/npm/common' 4 - import { validateScopeTeam } from '../../../../cli/src/npm-client' 5 - import { getSpdxLicenseUrl } from '../../../../shared/utils/spdx' 6 - 7 - describe('getSpdxLicenseUrl', () => { 8 - it('returns SPDX URL for valid license identifiers', () => { 9 - expect(getSpdxLicenseUrl('MIT')).toBe('https://spdx.org/licenses/MIT.html') 10 - expect(getSpdxLicenseUrl('ISC')).toBe('https://spdx.org/licenses/ISC.html') 11 - expect(getSpdxLicenseUrl('Apache-2.0')).toBe('https://spdx.org/licenses/Apache-2.0.html') 12 - expect(getSpdxLicenseUrl('GPL-3.0-only')).toBe('https://spdx.org/licenses/GPL-3.0-only.html') 13 - expect(getSpdxLicenseUrl('BSD-2-Clause')).toBe('https://spdx.org/licenses/BSD-2-Clause.html') 14 - expect(getSpdxLicenseUrl('GPL-3.0+')).toBe('https://spdx.org/licenses/GPL-3.0+.html') 15 - }) 16 - 17 - it('trims whitespace from license identifiers', () => { 18 - expect(getSpdxLicenseUrl(' MIT ')).toBe('https://spdx.org/licenses/MIT.html') 19 - }) 20 - 21 - it('returns null for undefined or empty', () => { 22 - expect(getSpdxLicenseUrl(undefined)).toBeNull() 23 - expect(getSpdxLicenseUrl('')).toBeNull() 24 - expect(getSpdxLicenseUrl(' ')).toBeNull() 25 - }) 26 - 27 - it('returns null for invalid license identifiers', () => { 28 - // Compound expressions are not in the SPDX list 29 - expect(getSpdxLicenseUrl('MIT OR Apache-2.0')).toBeNull() 30 - // Non-existent licenses 31 - expect(getSpdxLicenseUrl('INVALID-LICENSE')).toBeNull() 32 - expect(getSpdxLicenseUrl('Custom')).toBeNull() 33 - }) 34 - }) 35 - 36 - describe('buildScopeTeam', () => { 37 - it('constructs scope:team with @ prefix', () => { 38 - expect(buildScopeTeam('netlify', 'developers')).toBe('@netlify:developers') 39 - expect(buildScopeTeam('nuxt', 'core')).toBe('@nuxt:core') 40 - }) 41 - 42 - it('strips existing @ prefix from orgName', () => { 43 - expect(buildScopeTeam('@netlify', 'developers')).toBe('@netlify:developers') 44 - expect(buildScopeTeam('@nuxt', 'core')).toBe('@nuxt:core') 45 - }) 46 - 47 - it('produces format accepted by validateScopeTeam', () => { 48 - expect(() => validateScopeTeam(buildScopeTeam('netlify', 'developers'))).not.toThrow() 49 - expect(() => validateScopeTeam(buildScopeTeam('nuxt', 'core'))).not.toThrow() 50 - expect(() => validateScopeTeam(buildScopeTeam('my-org', 'my-team'))).not.toThrow() 51 - }) 52 - })
+22
test/unit/app/utils/npm/common.spec.ts
··· 1 + import { describe, expect, it } from 'vitest' 2 + 3 + import { buildScopeTeam } from '../../../../../app/utils/npm/common' 4 + import { validateScopeTeam } from '../../../../../cli/src/npm-client' 5 + 6 + describe('buildScopeTeam', () => { 7 + it('constructs scope:team with @ prefix', () => { 8 + expect(buildScopeTeam('netlify', 'developers')).toBe('@netlify:developers') 9 + expect(buildScopeTeam('nuxt', 'core')).toBe('@nuxt:core') 10 + }) 11 + 12 + it('strips existing @ prefix from orgName', () => { 13 + expect(buildScopeTeam('@netlify', 'developers')).toBe('@netlify:developers') 14 + expect(buildScopeTeam('@nuxt', 'core')).toBe('@nuxt:core') 15 + }) 16 + 17 + it('produces format accepted by validateScopeTeam', () => { 18 + expect(() => validateScopeTeam(buildScopeTeam('netlify', 'developers'))).not.toThrow() 19 + expect(() => validateScopeTeam(buildScopeTeam('nuxt', 'core'))).not.toThrow() 20 + expect(() => validateScopeTeam(buildScopeTeam('my-org', 'my-team'))).not.toThrow() 21 + }) 22 + })
+7 -1
test/unit/shared/utils/spdx.spec.ts
··· 25 25 }) 26 26 27 27 describe('getSpdxLicenseUrl', () => { 28 - it('returns URL for valid SPDX licenses', () => { 28 + it('returns URL for valid license identifiers', () => { 29 29 expect(getSpdxLicenseUrl('MIT')).toBe('https://spdx.org/licenses/MIT.html') 30 + expect(getSpdxLicenseUrl('ISC')).toBe('https://spdx.org/licenses/ISC.html') 30 31 expect(getSpdxLicenseUrl('Apache-2.0')).toBe('https://spdx.org/licenses/Apache-2.0.html') 32 + expect(getSpdxLicenseUrl('GPL-3.0-only')).toBe('https://spdx.org/licenses/GPL-3.0-only.html') 33 + expect(getSpdxLicenseUrl('BSD-2-Clause')).toBe('https://spdx.org/licenses/BSD-2-Clause.html') 34 + expect(getSpdxLicenseUrl('GPL-3.0+')).toBe('https://spdx.org/licenses/GPL-3.0+.html') 31 35 }) 32 36 33 37 it('returns null for invalid licenses', () => { 34 38 expect(getSpdxLicenseUrl('CustomLicense')).toBeNull() 35 39 expect(getSpdxLicenseUrl('INVALID')).toBeNull() 40 + expect(getSpdxLicenseUrl('MIT OR Apache-2.0')).toBeNull() 36 41 }) 37 42 38 43 it('returns null for undefined or empty', () => { 39 44 expect(getSpdxLicenseUrl(undefined)).toBeNull() 40 45 expect(getSpdxLicenseUrl('')).toBeNull() 46 + expect(getSpdxLicenseUrl(' ')).toBeNull() 41 47 }) 42 48 43 49 it('trims whitespace', () => {