-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(unpublish): Show warning on unpublish command when last version (#…
- Loading branch information
Showing
2 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,23 @@ const { fake: mockNpm } = require('../../fixtures/mock-npm') | |
|
||
let result = '' | ||
const noop = () => null | ||
const versions = async () => { | ||
return { | ||
versions: { | ||
'1.0.0': {}, | ||
'1.0.1': {}, | ||
}, | ||
} | ||
} | ||
|
||
const singleVersion = async () => { | ||
return { | ||
versions: { | ||
'1.0.0': {}, | ||
}, | ||
} | ||
} | ||
|
||
const config = { | ||
force: false, | ||
loglevel: 'silly', | ||
|
@@ -26,7 +43,7 @@ const npm = mockNpm({ | |
const mocks = { | ||
libnpmaccess: { lsPackages: noop }, | ||
libnpmpublish: { unpublish: noop }, | ||
'npm-registry-fetch': { json: noop }, | ||
'npm-registry-fetch': { json: versions }, | ||
'../../../lib/utils/otplease.js': async (opts, fn) => fn(opts), | ||
'../../../lib/utils/get-identity.js': async () => 'foo', | ||
'proc-log': { silly () {}, verbose () {} }, | ||
|
@@ -530,3 +547,32 @@ t.test('completion', async t => { | |
}) | ||
}) | ||
}) | ||
|
||
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(['[email protected]']), | ||
'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(['[email protected]']), | ||
'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.' | ||
) | ||
}) |