]>
git.immae.eu Git - github/fretlink/pronto-hlint.git/blob - spec/pronto/eslint_spec.rb
1 # frozen_string_literal: true
7 let(:eslint) { ESLintNpm
.new(patches
) }
11 subject(:run) { eslint
.run
}
13 context
'patches are nil' do
16 it
'returns an empty array' do
17 expect(run
).to
eql([])
21 context
'no patches' do
24 it
'returns an empty array' do
25 expect(run
).to
eql([])
29 context
'patches with a one and a four warnings' do
30 include_context
'test repo'
32 let(:patches) { repo
.diff('master') }
34 it
'returns correct number of errors' do
35 expect(run
.count
).to
eql(5)
38 it
'has correct first message' do
39 expect(run
.first
.msg
).to
eql("'foo' is not defined.")
43 'with files to lint config that never matches',
44 config
: { 'files_to_lint' => 'will never match' }
46 it
'returns zero errors' do
47 expect(run
.count
).to
eql(0)
52 'with files to lint config that matches only .js',
53 config
: { 'files_to_lint' => '\.js$' }
55 it
'returns correct amount of errors' do
56 expect(run
.count
).to
eql(2)
61 'with cmd_line_opts to include .html',
62 config
: { 'cmd_line_opts' => '--ext .html' }
64 it
'returns correct number of errors' do
65 expect(run
.count
).to eql
5
70 'with different eslint executable',
71 config
: { 'eslint_executable' => './custom_eslint.sh' }
73 it
'calls the custom eslint eslint_executable' do
74 expect
{ run
}.to
raise_error(JSON
::ParserError, /custom eslint called/)
79 context
'repo with ignored and not ignored file, each with three warnings' do
80 include_context
'eslintignore repo'
82 let(:patches) { repo
.diff('master') }
84 it
'returns correct number of errors' do
85 expect(run
.count
).to
eql(3)
88 it
'has correct first message' do
89 expect(run
.first
.msg
).to
eql("'HelloWorld' is defined but never used.")
94 describe
'#files_to_lint' do
95 subject(:files_to_lint) { eslint
.files_to_lint
}
97 it
'matches .js by default' do
98 expect(files_to_lint
).to
match('my_js.js')
101 it
'matches .es6 by default' do
102 expect(files_to_lint
).to
match('my_js.es6')
106 describe
'#eslint_executable' do
107 subject(:eslint_executable) { eslint
.eslint_executable
}
109 it
'is `eslint` by default' do
110 expect(eslint_executable
).to
eql('eslint')
114 'with different eslint executable config',
115 config
: { 'eslint_executable' => 'custom_eslint' }
119 expect(eslint_executable
).to
eql('custom_eslint')
124 describe
'#eslint_command_line' do
125 subject(:eslint_command_line) { eslint
.send(:eslint_command_line, path
) }
126 let(:path) { '/some/path.rb' }
128 it
'adds json output flag' do
129 expect(eslint_command_line
).to
include('-f json')
133 expect(eslint_command_line
).to
include(path
)
136 it
'starts with eslint executable' do
137 expect(eslint_command_line
).to
start_with(eslint
.eslint_executable
)
140 context
'with path that should be escaped' do
141 let(:path) { '/must be/$escaped' }
143 it
'escapes the path correctly' do
144 expect(eslint_command_line
).to
include('/must\\ be/\\$escaped')
147 it
'does not include unescaped path' do
148 expect(eslint_command_line
).not_to
include(path
)
153 'with some command line options',
154 config
: { 'cmd_line_opts' => '--my command --line opts' }
156 it
'includes the custom command line options' do
158 expect(eslint_command_line
).to
include('--my command --line opts')