Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-explorer.run-file command does not seem to work with Vim normal mode keybinding #221

Open
mnylen opened this issue Jul 31, 2021 · 1 comment

Comments

@mnylen
Copy link

mnylen commented Jul 31, 2021

I have vscodevim extension installed and have mapped the test-explorer.run-file command in normal mode to <leader>m:

  "vim.normalModeKeyBindings": [
    {
      "before": ["<Leader>", "m"],
      "commands": ["test-explorer.run-file"]
    }
  ],

(I've also tried vim.normalModeKeyBindingsNonRecursive)

The command seems to get executed when using <leader>m (at the bottom status bar I see it running test-explorer.run-file), but then nothing happens. No tests get run. This only happens when triggering via the Vim key binding, as using the "Test Explorer: Run tests in current file" straight from command palette does not have this issue.

Triggering other commands like "test-explorer.run-all" and "test-explorer.run-test-at-cursor" do seem to work via Vim keybindings, so I'm wondering if there's something special about the run-file command that makes it incompatible with the way Vim keybindings work.

Any ideas?

EDIT: "Solved it". I did some further digging and it seems like the fileUri is passed as empty string to utils.runTestsInFile when run using the vim keybinding. Don't yet know why this happens, but as there is already a fallback to vscode.window.activeTextEditor.document.uri.toString() when fileUri is not defined, a quick fix for this issue is to change the condition to also check for fileUri being empty, e.g.:

export function runTestsInFile(fileUri: string | undefined, testExplorer: TestExplorer): void {

	if ((!fileUri || fileUri.length === 0) && vscode.window.activeTextEditor) {
		fileUri = vscode.window.activeTextEditor.document.uri.toString();
	}
        // --snip --
}

Modifying the code in this way seems to fix the issue of the tests not running.

EDIT 2: It seems like there's another undocumented command test-explorer.run-this-file. Using this command in place of the test-explorer.run-file without the modifications above seems to work out-of-the-box. The only difference between these seems to be in the registration: (in main.ts)

        registerCommand('test-explorer.run-file', (file?: string) => runTestsInFile(file, testExplorer));
	registerCommand('test-explorer.run-this-file', (fileUri: vscode.Uri) => runTestsInFile(fileUri.toString(), testExplorer));

I'm not sure what the difference for these two commands is intended to be, but it seems run-this-file is the right one, as triggering the action from command palette also triggers the run-this-file command. So maybe this could be as easy fix as changing the documentation to refer to test-explorer.run-this-file instead of test-explorer.run-file?

@hbenl
Copy link
Owner

hbenl commented Aug 8, 2021

a quick fix for this issue is to change the condition to also check for fileUri being empty

That's strange, this change shouldn't make any difference since the empty string is considered falsy by javascript, i.e. if fileUri is "" then !fileUri is true.

I'm not sure what the difference for these two commands is intended to be

test-explorer.run-this-file is added to the editor's context menu if testExplorer.addToEditorContextMenu is set to true. When the command is called from the context menu, its first argument is set to a vscode.Uri instead of a string, that's why I created a separate command for that.

I documented the commands for use in keybindings, assuming that they would be called without any arguments in that case. I'm a bit surprised that vscodevim calls them with an argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants