Merge pull request #2777 from mansimarkaur/inc_test_cov

Added tests for language/node.rb
This commit is contained in:
Mike McQuaid 2017-06-24 22:30:47 +01:00 committed by GitHub
commit 73d81bb96d
2 changed files with 51 additions and 1 deletions

View File

@ -25,7 +25,11 @@ module Language
npmrc.write npm_cache_config npmrc.write npm_cache_config
# explicitly use our npm and node-gyp executables instead of the user # explicitly use our npm and node-gyp executables instead of the user
# managed ones in HOMEBREW_PREFIX/lib/node_modules which might be broken # managed ones in HOMEBREW_PREFIX/lib/node_modules which might be broken
ENV.prepend_path "PATH", Formula["node"].opt_libexec/"bin" begin
ENV.prepend_path "PATH", Formula["node"].opt_libexec/"bin"
rescue FormulaUnavailableError
nil
end
end end
def self.std_npm_install_args(libexec) def self.std_npm_install_args(libexec)

View File

@ -0,0 +1,46 @@
require "language/node"
describe Language::Node do
describe "#setup_npm_environment" do
it "does nothing when npmrc exists" do
expect(subject.setup_npm_environment).to be_nil
end
it "calls prepend_path when node formula exists and npmrc does not exist" do
node = formula "node" do
url "node-test"
end
stub_formula_loader(node)
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false)
expect(ENV).to receive(:prepend_path)
subject.setup_npm_environment
end
it "does not call prepend_path when node formula does not exist but npmrc exists" do
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false)
expect(subject.setup_npm_environment).to be_nil
end
end
describe "#std_npm_install_args" do
npm_install_arg = "libexec"
it "raises error with non zero exitstatus" do
expect { subject.std_npm_install_args(npm_install_arg) }.to \
raise_error("npm failed to pack #{Dir.pwd}")
end
it "does not raise error with a zero exitstatus" do
allow(Utils).to receive(:popen_read).with("npm pack").and_return("pack")
allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0)
allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(0)
resp = subject.std_npm_install_args(npm_install_arg)
expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack")
end
end
specify "#local_npm_install_args" do
resp = subject.local_npm_install_args
expect(resp).to include("--verbose")
end
end