<commit_before>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 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)

      subject.setup_npm_environment
      expect(ENV["PATH"]).to include(Formula["node"].opt_libexec/"bin")
    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)
      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
<commit_msg>Added test for non existent node formula and existent npmrc<commit_after>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)

      subject.setup_npm_environment
      expect(ENV["PATH"]).to include(Formula["node"].opt_libexec/"bin")
    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 eq(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)
      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

{'fraction_non_alphanumeric': 0.10458404074702886, 'fraction_numerical': 0.0006791171477079797, 'mean_word_length': 3.901830282861897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4321753', 'n_tokens_mistral': 971, 'n_tokens_neox': 923, 'n_words': 223}