aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/language/node.rb6
-rw-r--r--Library/Homebrew/test/language/node_spec.rb46
2 files changed, 51 insertions, 1 deletions
diff --git a/Library/Homebrew/language/node.rb b/Library/Homebrew/language/node.rb
index 47431e8e5..01d41041b 100644
--- a/Library/Homebrew/language/node.rb
+++ b/Library/Homebrew/language/node.rb
@@ -25,7 +25,11 @@ module Language
npmrc.write npm_cache_config
# explicitly use our npm and node-gyp executables instead of the user
# 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
def self.std_npm_install_args(libexec)
diff --git a/Library/Homebrew/test/language/node_spec.rb b/Library/Homebrew/test/language/node_spec.rb
new file mode 100644
index 000000000..b2114bc4f
--- /dev/null
+++ b/Library/Homebrew/test/language/node_spec.rb
@@ -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