2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-13 02:23:17 +05:30
|
|
|
require "language/node"
|
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe Language::Node do
|
2021-03-17 15:34:20 +00:00
|
|
|
let(:npm_pack_cmd) { ["npm", "pack", "--ignore-scripts"] }
|
2020-11-18 08:39:51 +01:00
|
|
|
|
2017-06-15 02:40:57 +05:30
|
|
|
describe "#setup_npm_environment" do
|
2017-06-26 21:47:47 +02:00
|
|
|
it "calls prepend_path when node formula exists only during the first call" do
|
2017-06-19 01:18:38 +05:30
|
|
|
node = formula "node" do
|
2020-02-28 14:33:34 -05:00
|
|
|
url "node-test-v1.0"
|
2017-06-19 01:18:38 +05:30
|
|
|
end
|
|
|
|
stub_formula_loader(node)
|
2024-02-18 15:08:05 -08:00
|
|
|
without_partial_double_verification do
|
|
|
|
expect(ENV).to receive(:prepend_path)
|
|
|
|
end
|
2021-01-31 13:14:23 -05:00
|
|
|
described_class.instance_variable_set(:@env_set, false)
|
2024-03-29 18:26:13 -04:00
|
|
|
described_class.setup_npm_environment
|
2017-06-26 21:47:47 +02:00
|
|
|
|
2022-03-01 00:02:36 +00:00
|
|
|
expect(described_class.instance_variable_get(:@env_set)).to be(true)
|
2024-02-18 15:08:05 -08:00
|
|
|
without_partial_double_verification do
|
|
|
|
expect(ENV).not_to receive(:prepend_path)
|
|
|
|
end
|
2024-03-29 18:26:13 -04:00
|
|
|
described_class.setup_npm_environment
|
2017-06-13 02:29:16 +05:30
|
|
|
end
|
2017-06-19 01:28:43 +05:30
|
|
|
|
2017-06-26 21:47:47 +02:00
|
|
|
it "does not call prepend_path when node formula does not exist" do
|
2024-03-29 18:26:13 -04:00
|
|
|
without_partial_double_verification do
|
|
|
|
expect(ENV).not_to receive(:prepend_path)
|
|
|
|
end
|
|
|
|
described_class.setup_npm_environment
|
2017-06-19 01:28:43 +05:30
|
|
|
end
|
2017-06-13 02:23:17 +05:30
|
|
|
end
|
|
|
|
|
2020-11-05 21:12:41 -05:00
|
|
|
describe "#std_pack_for_installation" do
|
|
|
|
it "removes prepare and prepack scripts" do
|
2020-11-18 08:39:51 +01:00
|
|
|
mktmpdir.cd do
|
|
|
|
path = Pathname("package.json")
|
|
|
|
path.atomic_write("{\"scripts\":{\"prepare\": \"ls\", \"prepack\": \"ls\", \"test\": \"ls\"}}")
|
2021-03-17 15:34:20 +00:00
|
|
|
allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`echo pack.tgz`)
|
2021-01-31 13:14:23 -05:00
|
|
|
described_class.pack_for_installation
|
2020-11-18 08:39:51 +01:00
|
|
|
expect(path.read).not_to include("prepare")
|
|
|
|
expect(path.read).not_to include("prepack")
|
|
|
|
expect(path.read).to include("test")
|
|
|
|
end
|
2020-11-05 21:12:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-15 02:40:57 +05:30
|
|
|
describe "#std_npm_install_args" do
|
2020-10-22 19:36:06 +02:00
|
|
|
npm_install_arg = Pathname("libexec")
|
2017-06-13 02:23:17 +05:30
|
|
|
|
2017-06-15 02:40:57 +05:30
|
|
|
it "raises error with non zero exitstatus" do
|
2021-03-17 15:34:20 +00:00
|
|
|
allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`false`)
|
2023-04-11 21:12:13 +01:00
|
|
|
expect { described_class.std_npm_install_args(npm_install_arg) }.to raise_error("npm failed to pack #{Dir.pwd}")
|
2017-06-26 21:34:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises error with empty npm pack output" do
|
2021-03-17 15:34:20 +00:00
|
|
|
allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`true`)
|
2023-04-11 21:12:13 +01:00
|
|
|
expect { described_class.std_npm_install_args(npm_install_arg) }.to raise_error("npm failed to pack #{Dir.pwd}")
|
2017-06-13 02:23:17 +05:30
|
|
|
end
|
|
|
|
|
2017-06-15 02:40:57 +05:30
|
|
|
it "does not raise error with a zero exitstatus" do
|
2021-03-17 15:34:20 +00:00
|
|
|
allow(Utils).to receive(:popen_read).with(*npm_pack_cmd).and_return(`echo pack.tgz`)
|
2021-01-31 13:14:23 -05:00
|
|
|
resp = described_class.std_npm_install_args(npm_install_arg)
|
2017-06-26 21:34:05 +02:00
|
|
|
expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack.tgz")
|
2017-06-13 02:23:17 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#local_npm_install_args" do
|
2021-01-31 13:14:23 -05:00
|
|
|
resp = described_class.local_npm_install_args
|
2017-06-26 21:47:47 +02:00
|
|
|
expect(resp).to include("-ddd", "--build-from-source", "--cache=#{HOMEBREW_CACHE}/npm_cache")
|
2017-06-13 02:23:17 +05:30
|
|
|
end
|
2017-06-13 02:29:16 +05:30
|
|
|
end
|