Skip to content

Commit 3fbc4c1

Browse files
authored
Merge pull request #3 from spinlock99/mocha-debug
Mocha debug
2 parents 0a15959 + 023e21a commit 3fbc4c1

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

plugin/spec.vim

+30-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ function! s:SetJavascriptCommand()
2121
endif
2222
endfunction
2323

24+
" Set Javascript Debug
25+
function! s:SetJavascriptDebugCommand()
26+
if !exists("g:mocha_debug_command")
27+
let s:cmd = "mocha debug {spec}"
28+
call s:GUIRunning()
29+
else
30+
let g:spec_command = g:mocha_debug_command
31+
endif
32+
endfunction
33+
2434
" Set Coffeescript
2535
function! s:SetCoffeescriptCommand()
2636
if !exists("g:mocha_coffee_command")
@@ -39,6 +49,10 @@ function! s:SetInitialSpecCommand()
3949
call s:SetRubyCommand()
4050
elseif l:filetype =~ 'js'
4151
call s:SetJavascriptCommand()
52+
elseif l:filetype =~ 'tsx'
53+
call s:SetJavascriptCommand()
54+
elseif l:filetype =~ 'ts'
55+
call s:SetJavascriptCommand()
4256
elseif l:filetype =~ 'coffee'
4357
call s:SetCoffeescriptCommand()
4458
else
@@ -47,13 +61,18 @@ function! s:SetInitialSpecCommand()
4761
endfunction
4862

4963
" Determine which command based on filetype
50-
function! s:GetCorrectCommand()
64+
function! s:GetCorrectCommand(debug)
5165
" Set default {rspec} command (ruby/rails)
5266
if &filetype ==? 'ruby'
5367
call s:SetRubyCommand()
54-
" Set default {mocha} command (javascript)
55-
elseif &filetype ==? 'javascript'
56-
call s:SetJavascriptCommand()
68+
" Set default {mocha} command (javascript)
69+
elseif &filetype ==? 'javascript' || &filetype ==? 'typescript.tsx' || &filetype ==? 'typescript'
70+
" set debug command here
71+
if a:debug
72+
call s:SetJavascriptDebugCommand()
73+
else
74+
call s:SetJavascriptCommand()
75+
endif
5776
" Set default {mocha} command (coffeescript)
5877
elseif &filetype ==? 'coffee'
5978
call s:SetCoffeescriptCommand()
@@ -106,29 +125,29 @@ function! RunAllSpecs()
106125
else
107126
let l:spec = ""
108127
endif
109-
call RunSpecs(l:spec)
128+
call RunSpecs(l:spec, 0)
110129
endfunction
111130

112131
" Current File
113132
function! RunCurrentSpecFile()
114133
if InSpecFile()
115134
let l:spec = @%
116-
call RunSpecs(l:spec)
135+
call RunSpecs(l:spec, 0)
117136
else
118137
call RunLastSpec()
119138
endif
120139
endfunction
121140

122141
" Nearest Spec
123-
function! RunNearestSpec()
142+
function! RunNearestSpec(debug)
124143
if InSpecFile()
125144
if &filetype ==? "ruby"
126145
let l:spec = @% . ":" . line(".")
127146
else
128147
call s:GetNearestTest()
129148
let l:spec = @% . " -g '" . s:nearestTest . "'"
130149
end
131-
call RunSpecs(l:spec)
150+
call RunSpecs(l:spec, a:debug)
132151
else
133152
call RunLastSpec()
134153
endif
@@ -143,7 +162,7 @@ endfunction
143162

144163
" Current Spec File Name
145164
function! InSpecFile()
146-
return match(expand("%"),'\v(.js|.coffee|_spec.rb|.feature)$') != -1
165+
return match(expand("%"),'\v(.tsx|.ts|.js|.coffee|_spec.rb|.feature)$') != -1
147166
endfunction
148167

149168
" Cache Last Spec Command
@@ -152,8 +171,8 @@ function! SetLastSpecCommand(spec)
152171
endfunction
153172

154173
" Spec Runner
155-
function! RunSpecs(spec)
156-
call s:GetCorrectCommand()
174+
function! RunSpecs(spec, debug)
175+
call s:GetCorrectCommand(a:debug)
157176
if g:spec_command ==? ""
158177
echom "No spec command specified."
159178
else

0 commit comments

Comments
 (0)