Skip to content

Instantly share code, notes, and snippets.

@yujinakayama
Created March 31, 2016 09:01
Show Gist options
  • Select an option

  • Save yujinakayama/7fb9954ea1c593fadf1eec21aaaa508d to your computer and use it in GitHub Desktop.

Select an option

Save yujinakayama/7fb9954ea1c593fadf1eec21aaaa508d to your computer and use it in GitHub Desktop.
require 'fileutils'
NPM_2 = File.expand_path('./npm/2.15.2/package/bin/npm-cli.js')
NPM_3 = File.expand_path('./npm/3.8.5/package/bin/npm-cli.js')
describe 'npm', :vcr do
def run!(*command)
Kernel.system(*command) || raise("Command exited with status #{$?}")
end
around do |example|
Dir.mktmpdir do |tmpdir|
FileUtils.copy('package.json', tmpdir)
Dir.chdir(tmpdir) do
example.run
end
end
end
def current_shrinkwrap_json
File.read('npm-shrinkwrap.json')
end
describe 'version 2' do
let(:npm) do
NPM_2
end
describe 'npm install --save' do
it 'does not update npm-shrinkwrap.json' do
run!(npm, 'shrinkwrap')
initial_shrinkwrap = current_shrinkwrap_json
run!(npm, 'install', '--save', 'lodash')
expect(current_shrinkwrap_json).to eq(initial_shrinkwrap)
end
end
end
describe 'version 3' do
let(:npm) do
NPM_3
end
describe 'npm install --save' do
it 'updates npm-shrinkwrap.json' do
run!(npm, 'shrinkwrap')
initial_shrinkwrap = current_shrinkwrap_json
run!(npm, 'install', '--save', 'lodash')
expect(current_shrinkwrap_json).not_to eq(initial_shrinkwrap)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment