@@ -190,6 +190,29 @@ def js_format(file_list=None):
190
190
js_file_list )
191
191
192
192
193
+ def js_test (file_list = None ):
194
+ """
195
+ Run JavaScript unit tests on relevant files ONLY as part of pre-commit hook
196
+ """
197
+ project_root = os .path .join (os .path .dirname (__file__ ), os .pardir , os .pardir ,
198
+ os .pardir )
199
+ jest_path = os .path .join (project_root , 'node_modules' , '.bin' , 'jest' )
200
+
201
+ if not os .path .exists (jest_path ):
202
+ from click import echo
203
+ echo ('[sentry.test] Skipping JavaScript testing because jest is not installed.' )
204
+ return False
205
+
206
+ js_file_list = get_js_files (file_list )
207
+
208
+ has_errors = False
209
+ if js_file_list :
210
+ status = Popen ([jest_path , '--bail' , '--findRelatedTests' ] + js_file_list ).wait ()
211
+ has_errors = status != 0
212
+
213
+ return has_errors
214
+
215
+
193
216
def py_format (file_list = None ):
194
217
try :
195
218
__import__ ('autopep8' )
@@ -237,7 +260,7 @@ def run_formatter(cmd, file_list, prompt_on_changes=True):
237
260
return has_errors
238
261
239
262
240
- def run (file_list = None , format = True , lint = True , js = True , py = True , yarn = True ):
263
+ def run (file_list = None , format = True , lint = True , js = True , py = True , yarn = True , test = False ):
241
264
# pep8.py uses sys.argv to find setup.cfg
242
265
old_sysargv = sys .argv
243
266
@@ -272,6 +295,10 @@ def run(file_list=None, format=True, lint=True, js=True, py=True, yarn=True):
272
295
if js :
273
296
results .append (js_lint (file_list ))
274
297
298
+ if test :
299
+ if js :
300
+ results .append (js_test (file_list ))
301
+
275
302
if any (results ):
276
303
return 1
277
304
return 0
0 commit comments