Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/commands/star.js')
-rw-r--r--test/lib/commands/star.js154
1 files changed, 41 insertions, 113 deletions
diff --git a/test/lib/commands/star.js b/test/lib/commands/star.js
index 5b79c0776..ce9d258be 100644
--- a/test/lib/commands/star.js
+++ b/test/lib/commands/star.js
@@ -1,133 +1,61 @@
const t = require('tap')
-const { fake: mockNpm } = require('../../fixtures/mock-npm')
+const { load: loadMockNpm } = require('../../fixtures/mock-npm.js')
+const MockRegistry = require('../../fixtures/mock-registry.js')
-let result = ''
-
-const noop = () => null
-const config = {
- unicode: false,
- 'star.unstar': false,
-}
-const npm = mockNpm({
- config,
- output: (...msg) => {
- result += msg.join('\n')
- },
-})
-const npmFetch = { json: noop }
-const log = { error: noop, info: noop, verbose: noop }
-const mocks = {
- 'proc-log': log,
- 'npm-registry-fetch': npmFetch,
- '../../../lib/utils/get-identity.js': async () => 'foo',
-}
-
-const Star = t.mock('../../../lib/commands/star.js', mocks)
-const star = new Star(npm)
-
-t.afterEach(() => {
- config.unicode = false
- config['star.unstar'] = false
- log.info = noop
- result = ''
-})
+const pkgName = '@npmcli/test-package'
+const authToken = 'test-auth-token'
+const username = 'test-user'
+const auth = { '//registry.npmjs.org/:_authToken': authToken }
t.test('no args', async t => {
+ const { npm } = await loadMockNpm(t)
await t.rejects(
- star.exec([]),
+ npm.exec('star', []),
{ code: 'EUSAGE' },
'should throw usage error'
)
})
-t.test('star a package', async t => {
- t.plan(4)
- const pkgName = '@npmcli/arborist'
- npmFetch.json = async (uri, opts) => {
- return {
- _id: pkgName,
- _rev: 'hash',
- users: (
- opts.method === 'PUT'
- ? { foo: true }
- : {}
- ),
- }
- }
- log.info = (title, msg, id) => {
- t.equal(title, 'star', 'should use expected title')
- t.equal(msg, 'starring', 'should use expected msg')
- t.equal(id, pkgName, 'should use expected id')
- }
- await star.exec([pkgName])
- t.equal(
- result,
- '(*) @npmcli/arborist',
- 'should output starred package msg'
- )
-})
+t.test('first person to star a package unicode:false', async t => {
+ const { npm, joinedOutput } = await loadMockNpm(t, {
+ config: { unicode: false, ...auth },
+ })
+ const registry = new MockRegistry({
+ tap: t,
+ registry: npm.config.get('registry'),
+ authorization: authToken,
+ })
+ const manifest = registry.manifest({ name: pkgName })
+ await registry.package({ manifest, query: { write: true } })
+ registry.whoami({ username })
+ registry.star(manifest, { [username]: true })
-t.test('unstar a package', async t => {
- t.plan(4)
- const pkgName = '@npmcli/arborist'
- config['star.unstar'] = true
- npmFetch.json = async (uri, opts) => {
- return {
- _id: pkgName,
- _rev: 'hash',
- ...(opts.method === 'PUT'
- ? {}
- : { foo: true }
- ),
- }
- }
- log.info = (title, msg, id) => {
- t.equal(title, 'unstar', 'should use expected title')
- t.equal(msg, 'unstarring', 'should use expected msg')
- t.equal(id, pkgName, 'should use expected id')
- }
- await star.exec([pkgName])
+ await npm.exec('star', [pkgName])
t.equal(
- result,
- '( ) @npmcli/arborist',
- 'should output unstarred package msg'
+ joinedOutput(),
+ '(*) @npmcli/test-package',
+ 'should output starred package msg'
)
})
-t.test('unicode', async t => {
- t.test('star a package', async t => {
- config.unicode = true
- npmFetch.json = async (uri, opts) => ({})
- await star.exec(['pkg'])
- t.equal(
- result,
- '\u2605 pkg',
- 'should output unicode starred package msg'
- )
+t.test('second person to star a package unicode:true', async t => {
+ const { npm, joinedOutput } = await loadMockNpm(t, {
+ config: { unicode: true, ...auth },
})
-
- t.test('unstar a package', async t => {
- config.unicode = true
- config['star.unstar'] = true
- npmFetch.json = async (uri, opts) => ({})
- await star.exec(['pkg'])
- t.equal(
- result,
- '\u2606 pkg',
- 'should output unstarred package msg'
- )
+ const registry = new MockRegistry({
+ tap: t,
+ registry: npm.config.get('registry'),
+ authorization: authToken,
})
-})
+ const manifest = registry.manifest({ name: pkgName, users: { otheruser: true } })
+ await registry.package({ manifest, query: { write: true } })
+ registry.whoami({ username })
+ registry.star(manifest, { otheruser: true, [username]: true })
-t.test('logged out user', async t => {
- const Star = t.mock('../../../lib/commands/star.js', {
- ...mocks,
- '../../../lib/utils/get-identity.js': async () => undefined,
- })
- const star = new Star(npm)
- await t.rejects(
- star.exec(['@npmcli/arborist']),
- /You need to be logged in/,
- 'should throw login required error'
+ await npm.exec('star', [pkgName])
+ t.equal(
+ joinedOutput(),
+ '★ @npmcli/test-package',
+ 'should output starred package msg'
)
})