Mix test feature: shortcut to run last tests?

some context, I’m running helix+tmux and have some shortcuts to run my tests. I’ve configured some shortcuts like: run line, run file, run all, run stale, run failed tests.

I’d like to be able to have a shortcut: run lasts ran tests. Whatever they were.
The reason is that for example: run tests on a line only works when I’m on that line of the tests.
Let’s say there is a bug, I’m trying to fix the test and I want to run the test again. Now I need to jump back to the testfile. A lot quicker would be: run that last test again.

Does anyone have an idea if this would be possible?

1 Like

How do you “run line”? If it somehow extracts file path and a line number to run

mix test <file_path>:<line_number>

Then perhaps we could come up with a command that takes the previous command from $history or the previous one that starts with “mix test” (from zsh or bash history or whatever shell is used)?

1 Like

That’s a great idea. Smacking myself in the forehead that I haven’t thought about that.
Will play around about with this until I have something working and will report back here.

As mentioned, this is more a shell or editor concern. If you use vim/nvim there is test.vim which does this. I imagine there are similar plugins for other editors since test.vim has been around for a very long time and it’s friggin’ awesome.

This is the command that I came up with: eval (atuin search --limit 1 --format "{command}" r/^mix test/)

I’m using https://atuin.sh/ and fish shell. So if you want to do something similar you probably will need to change it.

1 Like