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

Configure Feed

Select the types of activity you want to include in your feed.

test: add tests for binary-detection (#895)

authored by

James Garbutt and committed by
GitHub
971dbeaf 32267641

+90
+90
test/unit/shared/utils/binary-detection.spec.ts
··· 1 + import { describe, expect, it } from 'vitest' 2 + import { isBinaryOnlyPackage, isCreatePackage } from '../../../../shared/utils/binary-detection' 3 + 4 + describe('binary-detection', () => { 5 + describe('isCreatePackage', () => { 6 + it('returns true for create-* packages', () => { 7 + expect(isCreatePackage('create-vite')).toBe(true) 8 + expect(isCreatePackage('create-svelte-app')).toBe(true) 9 + expect(isCreatePackage('create-lit-app')).toBe(true) 10 + }) 11 + 12 + it('returns true for scoped create-* packages', () => { 13 + expect(isCreatePackage('@lit/create-lit')).toBe(true) 14 + expect(isCreatePackage('@scope/create-something')).toBe(true) 15 + }) 16 + 17 + it('returns false for non-create packages', () => { 18 + expect(isCreatePackage('vite')).toBe(false) 19 + expect(isCreatePackage('lit')).toBe(false) 20 + expect(isCreatePackage('my-create-tool')).toBe(false) 21 + }) 22 + 23 + it('returns false for scoped non-create packages', () => { 24 + expect(isCreatePackage('@scope/some-package')).toBe(false) 25 + }) 26 + }) 27 + 28 + describe('isBinaryOnlyPackage', () => { 29 + it('returns true for create-* packages regardless of fields', () => { 30 + expect(isBinaryOnlyPackage({ name: 'create-vite' })).toBe(true) 31 + expect(isBinaryOnlyPackage({ name: 'create-vite', main: './index.js' })).toBe(true) 32 + }) 33 + 34 + it('returns true for scoped create-* packages', () => { 35 + expect(isBinaryOnlyPackage({ name: '@lit/create-lit' })).toBe(true) 36 + }) 37 + 38 + it('returns true for packages with bin but no entry points', () => { 39 + expect(isBinaryOnlyPackage({ name: 'eslint', bin: './bin/eslint.js' })).toBe(true) 40 + expect( 41 + isBinaryOnlyPackage({ 42 + name: 'typescript', 43 + bin: { tsc: './bin/tsc', tsserver: './bin/tsserver' }, 44 + }), 45 + ).toBe(true) 46 + }) 47 + 48 + it('returns false for packages with bin and main', () => { 49 + expect( 50 + isBinaryOnlyPackage({ 51 + name: 'eslint', 52 + bin: './bin/eslint.js', 53 + main: './lib/index.js', 54 + }), 55 + ).toBe(false) 56 + }) 57 + 58 + it('returns false for packages with bin and module', () => { 59 + expect( 60 + isBinaryOnlyPackage({ 61 + name: 'some-pkg', 62 + bin: './bin/cli.js', 63 + module: './dist/index.mjs', 64 + }), 65 + ).toBe(false) 66 + }) 67 + 68 + it('returns false for packages with bin and exports', () => { 69 + expect( 70 + isBinaryOnlyPackage({ 71 + name: 'some-pkg', 72 + bin: './bin/cli.js', 73 + exports: { '.': './dist/index.js' }, 74 + }), 75 + ).toBe(false) 76 + }) 77 + 78 + it('returns false for packages with no bin and no entry points', () => { 79 + expect(isBinaryOnlyPackage({ name: 'some-pkg' })).toBe(false) 80 + }) 81 + 82 + it('returns false for packages with empty bin object', () => { 83 + expect(isBinaryOnlyPackage({ name: 'some-pkg', bin: {} })).toBe(false) 84 + }) 85 + 86 + it('returns false for library-only packages', () => { 87 + expect(isBinaryOnlyPackage({ name: 'lodash', main: './lodash.js' })).toBe(false) 88 + }) 89 + }) 90 + })