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

npm-usage.js « utils « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 035d4bbb21ef72612ed3b7d42ac5dcd8573e12bc (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
const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm.js')

t.test('usage', async t => {
  const { npm } = await loadMockNpm(t)
  t.afterEach(() => {
    npm.config.set('viewer', null)
    npm.config.set('long', false)
    npm.config.set('userconfig', '/some/config/file/.npmrc')
  })
  const { dirname } = require('path')
  const basedir = dirname(dirname(dirname(__dirname)))
  t.cleanSnapshot = str => str.split(basedir).join('{BASEDIR}')
    .split(require('../../../package.json').version).join('{VERSION}')

  npm.config.set('viewer', null)
  npm.config.set('long', false)
  npm.config.set('userconfig', '/some/config/file/.npmrc')

  t.test('basic usage', async t => {
    t.matchSnapshot(await npm.usage)
    t.end()
  })

  t.test('with browser', async t => {
    npm.config.set('viewer', 'browser')
    t.matchSnapshot(await npm.usage)
    t.end()
  })

  t.test('with long', async t => {
    npm.config.set('long', true)
    t.matchSnapshot(await npm.usage)
    t.end()
  })

  t.test('set process.stdout.columns', async t => {
    const { columns } = process.stdout
    t.teardown(() => {
      Object.defineProperty(process.stdout, 'columns', {
        value: columns,
        enumerable: true,
        configurable: true,
        writable: true,
      })
    })
    const cases = [0, 90]
    for (const cols of cases) {
      t.test(`columns=${cols}`, async t => {
        Object.defineProperty(process.stdout, 'columns', {
          value: cols,
          enumerable: true,
          configurable: true,
          writable: true,
        })
        t.matchSnapshot(await npm.usage)
      })
    }
  })
})