Skip to content

Commit 4f83375

Browse files
committed
fix npm --auth_method, add specs
1 parent a24ef8b commit 4f83375

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/dpl/providers/npm.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Npm < Provider
1919
opt '--registry URL', 'npm registry url'
2020
opt '--src SRC', 'directory or tarball to publish', default: '.'
2121
opt '--tag TAGS', 'distribution tags to add'
22-
opt '--auth_method', 'Authentication method', enum: %w(auth)
22+
opt '--auth_method METHOD', 'Authentication method', enum: %w(auth)
2323

2424
REGISTRY = 'registry.npmjs.org'
2525
NPMRC = '~/.npmrc'

spec/dpl/providers/npm_spec.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
describe Dpl::Providers::Npm do
22
let(:args) { |e| %w(--email email --api_key 12345) + args_from_description(e) }
33

4-
let(:npmrc) do
5-
sq(<<-rc)
6-
_auth = 12345
7-
email = email
8-
rc
9-
end
10-
4+
before { allow(ctx).to receive(:npm_version).and_return(npm_version) if defined?(npm_version) }
115
before { |c| subject.run if run?(c) }
126

137
describe 'by default', record: true do
@@ -17,7 +11,6 @@
1711
it { should have_run 'npm config set registry "registry.npmjs.org"' }
1812
it { should have_run 'npm publish .' }
1913
it { should have_run_in_order }
20-
it { should have_written '~/.npmrc', npmrc }
2114
end
2215

2316
describe 'given --registry registry' do
@@ -36,6 +29,24 @@
3629
it { should have_run 'npm publish . --tag="tag"' }
3730
end
3831

32+
let(:npmrc_1) { "_auth = 12345\nemail = email" }
33+
let(:npmrc_2) { '//registry.npmjs.org/:_authToken=12345' }
34+
35+
describe 'npm_version 1' do
36+
let(:npm_version) { '1' }
37+
it { should have_written '~/.npmrc', npmrc_1 }
38+
end
39+
40+
describe 'npm_version 2' do
41+
let(:npm_version) { '2' }
42+
it { should have_written '~/.npmrc', npmrc_2 }
43+
end
44+
45+
describe 'npm_version 2, given --auth_method auth' do
46+
let(:npm_version) { '2' }
47+
it { should have_written '~/.npmrc', npmrc_1 }
48+
end
49+
3950
describe 'with credentials in env vars', run: false do
4051
let(:args) { %w(--email email) }
4152
env NPM_API_TOKEN: '12345'

0 commit comments

Comments
 (0)