Emacs: projectile-toggle-between-implementation-and-test for TypeScript spec file discovery

432 Views Asked by At

I really enjoyed using this projectile function in other languages but I'm currently having a hard time trying to figure out a way to set it for a typical TypeScript project.

ls services/
foo.service.ts foo.service.spec.ts bar.ts bar.spec.ts

When I execute projectile-toggle-between-implementation-and-test in any of these 4 files I get the following error:

helm-M-x-execute-command: No matching test file found for project type ‘npm’

In other words, the rule is try to find a file in the same directory with/without *.spec.ts* suffix

1

There are 1 best solutions below

1
On

Turns out it is pretty simple. You need to evaluate the following snippet(notice the npm project-type):

(defun projectile-test-suffix (project-type)
  "Find default test files suffix based on PROJECT-TYPE."
  (cond
   ((member project-type '(emacs-cask)) "-test")
   ((member project-type '(rails-rspec ruby-rspec)) "_spec")
   ((member project-type '(rails-test ruby-test lein-test boot-clj go)) "_test")
   ((member project-type '(scons)) "test")
   ((member project-type '(npm)) ".spec")
   ((member project-type '(maven symfony)) "Test")
   ((member project-type '(gradle gradlew grails)) "Spec")))