| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 02:23:17 +05:30
										 |  |  | require "language/node" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe Language::Node do | 
					
						
							| 
									
										
										
										
											2020-11-18 08:39:51 +01:00
										 |  |  |   let(:npm_pack_cmd) { "npm pack --ignore-scripts" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2017-06-20 05:36:23 +05:30
										 |  |  |       expect(ENV).to receive(:prepend_path) | 
					
						
							| 
									
										
										
										
											2017-06-26 21:47:47 +02:00
										 |  |  |       subject.instance_variable_set(:@env_set, false) | 
					
						
							|  |  |  |       expect(subject.setup_npm_environment).to be_nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(subject.instance_variable_get(:@env_set)).to eq(true) | 
					
						
							|  |  |  |       expect(ENV).not_to receive(:prepend_path) | 
					
						
							|  |  |  |       expect(subject.setup_npm_environment).to be_nil | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2017-06-24 02:34:10 +05:30
										 |  |  |       expect(subject.setup_npm_environment).to be_nil | 
					
						
							| 
									
										
										
										
											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\"}}") | 
					
						
							|  |  |  |         allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`echo pack.tgz`) | 
					
						
							|  |  |  |         subject.pack_for_installation | 
					
						
							|  |  |  |         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 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`false`) | 
					
						
							| 
									
										
										
										
											2017-06-26 21:34:05 +02:00
										 |  |  |       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 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`true`) | 
					
						
							| 
									
										
										
										
											2017-06-24 02:34:10 +05:30
										 |  |  |       expect { subject.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 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       allow(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return(`echo pack.tgz`) | 
					
						
							| 
									
										
										
										
											2017-06-15 02:40:57 +05:30
										 |  |  |       resp = subject.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 | 
					
						
							| 
									
										
										
										
											2017-06-15 02:40:57 +05:30
										 |  |  |     resp = subject.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 |