diff --git a/lib/travis/build/script/node_js.rb b/lib/travis/build/script/node_js.rb index 0635c92f89..708d41f378 100644 --- a/lib/travis/build/script/node_js.rb +++ b/lib/travis/build/script/node_js.rb @@ -8,6 +8,10 @@ class NodeJs < Script NPM_QUIET_TREE_VERSION = '5' + DEFAULTS = { + node_modules: true + } + def export super if node_js_given_in_config? @@ -17,7 +21,7 @@ def export def setup super - prepend_path './node_modules/.bin' + prepend_path './node_modules/.bin' if config[:node_modules] convert_legacy_nodejs_config update_nvm nvm_install diff --git a/spec/build/script/node_js_spec.rb b/spec/build/script/node_js_spec.rb index 46c389234d..a66df157d8 100644 --- a/spec/build/script/node_js_spec.rb +++ b/spec/build/script/node_js_spec.rb @@ -68,6 +68,27 @@ expect(sexp).to include_sexp [:export, ['TRAVIS_NODE_VERSION', '0.10']] end end + + end + end + + describe 'PATH manipulation' do + let(:sexp) { sexp_find(subject, [:if, "$(echo :$PATH: | grep -v :./node_modules/.bin:)"]) } + + context "when node_modules option is not set" do + it 'does adds "./node_modules/.bin" to PATH' do + expect(sexp).to include_sexp [:export, ['PATH', "./node_modules/.bin:$PATH"], echo: true] + end + end + + context "when node_modules option is set to false" do + before :each do + data[:config][:node_modules] = false + end + + it 'does not add "./node_modules/.bin" to PATH' do + expect(sexp).not_to include_sexp [:export, ['PATH', "./node_modules/.bin:$PATH"], echo: true] + end end end