forked from vim-test/vim-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.vim
More file actions
30 lines (24 loc) · 854 Bytes
/
javascript.vim
File metadata and controls
30 lines (24 loc) · 854 Bytes
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
let test#javascript#patterns = {
\ 'whole_match': 1,
\ 'test': ['\v^\s*%(it|test|describe.each)[^''"`]*([''"`])\zs%(.{-}%(\\\1)?){-}\ze\1'],
\ 'namespace': ['\v^\s*%(describe|suite|context|module)\s*[^''"`]*([''"`])\zs%(.{-}%(\\\1)?){-}\ze\1']
\}
function! test#javascript#has_package(package) abort
if !filereadable('package.json')
return 0
endif
let l:packages = readfile('package.json')
if exists('*json_decode')
let l:dict = json_decode(join(packages, ''))
return has_key(get(dict, 'dependencies', {}), a:package) || has_key(get(dict, 'devDependencies', {}), a:package)
endif
for line in packages
if line =~ '"'.a:package.'"'
return 1
endif
endfor
return 0
endfunction
function! test#javascript#has_import(file, import) abort
return match(readfile(a:file), "^import.*" . a:import) != -1
endfunction