language/node: log verbose npm pack output

This makes npm pack to log verbose debug output to the console to
simplify debugging npm pack failures.
Refs: https://github.com/Homebrew/brew/pull/2820#discussion_r123890729
Prevously Utils.popen_read swallowed all debug output.
This commit is contained in:
Christian Moritz 2017-06-26 21:34:05 +02:00
parent 495520a1f9
commit fe39dbb78c
2 changed files with 15 additions and 3 deletions

View File

@ -10,7 +10,9 @@ module Language
# fed to `npm install` only symlinks are created linking back to that # fed to `npm install` only symlinks are created linking back to that
# directory, consequently breaking that assumption. We require a tarball # directory, consequently breaking that assumption. We require a tarball
# because npm install creates a "real" installation when fed a tarball. # because npm install creates a "real" installation when fed a tarball.
output = Utils.popen_read("npm pack").chomp pack_cmd = "npm pack -ddd"
ohai pack_cmd
output = `#{pack_cmd}`
if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty? if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty?
raise "npm failed to pack #{Dir.pwd}" raise "npm failed to pack #{Dir.pwd}"
end end

View File

@ -24,18 +24,28 @@ describe Language::Node do
describe "#std_npm_install_args" do describe "#std_npm_install_args" do
npm_install_arg = "libexec" npm_install_arg = "libexec"
npm_pack_cmd = "npm pack -ddd"
it "raises error with non zero exitstatus" do it "raises error with non zero exitstatus" do
allow(Language::Node).to receive(:`).with(npm_pack_cmd).and_return("error msg")
allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(42)
allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(42)
expect { subject.std_npm_install_args(npm_install_arg) }.to \
raise_error("npm failed to pack #{Dir.pwd}")
end
it "raises error with empty npm pack output" do
allow(Language::Node).to receive(:`).with(npm_pack_cmd).and_return("")
expect { subject.std_npm_install_args(npm_install_arg) }.to \ expect { subject.std_npm_install_args(npm_install_arg) }.to \
raise_error("npm failed to pack #{Dir.pwd}") raise_error("npm failed to pack #{Dir.pwd}")
end end
it "does not raise error with a zero exitstatus" do it "does not raise error with a zero exitstatus" do
allow(Utils).to receive(:popen_read).with("npm pack").and_return("pack") allow(Language::Node).to receive(:`).with(npm_pack_cmd).and_return("pack.tgz")
allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0) allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0)
allow_any_instance_of(nil::NilClass).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) resp = subject.std_npm_install_args(npm_install_arg)
expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack") expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack.tgz")
end end
end end