2020-12-09 10:33:11 -05:00
|
|
|
const t = require('tap')
|
2021-11-04 20:42:47 +00:00
|
|
|
const { fake: mockNpm } = require('../../fixtures/mock-npm')
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
let result = ''
|
|
|
|
const noop = () => null
|
2022-01-14 19:42:48 +02:00
|
|
|
const versions = async () => {
|
|
|
|
return {
|
|
|
|
versions: {
|
|
|
|
'1.0.0': {},
|
|
|
|
'1.0.1': {},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const singleVersion = async () => {
|
|
|
|
return {
|
|
|
|
versions: {
|
|
|
|
'1.0.0': {},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 14:58:11 -04:00
|
|
|
const config = {
|
|
|
|
force: false,
|
|
|
|
}
|
2021-05-20 15:54:50 -04:00
|
|
|
|
|
|
|
const testDir = t.testdir({
|
|
|
|
'package.json': JSON.stringify({
|
|
|
|
name: 'pkg',
|
|
|
|
version: '1.0.0',
|
|
|
|
}, null, 2),
|
|
|
|
})
|
|
|
|
|
2021-03-23 14:58:11 -04:00
|
|
|
const npm = mockNpm({
|
2021-05-20 15:54:50 -04:00
|
|
|
localPrefix: testDir,
|
2021-03-23 14:58:11 -04:00
|
|
|
config,
|
2021-03-11 17:54:23 -05:00
|
|
|
output: (...msg) => {
|
|
|
|
result += msg.join('\n')
|
|
|
|
},
|
2021-03-23 14:58:11 -04:00
|
|
|
})
|
2021-05-20 15:54:50 -04:00
|
|
|
|
2020-12-09 10:33:11 -05:00
|
|
|
const mocks = {
|
|
|
|
libnpmaccess: { lsPackages: noop },
|
|
|
|
libnpmpublish: { unpublish: noop },
|
2022-01-14 19:42:48 +02:00
|
|
|
'npm-registry-fetch': { json: versions },
|
2021-11-04 20:42:47 +00:00
|
|
|
'../../../lib/utils/otplease.js': async (opts, fn) => fn(opts),
|
|
|
|
'../../../lib/utils/get-identity.js': async () => 'foo',
|
2021-12-02 22:04:46 +00:00
|
|
|
'proc-log': { silly () {}, verbose () {} },
|
2020-12-09 10:33:11 -05:00
|
|
|
}
|
|
|
|
|
2021-04-15 21:53:45 -04:00
|
|
|
t.afterEach(() => {
|
2021-05-20 15:54:50 -04:00
|
|
|
npm.localPrefix = testDir
|
2020-12-09 10:33:11 -05:00
|
|
|
result = ''
|
2021-05-20 15:54:50 -04:00
|
|
|
config['dry-run'] = false
|
2021-03-23 14:58:11 -04:00
|
|
|
config.force = false
|
2022-02-24 21:41:49 +00:00
|
|
|
npm.config.set('loglevel', 'info')
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('no args --force', async t => {
|
2021-03-23 14:58:11 -04:00
|
|
|
config.force = true
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-12-02 22:04:46 +00:00
|
|
|
const log = {
|
2020-12-09 10:33:11 -05:00
|
|
|
silly (title) {
|
|
|
|
t.equal(title, 'unpublish', 'should silly log args')
|
|
|
|
},
|
|
|
|
verbose (title, msg) {
|
|
|
|
t.equal(title, 'unpublish', 'should have expected title')
|
|
|
|
t.match(
|
|
|
|
msg,
|
|
|
|
{ name: 'pkg', version: '1.0.0' },
|
|
|
|
'should have msg printing package.json contents'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const libnpmpublish = {
|
|
|
|
unpublish (spec, opts) {
|
2021-05-20 15:54:50 -04:00
|
|
|
t.equal(spec.raw, 'pkg@1.0.0', 'should unpublish expected spec')
|
2022-02-11 11:51:11 +02:00
|
|
|
t.match(
|
2020-12-09 10:33:11 -05:00
|
|
|
opts,
|
|
|
|
{
|
|
|
|
publishConfig: undefined,
|
|
|
|
},
|
|
|
|
'should unpublish with expected opts'
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmpublish,
|
2021-12-02 22:04:46 +00:00
|
|
|
'proc-log': log,
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
2021-05-20 15:54:50 -04:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.exec([])
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.equal(
|
|
|
|
result,
|
|
|
|
'- pkg@1.0.0',
|
|
|
|
'should output removed pkg@version on success'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('no args --force missing package.json', async t => {
|
2021-03-23 14:58:11 -04:00
|
|
|
config.force = true
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-05-20 15:54:50 -04:00
|
|
|
const testDir = t.testdir({})
|
|
|
|
npm.localPrefix = testDir
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await t.rejects(
|
|
|
|
unpublish.exec([]),
|
|
|
|
/Usage: npm unpublish/,
|
|
|
|
'should throw usage instructions on missing package.json'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('no args --force unknown error reading package.json', async t => {
|
2021-03-23 14:58:11 -04:00
|
|
|
config.force = true
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
'read-package-json': (path, cb) => cb(new Error('ERR')),
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await t.rejects(
|
|
|
|
unpublish.exec([]),
|
|
|
|
/ERR/,
|
|
|
|
'should throw unknown error from reading package.json'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('no args', async t => {
|
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await t.rejects(
|
|
|
|
unpublish.exec([]),
|
|
|
|
/Refusing to delete entire project/,
|
|
|
|
'should throw --force required error on no args'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('too many args', async t => {
|
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await t.rejects(
|
|
|
|
unpublish.exec(['a', 'b']),
|
|
|
|
/Usage: npm unpublish/,
|
|
|
|
'should throw usage instructions if too many args'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('unpublish <pkg>@version', async t => {
|
2021-12-02 22:04:46 +00:00
|
|
|
const log = {
|
2020-12-09 10:33:11 -05:00
|
|
|
silly (title, key, value) {
|
|
|
|
t.equal(title, 'unpublish', 'should silly log args')
|
2021-11-18 20:58:02 +00:00
|
|
|
if (key === 'spec') {
|
2021-05-20 15:54:50 -04:00
|
|
|
t.match(value, { name: 'pkg', rawSpec: '1.0.0' })
|
2021-11-18 20:58:02 +00:00
|
|
|
} else {
|
2020-12-09 10:33:11 -05:00
|
|
|
t.equal(value, 'pkg@1.0.0', 'should log originally passed arg')
|
2021-11-18 20:58:02 +00:00
|
|
|
}
|
2020-12-09 10:33:11 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const libnpmpublish = {
|
|
|
|
unpublish (spec, opts) {
|
2021-05-20 15:54:50 -04:00
|
|
|
t.equal(spec.raw, 'pkg@1.0.0', 'should unpublish expected parsed spec')
|
2020-12-09 10:33:11 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmpublish,
|
2021-12-02 22:04:46 +00:00
|
|
|
'proc-log': log,
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.exec(['pkg@1.0.0'])
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.equal(
|
|
|
|
result,
|
|
|
|
'- pkg@1.0.0',
|
|
|
|
'should output removed pkg@version on success'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('no version found in package.json', async t => {
|
2021-03-23 14:58:11 -04:00
|
|
|
config.force = true
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-05-20 15:54:50 -04:00
|
|
|
const testDir = t.testdir({
|
|
|
|
'package.json': JSON.stringify({
|
|
|
|
name: 'pkg',
|
|
|
|
}, null, 2),
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
2021-05-20 15:54:50 -04:00
|
|
|
npm.localPrefix = testDir
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.exec([])
|
|
|
|
t.equal(
|
|
|
|
result,
|
|
|
|
'- pkg',
|
|
|
|
'should output removed pkg on success'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('unpublish <pkg> --force no version set', async t => {
|
2021-03-23 14:58:11 -04:00
|
|
|
config.force = true
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.exec(['pkg'])
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.equal(
|
|
|
|
result,
|
|
|
|
'- pkg',
|
|
|
|
'should output pkg removed'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('silent', async t => {
|
2022-02-24 21:41:49 +00:00
|
|
|
npm.config.set('loglevel', 'silent')
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2021-05-20 15:54:50 -04:00
|
|
|
...mocks,
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
2021-05-20 15:54:50 -04:00
|
|
|
const unpublish = new Unpublish(npm)
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.exec(['pkg@1.0.0'])
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.equal(
|
|
|
|
result,
|
|
|
|
'',
|
|
|
|
'should have no output'
|
|
|
|
)
|
2021-05-20 15:54:50 -04:00
|
|
|
})
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('workspaces', async t => {
|
2021-05-20 15:54:50 -04:00
|
|
|
const testDir = t.testdir({
|
|
|
|
'package.json': JSON.stringify({
|
|
|
|
name: 'my-cool-pkg',
|
|
|
|
version: '1.0.0',
|
|
|
|
workspaces: ['workspace-a', 'workspace-b', 'workspace-c'],
|
|
|
|
}, null, 2),
|
|
|
|
'workspace-a': {
|
|
|
|
'package.json': JSON.stringify({
|
|
|
|
name: 'workspace-a',
|
|
|
|
version: '1.2.3-a',
|
|
|
|
repository: 'http://repo.workspace-a/',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
'workspace-b': {
|
|
|
|
'package.json': JSON.stringify({
|
|
|
|
name: 'workspace-b',
|
|
|
|
version: '1.2.3-n',
|
|
|
|
repository: 'https://github.com/npm/workspace-b',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
'workspace-c': {
|
|
|
|
'package.json': JSON.stringify({
|
|
|
|
name: 'workspace-n',
|
|
|
|
version: '1.2.3-n',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
})
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('no force', async t => {
|
2021-05-20 15:54:50 -04:00
|
|
|
npm.localPrefix = testDir
|
2021-11-04 20:42:47 +00:00
|
|
|
await t.rejects(
|
|
|
|
unpublish.execWorkspaces([], []),
|
|
|
|
/--force/,
|
|
|
|
'should require force'
|
|
|
|
)
|
2021-05-20 15:54:50 -04:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('all workspaces --force', async t => {
|
2021-05-20 15:54:50 -04:00
|
|
|
npm.localPrefix = testDir
|
|
|
|
config.force = true
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.execWorkspaces([], [])
|
|
|
|
t.matchSnapshot(result, 'should output all workspaces')
|
2021-05-20 15:54:50 -04:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('one workspace --force', async t => {
|
2021-05-20 15:54:50 -04:00
|
|
|
npm.localPrefix = testDir
|
|
|
|
config.force = true
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.execWorkspaces([], ['workspace-a'])
|
|
|
|
t.matchSnapshot(result, 'should output one workspaces')
|
2021-05-20 15:54:50 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('dryRun with spec', async t => {
|
2021-05-20 15:54:50 -04:00
|
|
|
config['dry-run'] = true
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2021-05-20 15:54:50 -04:00
|
|
|
...mocks,
|
|
|
|
libnpmpublish: { unpublish: () => {
|
|
|
|
throw new Error('should not be called')
|
|
|
|
} },
|
|
|
|
})
|
|
|
|
const unpublish = new Unpublish(npm)
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.exec(['pkg@1.0.0'])
|
|
|
|
|
|
|
|
t.equal(
|
|
|
|
result,
|
|
|
|
'- pkg@1.0.0',
|
|
|
|
'should output removed pkg@version on success'
|
|
|
|
)
|
2021-05-20 15:54:50 -04:00
|
|
|
})
|
|
|
|
|
2021-11-04 20:42:47 +00:00
|
|
|
t.test('dryRun with local package', async t => {
|
2021-05-20 15:54:50 -04:00
|
|
|
config['dry-run'] = true
|
|
|
|
config.force = true
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2021-05-20 15:54:50 -04:00
|
|
|
...mocks,
|
|
|
|
libnpmpublish: { unpublish: () => {
|
|
|
|
throw new Error('should not be called')
|
|
|
|
} },
|
|
|
|
})
|
|
|
|
const unpublish = new Unpublish(npm)
|
2021-11-04 20:42:47 +00:00
|
|
|
await unpublish.exec([])
|
|
|
|
t.equal(
|
|
|
|
result,
|
|
|
|
'- pkg@1.0.0',
|
|
|
|
'should output removed pkg@1.0.0 on success'
|
|
|
|
)
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
|
|
|
|
2021-03-01 11:38:43 -05:00
|
|
|
t.test('completion', async t => {
|
|
|
|
const testComp =
|
2021-03-04 17:40:28 -05:00
|
|
|
async (t, { unpublish, argv, partialWord, expect, title }) => {
|
|
|
|
const res = await unpublish.completion(
|
2021-11-18 20:58:02 +00:00
|
|
|
{ conf: { argv: { remain: argv } }, partialWord }
|
2021-03-04 17:40:28 -05:00
|
|
|
)
|
2021-03-01 11:38:43 -05:00
|
|
|
t.strictSame(res, expect, title || argv.join(' '))
|
|
|
|
}
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
t.test('completing with multiple versions from the registry', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmaccess: {
|
|
|
|
async lsPackages () {
|
|
|
|
return {
|
|
|
|
pkg: 'write',
|
|
|
|
bar: 'write',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'npm-registry-fetch': {
|
|
|
|
async json () {
|
|
|
|
return {
|
|
|
|
versions: {
|
|
|
|
'1.0.0': {},
|
|
|
|
'1.0.1': {},
|
|
|
|
'2.0.0': {},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish'],
|
|
|
|
partialWord: 'pkg',
|
|
|
|
expect: [
|
|
|
|
'pkg@1.0.0',
|
|
|
|
'pkg@1.0.1',
|
|
|
|
'pkg@2.0.0',
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('no versions retrieved', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmaccess: {
|
|
|
|
async lsPackages () {
|
|
|
|
return {
|
|
|
|
pkg: 'write',
|
|
|
|
bar: 'write',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'npm-registry-fetch': {
|
|
|
|
async json () {
|
|
|
|
return {
|
|
|
|
versions: {},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish'],
|
|
|
|
partialWord: 'pkg',
|
|
|
|
expect: [
|
|
|
|
'pkg',
|
|
|
|
],
|
|
|
|
title: 'should autocomplete package name only',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('packages starting with same letters', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmaccess: {
|
|
|
|
async lsPackages () {
|
|
|
|
return {
|
|
|
|
pkg: 'write',
|
|
|
|
pkga: 'write',
|
|
|
|
pkgb: 'write',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish'],
|
|
|
|
partialWord: 'pkg',
|
|
|
|
expect: [
|
|
|
|
'pkg',
|
|
|
|
'pkga',
|
|
|
|
'pkgb',
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('no packages retrieved', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmaccess: {
|
|
|
|
async lsPackages () {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish'],
|
|
|
|
partialWord: 'pkg',
|
|
|
|
expect: [],
|
|
|
|
title: 'should have no autocompletion',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('no pkg name to complete', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmaccess: {
|
|
|
|
async lsPackages () {
|
|
|
|
return {
|
|
|
|
pkg: {},
|
|
|
|
bar: {},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish'],
|
|
|
|
partialWord: undefined,
|
|
|
|
expect: ['pkg', 'bar'],
|
|
|
|
title: 'should autocomplete with available package names from user',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('no pkg names retrieved from user account', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
|
|
|
libnpmaccess: {
|
|
|
|
async lsPackages () {
|
|
|
|
return null
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish'],
|
|
|
|
partialWord: 'pkg',
|
|
|
|
expect: [],
|
|
|
|
title: 'should have no autocomplete',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('logged out user', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
2020-12-09 10:33:11 -05:00
|
|
|
...mocks,
|
2021-11-04 20:42:47 +00:00
|
|
|
'../../../lib/utils/get-identity.js': () => Promise.reject(new Error('ERR')),
|
2020-12-09 10:33:11 -05:00
|
|
|
})
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish'],
|
|
|
|
partialWord: 'pkg',
|
|
|
|
expect: [],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('too many args', async t => {
|
2021-11-04 20:42:47 +00:00
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', mocks)
|
2021-03-04 17:40:28 -05:00
|
|
|
const unpublish = new Unpublish(npm)
|
2020-12-09 10:33:11 -05:00
|
|
|
|
|
|
|
await testComp(t, {
|
2021-03-04 17:40:28 -05:00
|
|
|
unpublish,
|
2020-12-09 10:33:11 -05:00
|
|
|
argv: ['npm', 'unpublish', 'foo'],
|
|
|
|
partialWord: undefined,
|
|
|
|
expect: [],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2022-01-14 19:42:48 +02:00
|
|
|
|
|
|
|
t.test('show error on unpublish <pkg>@version with package.json and the last version', async t => {
|
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
|
|
|
...mocks,
|
|
|
|
'npm-registry-fetch': { json: singleVersion },
|
|
|
|
path: { resolve: () => testDir, join: () => testDir + '/package.json' },
|
|
|
|
})
|
|
|
|
const unpublish = new Unpublish(npm)
|
|
|
|
await t.rejects(
|
|
|
|
unpublish.exec(['pkg@1.0.0']),
|
|
|
|
'Refusing to delete the last version of the package. ' +
|
|
|
|
'It will block from republishing a new version for 24 hours.\n' +
|
|
|
|
'Run with --force to do this.'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.test('show error on unpublish <pkg>@version when the last version', async t => {
|
|
|
|
const Unpublish = t.mock('../../../lib/commands/unpublish.js', {
|
|
|
|
...mocks,
|
|
|
|
'npm-registry-fetch': { json: singleVersion },
|
|
|
|
})
|
|
|
|
const unpublish = new Unpublish(npm)
|
|
|
|
await t.rejects(
|
|
|
|
unpublish.exec(['pkg@1.0.0']),
|
|
|
|
'Refusing to delete the last version of the package. ' +
|
|
|
|
'It will block from republishing a new version for 24 hours.\n' +
|
|
|
|
'Run with --force to do this.'
|
|
|
|
)
|
|
|
|
})
|