Skip to content

Commit

Permalink
Add tests for npm.publish
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Dec 19, 2018
1 parent 1805766 commit ffcfed4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getTag = () => {
return _.get(preReleaseComponents, 0, config.getOption('npm.tag'));
};

const publish = (options, pkgName, otpPrompt) => {
const publish = (options, pkgName = '', otpPrompt) => {
const { publishPath, tag, access, otp } = options;
const isScopedPkg = pkgName.startsWith('@');
const accessArg = isScopedPkg && access ? `--access ${access}` : '';
Expand Down
29 changes: 27 additions & 2 deletions test/npm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const test = require('tape');
const proxyquire = require('proxyquire');
const { Config } = require('../lib/config');
const { getPackageUrl, getTag } = require('../lib/npm');
const mockStdIo = require('mock-stdio');
const { Config, config } = require('../lib/config');
const { getPackageUrl, getTag, publish } = require('../lib/npm');

const getMock = config =>
proxyquire('../lib/npm', {
Expand Down Expand Up @@ -35,3 +36,27 @@ test('getTag (pre-release w/ different tag)', t => {
t.equal(npm.getTag(), 'rc');
t.end();
});

test('publish', async t => {
const { verbose, 'dry-run': dryRun } = config.options;
config.options.verbose = true;
config.options['dry-run'] = true;

{
mockStdIo.start();
await publish({ publishPath: '.', tag: 'latest' });
const { stdout } = mockStdIo.end();
t.ok(stdout.includes('npm publish . --tag latest'));
}

{
mockStdIo.start();
await publish({ publishPath: '.', tag: 'beta', access: 'public' }, '@scoped/pkg');
const { stdout } = mockStdIo.end();
t.ok(stdout.includes('npm publish . --tag beta --access public'));
}

config.options.verbose = verbose;
config.options['dry-run'] = dryRun;
t.end();
});

0 comments on commit ffcfed4

Please sign in to comment.