2017-06-13 02:23:17 +05:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								require "language/node"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								describe Language::Node do
							 | 
						
					
						
							
								
									
										
										
										
											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
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        url "node-test"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      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
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 02:40:57 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  describe "#std_npm_install_args" do
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    npm_install_arg = "libexec"
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-29 20:49:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    npm_pack_cmd = "npm pack --ignore-scripts"
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-13 02:23:17 +05:30
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-15 02:40:57 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it "raises error with non zero exitstatus" do
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-07 15:11:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      allow(Utils).to receive(:popen_read).with(npm_pack_cmd) { `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
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-07 15:11:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      allow(Utils).to receive(:popen_read).with(npm_pack_cmd) { `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
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-07 15:11:41 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      allow(Utils).to receive(:popen_read).with(npm_pack_cmd) { `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
							 |