license_finder 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "license_finder_test",
3
+ "version": "0.0.1",
4
+ "description": "has a licenses string field",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "node-polyglot": "^2.0.0"
8
+ },
9
+ "devDependencies": {
10
+ "enzyme": "^2.8.2"
11
+ },
12
+ "scripts": {},
13
+ "repository": {},
14
+ "author": "",
15
+ "licenses": "MIT",
16
+ "bugs": {},
17
+ "private": true,
18
+ "engines": {
19
+ "node": "^6.11.0",
20
+ "yarn": "^0.24.6",
21
+ "npm": "^5.0.3"
22
+ }
23
+ }
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe NpmPackage do
5
+ subject do
6
+ described_class.new(
7
+ "name" => "jasmine-node",
8
+ "version" => "1.3.1",
9
+ "description" => "a description",
10
+ "readme" => "a readme",
11
+ "path" => "some/node/package/path",
12
+ "homepage" => "a homepage",
13
+ "dependencies" => {
14
+ "coffee-script" => {
15
+ "name" => "coffee-script",
16
+ }
17
+ }
18
+ )
19
+ end
20
+
21
+ its(:name) { should == "jasmine-node" }
22
+ its(:version) { should == "1.3.1" }
23
+ its(:summary) { should eq "" }
24
+ its(:description) { should == "a description" }
25
+ its(:homepage) { should == "a homepage" }
26
+ its(:groups) { should == [] } # TODO: put devDependencies in 'dev' group?
27
+ its(:children) { should == ["coffee-script"] }
28
+ its(:install_path) { should eq "some/node/package/path" }
29
+ its(:package_manager) { should eq 'Npm' }
30
+
31
+ describe '#license_names_from_spec' do
32
+ let(:node_module1) { {"license" => "MIT"} }
33
+ let(:node_module2) { {"licenses" => [{"type" => "BSD"}]} }
34
+ let(:node_module3) { {"license" => {"type" => "PSF"}} }
35
+ let(:node_module4) { {"licenses" => ["MIT"]} }
36
+ let(:misdeclared_node_module) { {"licenses" => {"type" => "MIT"}} }
37
+
38
+ it 'finds the license for both license structures' do
39
+ package = NpmPackage.new(node_module1)
40
+ expect(package.license_names_from_spec).to eq ["MIT"]
41
+
42
+ package = NpmPackage.new(node_module2)
43
+ expect(package.license_names_from_spec).to eq ["BSD"]
44
+
45
+ package = NpmPackage.new(node_module3)
46
+ expect(package.license_names_from_spec).to eq ["PSF"]
47
+
48
+ package = NpmPackage.new(node_module4)
49
+ expect(package.license_names_from_spec).to eq ["MIT"]
50
+
51
+ package = NpmPackage.new(misdeclared_node_module)
52
+ expect(package.license_names_from_spec).to eq ["MIT"]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -3,19 +3,19 @@ require 'fakefs/spec_helpers'
3
3
 
4
4
  module LicenseFinder
5
5
  describe NPM do
6
- let(:root) { "/fake-node-project" }
6
+ let(:root) { '/fake-node-project' }
7
7
  let(:npm) { NPM.new project_path: Pathname.new(root) }
8
8
 
9
- it_behaves_like "a PackageManager"
9
+ it_behaves_like 'a PackageManager'
10
10
 
11
11
  let(:package_json) do
12
12
  {
13
13
  dependencies: {
14
- "dependency.js" => "1.3.3.7",
15
- "dependency2.js" => "4.2"
14
+ 'dependency.js' => '1.3.3.7',
15
+ 'dependency2.js' => '4.2'
16
16
  },
17
17
  devDependencies: {
18
- "dependency3.js" => "4.2"
18
+ 'dependency3.js' => '4.2'
19
19
  }
20
20
  }.to_json
21
21
  end
@@ -88,31 +88,26 @@ module LicenseFinder
88
88
  NPM.instance_variable_set(:@modules, nil)
89
89
  FileUtils.mkdir_p(Dir.tmpdir)
90
90
  FileUtils.mkdir_p(root)
91
- File.write(File.join(root, "package.json"), package_json)
92
- allow(npm).to receive(:capture) do |command|
93
- filename = command.scan(/> (.*)$/).last.first
94
- File.write(filename, dependency_json)
95
- ['', true]
96
- end
91
+ File.write(File.join(root, 'package.json'), package_json)
92
+ allow(npm).to receive(:run_command_with_tempfile_buffer).and_return ['', JSON.parse(dependency_json), true]
97
93
  end
98
94
 
99
95
  it 'fetches data from npm' do
100
96
  current_packages = npm.current_packages
101
-
102
- expect(current_packages.map(&:name)).to eq(["dependency.js", "dependency1-1.js", "dependency2.js", "dependency2-1.js", "dependency3.js", "dependency3-1.js"])
97
+ expect(current_packages.map(&:name)).to eq(%w(dependency.js dependency1-1.js dependency2.js dependency2-1.js dependency3.js dependency3-1.js))
103
98
  end
104
99
 
105
- it "finds the groups for dependencies" do
100
+ it 'finds the groups for dependencies' do
106
101
  current_packages = npm.current_packages
107
- expect(current_packages.find { |p| p.name == "dependency.js" }.groups).to eq(["dependencies"])
108
- expect(current_packages.find { |p| p.name == "dependency1-1.js" }.groups).to eq(["dependencies", "devDependencies"])
109
- expect(current_packages.find { |p| p.name == "dependency2.js" }.groups).to eq(["dependencies"])
110
- expect(current_packages.find { |p| p.name == "dependency2-1.js" }.groups).to eq(["dependencies"])
111
- expect(current_packages.find { |p| p.name == "dependency3.js" }.groups).to eq(["devDependencies"])
112
- expect(current_packages.find { |p| p.name == "dependency3-1.js" }.groups).to eq(["devDependencies"])
102
+ expect(current_packages.find { |p| p.name == 'dependency.js' }.groups).to eq(['dependencies'])
103
+ expect(current_packages.find { |p| p.name == 'dependency1-1.js' }.groups).to eq(%w(dependencies devDependencies))
104
+ expect(current_packages.find { |p| p.name == 'dependency2.js' }.groups).to eq(['dependencies'])
105
+ expect(current_packages.find { |p| p.name == 'dependency2-1.js' }.groups).to eq(['dependencies'])
106
+ expect(current_packages.find { |p| p.name == 'dependency3.js' }.groups).to eq(['devDependencies'])
107
+ expect(current_packages.find { |p| p.name == 'dependency3-1.js' }.groups).to eq(['devDependencies'])
113
108
  end
114
109
 
115
- it "does not support name version string" do
110
+ it 'does not support name version string' do
116
111
  json = <<-JSON
117
112
  {
118
113
  "devDependencies": {
@@ -122,67 +117,102 @@ module LicenseFinder
122
117
  JSON
123
118
 
124
119
  allow(Dir).to receive(:chdir).with(Pathname('/fake-node-project')) { |&block| block.call }
125
- allow(npm).to receive(:capture) do |command|
126
- filename = command.scan(/> (.*)$/).last.first
127
- File.write(filename, json)
128
- ['', true]
129
- end
120
+ allow(npm).to receive(:run_command_with_tempfile_buffer).and_return ['', JSON.parse(json), true]
130
121
 
131
122
  current_packages = npm.current_packages
132
123
  expect(current_packages.map(&:name)).to eq([])
133
124
  end
134
125
 
135
- it "fails when command fails" do
136
- allow(npm).to receive(:capture).with(/npm/).and_return('Some error', false).once
126
+ it 'fails when command fails' do
127
+ allow(npm).to receive(:run_command_with_tempfile_buffer).with(/npm/).and_return('Some error', nil, false).once
137
128
  expect { npm.current_packages }.to raise_error(RuntimeError)
138
129
  end
139
130
 
140
- it "does not fail when command fails but produces output" do
141
- allow(npm).to receive(:capture) do |command|
142
- filename = command.scan(/> (.*)$/).last.first
143
- File.write(filename, '{"foo":"bar"}')
144
- ['', false]
145
- end
131
+ it 'does not fail when command fails but produces output' do
132
+ allow(npm).to receive(:run_command_with_tempfile_buffer).and_return ['', {'foo' => 'bar'}, false]
146
133
  silence_stderr { npm.current_packages }
147
134
  end
148
135
 
149
- context "npm circular license edge case - GH#307" do
136
+ context 'npm recursive dependency edge case - GH#211' do
137
+ let(:package_json) do
138
+ FakeFS.without do
139
+ File.read fixture_path 'npm-recursive-dependencies/package.json'
140
+ end
141
+ end
142
+ let(:dependency_json) do
143
+ FakeFS.without do
144
+ File.read fixture_path 'npm-recursive-dependencies/npm-list.json'
145
+ end
146
+ end
147
+
148
+ describe '.current_packages' do
149
+ it 'correctly navigates the dependencies tree and pulls out valid information' do
150
+ expect(npm.current_packages.find { |p| p.name == 'pui-react-alerts' }.version).to eq('3.0.0-alpha.2')
151
+ expect(npm.current_packages.find { |p| p.name == 'pui-react-media' }.version).to eq('3.0.0-alpha.2')
152
+ end
153
+ end
154
+ end
155
+
156
+ context 'npm circular license edge case - GH#307' do
157
+ let(:package_json) do
158
+ FakeFS.without do
159
+ File.read fixture_path 'npm-circular-licenses/package.json'
160
+ end
161
+ end
162
+ let(:dependency_json) do
163
+ FakeFS.without do
164
+ File.read fixture_path 'npm-circular-licenses/npm-list.json'
165
+ end
166
+ end
167
+
168
+ describe '.current_packages' do
169
+ it 'correctly navigates the dependencies tree and pulls out valid information' do
170
+ FakeFS::FileSystem.clone(File.expand_path('../../../../../lib/license_finder/license/templates', __FILE__))
171
+ expect(npm.current_packages.find {|p| p.name == 'has'}.licenses.map(&:name)).to eq ['MIT']
172
+ expect(npm.current_packages.find {|p| p.name == 'function-bind'}.licenses.map(&:name)).to eq ['MIT']
173
+ end
174
+ end
175
+ end
176
+
177
+ context 'npm licenses is a string - GH#317' do
150
178
  let(:package_json) do
151
179
  FakeFS.without do
152
- File.read fixture_path "npm-circular-licenses/package.json"
180
+ File.read fixture_path 'npm-licenses-string/package.json'
153
181
  end
154
182
  end
155
183
  let(:dependency_json) do
156
184
  FakeFS.without do
157
- File.read fixture_path "npm-circular-licenses/npm-list.json"
185
+ File.read fixture_path 'npm-licenses-string/npm-list.json'
158
186
  end
159
187
  end
160
188
 
161
- describe ".current_packages" do
162
- it "correctly navigates the dependencies tree and pulls out valid information" do
189
+ describe '.current_packages' do
190
+ it 'correctly reports the license type' do
163
191
  FakeFS::FileSystem.clone(File.expand_path('../../../../../lib/license_finder/license/templates', __FILE__))
164
- expect(npm.current_packages.find {|p| p.name == "has"}.licenses.map(&:name)).to eq ["MIT"]
165
- expect(npm.current_packages.find {|p| p.name == "function-bind"}.licenses.map(&:name)).to eq ["MIT"]
192
+ expect(npm.current_packages.find {|p| p.name == 'boolbase'}.licenses.map(&:name)).to eq ['ISC']
166
193
  end
167
194
  end
168
195
  end
169
196
 
170
- context "npm recursive dependency edge case - GH#211" do
197
+ context 'when packages have circular dependencies - GH#313' do
171
198
  let(:package_json) do
172
199
  FakeFS.without do
173
- File.read fixture_path "npm-recursive-dependencies/package.json"
200
+ File.read fixture_path 'npm-circular-dependencies/package.json'
174
201
  end
175
202
  end
176
203
  let(:dependency_json) do
177
204
  FakeFS.without do
178
- File.read fixture_path "npm-recursive-dependencies/npm-list.json"
205
+ File.read fixture_path 'npm-circular-dependencies/npm-list.json'
179
206
  end
180
207
  end
181
208
 
182
- describe ".current_packages" do
183
- it "correctly navigates the dependencies tree and pulls out valid information" do
184
- expect(npm.current_packages.find { |p| p.name == "pui-react-alerts" }.version).to eq("3.0.0-alpha.2")
185
- expect(npm.current_packages.find { |p| p.name == "pui-react-media" }.version).to eq("3.0.0-alpha.2")
209
+ describe '.current_packages' do
210
+ it 'should return package tree successfully' do
211
+ packages = npm.current_packages
212
+ expect(packages.count).to be > 1
213
+ expect(packages.select{|p| p.name == 'babel-register'}.count).to eq(1)
214
+ expect(packages.select{|p| p.name == 'babel-core'}.count).to eq(1)
215
+ expect(packages.find{|p| p.name == 'babel-register'}.dependencies.count).to be > 0
186
216
  end
187
217
  end
188
218
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Maine
@@ -20,7 +20,7 @@ authors:
20
20
  autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
- date: 2017-07-12 00:00:00.000000000 Z
23
+ date: 2017-07-27 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
@@ -92,20 +92,6 @@ dependencies:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
- - !ruby/object:Gem::Dependency
96
- name: yajl-ruby
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
95
  - !ruby/object:Gem::Dependency
110
96
  name: with_env
111
97
  requirement: !ruby/object:Gem::Requirement
@@ -477,8 +463,12 @@ files:
477
463
  - spec/fixtures/license_names/Mit-License
478
464
  - spec/fixtures/license_names/README.rdoc
479
465
  - spec/fixtures/nested_gem/vendor/LICENSE
466
+ - spec/fixtures/npm-circular-dependencies/npm-list.json
467
+ - spec/fixtures/npm-circular-dependencies/package.json
480
468
  - spec/fixtures/npm-circular-licenses/npm-list.json
481
469
  - spec/fixtures/npm-circular-licenses/package.json
470
+ - spec/fixtures/npm-licenses-string/npm-list.json
471
+ - spec/fixtures/npm-licenses-string/package.json
482
472
  - spec/fixtures/npm-recursive-dependencies/npm-list.json
483
473
  - spec/fixtures/npm-recursive-dependencies/package.json
484
474
  - spec/fixtures/utf8_gem/README
@@ -516,6 +506,7 @@ files:
516
506
  - spec/lib/license_finder/package_managers/maven_package_spec.rb
517
507
  - spec/lib/license_finder/package_managers/maven_spec.rb
518
508
  - spec/lib/license_finder/package_managers/merged_package_spec.rb
509
+ - spec/lib/license_finder/package_managers/npm_package_spec.rb
519
510
  - spec/lib/license_finder/package_managers/npm_spec.rb
520
511
  - spec/lib/license_finder/package_managers/nuget_package_spec.rb
521
512
  - spec/lib/license_finder/package_managers/nuget_spec.rb
@@ -647,8 +638,12 @@ test_files:
647
638
  - spec/fixtures/license_names/Mit-License
648
639
  - spec/fixtures/license_names/README.rdoc
649
640
  - spec/fixtures/nested_gem/vendor/LICENSE
641
+ - spec/fixtures/npm-circular-dependencies/npm-list.json
642
+ - spec/fixtures/npm-circular-dependencies/package.json
650
643
  - spec/fixtures/npm-circular-licenses/npm-list.json
651
644
  - spec/fixtures/npm-circular-licenses/package.json
645
+ - spec/fixtures/npm-licenses-string/npm-list.json
646
+ - spec/fixtures/npm-licenses-string/package.json
652
647
  - spec/fixtures/npm-recursive-dependencies/npm-list.json
653
648
  - spec/fixtures/npm-recursive-dependencies/package.json
654
649
  - spec/fixtures/utf8_gem/README
@@ -686,6 +681,7 @@ test_files:
686
681
  - spec/lib/license_finder/package_managers/maven_package_spec.rb
687
682
  - spec/lib/license_finder/package_managers/maven_spec.rb
688
683
  - spec/lib/license_finder/package_managers/merged_package_spec.rb
684
+ - spec/lib/license_finder/package_managers/npm_package_spec.rb
689
685
  - spec/lib/license_finder/package_managers/npm_spec.rb
690
686
  - spec/lib/license_finder/package_managers/nuget_package_spec.rb
691
687
  - spec/lib/license_finder/package_managers/nuget_spec.rb