Skip to content

feat(vscode): run mutation tests for a specific file directly from the Explorer or Editor context menu.#114

Open
jaspervdveen wants to merge 3 commits intomainfrom
feat/mutation-test-from-context-menu
Open

feat(vscode): run mutation tests for a specific file directly from the Explorer or Editor context menu.#114
jaspervdveen wants to merge 3 commits intomainfrom
feat/mutation-test-from-context-menu

Conversation

@jaspervdveen
Copy link
Member

@jaspervdveen jaspervdveen commented Feb 27, 2026

  • Run mutation tests for a specific file directly from the Explorer or Editor context menu.
  • Right-click any JavaScript/TypeScript file in the Explorer or on the editor tab to access the "Run Mutation Tests for File" command.

Closes #112

@jaspervdveen jaspervdveen changed the title feat(vscode): add run mutation tests for file menu option feat(vscode): run mutation tests for a specific file directly from the Explorer or Editor context menu. Feb 27, 2026
Copy link
Member

@nicojs nicojs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick look. Have you tried it inside the StrykerJS workspace?


private notify(level: string, message: string): void {
if (level === 'ERROR') {
void vscode.window.showErrorMessage(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're ignoring the resulting promise here. Can showXxxMessage never result in a rejection?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The promise resolves to undefined when the error message is dismissed, and since there is no need to wait for the dismissal here, I ignore the resulting promise. There is no error path documented that causes a rejected promise, so this should be fine.

import * as factory from '../factory.ts';

describe(TestRunner.name, () => {
let sandbox: sinon.SinonSandbox;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a sandbox is almost always unnessesary, as sinon itself is also a sandbox. You can simply use sinon.stub, etc instead of sandbox.stub and simply restore with sinon.restore()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good to know, I will change it.

{
"command": "strykerMutator.runMutationForFile",
"group": "strykerMutator",
"when": "resourceExtname =~ /\\.(js|jsx|ts|tsx|mjs|cjs|mts|cts)$/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the extensions be dynamic somehow?

Copy link
Member Author

@jaspervdveen jaspervdveen Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have explored this and I can use setContext to make this dynamic, but the setting key will always be window‑scoped, not resource‑scoped. So I can flip the context based on whether mutation testing is enabled (strykerMutator.enabled) and whether the file matches the watch pattern file extensions, but the result applies to the whole window rather than per workspace folder, so the added value is pretty minimal.

https://code.visualstudio.com/api/references/when-clause-contexts#check-a-setting-in-a-when-clause

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

Successfully merging this pull request may close these issues.

Add "Run Mutation Tests" context menu option for individual files

2 participants