 
   (when (get-buffer "*mocha tests*")
     (kill-buffer "*mocha tests*"))
-  (let ((test-command-to-run (mocha-generate-command mocha-file test)) (root-dir (mocha-find-project-root)))
+  (let ((test-command-to-run (mocha-generate-command nil mocha-file test)) (root-dir (mocha-find-project-root)))
     (with-current-buffer (get-buffer-create "*mocha tests*")
       (setq default-directory root-dir)
       (compilation-start test-command-to-run 'mocha-compilation-mode (lambda (m) (buffer-name))))))

      (setq i (+ i 1)))
    dir))

(defun mocha-generate-command (&optional mocha-file test)
  "The test command to run.

If MOCHA-FILE is specified run just that file otherwise run
MOCHA-PROJECT-TEST-DIRECTORY

IF TEST is specified run mocha with a grep for just that test."
  (let ((path (or mocha-file mocha-project-test-directory))
        (target (if test (concat "--grep \"" test "\" ") "")))
    (concat mocha-environment-variables " "
            mocha-which-node " "
            mocha-command " "
            mocha-options " "
            target
            path)))

(defun mocha-run (&optional mocha-file test)
  "Run mocha in a compilation buffer.

  (let ((file (buffer-file-name)) (test-at-point (mocha-find-current-test)))
    (mocha-run file test-at-point)))

;;;###autoload
(defun mocha-debug-project ()
  "Debug the current project."
  (interactive)
  (mocha-debug))

;;;###autoload
(defun mocha-debug-file ()
  "Debug the current file."
  (interactive)
  (mocha-debug (buffer-file-name)))

;;;###autoload
(defun mocha-debug-at-point ()
  "Debug the current innermost 'it' or 'describe' or the file if none is found."
  (interactive)
  (let ((file (buffer-file-name)) (test-at-point (mocha-find-current-test)))
    (mocha-debug file test-at-point)))

(provide 'mocha)
;;; mocha.el ends here
