]>
Commit | Line | Data |
---|---|---|
9be00a32 MM |
1 | require 'spec_helper' |
2 | ||
3 | module Pronto | |
5001cb27 MD |
4 | describe ESLintNpm do |
5 | let(:eslint) { ESLintNpm.new(patches) } | |
1845f2e3 | 6 | let(:patches) { [] } |
9be00a32 MM |
7 | |
8 | describe '#run' do | |
2add6782 | 9 | subject(:run) { eslint.run } |
9be00a32 MM |
10 | |
11 | context 'patches are nil' do | |
12 | let(:patches) { nil } | |
2add6782 MD |
13 | |
14 | it 'returns an empty array' do | |
15 | expect(run).to eql([]) | |
16 | end | |
9be00a32 MM |
17 | end |
18 | ||
19 | context 'no patches' do | |
20 | let(:patches) { [] } | |
2add6782 MD |
21 | |
22 | it 'returns an empty array' do | |
23 | expect(run).to eql([]) | |
24 | end | |
9be00a32 MM |
25 | end |
26 | ||
29509625 | 27 | context 'patches with a one and a four warnings' do |
9be00a32 MM |
28 | include_context 'test repo' |
29 | ||
30 | let(:patches) { repo.diff('master') } | |
31 | ||
2add6782 MD |
32 | it 'returns correct number of errors' do |
33 | expect(run.count).to eql(5) | |
34 | end | |
35 | ||
36 | it 'has correct first message' do | |
37 | expect(run.first.msg).to eql("'foo' is not defined.") | |
38 | end | |
1845f2e3 MD |
39 | |
40 | context( | |
41 | 'with files to lint config that never matches', | |
212da35b | 42 | config: { 'files_to_lint' => 'will never match' } |
1845f2e3 MD |
43 | ) do |
44 | it 'returns zero errors' do | |
45 | expect(run.count).to eql(0) | |
46 | end | |
47 | end | |
48 | ||
49 | context( | |
50 | 'with files to lint config that matches only .js', | |
212da35b | 51 | config: { 'files_to_lint' => /\.js/ } |
1845f2e3 MD |
52 | ) do |
53 | it 'returns correct amount of errors' do | |
54 | expect(run.count).to eql(2) | |
55 | end | |
56 | end | |
57 | ||
58 | context( | |
59 | 'with different eslint executable', | |
212da35b | 60 | config: { 'eslint_executable' => './custom_eslint.sh' } |
1845f2e3 MD |
61 | ) do |
62 | it 'calls the custom eslint eslint_executable' do | |
63 | expect { run }.to raise_error(JSON::ParserError, /custom eslint called/) | |
64 | end | |
65 | end | |
9be00a32 | 66 | end |
fb94b0e6 | 67 | |
29509625 | 68 | context 'repo with ignored and not ignored file, each with three warnings' do |
fb94b0e6 MD |
69 | include_context 'eslintignore repo' |
70 | ||
71 | let(:patches) { repo.diff('master') } | |
72 | ||
2add6782 MD |
73 | it 'returns correct number of errors' do |
74 | expect(run.count).to eql(3) | |
75 | end | |
76 | ||
77 | it 'has correct first message' do | |
78 | expect(run.first.msg).to eql("'HelloWorld' is defined but never used.") | |
79 | end | |
fb94b0e6 | 80 | end |
9be00a32 | 81 | end |
3403f9d1 | 82 | |
1845f2e3 MD |
83 | describe '#files_to_lint' do |
84 | subject(:files_to_lint) { eslint.files_to_lint } | |
3403f9d1 MD |
85 | |
86 | it 'matches .js by default' do | |
87 | expect(files_to_lint).to match('my_js.js') | |
88 | end | |
89 | ||
90 | it 'matches .es6 by default' do | |
91 | expect(files_to_lint).to match('my_js.es6') | |
92 | end | |
93 | end | |
94 | ||
1845f2e3 MD |
95 | describe '#eslint_executable' do |
96 | subject(:eslint_executable) { eslint.eslint_executable } | |
3403f9d1 MD |
97 | |
98 | it 'is `eslint` by default' do | |
99 | expect(eslint_executable).to eql('eslint') | |
100 | end | |
101 | end | |
9be00a32 MM |
102 | end |
103 | end |