summaryrefslogtreecommitdiff
path: root/test/test_eslint_executable_detection.vader
blob: 3fed63da7b2df275a555bc2756bda6b8cf9707ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Before:
  let g:ale_javascript_eslint_executable = 'eslint_d'

  call ale#test#SetDirectory('/testplugin/test')

  runtime ale_linters/javascript/eslint.vim

After:
  let g:ale_javascript_eslint_executable = 'eslint'
  let g:ale_javascript_eslint_use_global = 0

  call ale#test#RestoreDirectory()
  call ale#linter#Reset()

Execute(create-react-app directories should be detected correctly):
  call ale#test#SetFilename('eslint-test-files/react-app/subdir/testfile.js')

  AssertEqual
  \ ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'),
  \ ale#handlers#eslint#GetExecutable(bufnr(''))

Execute(use-global should override create-react-app detection):
  let g:ale_javascript_eslint_use_global = 1

  call ale#test#SetFilename('eslint-test-files/react-app/subdir/testfile.js')

  AssertEqual
  \ 'eslint_d',
  \ ale#handlers#eslint#GetExecutable(bufnr(''))

Execute(other app directories should be detected correctly):
  call ale#test#SetFilename('eslint-test-files/other-app/subdir/testfile.js')

  AssertEqual
  \ ale#path#Simplify(g:dir . '/eslint-test-files/node_modules/.bin/eslint'),
  \ ale#handlers#eslint#GetExecutable(bufnr(''))

Execute(use-global should override other app directories):
  let g:ale_javascript_eslint_use_global = 1

  call ale#test#SetFilename('eslint-test-files/other-app/subdir/testfile.js')

  AssertEqual
  \ 'eslint_d',
  \ ale#handlers#eslint#GetExecutable(bufnr(''))

Execute(eslint_d should be detected correctly):
  call ale#test#SetFilename('eslint-test-files/app-with-eslint-d/testfile.js')

  AssertEqual
  \ ale#path#Simplify(g:dir . '/eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d'),
  \ ale#handlers#eslint#GetExecutable(bufnr(''))

Execute(eslint.js executables should be run with node on Windows):
  call ale#test#SetFilename('eslint-test-files/react-app/subdir/testfile.js')

  " We have to execute the file with node.
  if has('win32')
    AssertEqual
    \ ale#path#CdString(ale#path#Simplify(g:dir . '/eslint-test-files/react-app'))
    \   . ale#Escape('node.exe') . ' '
    \   . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
    \   . ' -f json --stdin --stdin-filename %s',
    \ ale#handlers#eslint#GetCommand(bufnr(''))
  else
    AssertEqual
    \ ale#path#CdString(ale#path#Simplify(g:dir . '/eslint-test-files/react-app'))
    \   . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
    \   . ' -f json --stdin --stdin-filename %s',
    \ ale#handlers#eslint#GetCommand(bufnr(''))
  endif

Execute(eslint.js should be run from containing project with eslint):
  call ale#test#SetFilename('eslint-test-files/react-app/subdir-with-package-json/testfile.js')

  " We have to execute the file with node.
  if has('win32')
    AssertEqual
    \ ale#path#CdString(ale#path#Simplify(g:dir . '/eslint-test-files/react-app'))
    \   . ale#Escape('node.exe') . ' '
    \   . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
    \   . ' -f json --stdin --stdin-filename %s',
    \ ale#handlers#eslint#GetCommand(bufnr(''))
  else
    AssertEqual
    \ ale#path#CdString(ale#path#Simplify(g:dir . '/eslint-test-files/react-app'))
    \   . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js'))
    \   . ' -f json --stdin --stdin-filename %s',
    \ ale#handlers#eslint#GetCommand(bufnr(''))
  endif

Execute(eslint.js executables can be run outside project dir):
  " Set filename above eslint-test-files (which contains node_modules)
  call ale#test#SetFilename('testfile.js')

  " cd "..." not present, since project root not found (from node_modules)
  AssertEqual
  \ ale#Escape(ale#handlers#eslint#GetExecutable(bufnr('')))
  \   . ' -f json --stdin --stdin-filename %s',
  \ ale#handlers#eslint#GetCommand(bufnr(''))