nodejs/deps/npm/test/lib/utils/did-you-mean.js
npm CLI robot dad539f0c3
deps: upgrade npm to 10.8.0
PR-URL: https://github.com/nodejs/node/pull/53014
Reviewed-By: Luke Karrys <luke@lukekarrys.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2024-05-16 12:38:49 +00:00

48 lines
1.2 KiB
JavaScript

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