]>
Commit | Line | Data |
---|---|---|
1 | require 'spec_helper' | |
2 | ||
3 | module Pronto | |
4 | describe ESLintNpm do | |
5 | let(:eslint) { ESLintNpm.new(patches) } | |
6 | let(:patches) { [] } | |
7 | ||
8 | describe '#run' do | |
9 | subject(:run) { eslint.run } | |
10 | ||
11 | context 'patches are nil' do | |
12 | let(:patches) { nil } | |
13 | ||
14 | it 'returns an empty array' do | |
15 | expect(run).to eql([]) | |
16 | end | |
17 | end | |
18 | ||
19 | context 'no patches' do | |
20 | let(:patches) { [] } | |
21 | ||
22 | it 'returns an empty array' do | |
23 | expect(run).to eql([]) | |
24 | end | |
25 | end | |
26 | ||
27 | context 'patches with a one and a four warnings' do | |
28 | include_context 'test repo' | |
29 | ||
30 | let(:patches) { repo.diff('master') } | |
31 | ||
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 | |
39 | ||
40 | context( | |
41 | 'with files to lint config that never matches', | |
42 | config: { 'files_to_lint' => 'will never match' } | |
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', | |
51 | config: { 'files_to_lint' => '\.js$' } | |
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', | |
60 | config: { 'eslint_executable' => './custom_eslint.sh' } | |
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 | |
66 | end | |
67 | ||
68 | context 'repo with ignored and not ignored file, each with three warnings' do | |
69 | include_context 'eslintignore repo' | |
70 | ||
71 | let(:patches) { repo.diff('master') } | |
72 | ||
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 | |
80 | end | |
81 | end | |
82 | ||
83 | describe '#files_to_lint' do | |
84 | subject(:files_to_lint) { eslint.files_to_lint } | |
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 | ||
95 | describe '#eslint_executable' do | |
96 | subject(:eslint_executable) { eslint.eslint_executable } | |
97 | ||
98 | it 'is `eslint` by default' do | |
99 | expect(eslint_executable).to eql('eslint') | |
100 | end | |
101 | end | |
102 | end | |
103 | end |