]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/fixers/test_eslint_fixer_callback.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / fixers / test_eslint_fixer_callback.vader
1 Before:
2   call ale#assert#SetUpFixerTest('javascript', 'eslint')
3   Save g:ale_command_wrapper
4
5   runtime autoload/ale/handlers/eslint.vim
6
7   let g:ale_command_wrapper = ''
8
9 After:
10   call ale#assert#TearDownFixerTest()
11
12 Execute(The executable path should be correct):
13   call ale#test#SetFilename('../test-files/eslint/react-app/subdir/testfile.js')
14
15   " eslint_d output with an older eslint version is used here.
16   GivenCommandOutput ['v4.4.1 (eslint_d v5.1.0)']
17   AssertFixer
18   \ {
19   \   'read_temporary_file': 1,
20   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'),
21   \   'command': (has('win32') ? 'node.exe ' : '')
22   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
23   \     . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/.eslintrc.js'))
24   \     . ' --fix %t',
25   \ }
26
27 Execute(The ESLint fixer shouldn't run if no configuration file can be found):
28   call ale#test#SetFilename('../no-configuration')
29   AssertFixerNotExecuted
30
31 Execute(The ESLint fixer should use a config file option if set for old versions):
32   call ale#test#SetFilename('../no-configuration')
33   let b:ale_javascript_eslint_options = '-c /foo.cfg'
34
35   AssertFixer
36   \ {
37   \   'read_temporary_file': 1,
38   \   'cwd': '',
39   \   'command': ale#Escape('eslint') . ' -c /foo.cfg --fix %t',
40   \ }
41
42   let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
43
44   AssertFixer
45   \ {
46   \   'read_temporary_file': 1,
47   \   'cwd': '',
48   \   'command': ale#Escape('eslint') . ' --bar -c /foo.cfg --fix %t',
49   \ }
50
51   let b:ale_javascript_eslint_options = '--config /foo.cfg'
52
53   AssertFixer
54   \ {
55   \   'read_temporary_file': 1,
56   \   'cwd': '',
57   \   'command': ale#Escape('eslint') . ' --config /foo.cfg --fix %t',
58   \ }
59
60   let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
61
62   AssertFixer
63   \ {
64   \   'read_temporary_file': 1,
65   \   'cwd': '',
66   \   'command': ale#Escape('eslint') . ' --bar --config /foo.cfg --fix %t',
67   \ }
68
69 Execute(The ESLint fixer should use a -c file option if set for eslint_d):
70   let b:ale_javascript_eslint_executable = '/bin/eslint_d'
71   GivenCommandOutput ['v3.19.0 (eslint_d v4.2.0)']
72   call ale#test#SetFilename('../no-configuration')
73   let b:ale_javascript_eslint_options = '-c /foo.cfg'
74
75   AssertFixer
76   \ {
77   \   'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
78   \   'cwd': '',
79   \   'command': ale#Escape('/bin/eslint_d')
80   \     . ' -c /foo.cfg'
81   \     . ' --stdin-filename %s --stdin --fix-to-stdout'
82   \ }
83
84   let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
85
86   AssertFixer
87   \ {
88   \   'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
89   \   'cwd': '',
90   \   'command': ale#Escape('/bin/eslint_d')
91   \     . ' --bar -c /foo.cfg'
92   \     . ' --stdin-filename %s --stdin --fix-to-stdout'
93   \ }
94
95   let b:ale_javascript_eslint_options = '--config /foo.cfg'
96
97   AssertFixer
98   \ {
99   \   'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
100   \   'cwd': '',
101   \   'command': ale#Escape('/bin/eslint_d')
102   \     . ' --config /foo.cfg'
103   \     . ' --stdin-filename %s --stdin --fix-to-stdout'
104   \ }
105
106   let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
107
108   AssertFixer
109   \ {
110   \   'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
111   \   'cwd': '',
112   \   'command': ale#Escape('/bin/eslint_d')
113   \     . ' --bar --config /foo.cfg'
114   \     . ' --stdin-filename %s --stdin --fix-to-stdout'
115   \ }
116
117 Execute(The ESLint fixer should use a config file option if set for new versions):
118   GivenCommandOutput ['4.9.0']
119   call ale#test#SetFilename('../no-configuration')
120   let b:ale_javascript_eslint_options = '-c /foo.cfg'
121
122   AssertFixer
123   \ {
124   \   'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
125   \   'cwd': '',
126   \   'command': ale#Escape('eslint')
127   \     . ' -c /foo.cfg'
128   \     . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
129   \ }
130
131   let b:ale_javascript_eslint_options = '--bar -c /foo.cfg'
132
133   AssertFixer
134   \ {
135   \   'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
136   \   'cwd': '',
137   \   'command': ale#Escape('eslint')
138   \     . ' --bar -c /foo.cfg'
139   \     . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
140   \ }
141
142   let b:ale_javascript_eslint_options = '--config /foo.cfg'
143
144   AssertFixer
145   \ {
146   \   'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
147   \   'cwd': '',
148   \   'command': ale#Escape('eslint')
149   \     . ' --config /foo.cfg'
150   \     . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
151   \ }
152
153   let b:ale_javascript_eslint_options = '--bar --config /foo.cfg'
154
155   AssertFixer
156   \ {
157   \   'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
158   \   'cwd': '',
159   \   'command': ale#Escape('eslint')
160   \     . ' --bar --config /foo.cfg'
161   \     . ' --stdin-filename %s --stdin --fix-dry-run --format=json'
162   \ }
163
164 Execute(The lower priority configuration file in a nested directory should be preferred):
165   call ale#test#SetFilename('../test-files/eslint/react-app/subdir-with-config/testfile.js')
166
167   AssertFixer
168   \ {
169   \   'read_temporary_file': 1,
170   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'),
171   \   'command': (has('win32') ? 'node.exe ' : '')
172   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
173   \     . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config/.eslintrc'))
174   \     . ' --fix %t',
175   \ }
176
177 Execute(--config in options should override configuration file detection for old versions):
178   call ale#test#SetFilename('../test-files/eslint/react-app/subdir-with-config/testfile.js')
179
180   let b:ale_javascript_eslint_options = '--config /foo.cfg'
181
182   AssertFixer
183   \ {
184   \   'read_temporary_file': 1,
185   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'),
186   \   'command': (has('win32') ? 'node.exe ' : '')
187   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
188   \     . ' --config /foo.cfg'
189   \     . ' --fix %t',
190   \ }
191
192   let b:ale_javascript_eslint_options = '-c /foo.cfg'
193
194   AssertFixer
195   \ {
196   \   'read_temporary_file': 1,
197   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'),
198   \   'command': (has('win32') ? 'node.exe ' : '')
199   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
200   \     . ' -c /foo.cfg'
201   \     . ' --fix %t',
202   \ }
203
204 Execute(package.json should be used as a last resort):
205   call ale#test#SetFilename('../test-files/eslint/react-app/subdir-with-package-json/testfile.js')
206
207   AssertFixer
208   \ {
209   \   'read_temporary_file': 1,
210   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'),
211   \   'command': (has('win32') ? 'node.exe ' : '')
212   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
213   \     . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/.eslintrc.js'))
214   \     . ' --fix %t',
215   \ }
216
217   call ale#test#SetFilename('../test-files/eslint/package.json')
218
219   AssertFixer
220   \ {
221   \   'read_temporary_file': 1,
222   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint'),
223   \   'command': ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/node_modules/.bin/eslint'))
224   \     . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/package.json'))
225   \     . ' --fix %t',
226   \ }
227
228 Execute(The version check should be correct):
229   call ale#test#SetFilename('../test-files/eslint/react-app/subdir-with-config/testfile.js')
230
231   " We should run the command to get the version the first time.
232   GivenCommandOutput ['4.9.0']
233   AssertFixer [
234   \ (has('win32') ? 'node.exe ' : '')
235   \   . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
236   \   . ' --version',
237   \ {
238   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'),
239   \   'command': (has('win32') ? 'node.exe ' : '')
240   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
241   \     . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
242   \   'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
243   \ },
244   \]
245
246   AssertFixer [
247   \ {
248   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/subdir-with-config'),
249   \   'command': (has('win32') ? 'node.exe ' : '')
250   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
251   \     . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
252   \   'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
253   \ },
254   \]
255
256 Execute(--fix-dry-run should be used for 4.9.0 and up):
257   call ale#test#SetFilename('../test-files/eslint/react-app/subdir/testfile.js')
258
259   GivenCommandOutput ['4.9.0']
260   AssertFixer
261   \ {
262   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/react-app'),
263   \   'command': (has('win32') ? 'node.exe ' : '')
264   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/react-app/node_modules/eslint/bin/eslint.js'))
265   \     . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
266   \   'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
267   \ }
268
269 Execute(The --fix-dry-run post-processor should handle JSON output correctly):
270   AssertEqual
271   \ [],
272   \ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), [])
273   AssertEqual
274   \ [],
275   \ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), [''])
276   AssertEqual
277   \ [],
278   \ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), ['[{}]'])
279   AssertEqual
280   \ ['foo', 'bar'],
281   \ ale#fixers#eslint#ProcessFixDryRunOutput(bufnr(''), ['[{"output": "foo\nbar"}]'])
282
283 Execute(The eslint_d post-processor should permit regular JavaScript content):
284   AssertEqual
285   \ [
286   \   'const x = ''Error: foo''',
287   \   'const y = 3',
288   \ ],
289   \ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
290   \   'const x = ''Error: foo''',
291   \   'const y = 3',
292   \ ])
293
294 Execute(The eslint_d post-processor should handle error messages correctly):
295   AssertEqual
296   \ [],
297   \ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
298   \   'Error: No ESLint configuration found.',
299   \ ])
300
301 Execute(The eslint_d post-processor should handle failing to connect properly):
302   AssertEqual
303   \ [],
304   \ ale#fixers#eslint#ProcessEslintDOutput(bufnr(''), [
305   \   'Could not connect',
306   \ ])
307
308 Execute(The executable path should be correct for astro app):
309   call ale#test#SetFilename('../test-files/eslint/astro-app/src/pages/index.astro')
310
311   " eslint_d output with an older eslint version is used here.
312   GivenCommandOutput ['v4.4.1 (eslint_d v5.1.0)']
313   AssertFixer
314   \ {
315   \   'read_temporary_file': 1,
316   \   'cwd': ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app'),
317   \   'command': (has('win32') ? 'node.exe ' : '')
318   \     . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app/node_modules/eslint/bin/eslint.js'))
319   \     . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../test-files/eslint/astro-app/.eslintrc.js'))
320   \     . ' --fix %t',
321   \ }