-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.vim
More file actions
108 lines (85 loc) · 2.53 KB
/
javascript.vim
File metadata and controls
108 lines (85 loc) · 2.53 KB
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
101
102
103
104
105
106
107
108
if exists("g:loaded_vimux_javascript_test") || &cp
finish
endif
let g:loaded_vimux_javascript_test = 1
if !has("ruby")
finish
end
command RunAllJasmineTests :call s:RunAllJasmineTests()
command RunFocusedJasmineTest :call s:RunFocusedJasmineTest()
function s:RunAllJasmineTests()
ruby Jasmine.new.run_all
endfunction
function s:RunFocusedJasmineTest()
ruby Jasmine.new.run_spec
endfunction
ruby << EOF
module VIM
class Buffer
def method_missing(method, *args, &block)
VIM.command "#{method} #{self.name}"
end
end
end
require 'uri'
class Jasmine
def current_file
"http://localhost:8888/?&rand_#{Time.now.to_i}=1"
end
def current_line_number
VIM::Buffer.current.line_number
end
def focussed_spec_name
nested_describe = ''
it_name = ''
it_indent_level = 999
last_describe_indent_level = 999
seen_describe = false
(current_line_number).downto(1) do |line_number|
if it_name.empty? &&
!seen_describe &&
(VIM::Buffer.current[line_number] =~ /(.*)(?:it)\("([^"]+)"/ ||
VIM::Buffer.current[line_number] =~ /(.*)(?:it)\('([^']+)'/)
it_indent_level = $1.length
it_name = $2
end
if VIM::Buffer.current[line_number] =~ /(.*)(?:describe)\("([^"]+)"/ ||
VIM::Buffer.current[line_number] =~ /(.*)(?:describe)\('([^']+)'/
seen_describe = true
current_describe_indent_level = $1.length
if current_describe_indent_level < last_describe_indent_level &&
current_describe_indent_level < it_indent_level
nested_describe = nested_describe.empty? ? $2 : "#{$2} #{nested_describe}"
last_describe_indent_level = current_describe_indent_level
end
end
end
spec_name = nested_describe
spec_name += " #{it_name}" unless it_name.empty?
URI.escape(spec_name)
end
def file_spec_name
describe_name = ''
1.upto(current_line_number + 1) do |line_number|
if VIM::Buffer.current[line_number] =~ /(?:describe)\("([^"]+)"/ ||
VIM::Buffer.current[line_number] =~ /(?:describe)\('([^']+)'/
describe_name = $1
break
end
end
URI.escape(describe_name)
end
def run_spec
send_to_vimux("#{test_command} '#{current_file}&spec=#{focussed_spec_name}'")
end
def run_all
send_to_vimux("#{test_command} '#{current_file}&spec=#{file_spec_name}'")
end
def test_command
"open -a 'Google Chrome'"
end
def send_to_vimux(test_command)
Vim.command("call RunVimTmuxCommand(\"clear && #{test_command}\")")
end
end
EOF