1const t = require('tap') 2 3const dym = require('../../../lib/utils/did-you-mean.js') 4 5t.test('did-you-mean', async t => { 6 t.test('with package.json', async t => { 7 const testdir = t.testdir({ 8 'package.json': JSON.stringify({ 9 bin: { 10 npx: 'exists', 11 }, 12 scripts: { 13 install: 'exists', 14 posttest: 'exists', 15 }, 16 }), 17 }) 18 t.test('nistall', async t => { 19 const result = await dym(testdir, 'nistall') 20 t.match(result, 'npm install') 21 }) 22 t.test('sttest', async t => { 23 const result = await dym(testdir, 'sttest') 24 t.match(result, 'npm test') 25 t.match(result, 'npm run posttest') 26 }) 27 t.test('npz', async t => { 28 const result = await dym(testdir, 'npxx') 29 t.match(result, 'npm exec npx') 30 }) 31 t.test('qwuijbo', async t => { 32 const result = await dym(testdir, 'qwuijbo') 33 t.match(result, '') 34 }) 35 }) 36 t.test('with no package.json', t => { 37 const testdir = t.testdir({}) 38 t.test('nistall', async t => { 39 const result = await dym(testdir, 'nistall') 40 t.match(result, 'npm install') 41 }) 42 t.end() 43 }) 44 t.test('missing bin and script properties', async t => { 45 const testdir = t.testdir({ 46 'package.json': JSON.stringify({ 47 name: 'missing-bin', 48 }), 49 }) 50 51 const result = await dym(testdir, 'nistall') 52 t.match(result, 'npm install') 53 }) 54}) 55