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

unstar.js « commands « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85c33d279356398b40eace1672c19fcf6da7a367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm.js')
const MockRegistry = require('../../fixtures/mock-registry.js')

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(
    npm.exec('unstar', []),
    { code: 'EUSAGE' },
    'should throw usage error'
  )
})

t.test('unstar 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, users: { [username]: true } })
  await registry.package({ manifest, query: { write: true } })
  registry.whoami({ username })
  registry.star(manifest, {})

  await npm.exec('unstar', [pkgName])
  t.equal(
    joinedOutput(),
    '( ) @npmcli/test-package',
    'should output unstarred package msg'
  )
})

t.test('unstar a package unicode:true', async t => {
  const { npm, joinedOutput } = await loadMockNpm(t, {
    config: { unicode: true, ...auth },
  })

  const registry = new MockRegistry({
    tap: t,
    registry: npm.config.get('registry'),
    authorization: authToken,
  })
  const manifest = registry.manifest({ name: pkgName, users: { [username]: true } })
  await registry.package({ manifest, query: { write: true } })
  registry.whoami({ username })
  registry.star(manifest, {})

  await npm.exec('unstar', [pkgName])
  t.equal(
    joinedOutput(),
    '☆  @npmcli/test-package',
    'should output unstarred package msg'
  )
})