Switch between a file and its unit test:
On MacOS, press Shift+Cmd+Y
.
On Windows / Linux, press Shift+Ctrl+Y
.
The following formats are supported:
framework | application file | unit test file |
---|---|---|
all | *.* |
*.test.* |
JavaScript / TypeScript | *.* |
__tests__/*.test.* |
JavaScript / TypeScript | *.* |
test/*.test.* |
JavaScript / TypeScript | *.* |
test/suite/*.test.* |
JavaScript / TypeScript | *.* |
*.stories.* |
Python | *.py |
test/test_*.py |
Python | src/*/*.py |
test/*/test_*.py |
Go | *.go |
*_test.go |
Ruby on Rails 1-5 | app/*/*.rb |
spec/*/*_spec.rb |
Ruby on Rails 6+ | app/*/*.rb |
test/*/*_test.rb |
Ruby minitest | app/*.rb |
test/unit/*_test.rb |
Ruby minitest | app/controllers/*.rb |
test/integration/*.rb |
You can add your own formats by editing test-switcher.rules
.
Here's what it would look like to add Ruby on Rails support:
"test-switcher.rules": [
{ "pattern": "app/(.*)\\.rb", "replacement": "spec/$1_spec.rb" },
{ "pattern": "spec/(.*)_spec\\.rb", "replacement": "app/$1.rb" },
]
Effectively, this extension runs path.replace(new RegExp(pattern), replacement)
. If the source file matches the regex the replaced filename exists, you'll switch to that file. Otherwise, it will try the next rule.
See CHANGELOG.md.