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

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

const dym = require('../../../lib/utils/did-you-mean.js')
t.test('did-you-mean', async t => {
  const { npm } = await loadMockNpm(t)
  t.test('with package.json', async t => {
    const testdir = t.testdir({
      'package.json': JSON.stringify({
        bin: {
          npx: 'exists',
        },
        scripts: {
          install: 'exists',
          posttest: 'exists',
        },
      }),
    })
    t.test('nistall', async t => {
      const result = await dym(npm, testdir, 'nistall')
      t.match(result, 'npm install')
    })
    t.test('sttest', async t => {
      const result = await dym(npm, testdir, 'sttest')
      t.match(result, 'npm test')
      t.match(result, 'npm run posttest')
    })
    t.test('npz', async t => {
      const result = await dym(npm, testdir, 'npxx')
      t.match(result, 'npm exec npx')
    })
    t.test('qwuijbo', async t => {
      const result = await dym(npm, testdir, 'qwuijbo')
      t.match(result, '')
    })
  })
  t.test('with no package.json', t => {
    const testdir = t.testdir({})
    t.test('nistall', async t => {
      const result = await dym(npm, testdir, 'nistall')
      t.match(result, 'npm install')
    })
    t.end()
  })
  t.test('missing bin and script properties', async t => {
    const testdir = t.testdir({
      'package.json': JSON.stringify({
        name: 'missing-bin',
      }),
    })

    const result = await dym(npm, testdir, 'nistall')
    t.match(result, 'npm install')
  })
})