1const t = require('tap') 2const { load: loadMockNpm } = require('../../fixtures/mock-npm.js') 3const MockRegistry = require('@npmcli/mock-registry') 4 5const pkgName = '@npmcli/test-package' 6const authToken = 'test-auth-token' 7const username = 'test-user' 8const auth = { '//registry.npmjs.org/:_authToken': authToken } 9 10t.test('no args', async t => { 11 const { npm } = await loadMockNpm(t) 12 await t.rejects( 13 npm.exec('star', []), 14 { code: 'EUSAGE' }, 15 'should throw usage error' 16 ) 17}) 18 19t.test('first person to star a package unicode:false', async t => { 20 const { npm, joinedOutput } = await loadMockNpm(t, { 21 config: { unicode: false, ...auth }, 22 }) 23 const registry = new MockRegistry({ 24 tap: t, 25 registry: npm.config.get('registry'), 26 authorization: authToken, 27 }) 28 const manifest = registry.manifest({ name: pkgName }) 29 await registry.package({ manifest, query: { write: true } }) 30 registry.whoami({ username }) 31 registry.star(manifest, { [username]: true }) 32 33 await npm.exec('star', [pkgName]) 34 t.equal( 35 joinedOutput(), 36 '(*) @npmcli/test-package', 37 'should output starred package msg' 38 ) 39}) 40 41t.test('second person to star a package unicode:true', async t => { 42 const { npm, joinedOutput } = await loadMockNpm(t, { 43 config: { unicode: true, ...auth }, 44 }) 45 const registry = new MockRegistry({ 46 tap: t, 47 registry: npm.config.get('registry'), 48 authorization: authToken, 49 }) 50 const manifest = registry.manifest({ name: pkgName, users: { otheruser: true } }) 51 await registry.package({ manifest, query: { write: true } }) 52 registry.whoami({ username }) 53 registry.star(manifest, { otheruser: true, [username]: true }) 54 55 await npm.exec('star', [pkgName]) 56 t.equal( 57 joinedOutput(), 58 '★ @npmcli/test-package', 59 'should output starred package msg' 60 ) 61}) 62