-
Notifications
You must be signed in to change notification settings - Fork 51
WIP: run all tests button and context menus #191
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
import * as vscode from "vscode"; | ||
|
||
import { BaseNode } from "../basenode"; | ||
import { Test, Tests } from "../../types"; | ||
import { Test, Tests, pseudoAllTarget } from "../../types"; | ||
import { extensionRelative } from "../../utils"; | ||
import { IRunnableNode } from "./base"; | ||
|
||
export class TestRootNode extends BaseNode { | ||
function getTestCommand(isBenchmark: boolean): string { | ||
return isBenchmark ? "benchmark" : "test"; | ||
} | ||
|
||
export class TestRootNode extends BaseNode implements IRunnableNode { | ||
constructor( | ||
parentId: string, | ||
private readonly tests: Tests, | ||
private readonly isBenchmark: boolean, | ||
) { | ||
super(`${parentId}-${isBenchmark ? "benchmarks" : "tests"}`); | ||
super(`${parentId}-${getTestCommand(isBenchmark)}`); | ||
} | ||
|
||
override getTreeItem() { | ||
|
@@ -21,39 +26,58 @@ export class TestRootNode extends BaseNode { | |
item.collapsibleState = | ||
this.tests.length === 0 ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed; | ||
|
||
// To key in to "when": "view == meson-project && viewItem == meson-test-root" in package.json. | ||
item.contextValue = "meson-test-root"; | ||
|
||
return item; | ||
} | ||
|
||
override getChildren() { | ||
return this.tests.map((test) => new TestNode(this.id, test, this.isBenchmark)); | ||
} | ||
|
||
run() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a return type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can do, though it's from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, the gain is explicit return types. Helps when reading code. Everyone has different preferences though. |
||
return vscode.commands.executeCommand(`mesonbuild.${getTestCommand(this.isBenchmark)}`, pseudoAllTarget); | ||
} | ||
} | ||
|
||
class TestNode extends BaseNode { | ||
class TestNode extends BaseNode implements IRunnableNode { | ||
private readonly taskName: string; | ||
private readonly command: string; | ||
|
||
constructor( | ||
parentId: string, | ||
private readonly test: Test, | ||
private readonly isBenchmark: boolean, | ||
) { | ||
super(`${parentId}-${test.suite[0]}-${test.name}`); | ||
|
||
this.command = getTestCommand(this.isBenchmark); | ||
const project = this.test.suite[0].split(":")[0]; | ||
this.taskName = `${project}:${this.test.name}`; | ||
} | ||
|
||
override getTreeItem() { | ||
const item = super.getTreeItem() as vscode.TreeItem; | ||
const project = this.test.suite[0].split(":")[0]; | ||
const name = `${project}:${this.test.name}`; | ||
|
||
item.label = this.test.name; | ||
item.iconPath = extensionRelative("res/meson_32.svg"); | ||
item.command = { | ||
title: `Run ${this.isBenchmark ? "benchmark" : "test"}`, | ||
command: `mesonbuild.${this.isBenchmark ? "benchmark" : "test"}`, | ||
arguments: [name], | ||
title: `Run ${this.command}`, | ||
command: `mesonbuild.${this.command}`, | ||
arguments: [this.taskName], | ||
}; | ||
|
||
// No children currently, so don't display toggle. | ||
item.collapsibleState = vscode.TreeItemCollapsibleState.None; | ||
|
||
// To key in to "when": "view == meson-project && viewItem == meson-test" in package.json. | ||
item.contextValue = "meson-test"; | ||
|
||
return item; | ||
} | ||
|
||
run() { | ||
return vscode.commands.executeCommand(`mesonbuild.${this.command}`, this.taskName); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.